@@ -16340,6 +16340,160 @@ def test_setup_azure_monitor_logs_no_retina_flags_without_cnl(self):
1634016340 self.assertIsNotNone(addon_profile)
1634116341 self.assertNotIn("enableRetinaNetworkFlags", addon_profile.config)
1634216342
16343+ # ------------------------------------------------------------------
16344+ # Tests for _setup_azure_monitor_logs workspace change detection
16345+ # ------------------------------------------------------------------
16346+ def test_setup_azure_monitor_logs_workspace_change_triggers_postprocessing(self):
16347+ """_setup_azure_monitor_logs sets monitoring_addon_postprocessing_required when workspace changes."""
16348+ old_ws = "/subscriptions/test/resourceGroups/test/providers/Microsoft.OperationalInsights/workspaces/old-ws"
16349+ new_ws = "/subscriptions/test/resourceGroups/test/providers/Microsoft.OperationalInsights/workspaces/new-ws"
16350+ dec = AKSPreviewManagedClusterUpdateDecorator(
16351+ self.cmd,
16352+ self.client,
16353+ {
16354+ "enable_azure_monitor_logs": True,
16355+ "workspace_resource_id": new_ws,
16356+ },
16357+ CUSTOM_MGMT_AKS_PREVIEW,
16358+ )
16359+ mc = self.models.ManagedCluster(
16360+ location="test_location",
16361+ addon_profiles={
16362+ CONST_MONITORING_ADDON_NAME: self.models.ManagedClusterAddonProfile(
16363+ enabled=True,
16364+ config={
16365+ "logAnalyticsWorkspaceResourceID": old_ws,
16366+ "useAADAuth": "true",
16367+ },
16368+ )
16369+ },
16370+ )
16371+ dec.context.attach_mc(mc)
16372+ dec.context.set_intermediate("subscription_id", "test-subscription-id")
16373+
16374+ with patch.object(
16375+ dec.context.external_functions,
16376+ "sanitize_loganalytics_ws_resource_id",
16377+ side_effect=lambda x: x,
16378+ ):
16379+ dec._setup_azure_monitor_logs(mc)
16380+
16381+ self.assertTrue(
16382+ dec.context.get_intermediate("monitoring_addon_postprocessing_required", default_value=False)
16383+ )
16384+ # Verify workspace was updated
16385+ actual_key = next(k for k in mc.addon_profiles if k.lower() == "omsagent")
16386+ self.assertEqual(mc.addon_profiles[actual_key].config["logAnalyticsWorkspaceResourceID"], new_ws)
16387+
16388+ def test_setup_azure_monitor_logs_same_workspace_no_postprocessing(self):
16389+ """_setup_azure_monitor_logs does NOT set monitoring_addon_postprocessing_required when workspace is unchanged."""
16390+ ws = "/subscriptions/test/resourceGroups/test/providers/Microsoft.OperationalInsights/workspaces/same-ws"
16391+ dec = AKSPreviewManagedClusterUpdateDecorator(
16392+ self.cmd,
16393+ self.client,
16394+ {
16395+ "enable_azure_monitor_logs": True,
16396+ "workspace_resource_id": ws,
16397+ },
16398+ CUSTOM_MGMT_AKS_PREVIEW,
16399+ )
16400+ mc = self.models.ManagedCluster(
16401+ location="test_location",
16402+ addon_profiles={
16403+ CONST_MONITORING_ADDON_NAME: self.models.ManagedClusterAddonProfile(
16404+ enabled=True,
16405+ config={
16406+ "logAnalyticsWorkspaceResourceID": ws,
16407+ "useAADAuth": "true",
16408+ },
16409+ )
16410+ },
16411+ )
16412+ dec.context.attach_mc(mc)
16413+ dec.context.set_intermediate("subscription_id", "test-subscription-id")
16414+
16415+ with patch.object(
16416+ dec.context.external_functions,
16417+ "sanitize_loganalytics_ws_resource_id",
16418+ side_effect=lambda x: x,
16419+ ):
16420+ dec._setup_azure_monitor_logs(mc)
16421+
16422+ self.assertFalse(
16423+ dec.context.get_intermediate("monitoring_addon_postprocessing_required", default_value=False)
16424+ )
16425+
16426+ def test_setup_azure_monitor_logs_workspace_change_case_insensitive(self):
16427+ """_setup_azure_monitor_logs compares workspaces case-insensitively (no false positives on casing)."""
16428+ ws_lower = "/subscriptions/test/resourcegroups/test/providers/microsoft.operationalinsights/workspaces/my-ws"
16429+ ws_mixed = "/subscriptions/test/resourceGroups/test/providers/Microsoft.OperationalInsights/workspaces/my-ws"
16430+ dec = AKSPreviewManagedClusterUpdateDecorator(
16431+ self.cmd,
16432+ self.client,
16433+ {
16434+ "enable_azure_monitor_logs": True,
16435+ "workspace_resource_id": ws_mixed,
16436+ },
16437+ CUSTOM_MGMT_AKS_PREVIEW,
16438+ )
16439+ mc = self.models.ManagedCluster(
16440+ location="test_location",
16441+ addon_profiles={
16442+ CONST_MONITORING_ADDON_NAME: self.models.ManagedClusterAddonProfile(
16443+ enabled=True,
16444+ config={
16445+ "logAnalyticsWorkspaceResourceID": ws_lower,
16446+ "useAADAuth": "true",
16447+ },
16448+ )
16449+ },
16450+ )
16451+ dec.context.attach_mc(mc)
16452+ dec.context.set_intermediate("subscription_id", "test-subscription-id")
16453+
16454+ with patch.object(
16455+ dec.context.external_functions,
16456+ "sanitize_loganalytics_ws_resource_id",
16457+ side_effect=lambda x: x,
16458+ ):
16459+ dec._setup_azure_monitor_logs(mc)
16460+
16461+ # Same workspace (different casing) should NOT trigger postprocessing
16462+ self.assertFalse(
16463+ dec.context.get_intermediate("monitoring_addon_postprocessing_required", default_value=False)
16464+ )
16465+
16466+ def test_setup_azure_monitor_logs_new_addon_no_postprocessing(self):
16467+ """_setup_azure_monitor_logs does NOT trigger postprocessing when there is no existing addon (fresh enable)."""
16468+ new_ws = "/subscriptions/test/resourceGroups/test/providers/Microsoft.OperationalInsights/workspaces/new-ws"
16469+ dec = AKSPreviewManagedClusterUpdateDecorator(
16470+ self.cmd,
16471+ self.client,
16472+ {
16473+ "enable_azure_monitor_logs": True,
16474+ "workspace_resource_id": new_ws,
16475+ },
16476+ CUSTOM_MGMT_AKS_PREVIEW,
16477+ )
16478+ mc = self.models.ManagedCluster(
16479+ location="test_location",
16480+ addon_profiles={},
16481+ )
16482+ dec.context.attach_mc(mc)
16483+ dec.context.set_intermediate("subscription_id", "test-subscription-id")
16484+
16485+ with patch.object(
16486+ dec.context.external_functions,
16487+ "sanitize_loganalytics_ws_resource_id",
16488+ side_effect=lambda x: x,
16489+ ):
16490+ dec._setup_azure_monitor_logs(mc)
16491+
16492+ # Fresh enable — no old workspace to compare, should NOT trigger postprocessing
16493+ self.assertFalse(
16494+ dec.context.get_intermediate("monitoring_addon_postprocessing_required", default_value=False)
16495+ )
16496+
1634316497 # ------------------------------------------------------------------
1634416498 # Tests for _disable_azure_monitor_logs disabling containerInsights
1634516499 # ------------------------------------------------------------------
0 commit comments