зеркало из https://github.com/microsoft/lisa.git
Azure: refactoring code indent
This commit is contained in:
Родитель
d4bb0766b2
Коммит
887585a3d0
|
@ -365,149 +365,150 @@ class AzurePlatform(Platform):
|
||||||
3. check capability for each node by order of pattern.
|
3. check capability for each node by order of pattern.
|
||||||
4. get min capability for each match
|
4. get min capability for each match
|
||||||
"""
|
"""
|
||||||
is_success: bool = True
|
|
||||||
|
|
||||||
if environment.runbook.nodes_requirement:
|
if not environment.runbook.nodes_requirement:
|
||||||
is_success = False
|
return True
|
||||||
nodes_requirement = environment.runbook.nodes_requirement
|
|
||||||
node_count = len(nodes_requirement)
|
|
||||||
# fills predefined locations here.
|
|
||||||
predefined_caps: List[Any] = [None] * node_count
|
|
||||||
# make sure all vms are in same location.
|
|
||||||
predefined_cost: int = 0
|
|
||||||
|
|
||||||
for req in nodes_requirement:
|
is_success: bool = False
|
||||||
# covert to azure node space, so the azure extensions can be loaded.
|
nodes_requirement = environment.runbook.nodes_requirement
|
||||||
_convert_to_azure_node_space(req)
|
node_count = len(nodes_requirement)
|
||||||
|
# fills predefined locations here.
|
||||||
|
predefined_caps: List[Any] = [None] * node_count
|
||||||
|
# make sure all vms are in same location.
|
||||||
|
predefined_cost: int = 0
|
||||||
|
|
||||||
existing_location = _get_existing_location(nodes_requirement)
|
for req in nodes_requirement:
|
||||||
|
# covert to azure node space, so the azure extensions can be loaded.
|
||||||
|
_convert_to_azure_node_space(req)
|
||||||
|
|
||||||
if existing_location:
|
existing_location = _get_existing_location(nodes_requirement)
|
||||||
locations = [existing_location]
|
|
||||||
else:
|
|
||||||
locations = LOCATIONS
|
|
||||||
|
|
||||||
# check eligible locations
|
if existing_location:
|
||||||
found_or_skipped = False
|
locations = [existing_location]
|
||||||
for location_name in locations:
|
else:
|
||||||
predefined_cost = 0
|
locations = LOCATIONS
|
||||||
predefined_caps = [None] * node_count
|
|
||||||
for req_index, req in enumerate(nodes_requirement):
|
|
||||||
found_or_skipped = False
|
|
||||||
node_runbook = req.get_extended_runbook(AzureNodeSchema, AZURE)
|
|
||||||
if not node_runbook.vm_size:
|
|
||||||
# not to check, if no vm_size set
|
|
||||||
found_or_skipped = True
|
|
||||||
continue
|
|
||||||
|
|
||||||
# find predefined vm size on all available's.
|
# check eligible locations
|
||||||
location_info: AzureLocation = self._get_location_info(
|
found_or_skipped = False
|
||||||
location_name, log
|
for location_name in locations:
|
||||||
)
|
predefined_cost = 0
|
||||||
matched_score: float = 0
|
predefined_caps = [None] * node_count
|
||||||
matched_cap: Optional[AzureCapability] = None
|
for req_index, req in enumerate(nodes_requirement):
|
||||||
matcher = SequenceMatcher(None, node_runbook.vm_size.lower(), "")
|
found_or_skipped = False
|
||||||
for azure_cap in location_info.capabilities:
|
node_runbook = req.get_extended_runbook(AzureNodeSchema, AZURE)
|
||||||
matcher.set_seq2(azure_cap.vm_size.lower())
|
if not node_runbook.vm_size:
|
||||||
if (
|
# not to check, if no vm_size set
|
||||||
node_runbook.vm_size.lower() in azure_cap.vm_size.lower()
|
found_or_skipped = True
|
||||||
and matched_score < matcher.ratio()
|
|
||||||
):
|
|
||||||
matched_cap = azure_cap
|
|
||||||
matched_score = matcher.ratio()
|
|
||||||
if matched_cap:
|
|
||||||
# If max capability is set, use the max capability,
|
|
||||||
# instead of the real capability. It needs to be in the
|
|
||||||
# loop, to find supported locations.
|
|
||||||
if node_runbook.maximize_capability:
|
|
||||||
matched_cap = self._generate_max_capability(
|
|
||||||
node_runbook.vm_size, location_name
|
|
||||||
)
|
|
||||||
|
|
||||||
predefined_cost += matched_cap.estimated_cost
|
|
||||||
|
|
||||||
min_cap = self._generate_min_capability(
|
|
||||||
req, matched_cap, location_name
|
|
||||||
)
|
|
||||||
|
|
||||||
if not existing_location:
|
|
||||||
existing_location = location_name
|
|
||||||
predefined_caps[req_index] = min_cap
|
|
||||||
found_or_skipped = True
|
|
||||||
else:
|
|
||||||
# if not found any, skip and try next location
|
|
||||||
break
|
|
||||||
if found_or_skipped:
|
|
||||||
# if found all, skip other locations
|
|
||||||
break
|
|
||||||
if not found_or_skipped:
|
|
||||||
# no location/vm_size meets requirement, so generate mockup to
|
|
||||||
# continue to test. It applies to some preview vm_size may not
|
|
||||||
# be listed by API.
|
|
||||||
location = next((x for x in locations))
|
|
||||||
for req_index, req in enumerate(nodes_requirement):
|
|
||||||
if not node_runbook.vm_size or predefined_caps[req_index]:
|
|
||||||
continue
|
|
||||||
|
|
||||||
log.info(
|
|
||||||
f"Cannot find vm_size {node_runbook.vm_size} in {location}. "
|
|
||||||
f"Mockup capability to run tests."
|
|
||||||
)
|
|
||||||
mock_up_capability = self._generate_max_capability(
|
|
||||||
node_runbook.vm_size, location
|
|
||||||
)
|
|
||||||
min_cap = self._generate_min_capability(
|
|
||||||
req, mock_up_capability, location
|
|
||||||
)
|
|
||||||
predefined_caps[req_index] = min_cap
|
|
||||||
|
|
||||||
for location_name in locations:
|
|
||||||
# in each location, all node must be found
|
|
||||||
# fill them as None and check after met capability
|
|
||||||
found_capabilities: List[Any] = list(predefined_caps)
|
|
||||||
|
|
||||||
# skip unmatched location
|
|
||||||
if existing_location and existing_location != location_name:
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
estimated_cost: int = 0
|
# find predefined vm size on all available's.
|
||||||
location_caps = self.get_eligible_vm_sizes(location_name, log)
|
location_info: AzureLocation = self._get_location_info(
|
||||||
for req_index, req in enumerate(nodes_requirement):
|
location_name, log
|
||||||
for azure_cap in location_caps:
|
)
|
||||||
if found_capabilities[req_index]:
|
matched_score: float = 0
|
||||||
# found, so skipped
|
matched_cap: Optional[AzureCapability] = None
|
||||||
break
|
matcher = SequenceMatcher(None, node_runbook.vm_size.lower(), "")
|
||||||
check_result = req.check(azure_cap.capability)
|
for azure_cap in location_info.capabilities:
|
||||||
if check_result.result:
|
matcher.set_seq2(azure_cap.vm_size.lower())
|
||||||
min_cap = self._generate_min_capability(
|
if (
|
||||||
req, azure_cap, azure_cap.location
|
node_runbook.vm_size.lower() in azure_cap.vm_size.lower()
|
||||||
)
|
and matched_score < matcher.ratio()
|
||||||
|
):
|
||||||
|
matched_cap = azure_cap
|
||||||
|
matched_score = matcher.ratio()
|
||||||
|
if matched_cap:
|
||||||
|
# If max capability is set, use the max capability,
|
||||||
|
# instead of the real capability. It needs to be in the
|
||||||
|
# loop, to find supported locations.
|
||||||
|
if node_runbook.maximize_capability:
|
||||||
|
matched_cap = self._generate_max_capability(
|
||||||
|
node_runbook.vm_size, location_name
|
||||||
|
)
|
||||||
|
|
||||||
estimated_cost += azure_cap.estimated_cost
|
predefined_cost += matched_cap.estimated_cost
|
||||||
|
|
||||||
found_capabilities[req_index] = min_cap
|
min_cap = self._generate_min_capability(
|
||||||
if all(x for x in found_capabilities):
|
req, matched_cap, location_name
|
||||||
break
|
|
||||||
|
|
||||||
if all(x for x in found_capabilities):
|
|
||||||
# all found and replace current requirement
|
|
||||||
environment.runbook.nodes_requirement = found_capabilities
|
|
||||||
environment.cost = estimated_cost + predefined_cost
|
|
||||||
is_success = True
|
|
||||||
log.debug(
|
|
||||||
f"requirement meet, "
|
|
||||||
f"cost: {environment.cost}, "
|
|
||||||
f"cap: {environment.runbook.nodes_requirement}"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not existing_location:
|
||||||
|
existing_location = location_name
|
||||||
|
predefined_caps[req_index] = min_cap
|
||||||
|
found_or_skipped = True
|
||||||
|
else:
|
||||||
|
# if not found any, skip and try next location
|
||||||
|
break
|
||||||
|
if found_or_skipped:
|
||||||
|
# if found all, skip other locations
|
||||||
|
break
|
||||||
|
if not found_or_skipped:
|
||||||
|
# no location/vm_size meets requirement, so generate mockup to
|
||||||
|
# continue to test. It applies to some preview vm_size may not
|
||||||
|
# be listed by API.
|
||||||
|
location = next((x for x in locations))
|
||||||
|
for req_index, req in enumerate(nodes_requirement):
|
||||||
|
if not node_runbook.vm_size or predefined_caps[req_index]:
|
||||||
|
continue
|
||||||
|
|
||||||
|
log.info(
|
||||||
|
f"Cannot find vm_size {node_runbook.vm_size} in {location}. "
|
||||||
|
f"Mockup capability to run tests."
|
||||||
|
)
|
||||||
|
mock_up_capability = self._generate_max_capability(
|
||||||
|
node_runbook.vm_size, location
|
||||||
|
)
|
||||||
|
min_cap = self._generate_min_capability(
|
||||||
|
req, mock_up_capability, location
|
||||||
|
)
|
||||||
|
predefined_caps[req_index] = min_cap
|
||||||
|
|
||||||
|
for location_name in locations:
|
||||||
|
# in each location, all node must be found
|
||||||
|
# fill them as None and check after met capability
|
||||||
|
found_capabilities: List[Any] = list(predefined_caps)
|
||||||
|
|
||||||
|
# skip unmatched location
|
||||||
|
if existing_location and existing_location != location_name:
|
||||||
|
continue
|
||||||
|
|
||||||
|
estimated_cost: int = 0
|
||||||
|
location_caps = self.get_eligible_vm_sizes(location_name, log)
|
||||||
|
for req_index, req in enumerate(nodes_requirement):
|
||||||
|
for azure_cap in location_caps:
|
||||||
|
if found_capabilities[req_index]:
|
||||||
|
# found, so skipped
|
||||||
|
break
|
||||||
|
check_result = req.check(azure_cap.capability)
|
||||||
|
if check_result.result:
|
||||||
|
min_cap = self._generate_min_capability(
|
||||||
|
req, azure_cap, azure_cap.location
|
||||||
|
)
|
||||||
|
|
||||||
|
estimated_cost += azure_cap.estimated_cost
|
||||||
|
|
||||||
|
found_capabilities[req_index] = min_cap
|
||||||
|
if all(x for x in found_capabilities):
|
||||||
break
|
break
|
||||||
|
|
||||||
for req in nodes_requirement:
|
if all(x for x in found_capabilities):
|
||||||
node_runbook = req.get_extended_runbook(AzureNodeSchema, AZURE)
|
# all found and replace current requirement
|
||||||
if node_runbook.location and node_runbook.marketplace:
|
environment.runbook.nodes_requirement = found_capabilities
|
||||||
# resolve Latest to specified version
|
environment.cost = estimated_cost + predefined_cost
|
||||||
node_runbook.marketplace = self._parse_marketplace_image(
|
is_success = True
|
||||||
node_runbook.location, node_runbook.marketplace
|
log.debug(
|
||||||
)
|
f"requirement meet, "
|
||||||
|
f"cost: {environment.cost}, "
|
||||||
|
f"cap: {environment.runbook.nodes_requirement}"
|
||||||
|
)
|
||||||
|
break
|
||||||
|
|
||||||
|
for req in nodes_requirement:
|
||||||
|
node_runbook = req.get_extended_runbook(AzureNodeSchema, AZURE)
|
||||||
|
if node_runbook.location and node_runbook.marketplace:
|
||||||
|
# resolve Latest to specified version
|
||||||
|
node_runbook.marketplace = self._parse_marketplace_image(
|
||||||
|
node_runbook.location, node_runbook.marketplace
|
||||||
|
)
|
||||||
return is_success
|
return is_success
|
||||||
|
|
||||||
def _deploy_environment(self, environment: Environment, log: Logger) -> None:
|
def _deploy_environment(self, environment: Environment, log: Logger) -> None:
|
||||||
|
|
Загрузка…
Ссылка в новой задаче