@@ -2272,6 +2272,55 @@ def test_get_azure_keyvault_kms_key_vault_resource_id(self):
22722272 with self .assertRaises (ArgumentUsageError ):
22732273 ctx_9 .get_azure_keyvault_kms_key_vault_resource_id ()
22742274
2275+ def test_get_kms_infrastructure_encryption (self ):
2276+ # default
2277+ ctx_0 = AKSPreviewManagedClusterContext (
2278+ self .cmd ,
2279+ AKSManagedClusterParamDict ({}),
2280+ self .models ,
2281+ decorator_mode = DecoratorMode .CREATE ,
2282+ )
2283+ self .assertIsNone (ctx_0 .get_kms_infrastructure_encryption ())
2284+
2285+ # with explicit Disabled value
2286+ ctx_1 = AKSPreviewManagedClusterContext (
2287+ self .cmd ,
2288+ AKSManagedClusterParamDict (
2289+ {
2290+ "kms_infrastructure_encryption" : "Disabled" ,
2291+ }
2292+ ),
2293+ self .models ,
2294+ decorator_mode = DecoratorMode .CREATE ,
2295+ )
2296+ self .assertEqual (ctx_1 .get_kms_infrastructure_encryption (), "Disabled" )
2297+
2298+ # with Enabled value
2299+ ctx_2 = AKSPreviewManagedClusterContext (
2300+ self .cmd ,
2301+ AKSManagedClusterParamDict (
2302+ {
2303+ "kms_infrastructure_encryption" : "Enabled" ,
2304+ }
2305+ ),
2306+ self .models ,
2307+ decorator_mode = DecoratorMode .CREATE ,
2308+ )
2309+ self .assertEqual (ctx_2 .get_kms_infrastructure_encryption (), "Enabled" )
2310+
2311+ # test in update mode
2312+ ctx_3 = AKSPreviewManagedClusterContext (
2313+ self .cmd ,
2314+ AKSManagedClusterParamDict (
2315+ {
2316+ "kms_infrastructure_encryption" : "Enabled" ,
2317+ }
2318+ ),
2319+ self .models ,
2320+ decorator_mode = DecoratorMode .UPDATE ,
2321+ )
2322+ self .assertEqual (ctx_3 .get_kms_infrastructure_encryption (), "Enabled" )
2323+
22752324 def test_get_cluster_snapshot_id (self ):
22762325 # default
22772326 ctx_1 = AKSPreviewManagedClusterContext (
@@ -4897,6 +4946,93 @@ def test_set_up_azure_keyvault_kms(self):
48974946
48984947 self .assertEqual (dec_mc_3 , ground_truth_mc_3 )
48994948
4949+ def test_set_up_kms_infrastructure_encryption (self ):
4950+ # test default (no infrastructure encryption)
4951+ dec_1 = AKSPreviewManagedClusterCreateDecorator (
4952+ self .cmd ,
4953+ self .client ,
4954+ {},
4955+ CUSTOM_MGMT_AKS_PREVIEW ,
4956+ )
4957+ mc_1 = self .models .ManagedCluster (location = "test_location" )
4958+ dec_1 .context .attach_mc (mc_1 )
4959+ dec_mc_1 = dec_1 .set_up_kms_infrastructure_encryption (mc_1 )
4960+ # no change expected
4961+ ground_truth_mc_1 = self .models .ManagedCluster (location = "test_location" )
4962+ self .assertEqual (dec_mc_1 , ground_truth_mc_1 )
4963+
4964+ # test with Disabled
4965+ dec_2 = AKSPreviewManagedClusterCreateDecorator (
4966+ self .cmd ,
4967+ self .client ,
4968+ {
4969+ "kms_infrastructure_encryption" : "Disabled" ,
4970+ },
4971+ CUSTOM_MGMT_AKS_PREVIEW ,
4972+ )
4973+ mc_2 = self .models .ManagedCluster (location = "test_location" )
4974+ dec_2 .context .attach_mc (mc_2 )
4975+ dec_mc_2 = dec_2 .set_up_kms_infrastructure_encryption (mc_2 )
4976+ # no change expected
4977+ ground_truth_mc_2 = self .models .ManagedCluster (location = "test_location" )
4978+ self .assertEqual (dec_mc_2 , ground_truth_mc_2 )
4979+
4980+ # test with Enabled
4981+ dec_3 = AKSPreviewManagedClusterCreateDecorator (
4982+ self .cmd ,
4983+ self .client ,
4984+ {
4985+ "kms_infrastructure_encryption" : "Enabled" ,
4986+ },
4987+ CUSTOM_MGMT_AKS_PREVIEW ,
4988+ )
4989+ mc_3 = self .models .ManagedCluster (location = "test_location" )
4990+ dec_3 .context .attach_mc (mc_3 )
4991+ dec_mc_3 = dec_3 .set_up_kms_infrastructure_encryption (mc_3 )
4992+
4993+ # expected security profile with infrastructure encryption
4994+ ground_truth_kube_resource_encryption_profile_3 = self .models .KubernetesResourceObjectEncryptionProfile (
4995+ infrastructure_encryption = "Enabled"
4996+ )
4997+ ground_truth_security_profile_3 = self .models .ManagedClusterSecurityProfile (
4998+ kubernetes_resource_object_encryption_profile = ground_truth_kube_resource_encryption_profile_3 ,
4999+ )
5000+ ground_truth_mc_3 = self .models .ManagedCluster (
5001+ location = "test_location" ,
5002+ security_profile = ground_truth_security_profile_3 ,
5003+ )
5004+ self .assertEqual (dec_mc_3 , ground_truth_mc_3 )
5005+
5006+ # test with existing security profile
5007+ dec_4 = AKSPreviewManagedClusterCreateDecorator (
5008+ self .cmd ,
5009+ self .client ,
5010+ {
5011+ "kms_infrastructure_encryption" : "Enabled" ,
5012+ },
5013+ CUSTOM_MGMT_AKS_PREVIEW ,
5014+ )
5015+ existing_security_profile = self .models .ManagedClusterSecurityProfile ()
5016+ mc_4 = self .models .ManagedCluster (
5017+ location = "test_location" ,
5018+ security_profile = existing_security_profile ,
5019+ )
5020+ dec_4 .context .attach_mc (mc_4 )
5021+ dec_mc_4 = dec_4 .set_up_kms_infrastructure_encryption (mc_4 )
5022+
5023+ # should add to existing security profile
5024+ ground_truth_kube_resource_encryption_profile_4 = self .models .KubernetesResourceObjectEncryptionProfile (
5025+ infrastructure_encryption = "Enabled"
5026+ )
5027+ ground_truth_security_profile_4 = self .models .ManagedClusterSecurityProfile (
5028+ kubernetes_resource_object_encryption_profile = ground_truth_kube_resource_encryption_profile_4 ,
5029+ )
5030+ ground_truth_mc_4 = self .models .ManagedCluster (
5031+ location = "test_location" ,
5032+ security_profile = ground_truth_security_profile_4 ,
5033+ )
5034+ self .assertEqual (dec_mc_4 , ground_truth_mc_4 )
5035+
49005036 def test_set_up_creationdata_of_cluster_snapshot (self ):
49015037 dec_1 = AKSPreviewManagedClusterCreateDecorator (
49025038 self .cmd ,
0 commit comments