Skip to content

Commit 7826334

Browse files
committed
unit test
1 parent f7e7947 commit 7826334

1 file changed

Lines changed: 167 additions & 0 deletions

File tree

src/aks-preview/azext_aks_preview/tests/latest/test_managed_cluster_decorator.py

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5002,6 +5002,63 @@ def test_get_disable_default_domain(self):
50025002
disable_default_domain_3 = ctx_3.get_disable_default_domain()
50035003
self.assertEqual(disable_default_domain_3, False)
50045004

5005+
def test_get_enable_continuous_control_plane_monitor(self):
5006+
# default value
5007+
ctx_0 = AKSPreviewManagedClusterContext(
5008+
self.cmd,
5009+
AKSManagedClusterParamDict({}),
5010+
self.models,
5011+
decorator_mode=DecoratorMode.CREATE,
5012+
)
5013+
self.assertEqual(ctx_0.get_enable_continuous_control_plane_monitor(), None)
5014+
5015+
# custom value - True
5016+
ctx_1 = AKSPreviewManagedClusterContext(
5017+
self.cmd,
5018+
AKSManagedClusterParamDict({"enable_continuous_control_plane_monitor": True}),
5019+
self.models,
5020+
decorator_mode=DecoratorMode.CREATE,
5021+
)
5022+
self.assertEqual(ctx_1.get_enable_continuous_control_plane_monitor(), True)
5023+
5024+
# custom value - False
5025+
ctx_2 = AKSPreviewManagedClusterContext(
5026+
self.cmd,
5027+
AKSManagedClusterParamDict({"enable_continuous_control_plane_monitor": False}),
5028+
self.models,
5029+
decorator_mode=DecoratorMode.CREATE,
5030+
)
5031+
self.assertEqual(ctx_2.get_enable_continuous_control_plane_monitor(), False)
5032+
5033+
def test_get_disable_continuous_control_plane_monitor(self):
5034+
# default value
5035+
ctx_0 = AKSPreviewManagedClusterContext(
5036+
self.cmd,
5037+
AKSManagedClusterParamDict({}),
5038+
self.models,
5039+
decorator_mode=DecoratorMode.UPDATE,
5040+
)
5041+
self.assertEqual(ctx_0.get_disable_continuous_control_plane_monitor(), None)
5042+
5043+
# custom value - True
5044+
ctx_1 = AKSPreviewManagedClusterContext(
5045+
self.cmd,
5046+
AKSManagedClusterParamDict({"disable_continuous_control_plane_monitor": True}),
5047+
self.models,
5048+
decorator_mode=DecoratorMode.UPDATE,
5049+
)
5050+
self.assertEqual(ctx_1.get_disable_continuous_control_plane_monitor(), True)
5051+
5052+
# custom value - False
5053+
ctx_2 = AKSPreviewManagedClusterContext(
5054+
self.cmd,
5055+
AKSManagedClusterParamDict({"disable_continuous_control_plane_monitor": False}),
5056+
self.models,
5057+
decorator_mode=DecoratorMode.UPDATE,
5058+
)
5059+
self.assertEqual(ctx_2.get_disable_continuous_control_plane_monitor(), False)
5060+
5061+
50055062
class AKSPreviewManagedClusterCreateDecoratorTestCase(unittest.TestCase):
50065063
def setUp(self):
50075064
# manually register CUSTOM_MGMT_AKS_PREVIEW
@@ -7463,6 +7520,41 @@ def test_get_enable_azure_monitor_logs_create_mode_succeeds(self):
74637520
self.assertTrue(result)
74647521

74657522

7523+
def test_set_up_health_monitor_profile(self):
7524+
# no flag - no change
7525+
dec_0 = AKSPreviewManagedClusterCreateDecorator(
7526+
self.cmd,
7527+
self.client,
7528+
{},
7529+
CUSTOM_MGMT_AKS_PREVIEW,
7530+
)
7531+
mc_0 = self.models.ManagedCluster(location="test_location")
7532+
dec_0.context.attach_mc(mc_0)
7533+
dec_mc_0 = dec_0.set_up_health_monitor_profile(mc_0)
7534+
ground_truth_mc_0 = self.models.ManagedCluster(location="test_location")
7535+
self.assertEqual(dec_mc_0, ground_truth_mc_0)
7536+
7537+
# enable flag set
7538+
dec_1 = AKSPreviewManagedClusterCreateDecorator(
7539+
self.cmd,
7540+
self.client,
7541+
{
7542+
"enable_continuous_control_plane_monitor": True,
7543+
},
7544+
CUSTOM_MGMT_AKS_PREVIEW,
7545+
)
7546+
mc_1 = self.models.ManagedCluster(location="test_location")
7547+
dec_1.context.attach_mc(mc_1)
7548+
dec_mc_1 = dec_1.set_up_health_monitor_profile(mc_1)
7549+
ground_truth_mc_1 = self.models.ManagedCluster(
7550+
location="test_location",
7551+
health_monitor_profile=self.models.ManagedClusterHealthMonitorProfile(
7552+
enable_continuous_control_plane_and_addon_monitor=True,
7553+
),
7554+
)
7555+
self.assertEqual(dec_mc_1, ground_truth_mc_1)
7556+
7557+
74667558
class AKSPreviewManagedClusterUpdateDecoratorTestCase(unittest.TestCase):
74677559
def setUp(self):
74687560
# manually register CUSTOM_MGMT_AKS_PREVIEW
@@ -13803,5 +13895,80 @@ def test_update_agentpool_profile_with_empty_agent_pool_profiles(self):
1380313895
with self.assertRaises(UnknownError):
1380413896
dec_4.update_agentpool_profile(mc_4)
1380513897

13898+
def test_update_health_monitor_profile(self):
13899+
# no flags - no change
13900+
dec_0 = AKSPreviewManagedClusterUpdateDecorator(
13901+
self.cmd,
13902+
self.client,
13903+
{},
13904+
CUSTOM_MGMT_AKS_PREVIEW,
13905+
)
13906+
mc_0 = self.models.ManagedCluster(location="test_location")
13907+
dec_0.context.attach_mc(mc_0)
13908+
dec_mc_0 = dec_0.update_health_monitor_profile(mc_0)
13909+
ground_truth_mc_0 = self.models.ManagedCluster(location="test_location")
13910+
self.assertEqual(dec_mc_0, ground_truth_mc_0)
13911+
13912+
# both flags - mutual exclusivity error
13913+
dec_1 = AKSPreviewManagedClusterUpdateDecorator(
13914+
self.cmd,
13915+
self.client,
13916+
{
13917+
"enable_continuous_control_plane_monitor": True,
13918+
"disable_continuous_control_plane_monitor": True,
13919+
},
13920+
CUSTOM_MGMT_AKS_PREVIEW,
13921+
)
13922+
mc_1 = self.models.ManagedCluster(location="test_location")
13923+
dec_1.context.attach_mc(mc_1)
13924+
with self.assertRaises(MutuallyExclusiveArgumentError):
13925+
dec_1.update_health_monitor_profile(mc_1)
13926+
13927+
# enable flag
13928+
dec_2 = AKSPreviewManagedClusterUpdateDecorator(
13929+
self.cmd,
13930+
self.client,
13931+
{
13932+
"enable_continuous_control_plane_monitor": True,
13933+
},
13934+
CUSTOM_MGMT_AKS_PREVIEW,
13935+
)
13936+
mc_2 = self.models.ManagedCluster(location="test_location")
13937+
dec_2.context.attach_mc(mc_2)
13938+
dec_mc_2 = dec_2.update_health_monitor_profile(mc_2)
13939+
ground_truth_mc_2 = self.models.ManagedCluster(
13940+
location="test_location",
13941+
health_monitor_profile=self.models.ManagedClusterHealthMonitorProfile(
13942+
enable_continuous_control_plane_and_addon_monitor=True,
13943+
),
13944+
)
13945+
self.assertEqual(dec_mc_2, ground_truth_mc_2)
13946+
13947+
# disable flag on existing enabled profile
13948+
dec_3 = AKSPreviewManagedClusterUpdateDecorator(
13949+
self.cmd,
13950+
self.client,
13951+
{
13952+
"disable_continuous_control_plane_monitor": True,
13953+
},
13954+
CUSTOM_MGMT_AKS_PREVIEW,
13955+
)
13956+
mc_3 = self.models.ManagedCluster(
13957+
location="test_location",
13958+
health_monitor_profile=self.models.ManagedClusterHealthMonitorProfile(
13959+
enable_continuous_control_plane_and_addon_monitor=True,
13960+
),
13961+
)
13962+
dec_3.context.attach_mc(mc_3)
13963+
dec_mc_3 = dec_3.update_health_monitor_profile(mc_3)
13964+
ground_truth_mc_3 = self.models.ManagedCluster(
13965+
location="test_location",
13966+
health_monitor_profile=self.models.ManagedClusterHealthMonitorProfile(
13967+
enable_continuous_control_plane_and_addon_monitor=False,
13968+
),
13969+
)
13970+
self.assertEqual(dec_mc_3, ground_truth_mc_3)
13971+
13972+
1380613973
if __name__ == "__main__":
1380713974
unittest.main()

0 commit comments

Comments
 (0)