Exemple #1
0
    def test_KubernetesResourceDefinitionGeneral(self):
        instance = KubernetesResourceDefinition(kind="1.2.3.4",
                                                apiVersion="v1",
                                                metadata="metadata",
                                                spec="spec")

        self.assertEqual(instance.kind, "4")
        self.assertEqual(instance.api_version, "v1")
        self.assertEqual(instance.metadata, "metadata")
        self.assertEqual(instance.spec, "spec")
Exemple #2
0
    def test_KubernetesConfig(self):
        instance = KubernetesResourceDefinition(kind="1.2.3.4",
                                                apiVersion="v1",
                                                metadata="metadata",
                                                data="data")

        self.assertEqual(instance.kind, "4")
        self.assertEqual(instance.api_version, "v1")
        self.assertEqual(instance.metadata, "metadata")
        self.assertEqual(instance.data, "data")
Exemple #3
0
    def test_KubernetesResourceDefinitionStorage(self):
        instance = KubernetesResourceDefinition(kind="1.2.3.4",
                                                apiVersion="v1",
                                                metadata="metadata",
                                                parameters="parameters",
                                                provisioner="provisioner")

        self.assertEqual(instance.kind, "4")
        self.assertEqual(instance.api_version, "v1")
        self.assertEqual(instance.metadata, "metadata")
        self.assertEqual(instance.parameters, "parameters")
        self.assertEqual(instance.provisioner, "provisioner")
Exemple #4
0
    def test_KubernetesRole(self):
        instance = KubernetesResourceDefinition(kind="1.2.3.4",
                                                apiVersion="v1",
                                                metadata="metadata",
                                                roleRef="roleRef",
                                                subjects="subjects")

        self.assertEqual(instance.kind, "4")
        self.assertEqual(instance.api_version, "v1")
        self.assertEqual(instance.metadata, "metadata")
        self.assertEqual(instance.role_ref, "roleRef")
        self.assertEqual(instance.subjects, "subjects")
Exemple #5
0
    def test_execute_update_resource(self):

        instance, mappingMock = self._prepere_mocks()

        self.assertEqual(
            instance.update_resource(
                mappingMock,
                KubernetesResourceDefinition(kind="1.2.3.4",
                                             apiVersion="v1",
                                             metadata={"name": 'name1'},
                                             spec="spec"),
                {'first': 'b'}
            ).to_dict(),
            {
                'body': {'payload_param': 'payload_value'},
                'first': 'b'
            }
        )
Exemple #6
0
    def test_execute_create_role_resource(self):

        instance, mappingMock = self._prepere_mocks()

        self.assertEqual(
            instance.create_resource(
                mappingMock,
                KubernetesResourceDefinition(kind="ClusterRoleBinding",
                                             apiVersion="v1",
                                             metadata="metadata",
                                             roleRef="roleRef",
                                             subjects="subjects"),
                {'first': 'b'}
            ).to_dict(),
            {
                'body': {'payload_param': 'payload_value'},
                'first': 'b'
            }
        )
    def test_resource_task_retrieve_NonRecoverableError(self):
        _, _ctx = self._prepare_master_node()

        decorators.resource_task(MagicMock(), MagicMock())(MagicMock())()

        mock_isfile = MagicMock(return_value=True)
        _ctx.download_resource = MagicMock(return_value="downloaded_resource")

        defintion = KubernetesResourceDefinition(
            **_ctx.node.properties['definition'])

        with patch('os.path.isfile', mock_isfile):
            with self.assertRaises(NonRecoverableError) as error:
                decorators.resource_task(
                    retrieve_resources_definitions=MagicMock(
                        return_value=[defintion]),
                    retrieve_mapping=MagicMock(),
                    use_existing=True)(MagicMock(
                        side_effect=NonRecoverableError('error_text')))()

        self.assertEqual(str(error.exception), "error_text")