Skip to content

Commit df7aaf1

Browse files
authored
{App Service} az appservice ase: Fix issue with resource group in new SDK (#20536)
* Fix issue with resource group in new SDK * update tests * build
1 parent 23a4a35 commit df7aaf1

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

src/azure-cli/azure/cli/command_modules/appservice/appservice_environment.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ def _get_resource_group_name_from_ase(ase_client, ase_name):
212212
ase_found = False
213213
for ase in ase_list:
214214
if ase.name.lower() == ase_name.lower():
215-
resource_group = ase.resource_group
215+
ase_id_parts = parse_resource_id(ase.id)
216+
resource_group = ase_id_parts['resource_group']
216217
ase_found = True
217218
break
218219
if not ase_found:

src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_app_service_environment_commands_thru_mock.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ def test_app_service_environment_show(self, ase_client_factory_mock):
3737
rg_name = 'mock_rg_name'
3838
ase_client = mock.MagicMock()
3939
ase_client_factory_mock.return_value = ase_client
40-
host_env = HostingEnvironmentProfile(id='id1')
41-
host_env.name = ase_name
42-
host_env.resource_group = rg_name
40+
host_env = HostingEnvironmentProfile(id='/subscriptions/11111111-1111-1111-1111-111111111111/resourceGroups/mock_rg_name/Microsoft.Web/hostingEnvironments/mock_ase_name')
41+
host_env.name = ase_name
4342
ase_client.get.return_value = host_env
4443
ase_client.list.return_value = [host_env]
4544

@@ -56,14 +55,12 @@ def test_app_service_environment_list(self, ase_client_factory_mock):
5655
rg_name_2 = 'mock_rg_name_2'
5756
ase_client = mock.MagicMock()
5857
ase_client_factory_mock.return_value = ase_client
59-
host_env1 = HostingEnvironmentProfile(id='id1')
58+
host_env1 = HostingEnvironmentProfile(id='/subscriptions/11111111-1111-1111-1111-111111111111/resourceGroups/mock_rg_name_1/Microsoft.Web/hostingEnvironments/mock_ase_name_1')
6059
host_env1.name = ase_name_1
6160
host_env1.kind = 'ASEv2'
62-
host_env1.resource_group = rg_name_1
63-
host_env2 = HostingEnvironmentProfile(id='id2')
61+
host_env2 = HostingEnvironmentProfile(id='/subscriptions/11111111-1111-1111-1111-111111111111/resourceGroups/mock_rg_name_2/Microsoft.Web/hostingEnvironments/mock_ase_name_2')
6462
host_env2.name = ase_name_2
6563
host_env2.kind = 'ASEv3'
66-
host_env2.resource_group = rg_name_2
6764
ase_client.list.return_value = [host_env1, host_env2]
6865

6966
ase_client.get.return_value = host_env1
@@ -141,20 +138,18 @@ def test_app_service_environment_update(self, ase_client_factory_mock, resource_
141138

142139
resource_group_mock.return_value = rg_name
143140

144-
host_env = HostingEnvironmentProfile(id='id1')
141+
host_env = HostingEnvironmentProfile(id='/subscriptions/11111111-1111-1111-1111-111111111111/resourceGroups/mock_rg_name/Microsoft.Web/hostingEnvironments/mock_ase_name')
145142
host_env.name = ase_name
146143
host_env.kind = 'ASEv2'
147-
host_env.resource_group = rg_name
148144
ase_client.get.return_value = host_env
149145
ase_client.list.return_value = [host_env]
150146

151147
update_appserviceenvironment(self.mock_cmd, ase_name, front_end_scale_factor=10)
152148

153149
# Assert create_or_update is called with correct properties
154-
assert_host_env = HostingEnvironmentProfile(id='id1')
150+
assert_host_env = HostingEnvironmentProfile(id='/subscriptions/11111111-1111-1111-1111-111111111111/resourceGroups/mock_rg_name/Microsoft.Web/hostingEnvironments/mock_ase_name')
155151
assert_host_env.name = ase_name
156152
assert_host_env.kind = 'ASEv2'
157-
assert_host_env.resource_group = rg_name
158153
assert_host_env.internal_load_balancing_mode = None
159154
assert_host_env.front_end_scale_factor = 10
160155
ase_client.begin_create_or_update.assert_called_once_with(resource_group_name=rg_name, name=ase_name,
@@ -171,10 +166,9 @@ def test_app_service_environment_update_asev3(self, ase_client_factory_mock, res
171166

172167
resource_group_mock.return_value = rg_name
173168

174-
host_env = HostingEnvironmentProfile(id='id1')
169+
host_env = HostingEnvironmentProfile(id='/subscriptions/11111111-1111-1111-1111-111111111111/resourceGroups/mock_rg_name/Microsoft.Web/hostingEnvironments/mock_ase_name')
175170
host_env.name = ase_name
176171
host_env.kind = 'ASEv3'
177-
host_env.resource_group = rg_name
178172
ase_client.get.return_value = host_env
179173
ase_client.list.return_value = [host_env]
180174
ase_networking_conf = AseV3NetworkingConfiguration(allow_new_private_endpoint_connections=False)
@@ -198,19 +192,17 @@ def test_app_service_environment_delete(self, ase_client_factory_mock, resource_
198192

199193
resource_group_mock.return_value = rg_name
200194

201-
host_env = HostingEnvironmentProfile(id='id1')
195+
host_env = HostingEnvironmentProfile(id='/subscriptions/11111111-1111-1111-1111-111111111111/resourceGroups/mock_rg_name/Microsoft.Web/hostingEnvironments/mock_ase_name')
202196
host_env.name = ase_name
203-
host_env.resource_group = rg_name
204197
host_env.worker_pools = []
205198
ase_client.get.return_value = host_env
206199
ase_client.list.return_value = [host_env]
207200

208201
delete_appserviceenvironment(self.mock_cmd, ase_name)
209202

210203
# Assert delete is called with correct properties
211-
assert_host_env = HostingEnvironmentProfile(id='id1')
204+
assert_host_env = HostingEnvironmentProfile(id='/subscriptions/11111111-1111-1111-1111-111111111111/resourceGroups/mock_rg_name/Microsoft.Web/hostingEnvironments/mock_ase_name')
212205
assert_host_env.name = ase_name
213-
assert_host_env.resource_group = rg_name
214206
ase_client.begin_delete.assert_called_once_with(name=ase_name, resource_group_name=rg_name)
215207

216208
@mock.patch('azure.cli.command_modules.appservice.appservice_environment._get_unique_deployment_name', autospec=True)

0 commit comments

Comments
 (0)