|
41 | 41 | CONST_MANAGED_GATEWAY_INSTALLATION_DISABLED, |
42 | 42 | CONST_MANAGED_GATEWAY_INSTALLATION_STANDARD, |
43 | 43 | CONST_MONITORING_ADDON_NAME, |
| 44 | + CONST_MONITORING_ADDON_NAME_CAMELCASE, |
44 | 45 | CONST_MONITORING_LOG_ANALYTICS_WORKSPACE_RESOURCE_ID, |
45 | 46 | CONST_MONITORING_USING_AAD_MSI_AUTH, |
46 | 47 | CONST_NODEPOOL_MODE_SYSTEM, |
@@ -5137,6 +5138,36 @@ def test_get_enable_high_log_scale_mode_update_monitoring_camelcase_key(self): |
5137 | 5138 | result = ctx.get_enable_high_log_scale_mode() |
5138 | 5139 | self.assertTrue(result) |
5139 | 5140 |
|
| 5141 | + def test_get_enable_msi_auth_for_monitoring_with_msi_service_principal(self): |
| 5142 | + """Test that MSI auth is correctly detected when service_principal_profile.client_id='msi'. |
| 5143 | + |
| 5144 | + The base class returns False when client_id is not None, but MSI-based clusters set |
| 5145 | + client_id to 'msi'. The preview override should check the addon config for useAADAuth. |
| 5146 | + """ |
| 5147 | + ctx = AKSPreviewManagedClusterContext( |
| 5148 | + self.cmd, |
| 5149 | + AKSManagedClusterParamDict({}), |
| 5150 | + self.models, |
| 5151 | + decorator_mode=DecoratorMode.UPDATE, |
| 5152 | + ) |
| 5153 | + mc = self.models.ManagedCluster( |
| 5154 | + location="test_location", |
| 5155 | + service_principal_profile=self.models.ManagedClusterServicePrincipalProfile( |
| 5156 | + client_id="msi", |
| 5157 | + ), |
| 5158 | + addon_profiles={ |
| 5159 | + "omsagent": self.models.ManagedClusterAddonProfile( |
| 5160 | + enabled=True, |
| 5161 | + config={ |
| 5162 | + CONST_MONITORING_USING_AAD_MSI_AUTH: "true", |
| 5163 | + } |
| 5164 | + ) |
| 5165 | + }, |
| 5166 | + ) |
| 5167 | + ctx.attach_mc(mc) |
| 5168 | + result = ctx.get_enable_msi_auth_for_monitoring() |
| 5169 | + self.assertTrue(result) |
| 5170 | + |
5140 | 5171 | def test_get_enable_default_domain(self): |
5141 | 5172 | # default value |
5142 | 5173 | ctx_1 = AKSPreviewManagedClusterContext( |
@@ -7967,6 +7998,33 @@ def test_postprocessing_create_dcr_true_when_cnl_and_hlsm_both_set(self): |
7967 | 7998 | _, kwargs = mock_ecifm.call_args |
7968 | 7999 | self.assertTrue(kwargs["create_dcr"]) |
7969 | 8000 |
|
| 8001 | + def test_postprocessing_create_dcr_true_with_camelcase_addon_key(self): |
| 8002 | + """create_dcr=True when the API response uses the camelCase 'omsAgent' addon key. |
| 8003 | + |
| 8004 | + The API may return 'omsAgent' instead of 'omsagent'. The postprocessing must |
| 8005 | + handle both key variants to ensure the DCR is updated. |
| 8006 | + """ |
| 8007 | + dec = self._make_postprocessing_decorator( |
| 8008 | + {"enable_container_network_logs": True, "enable_high_log_scale_mode": True} |
| 8009 | + ) |
| 8010 | + # Build cluster with camelCase addon key (as the API might return) |
| 8011 | + cluster = self.models.ManagedCluster( |
| 8012 | + location="test_location", |
| 8013 | + addon_profiles={ |
| 8014 | + CONST_MONITORING_ADDON_NAME_CAMELCASE: self.models.ManagedClusterAddonProfile(enabled=True) |
| 8015 | + }, |
| 8016 | + ) |
| 8017 | + external_functions = dec.context.external_functions |
| 8018 | + with patch.object( |
| 8019 | + external_functions, "ensure_container_insights_for_monitoring", return_value=None |
| 8020 | + ) as mock_ecifm, patch.object( |
| 8021 | + dec.context, "get_enable_high_log_scale_mode", return_value=True |
| 8022 | + ): |
| 8023 | + dec.postprocessing_after_mc_created(cluster) |
| 8024 | + mock_ecifm.assert_called_once() |
| 8025 | + _, kwargs = mock_ecifm.call_args |
| 8026 | + self.assertTrue(kwargs["create_dcr"]) |
| 8027 | + |
7970 | 8028 |
|
7971 | 8029 | def test_set_up_health_monitor_profile(self): |
7972 | 8030 | # no flag - no change |
@@ -13738,6 +13796,71 @@ def test_update_disable_hlsm_standalone_no_postprocessing(self): |
13738 | 13796 | dec.context.get_intermediate("monitoring_addon_postprocessing_required", default_value=False) |
13739 | 13797 | ) |
13740 | 13798 |
|
| 13799 | + def test_update_postprocessing_with_camelcase_addon_key(self): |
| 13800 | + """Test that update postprocessing works when the API response uses 'omsAgent' (camelCase). |
| 13801 | + |
| 13802 | + The API may return the monitoring addon as 'omsAgent' instead of 'omsagent'. |
| 13803 | + The postprocessing must handle both key variants so the DCR gets updated. |
| 13804 | + """ |
| 13805 | + dec = AKSPreviewManagedClusterUpdateDecorator( |
| 13806 | + self.cmd, |
| 13807 | + self.client, |
| 13808 | + { |
| 13809 | + "enable_container_network_logs": True, |
| 13810 | + "enable_high_log_scale_mode": True, |
| 13811 | + "name": "test_name", |
| 13812 | + "resource_group_name": "test_rg_name", |
| 13813 | + "location": "test_location", |
| 13814 | + "enable_msi_auth_for_monitoring": True, |
| 13815 | + "enable_syslog": False, |
| 13816 | + "data_collection_settings": None, |
| 13817 | + }, |
| 13818 | + CUSTOM_MGMT_AKS_PREVIEW, |
| 13819 | + ) |
| 13820 | + mc = self.models.ManagedCluster( |
| 13821 | + location="test_location", |
| 13822 | + network_profile=self.models.ContainerServiceNetworkProfile( |
| 13823 | + advanced_networking=self.models.AdvancedNetworking( |
| 13824 | + enabled=True, |
| 13825 | + ), |
| 13826 | + ), |
| 13827 | + addon_profiles={ |
| 13828 | + "omsagent": self.models.ManagedClusterAddonProfile( |
| 13829 | + enabled=True, |
| 13830 | + config={ |
| 13831 | + CONST_MONITORING_USING_AAD_MSI_AUTH: "true", |
| 13832 | + } |
| 13833 | + ) |
| 13834 | + }, |
| 13835 | + ) |
| 13836 | + dec.context.attach_mc(mc) |
| 13837 | + dec.context.set_intermediate("subscription_id", "test_subscription_id") |
| 13838 | + # Simulate profile update setting the postprocessing flag |
| 13839 | + dec.update_monitoring_profile_flow_logs(mc) |
| 13840 | + self.assertTrue(dec.context.get_intermediate("monitoring_addon_postprocessing_required")) |
| 13841 | + |
| 13842 | + # Build API response cluster with camelCase addon key |
| 13843 | + cluster = self.models.ManagedCluster( |
| 13844 | + location="test_location", |
| 13845 | + addon_profiles={ |
| 13846 | + CONST_MONITORING_ADDON_NAME_CAMELCASE: self.models.ManagedClusterAddonProfile( |
| 13847 | + enabled=True, |
| 13848 | + config={ |
| 13849 | + CONST_MONITORING_USING_AAD_MSI_AUTH: "true", |
| 13850 | + } |
| 13851 | + ) |
| 13852 | + }, |
| 13853 | + ) |
| 13854 | + external_functions = dec.context.external_functions |
| 13855 | + with patch.object( |
| 13856 | + external_functions, "ensure_container_insights_for_monitoring", return_value=None |
| 13857 | + ) as mock_ecifm: |
| 13858 | + dec.postprocessing_after_mc_created(cluster) |
| 13859 | + mock_ecifm.assert_called_once() |
| 13860 | + _, kwargs = mock_ecifm.call_args |
| 13861 | + self.assertTrue(kwargs["create_dcr"]) |
| 13862 | + self.assertTrue(kwargs["enable_high_log_scale_mode"]) |
| 13863 | + |
13741 | 13864 | def test_update_node_provisioning_profile(self): |
13742 | 13865 | dec_0 = AKSPreviewManagedClusterUpdateDecorator( |
13743 | 13866 | self.cmd, |
|
0 commit comments