[ARM] Fix an issue where What-If shows two resource group scopes with different casing (#15631)

* Normalize resource scope casing

* Fix style issue
This commit is contained in:
Shenglong Li 2020-11-02 22:14:06 -08:00 коммит произвёл GitHub
Родитель b64a1e8e3b
Коммит 1ad8b2b178
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 12 добавлений и 6 удалений

Просмотреть файл

@ -148,14 +148,16 @@ def _format_resource_changes(builder, resource_changes):
if not resource_changes:
return
num_scopes = len(set(map(_get_scope, resource_changes)))
resource_changes_by_scope = groupby(sorted(resource_changes, key=_get_scope), _get_scope)
num_scopes = len(set(map(_get_scope_uppercase, resource_changes)))
resource_changes_by_scope = groupby(sorted(resource_changes, key=_get_scope_uppercase), _get_scope_uppercase)
builder.append_line()
builder.append_line(f"The deployment will update the following {'scope:' if num_scopes == 1 else 'scopes'}")
for scope, resource_changes_in_scope in resource_changes_by_scope:
_format_resource_changes_in_scope(builder, scope, resource_changes_in_scope)
for _, resource_changes_in_scope in resource_changes_by_scope:
resource_changes_in_scope_list = list(resource_changes_in_scope)
scope = _get_scope(resource_changes_in_scope_list[0])
_format_resource_changes_in_scope(builder, scope, resource_changes_in_scope_list)
def _format_resource_changes_in_scope(builder, scope, resource_changes_in_scope):
@ -361,6 +363,10 @@ def _get_scope(resource_change):
return scope
def _get_scope_uppercase(resource_change):
return _get_scope(resource_change).upper()
def _get_relative_resource_id(resource_change):
_, relative_resource_id = split_resource_id(resource_change.resource_id)
return relative_resource_id

Просмотреть файл

@ -188,7 +188,7 @@ class TestFormatWhatIfOperationResult(unittest.TestCase):
def test_group_resources_changes_by_sorted_scope(self):
changes = [
WhatIfChange(
resource_id="/subscriptions/00000000-0000-0000-0000-000000000001/resourceGroups/rg1/providers/p1/foo1",
resource_id="/subscriptions/00000000-0000-0000-0000-000000000001/resourceGroups/RG1/providers/p1/foo1",
change_type=ChangeType.create,
),
WhatIfChange(
@ -214,7 +214,7 @@ class TestFormatWhatIfOperationResult(unittest.TestCase):
]
expected = f"""
Scope: /subscriptions/00000000-0000-0000-0000-000000000001/resourceGroups/rg1
Scope: /subscriptions/00000000-0000-0000-0000-000000000001/resourceGroups/RG1
{Color.GREEN}
+ p1/foo1
+ p2/bar