Esempio n. 1
0
class BaseAKSManagedClusterDecoratorTestCase(unittest.TestCase):
    def setUp(self):
        self.cli_ctx = MockCLI()
        self.cmd = MockCmd(self.cli_ctx)
        self.client = MockClient()
        self.test_models = BaseAKSModels(self.cmd, ResourceType.MGMT_CONTAINERSERVICE)

    def test_init(self):
        dec_1 = BaseAKSManagedClusterDecorator(self.cmd, self.client)
        self.assertEqual(dec_1.cmd, self.cmd)
        self.assertEqual(dec_1.client, self.client)

    def test_init_models(self):
        dec_1 = BaseAKSManagedClusterDecorator(self.cmd, self.client)
        with self.assertRaises(NotImplementedError):
            dec_1.init_models()

    def test_init_context(self):
        dec_1 = BaseAKSManagedClusterDecorator(self.cmd, self.client)
        with self.assertRaises(NotImplementedError):
            dec_1.init_context()

    def test_check_is_postprocessing_required(self):
        dec_1 = BaseAKSManagedClusterDecorator(self.cmd, self.client)
        mc_1 = self.test_models.ManagedCluster(location="test_location")
        with self.assertRaises(NotImplementedError):
            dec_1.check_is_postprocessing_required(mc_1)

    def test_immediate_processing_after_request(self):
        dec_1 = BaseAKSManagedClusterDecorator(self.cmd, self.client)
        mc_1 = self.test_models.ManagedCluster(location="test_location")
        with self.assertRaises(NotImplementedError):
            dec_1.immediate_processing_after_request(mc_1)

    def test_postprocessing_after_mc_created(self):
        dec_1 = BaseAKSManagedClusterDecorator(self.cmd, self.client)
        mc_1 = self.test_models.ManagedCluster(location="test_location")
        with self.assertRaises(NotImplementedError):
            dec_1.postprocessing_after_mc_created(mc_1)

    def test_put_mc(self):
        dec_1 = BaseAKSManagedClusterDecorator(self.cmd, self.client)
        mc_1 = self.test_models.ManagedCluster(location="test_location")
        with self.assertRaises(NotImplementedError):
            dec_1.put_mc(mc_1)
Esempio n. 2
0
    def test_serialize(self):
        models = BaseAKSModels(self.cmd, ResourceType.MGMT_CONTAINERSERVICE)

        agentpool = models.AgentPool(os_disk_size_gb=2049)
        # fail on os_disk_size_gb > 2048
        with self.assertRaises(ValidationError):
            models.serialize(agentpool, "AgentPool")

        agentpool_upgrade_settings = models.AgentPoolUpgradeSettings()
        self.assertEqual(models.serialize(agentpool_upgrade_settings, "AgentPoolUpgradeSettings"), {})
Esempio n. 3
0
    def test_models(self):
        # load models directly (instead of through the `get_sdk` method provided by the cli component)
        from azure.cli.core.profiles._shared import AZURE_API_PROFILES

        sdk_profile = AZURE_API_PROFILES["latest"][ResourceType.MGMT_CONTAINERSERVICE]
        api_version = sdk_profile.default_api_version
        module_name = "azure.mgmt.containerservice.v{}.models".format(api_version.replace("-", "_"))
        module = importlib.import_module(module_name)

        models = BaseAKSModels(self.cmd, ResourceType.MGMT_CONTAINERSERVICE)
        self.assertEqual(models.model_module, module)
        self.assertEqual(models.AgentPool, module.AgentPool)
Esempio n. 4
0
 def setUp(self):
     self.cli_ctx = MockCLI()
     self.cmd = MockCmd(self.cli_ctx)
     self.models = BaseAKSModels(self.cmd, ResourceType.MGMT_CONTAINERSERVICE)
Esempio n. 5
0
class DecoratorFunctionsTestCase(unittest.TestCase):
    def setUp(self):
        self.cli_ctx = MockCLI()
        self.cmd = MockCmd(self.cli_ctx)
        self.models = BaseAKSModels(self.cmd,
                                    ResourceType.MGMT_CONTAINERSERVICE)

    def test_format_parameter_name_to_option_name(self):
        self.assertEqual(format_parameter_name_to_option_name("abc_xyz"),
                         "--abc-xyz")

    def test_safe_list_get(self):
        list_1 = [1, 2, 3]
        self.assertEqual(safe_list_get(list_1, 0), 1)
        self.assertEqual(safe_list_get(list_1, 10), None)

        tuple_1 = (1, 2, 3)
        self.assertEqual(safe_list_get(tuple_1, 0), None)

    def test_safe_lower(self):
        self.assertEqual(safe_lower(None), None)
        self.assertEqual(safe_lower("ABC"), "abc")

    def test_get_property_from_dict_or_object(self):
        self.assertEqual(
            get_property_from_dict_or_object({"abc": "xyz"}, "abc"), "xyz")
        self.assertEqual(
            get_property_from_dict_or_object(Mock(abc="xyz"), "abc"), "xyz")
        with self.assertRaises(KeyError):
            self.assertEqual(get_property_from_dict_or_object({}, "abc"),
                             "xyz")
        with self.assertRaises(AttributeError):
            self.assertEqual(get_property_from_dict_or_object(object(), "abc"),
                             "xyz")

    def test_check_is_msi_cluster(self):
        self.assertEqual(check_is_msi_cluster(None), False)

        mc_1 = self.models.ManagedCluster(
            location="test_location",
            identity=self.models.ManagedClusterIdentity(type="SystemAssigned"),
        )
        self.assertEqual(check_is_msi_cluster(mc_1), True)

        mc_2 = self.models.ManagedCluster(
            location="test_location",
            identity=self.models.ManagedClusterIdentity(type="UserAssigned"),
        )
        self.assertEqual(check_is_msi_cluster(mc_2), True)

        mc_3 = self.models.ManagedCluster(
            location="test_location",
            identity=self.models.ManagedClusterIdentity(type="Test"),
        )
        self.assertEqual(check_is_msi_cluster(mc_3), False)

    def test_check_is_private_cluster(self):
        self.assertEqual(check_is_private_cluster(None), False)

        mc_1 = self.models.ManagedCluster(
            location="test_location",
            api_server_access_profile=self.models.
            ManagedClusterAPIServerAccessProfile(
                enable_private_cluster=True, ),
        )
        self.assertEqual(check_is_private_cluster(mc_1), True)

        mc_2 = self.models.ManagedCluster(
            location="test_location",
            api_server_access_profile=self.models.
            ManagedClusterAPIServerAccessProfile(
                enable_private_cluster=False, ),
        )
        self.assertEqual(check_is_private_cluster(mc_2), False)

        mc_3 = self.models.ManagedCluster(
            location="test_location",
            api_server_access_profile=self.models.
            ManagedClusterAPIServerAccessProfile(),
        )
        self.assertEqual(check_is_private_cluster(mc_3), False)

        mc_4 = self.models.ManagedCluster(location="test_location", )
        self.assertEqual(check_is_private_cluster(mc_4), False)

    def test_check_is_managed_aad_cluster(self):
        self.assertEqual(check_is_managed_aad_cluster(None), False)

        mc_1 = self.models.ManagedCluster(location="test_location", )
        self.assertEqual(check_is_managed_aad_cluster(mc_1), False)

        mc_2 = self.models.ManagedCluster(
            location="test_location",
            aad_profile=self.models.ManagedClusterAADProfile(managed=True, ),
        )
        self.assertEqual(check_is_managed_aad_cluster(mc_2), True)