Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SCVMM] Public Preview refresh using New Resource Model #6708

Merged
merged 19 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bug fix for get_resource_id
  • Loading branch information
nascarsayan committed Aug 20, 2023
commit 448ff04d508e6f77beddd15a19287ac2f01ae129
24 changes: 15 additions & 9 deletions src/scvmm/azext_scvmm/scvmm_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ def get_resource_id(
if name is None and not kwargs:
return None

removed_keys_from_parsed_resource_id = [
"last_child_num",
"resource_parent",
"resource_namespace",
"resource_type",
"resource_name",
]
selected_keys = {
"subscription", "resource_group", "namespace", "type", "name"
}
selected_key_prefixes = {
"child_type_",
"child_name_",
"child_namespace_",
}

def process_resource_name(
rid_parts: dict[str, str],
Expand All @@ -84,8 +85,13 @@ def process_resource_name(
rid_parts[resource_name_key] = resource_name
return
child_rid_parts = parse_resource_id(resource_name)
for key in removed_keys_from_parsed_resource_id:
child_rid_parts.pop(key, None)
child_rid_parts_keys = list(child_rid_parts.keys())
for key in child_rid_parts_keys:
if key in selected_keys:
continue
if any([key.startswith(prefix) for prefix in selected_key_prefixes]):
continue
child_rid_parts.pop(key)
child_set = {
k.lower(): v.lower() for k, v in child_rid_parts.items() if v is not None
}
Expand Down
27 changes: 27 additions & 0 deletions src/scvmm/azext_scvmm/scvmm_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,33 @@ def test_get_resource_id_with_intermediate_id_and_diff_sub_id(self):
assert result is not None
self.assertEqual(result.lower(), expected_result.lower())

def test_get_resource_id_with_multiple_id(self):
cmd = self._get_test_cmd()

inter_res_id = (
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/contoso-rg"
"/providers/Microsoft.HybridCompute/Machines/contoso-machine"
"/providers/Microsoft.ConnectedVMwarevSphere/VirtualMachineInstances/default"
)

res_id = f"{inter_res_id}/guestagents/default"

result = get_resource_id(
cmd,
"contoso-rg",
"Microsoft.HybridCompute",
"Machines",
None,
child_type_1="VirtualMachineInstances",
child_name_1=inter_res_id,
child_type_2="guestagents",
child_name_2=res_id,
)

expected_result = res_id
assert result is not None
self.assertEqual(result.lower(), expected_result.lower())

def test_get_resource_id_with_invalid_child_type(self):
cmd = self._get_test_cmd()

Expand Down