Skip to content

Commit 598d64f

Browse files
committed
Fix integration tests
1 parent 236fa2c commit 598d64f

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
@@ -5748,6 +5748,11 @@ def update_monitoring_profile_flow_logs(self, mc: ManagedCluster) -> ManagedClus
57485748
"""
57495749
self._ensure_mc(mc)
57505750

5751+
# Call the base class implementation if it exists (CLI >= 2.84.0 added this method to the base).
5752+
# This ensures any base-class monitoring handling (e.g., enable/disable) is applied first.
5753+
if hasattr(super(), 'update_monitoring_profile_flow_logs'):
5754+
mc = super().update_monitoring_profile_flow_logs(mc)
5755+
57515756
# Trigger validation for high log scale mode when container network logs are enabled.
57525757
# This ensures proper error messages are raised before cluster update if the user
57535758
# explicitly disables high log scale mode while enabling container network logs.
@@ -5784,35 +5789,45 @@ def update_monitoring_profile_flow_logs(self, mc: ManagedCluster) -> ManagedClus
57845789
# monitoring with MSI auth is already enabled, then trigger the DCR update via postprocessing.
57855790
enable_high_log_scale_mode = self.context.raw_param.get("enable_high_log_scale_mode")
57865791
if enable_high_log_scale_mode is True:
5787-
addon_consts = self.context.get_addon_consts()
5788-
CONST_MONITORING_ADDON_NAME = addon_consts.get("CONST_MONITORING_ADDON_NAME")
5789-
CONST_MONITORING_USING_AAD_MSI_AUTH = addon_consts.get("CONST_MONITORING_USING_AAD_MSI_AUTH")
5792+
# Check if monitoring is being enabled in the same command
5793+
enable_azure_monitor_logs = self.context.raw_param.get("enable_azure_monitor_logs")
5794+
enable_addons = self.context.raw_param.get("enable_addons")
5795+
monitoring_being_enabled = (
5796+
enable_azure_monitor_logs or
5797+
(enable_addons and "monitoring" in enable_addons)
5798+
)
57905799

5791-
# Resolve the addon profile, handling both "omsagent" and "omsAgent" key variants.
5792-
monitoring_addon_profile = None
5793-
if mc.addon_profiles:
5794-
monitoring_addon_profile = (
5795-
mc.addon_profiles.get(CONST_MONITORING_ADDON_NAME) or
5796-
mc.addon_profiles.get(CONST_MONITORING_ADDON_NAME_CAMELCASE)
5797-
)
5800+
if not monitoring_being_enabled:
5801+
# Only validate existing addon state when not enabling monitoring simultaneously
5802+
addon_consts = self.context.get_addon_consts()
5803+
CONST_MONITORING_ADDON_NAME = addon_consts.get("CONST_MONITORING_ADDON_NAME")
5804+
CONST_MONITORING_USING_AAD_MSI_AUTH = addon_consts.get("CONST_MONITORING_USING_AAD_MSI_AUTH")
5805+
5806+
# Resolve the addon profile, handling both "omsagent" and "omsAgent" key variants.
5807+
monitoring_addon_profile = None
5808+
if mc.addon_profiles:
5809+
monitoring_addon_profile = (
5810+
mc.addon_profiles.get(CONST_MONITORING_ADDON_NAME) or
5811+
mc.addon_profiles.get(CONST_MONITORING_ADDON_NAME_CAMELCASE)
5812+
)
57985813

5799-
if not monitoring_addon_profile or not monitoring_addon_profile.enabled:
5800-
raise RequiredArgumentMissingError(
5801-
"--enable-high-log-scale-mode requires the Azure Monitor logs addon (omsagent) "
5802-
"to be enabled on the cluster. Please enable it first with "
5803-
"--enable-addons monitoring or --enable-azure-monitor-logs."
5804-
)
5814+
if not monitoring_addon_profile or not monitoring_addon_profile.enabled:
5815+
raise RequiredArgumentMissingError(
5816+
"--enable-high-log-scale-mode requires the Azure Monitor logs addon (omsagent) "
5817+
"to be enabled on the cluster. Please enable it first with "
5818+
"--enable-addons monitoring or --enable-azure-monitor-logs."
5819+
)
58055820

5806-
addon_config = monitoring_addon_profile.config or {}
5807-
msi_auth_enabled = (
5808-
CONST_MONITORING_USING_AAD_MSI_AUTH in addon_config and
5809-
str(addon_config[CONST_MONITORING_USING_AAD_MSI_AUTH]).lower() == "true"
5810-
)
5811-
if not msi_auth_enabled:
5812-
raise RequiredArgumentMissingError(
5813-
"--enable-high-log-scale-mode requires MSI authentication to be enabled "
5814-
"for the monitoring addon. Please enable it with --enable-msi-auth-for-monitoring."
5821+
addon_config = monitoring_addon_profile.config or {}
5822+
msi_auth_enabled = (
5823+
CONST_MONITORING_USING_AAD_MSI_AUTH in addon_config and
5824+
str(addon_config[CONST_MONITORING_USING_AAD_MSI_AUTH]).lower() == "true"
58155825
)
5826+
if not msi_auth_enabled:
5827+
raise RequiredArgumentMissingError(
5828+
"--enable-high-log-scale-mode requires MSI authentication to be enabled "
5829+
"for the monitoring addon. Please enable it with --enable-msi-auth-for-monitoring."
5830+
)
58165831

58175832
self.context.set_intermediate("monitoring_addon_postprocessing_required", True, overwrite_exists=True)
58185833

@@ -7777,10 +7792,14 @@ def _disable_azure_monitor_logs(self, mc: ManagedCluster) -> None:
77777792

77787793
# Now disable the addon and clear configuration
77797794
mc.addon_profiles[addon_key].enabled = False
7795+
mc.addon_profiles[addon_key].config = None
77807796

7781-
# Use empty dict instead of None - setting config=None causes the SDK serializer
7782-
# to omit the config key entirely, which Azure interprets as "keep existing config"
7783-
mc.addon_profiles[addon_key].config = {}
7797+
# Also disable azureMonitorProfile.containerInsights (the new API surface)
7798+
# The RP uses containerInsights.enabled as the source of truth; if it remains
7799+
# true while the legacy addon is disabled, the RP re-enables the addon.
7800+
if (mc.azure_monitor_profile and
7801+
mc.azure_monitor_profile.container_insights):
7802+
mc.azure_monitor_profile.container_insights.enabled = False
77847803

77857804
# Also disable OpenTelemetry logs when disabling Azure Monitor logs
77867805
if opentelemetry_logs_enabled:
@@ -7917,7 +7936,10 @@ def update_mc_profile_preview(self) -> ManagedCluster:
79177936
# update acns in network_profile
79187937
mc = self.update_acns_in_network_profile(mc)
79197938
# update update_monitoring_profile_flow_logs
7920-
mc = self.update_monitoring_profile_flow_logs(mc)
7939+
# Only call here if the base class doesn't already call it in update_mc_profile_default
7940+
# (CLI >= 2.84.0 added this call to the base class)
7941+
if not hasattr(super(), 'update_monitoring_profile_flow_logs'):
7942+
mc = self.update_monitoring_profile_flow_logs(mc)
79217943
# update kubernetes support plan
79227944
mc = self.update_k8s_support_plan(mc)
79237945
# 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)