diff --git a/src/azure-cli/azure/cli/command_modules/acs/managed_cluster_decorator.py b/src/azure-cli/azure/cli/command_modules/acs/managed_cluster_decorator.py index 0cbafafdb37..988f9ade01b 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/managed_cluster_decorator.py +++ b/src/azure-cli/azure/cli/command_modules/acs/managed_cluster_decorator.py @@ -4706,17 +4706,13 @@ def get_k8s_support_plan(self) -> Union[str, None]: :return: string or None """ - # default to None - support_plan = None - # try to read the property value corresponding to the parameter from the `mc` object - if self.mc and hasattr(self.mc, "support_plan") and self.mc.support_plan is not None: - support_plan = self.mc.support_plan - - # if specified by customer, use the specified value + # take input support_plan = self.raw_param.get("k8s_support_plan") + if support_plan is None: + # user didn't update this property, load from existing ManagedCluster + if self.mc and hasattr(self.mc, "support_plan") and self.mc.support_plan is not None: + support_plan = self.mc.support_plan - # this parameter does not need dynamic completion - # this parameter does not need validation return support_plan def get_yes(self) -> bool: diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_managed_cluster_decorator.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_managed_cluster_decorator.py index a27d4f04549..6f7ec16dc28 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_managed_cluster_decorator.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_managed_cluster_decorator.py @@ -10467,5 +10467,116 @@ def test_update_http_proxy_config(self): ) self.assertEqual(dec_mc_1, ground_truth_mc_1) + def test_setup_supportPlan(self): + # default value in `aks_create` + ltsDecorator = AKSManagedClusterCreateDecorator( + self.cmd, + self.client, + { + "k8s_support_plan": "AKSLongTermSupport" + }, + ResourceType.MGMT_CONTAINERSERVICE, + ) + + premiumSKU = self.models.ManagedClusterSKU( + name="Base", + tier="Premium") + premiumCluster = self.models.ManagedCluster( + location="test_location", + support_plan=None, + sku=premiumSKU, + ) + ltsDecorator.context.attach_mc(premiumCluster) + + # fail on passing the wrong mc object + with self.assertRaises(CLIInternalError): + ltsDecorator.set_up_k8s_support_plan(None) + + ltsClusterCalculated = ltsDecorator.set_up_k8s_support_plan(premiumCluster) + expectedLTSCluster = self.models.ManagedCluster( + location="test_location", + support_plan="AKSLongTermSupport", + sku=premiumSKU, + ) + self.assertEqual(ltsClusterCalculated, expectedLTSCluster) + + nonLTSDecorator = AKSManagedClusterCreateDecorator( + self.cmd, + self.client, + { + "k8s_support_plan": "KubernetesOfficial" + }, + ResourceType.MGMT_CONTAINERSERVICE, + ) + nonLTSDecorator.context.attach_mc(premiumCluster) + nonLTSClusterCalculated = nonLTSDecorator.set_up_k8s_support_plan(premiumCluster) + expectedNonLTSCluster = self.models.ManagedCluster( + location="test_location", + support_plan="KubernetesOfficial", + sku=premiumSKU, + ) + self.assertEqual(nonLTSClusterCalculated, expectedNonLTSCluster) + + def test_update_supportPlan(self): + # default value in `aks_create` + noopDecorator = AKSManagedClusterUpdateDecorator( + self.cmd, + self.client, + {}, + ResourceType.MGMT_CONTAINERSERVICE, + ) + + premiumSKU = self.models.ManagedClusterSKU( + name="Base", + tier="Premium") + ltsCluster = self.models.ManagedCluster( + location="test_location", + sku=premiumSKU, + support_plan="AKSLongTermSupport", + ) + noopDecorator.context.attach_mc(ltsCluster) + + # fail on passing the wrong mc object + with self.assertRaises(CLIInternalError): + noopDecorator.update_k8s_support_plan(None) + + ltsClusterCalculated = noopDecorator.update_k8s_support_plan(ltsCluster) + self.assertEqual(ltsClusterCalculated, ltsCluster) + + disableLTSDecorator = AKSManagedClusterUpdateDecorator( + self.cmd, + self.client, + { + "k8s_support_plan": "KubernetesOfficial" + }, + ResourceType.MGMT_CONTAINERSERVICE, + ) + disableLTSDecorator.context.attach_mc(ltsCluster) + nonLTSClusterCalculated = disableLTSDecorator.update_k8s_support_plan(ltsCluster) + expectedNonLTSCluster = self.models.ManagedCluster( + location="test_location", + support_plan="KubernetesOfficial", + sku=premiumSKU, + ) + self.assertEqual(nonLTSClusterCalculated, expectedNonLTSCluster) + + normalCluster = self.models.ManagedCluster( + location="test_location", + sku=self.models.ManagedClusterSKU( + name="Base", + tier="Standard"), + support_plan="KubernetesOfficial", + ) + noopDecorator3 = AKSManagedClusterUpdateDecorator( + self.cmd, + self.client, + {}, + ResourceType.MGMT_CONTAINERSERVICE, + ) + noopDecorator3.context.attach_mc(normalCluster) + normalClusterCalculated = noopDecorator3.update_k8s_support_plan(normalCluster) + self.assertEqual(normalClusterCalculated, normalCluster) + + if __name__ == "__main__": unittest.main()