Skip to content

Commit 352bbdf

Browse files
committed
{AKS} Fix missing wait on LRO pollers in azuremonitormetrics helpers
create_dce, create_dcr, create_dcra, addon_put, create_default_mac and link_grafana_instance all call begin_create_or_update[_by_id] but never call .result()/.wait() on the returned poller before returning. Since the generic ResourceManagementClient used here polls via a background thread, the calling code proceeds as soon as the initial PUT is accepted, without waiting for the resource to actually finish provisioning. This is normally invisible in VCR-recorded tests (responses replay instantly), but is exposed in live tests: azure-cli-testsdk's tearDown() asserts that no thread named "LROPoller" is still alive (scenario_tests/base.py), which fails when a live 'az aks create --sku automatic' run leaves one of these pollers still polling in the background after the command returns. Fix: capture the poller returned by each begin_create_or_update[_by_id] call and call .result() on it before returning, so callers only get control back once the resource has actually finished provisioning.
1 parent fe875eb commit 352bbdf

6 files changed

Lines changed: 14 additions & 7 deletions

File tree

src/azure-cli/azure/cli/command_modules/acs/azuremonitormetrics/addonput.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def addon_put(cmd, cluster_subscription, cluster_resource_group_name, cluster_na
2222
if getattr(mc.azure_monitor_profile.metrics, "enabled", None) is False:
2323
mc.azure_monitor_profile.metrics.enabled = True
2424
try:
25-
client.begin_create_or_update(cluster_resource_group_name, cluster_name, mc)
25+
poller = client.begin_create_or_update(cluster_resource_group_name, cluster_name, mc)
26+
poller.result()
2627
except Exception as e:
2728
raise UnknownError(e)

src/azure-cli/azure/cli/command_modules/acs/azuremonitormetrics/amg/link.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,12 @@ def link_grafana_instance(cmd, raw_parameters, azure_monitor_workspace_resource_
6969
}
7070
}
7171
try:
72-
resources.begin_create_or_update_by_id(
72+
poller = resources.begin_create_or_update_by_id(
7373
roleAssignmentResourceId,
7474
GRAFANA_ROLE_ASSIGNMENT_API,
7575
association_body
7676
)
77+
poller.result()
7778
except HttpResponseError as e:
7879
# If already exists (RoleAssignmentExists), warn and continue, else print error
7980
if e.error and e.error.code == "RoleAssignmentExists":
@@ -109,11 +110,12 @@ def link_grafana_instance(cmd, raw_parameters, azure_monitor_workspace_resource_
109110
targetGrafanaArmPayload["properties"]["grafanaIntegrations"]["azureMonitorWorkspaceIntegrations"].append({
110111
"azureMonitorWorkspaceResourceId": azure_monitor_workspace_resource_id
111112
})
112-
resources.begin_create_or_update_by_id(
113+
poller = resources.begin_create_or_update_by_id(
113114
grafana_resource_id,
114115
GRAFANA_API,
115116
targetGrafanaArmPayload
116117
)
118+
poller.result()
117119
except CLIError as e:
118120
raise CLIError(e)
119121
return GrafanaLink.SUCCESS

src/azure-cli/azure/cli/command_modules/acs/azuremonitormetrics/amw/create.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@ def create_default_mac(cmd, cluster_subscription, cluster_region):
3434
else:
3535
resource_groups.create_or_update(default_resource_group_name, {"location": default_mac_region})
3636
try:
37-
resources.begin_create_or_update_by_id(
37+
poller = resources.begin_create_or_update_by_id(
3838
azure_monitor_workspace_resource_id,
3939
MAC_API,
4040
{
4141
"location": default_mac_region,
4242
"properties": {}
4343
}
4444
)
45+
poller.result()
4546
return azure_monitor_workspace_resource_id, default_mac_region
4647
except Exception as e:
4748
raise CLIError(e)

src/azure-cli/azure/cli/command_modules/acs/azuremonitormetrics/dc/dce_api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def create_dce(cmd, cluster_subscription, cluster_resource_group_name, cluster_n
2020
from azure.cli.command_modules.acs._client_factory import get_resources_client
2121
resources = get_resources_client(cmd.cli_ctx, cluster_subscription)
2222
try:
23-
resources.begin_create_or_update_by_id(
23+
poller = resources.begin_create_or_update_by_id(
2424
dce_resource_id,
2525
DC_API,
2626
{
@@ -30,6 +30,7 @@ def create_dce(cmd, cluster_subscription, cluster_resource_group_name, cluster_n
3030
"properties": {}
3131
}
3232
)
33+
poller.result()
3334
return dce_resource_id
3435
except Exception as error:
3536
raise CLIError(error)

src/azure-cli/azure/cli/command_modules/acs/azuremonitormetrics/dc/dcr_api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ def create_dcr(cmd, mac_region, azure_monitor_workspace_resource_id, cluster_sub
3333
}
3434
}
3535
try:
36-
resources.begin_create_or_update_by_id(
36+
poller = resources.begin_create_or_update_by_id(
3737
dcr_resource_id,
3838
DC_API,
3939
dcr_creation_body
4040
)
41+
poller.result()
4142
return dcr_resource_id
4243
except Exception as error:
4344
raise CLIError(error)

src/azure-cli/azure/cli/command_modules/acs/azuremonitormetrics/dc/dcra_api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ def create_dcra(cmd, cluster_region, cluster_subscription, cluster_resource_grou
3131
from azure.cli.command_modules.acs._client_factory import get_resources_client
3232
resources = get_resources_client(cmd.cli_ctx, cluster_subscription)
3333
try:
34-
resources.begin_create_or_update_by_id(
34+
poller = resources.begin_create_or_update_by_id(
3535
f"{cluster_resource_id}/providers/Microsoft.Insights/dataCollectionRuleAssociations/{dcra_name}",
3636
DC_API,
3737
association_body
3838
)
39+
poller.result()
3940
return dcra_resource_id
4041
except Exception as error:
4142
raise CLIError(error)

0 commit comments

Comments
 (0)