Skip to content

Commit 2959c0a

Browse files
committed
Fix integration tests
1 parent 2784c37 commit 2959c0a

File tree

3 files changed

+54
-32
lines changed

3 files changed

+54
-32
lines changed

src/aks-preview/azext_aks_preview/managed_cluster_decorator.py

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5720,6 +5720,11 @@ def update_monitoring_profile_flow_logs(self, mc: ManagedCluster) -> ManagedClus
57205720
"""
57215721
self._ensure_mc(mc)
57225722

5723+
# Call the base class implementation if it exists (CLI >= 2.84.0 added this method to the base).
5724+
# This ensures any base-class monitoring handling (e.g., enable/disable) is applied first.
5725+
if hasattr(super(), 'update_monitoring_profile_flow_logs'):
5726+
mc = super().update_monitoring_profile_flow_logs(mc)
5727+
57235728
# Trigger validation for high log scale mode when container network logs are enabled.
57245729
# This ensures proper error messages are raised before cluster update if the user
57255730
# explicitly disables high log scale mode while enabling container network logs.
@@ -5756,35 +5761,45 @@ def update_monitoring_profile_flow_logs(self, mc: ManagedCluster) -> ManagedClus
57565761
# monitoring with MSI auth is already enabled, then trigger the DCR update via postprocessing.
57575762
enable_high_log_scale_mode = self.context.raw_param.get("enable_high_log_scale_mode")
57585763
if enable_high_log_scale_mode is True:
5759-
addon_consts = self.context.get_addon_consts()
5760-
CONST_MONITORING_ADDON_NAME = addon_consts.get("CONST_MONITORING_ADDON_NAME")
5761-
CONST_MONITORING_USING_AAD_MSI_AUTH = addon_consts.get("CONST_MONITORING_USING_AAD_MSI_AUTH")
5764+
# Check if monitoring is being enabled in the same command
5765+
enable_azure_monitor_logs = self.context.raw_param.get("enable_azure_monitor_logs")
5766+
enable_addons = self.context.raw_param.get("enable_addons")
5767+
monitoring_being_enabled = (
5768+
enable_azure_monitor_logs or
5769+
(enable_addons and "monitoring" in enable_addons)
5770+
)
57625771

5763-
# Resolve the addon profile, handling both "omsagent" and "omsAgent" key variants.
5764-
monitoring_addon_profile = None
5765-
if mc.addon_profiles:
5766-
monitoring_addon_profile = (
5767-
mc.addon_profiles.get(CONST_MONITORING_ADDON_NAME) or
5768-
mc.addon_profiles.get(CONST_MONITORING_ADDON_NAME_CAMELCASE)
5769-
)
5772+
if not monitoring_being_enabled:
5773+
# Only validate existing addon state when not enabling monitoring simultaneously
5774+
addon_consts = self.context.get_addon_consts()
5775+
CONST_MONITORING_ADDON_NAME = addon_consts.get("CONST_MONITORING_ADDON_NAME")
5776+
CONST_MONITORING_USING_AAD_MSI_AUTH = addon_consts.get("CONST_MONITORING_USING_AAD_MSI_AUTH")
5777+
5778+
# Resolve the addon profile, handling both "omsagent" and "omsAgent" key variants.
5779+
monitoring_addon_profile = None
5780+
if mc.addon_profiles:
5781+
monitoring_addon_profile = (
5782+
mc.addon_profiles.get(CONST_MONITORING_ADDON_NAME) or
5783+
mc.addon_profiles.get(CONST_MONITORING_ADDON_NAME_CAMELCASE)
5784+
)
57705785

5771-
if not monitoring_addon_profile or not monitoring_addon_profile.enabled:
5772-
raise RequiredArgumentMissingError(
5773-
"--enable-high-log-scale-mode requires the Azure Monitor logs addon (omsagent) "
5774-
"to be enabled on the cluster. Please enable it first with "
5775-
"--enable-addons monitoring or --enable-azure-monitor-logs."
5776-
)
5786+
if not monitoring_addon_profile or not monitoring_addon_profile.enabled:
5787+
raise RequiredArgumentMissingError(
5788+
"--enable-high-log-scale-mode requires the Azure Monitor logs addon (omsagent) "
5789+
"to be enabled on the cluster. Please enable it first with "
5790+
"--enable-addons monitoring or --enable-azure-monitor-logs."
5791+
)
57775792

5778-
addon_config = monitoring_addon_profile.config or {}
5779-
msi_auth_enabled = (
5780-
CONST_MONITORING_USING_AAD_MSI_AUTH in addon_config and
5781-
str(addon_config[CONST_MONITORING_USING_AAD_MSI_AUTH]).lower() == "true"
5782-
)
5783-
if not msi_auth_enabled:
5784-
raise RequiredArgumentMissingError(
5785-
"--enable-high-log-scale-mode requires MSI authentication to be enabled "
5786-
"for the monitoring addon. Please enable it with --enable-msi-auth-for-monitoring."
5793+
addon_config = monitoring_addon_profile.config or {}
5794+
msi_auth_enabled = (
5795+
CONST_MONITORING_USING_AAD_MSI_AUTH in addon_config and
5796+
str(addon_config[CONST_MONITORING_USING_AAD_MSI_AUTH]).lower() == "true"
57875797
)
5798+
if not msi_auth_enabled:
5799+
raise RequiredArgumentMissingError(
5800+
"--enable-high-log-scale-mode requires MSI authentication to be enabled "
5801+
"for the monitoring addon. Please enable it with --enable-msi-auth-for-monitoring."
5802+
)
57885803

57895804
self.context.set_intermediate("monitoring_addon_postprocessing_required", True, overwrite_exists=True)
57905805

@@ -7749,10 +7764,14 @@ def _disable_azure_monitor_logs(self, mc: ManagedCluster) -> None:
77497764

77507765
# Now disable the addon and clear configuration
77517766
mc.addon_profiles[addon_key].enabled = False
7767+
mc.addon_profiles[addon_key].config = None
77527768

7753-
# Use empty dict instead of None - setting config=None causes the SDK serializer
7754-
# to omit the config key entirely, which Azure interprets as "keep existing config"
7755-
mc.addon_profiles[addon_key].config = {}
7769+
# Also disable azureMonitorProfile.containerInsights (the new API surface)
7770+
# The RP uses containerInsights.enabled as the source of truth; if it remains
7771+
# true while the legacy addon is disabled, the RP re-enables the addon.
7772+
if (mc.azure_monitor_profile and
7773+
mc.azure_monitor_profile.container_insights):
7774+
mc.azure_monitor_profile.container_insights.enabled = False
77567775

77577776
# Also disable OpenTelemetry logs when disabling Azure Monitor logs
77587777
if opentelemetry_logs_enabled:
@@ -7889,7 +7908,10 @@ def update_mc_profile_preview(self) -> ManagedCluster:
78897908
# update acns in network_profile
78907909
mc = self.update_acns_in_network_profile(mc)
78917910
# update update_monitoring_profile_flow_logs
7892-
mc = self.update_monitoring_profile_flow_logs(mc)
7911+
# Only call here if the base class doesn't already call it in update_mc_profile_default
7912+
# (CLI >= 2.84.0 added this call to the base class)
7913+
if not hasattr(super(), 'update_monitoring_profile_flow_logs'):
7914+
mc = self.update_monitoring_profile_flow_logs(mc)
78937915
# update kubernetes support plan
78947916
mc = self.update_k8s_support_plan(mc)
78957917
# update AI toolchain operator

src/aks-preview/azext_aks_preview/tests/latest/test_aks_commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19123,7 +19123,7 @@ def test_aks_update_standalone_enable_high_log_scale_mode(
1912319123
# Verify DCR contains the HighScale stream
1912419124
get_cmd = f'rest --method get --url https://management.azure.com{dcr_resource_id}?api-version=2022-06-01'
1912519125
self.cmd(get_cmd, checks=[
19126-
self.check('properties.dataFlows[0].streams[-1]', 'Microsoft-ContainerLogV2-HighScale'),
19126+
self.check("contains(properties.dataFlows[0].streams, 'Microsoft-ContainerLogV2-HighScale')", True),
1912719127
])
1912819128

1912919129
# Now disable high log scale mode

src/aks-preview/azext_aks_preview/tests/latest/test_managed_cluster_decorator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11289,7 +11289,7 @@ def test_disable_azure_monitor_logs_with_omsagent_camelcase(self):
1128911289
# Verify: omsAgent should be disabled
1129011290
self.assertIn("omsAgent", mc_1.addon_profiles)
1129111291
self.assertFalse(mc_1.addon_profiles["omsAgent"].enabled)
11292-
self.assertEqual(mc_1.addon_profiles["omsAgent"].config, {})
11292+
self.assertIsNone(mc_1.addon_profiles["omsAgent"].config)
1129311293

1129411294
def test_disable_azure_monitor_logs_with_omsagent_lowercase(self):
1129511295
# Test that _disable_azure_monitor_logs handles omsagent (lowercase) correctly
@@ -11325,7 +11325,7 @@ def test_disable_azure_monitor_logs_with_omsagent_lowercase(self):
1132511325
# Verify: omsagent should be disabled
1132611326
self.assertIn("omsagent", mc_1.addon_profiles)
1132711327
self.assertFalse(mc_1.addon_profiles["omsagent"].enabled)
11328-
self.assertEqual(mc_1.addon_profiles["omsagent"].config, {})
11328+
self.assertIsNone(mc_1.addon_profiles["omsagent"].config)
1132911329

1133011330
def test_get_enable_opentelemetry_logs_validation_with_omsagent_camelcase(self):
1133111331
# Test that OpenTelemetry logs validation recognizes omsAgent (camelCase) as enabled

0 commit comments

Comments
 (0)