Skip to content

Commit

Permalink
workaround api failures on loading environments
Browse files Browse the repository at this point in the history
  • Loading branch information
squirrelsc committed Oct 3, 2023
1 parent 9470d0a commit 71db906
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions lisa/sut_orchestrator/azure/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
)
from azure.keyvault.secrets import SecretClient
from azure.mgmt.compute import ComputeManagementClient
from azure.mgmt.compute.models import NetworkProfile, VirtualMachine
from azure.mgmt.compute.models import VirtualMachine
from azure.mgmt.keyvault import KeyVaultManagementClient
from azure.mgmt.keyvault.models import (
AccessPolicyEntry,
Expand Down Expand Up @@ -99,7 +99,6 @@
AZURE_VIRTUAL_NETWORK_NAME = "lisa-virtualNetwork"
AZURE_SUBNET_PREFIX = "lisa-subnet-"


NIC_NAME_PATTERN = re.compile(r"Microsoft.Network/networkInterfaces/(.*)", re.M)
PATTERN_PUBLIC_IP_NAME = re.compile(
r"providers/Microsoft.Network/publicIPAddresses/(.*)", re.M
Expand Down Expand Up @@ -1540,7 +1539,10 @@ def load_environment(
environment_runbook.nodes_raw = []

vms_map: Dict[str, VirtualMachine] = {}
compute_client = get_compute_client(platform)
# When lists VMs, it may raise unsupported api version error on "2022-08-01"
# in some subscriptions. This version should be safe for those
# subscriptions. Once the new version is supported, we can remove this.
compute_client = get_compute_client(platform, api_version="2022-03-01")
vms = compute_client.virtual_machines.list(resource_group_name)
for vm in vms:
node_schema = schema.RemoteNode(name=vm.name)
Expand Down Expand Up @@ -1615,9 +1617,8 @@ def get_primary_ip_addresses(
platform: "AzurePlatform", resource_group_name: str, vm: VirtualMachine
) -> Tuple[str, str]:
network_client = get_network_client(platform)
assert isinstance(
vm.network_profile, NetworkProfile
), f"actual: {type(vm.network_profile)}"

assert vm.network_profile, "no network profile found"
assert isinstance(
vm.network_profile.network_interfaces, List
), f"actual: {type(vm.network_profile.network_interfaces)}"
Expand Down
2 changes: 1 addition & 1 deletion lisa/sut_orchestrator/azure/platform_.py
Original file line number Diff line number Diff line change
Expand Up @@ -1584,7 +1584,7 @@ def _parse_detail_errors(self, error: Any) -> List[str]:
def _load_vms(
self, resource_group_name: str, log: Logger
) -> Dict[str, VirtualMachine]:
compute_client = get_compute_client(self, api_version="2020-06-01")
compute_client = get_compute_client(self)

log.debug(f"listing vm in resource group {resource_group_name}")
vms_map: Dict[str, VirtualMachine] = {}
Expand Down

0 comments on commit 71db906

Please sign in to comment.