Skip to content

Commit

Permalink
AKS] az aks update: Fix bug where supportPlan can be reset to None (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
andyliuliming authored Oct 24, 2023
1 parent 224043a commit 2468810
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 2468810

Please sign in to comment.