Пример #1
0
    def test_dict_merge_simple(self):
        a = {'key': 'value'}
        b = {'key': 'value'}

        c = utils.dict_merge(a, b)
        self.assertEqual(c, {'key': 'value'})

        a = {'key': 'value'}
        b = {'key2': 'value'}

        c = utils.dict_merge(a, b)
        self.assertEqual(c, {'key': 'value', 'key2': 'value'})
Пример #2
0
    def test_dict_merge_simple(self):
        a = {'key': 'value'}
        b = {'key': 'value'}

        c = utils.dict_merge(a, b)
        self.assertEqual(c, {'key': 'value'})

        a = {'key': 'value'}
        b = {'key2': 'value'}

        c = utils.dict_merge(a, b)
        self.assertEqual(c, {'key': 'value', 'key2': 'value'})
Пример #3
0
    def test_dict_merge_with_list(self):
        a = {'key': 'value', 'names': ['bob', 'kyle', 'kenny', 'jimbo']}
        b = {'key': 'value', 'names': ['kenny', 'cartman', 'stan']}

        c = utils.dict_merge(a, b)
        self.assertEqual(c, {'key': 'value', 'names': ['bob', 'kyle', 'kenny',
                                                       'jimbo', 'cartman', 'stan']})

        a = {'key': 'value', 'names': ['bob', 'kyle', 'kenny', 'jimbo']}
        b = {'key': 'value', 'last_names': ['kenny', 'cartman', 'stan']}

        c = utils.dict_merge(a, b)
        self.assertEqual(c, {'key': 'value',
                             'names': ['bob', 'kyle', 'kenny', 'jimbo'],
                             'last_names': ['kenny', 'cartman', 'stan']})
Пример #4
0
    def test_dict_merge_bad_merge(self):
        """Returns b because it isn't a dict"""
        a = {'key': 'value'}
        b = 'duh'

        c = utils.dict_merge(a, b)
        self.assertEqual(c, b)
Пример #5
0
    def create(self, namespace_name, name, **kwargs):
        """
        Create resource quota for namespace
        """
        url = self.api("/namespaces/{}/resourcequotas".format(namespace_name))
        manifest = {
            "kind": "ResourceQuota",
            "apiVersion": "v1",
            "metadata": {
                "namespace": namespace_name,
                "name": name,
                'labels': {
                    'app': namespace_name,
                    'heritage': 'deis'
                },
            },
            'spec': {}
        }

        data = dict_merge(manifest, kwargs.get('data', {}))
        response = self.http_post(url, json=data)
        if not response.status_code == 201:
            raise KubeHTTPException(
                response, "create quota {} for namespace {}".format(
                    name, namespace_name))

        return response
Пример #6
0
    def test_dict_merge_bad_merge(self):
        """Returns b because it isn't a dict"""
        a = {'key': 'value'}
        b = 'duh'

        c = utils.dict_merge(a, b)
        self.assertEqual(c, b)
Пример #7
0
    def test_dict_merge_even_deeper(self):
        a = {
            'key': 'value',
            'here': {'without': 'you'},
            'other': {'scrubs': {'char3': 'Cox'}}

        }

        b = {
            'this': 'that',
            'here': {'with': 'me'},
            'other': {'magic': 'unicorn', 'scrubs': {'char1': 'JD', 'char2': 'Turk'}}
        }

        c = utils.dict_merge(a, b)
        self.assertEqual(c, {
            'key': 'value',
            'this': 'that',
            'here': {'with': 'me', 'without': 'you'},
            'other': {
                'magic': 'unicorn',
                'scrubs': {
                    'char1': 'JD',
                    'char2': 'Turk',
                    'char3': 'Cox'
                }
            }
        })
Пример #8
0
 def test_dict_merge_not_dict(self):
     """
     second item is not a dict, which dict_merge will just return
     """
     a = {'key': 'value'}
     b = 'somethig'
     c = utils.dict_merge(a, b)
     self.assertEqual(c, b)
Пример #9
0
 def test_dict_merge_not_dict(self):
     """
     second item is not a dict, which dict_merge will just return
     """
     a = {'key': 'value'}
     b = 'somethig'
     c = utils.dict_merge(a, b)
     self.assertEqual(c, b)
Пример #10
0
    def test_dict_merge_with_list(self):
        a = {'key': 'value', 'names': ['bob', 'kyle', 'kenny', 'jimbo']}
        b = {'key': 'value', 'names': ['kenny', 'cartman', 'stan']}

        c = utils.dict_merge(a, b)
        self.assertEqual(
            c, {
                'key': 'value',
                'names': ['bob', 'kyle', 'kenny', 'jimbo', 'cartman', 'stan']
            })

        a = {'key': 'value', 'names': ['bob', 'kyle', 'kenny', 'jimbo']}
        b = {'key': 'value', 'last_names': ['kenny', 'cartman', 'stan']}

        c = utils.dict_merge(a, b)
        self.assertEqual(
            c, {
                'key': 'value',
                'names': ['bob', 'kyle', 'kenny', 'jimbo'],
                'last_names': ['kenny', 'cartman', 'stan']
            })
Пример #11
0
    def test_dict_merge_deeper(self):
        a = {'key': 'value', 'here': {'without': 'you'}}
        b = {'this': 'that', 'here': {'with': 'me'}, 'other': {'magic', 'unicorn'}}

        c = utils.dict_merge(a, b)
        self.assertEqual(c, {
            'key': 'value',
            'this': 'that',
            'here': {
                'with': 'me',
                'without': 'you'
            },
            'other': {'magic', 'unicorn'}
        })
Пример #12
0
    def test_dict_merge_even_deeper(self):
        a = {
            'key': 'value',
            'here': {
                'without': 'you'
            },
            'other': {
                'scrubs': {
                    'char3': 'Cox'
                }
            }
        }

        b = {
            'this': 'that',
            'here': {
                'with': 'me'
            },
            'other': {
                'magic': 'unicorn',
                'scrubs': {
                    'char1': 'JD',
                    'char2': 'Turk'
                }
            }
        }

        c = utils.dict_merge(a, b)
        self.assertEqual(
            c, {
                'key': 'value',
                'this': 'that',
                'here': {
                    'with': 'me',
                    'without': 'you'
                },
                'other': {
                    'magic': 'unicorn',
                    'scrubs': {
                        'char1': 'JD',
                        'char2': 'Turk',
                        'char3': 'Cox'
                    }
                }
            })
Пример #13
0
    def test_dict_merge_deeper(self):
        a = {'key': 'value', 'here': {'without': 'you'}}
        b = {
            'this': 'that',
            'here': {
                'with': 'me'
            },
            'other': {'magic', 'unicorn'}
        }

        c = utils.dict_merge(a, b)
        self.assertEqual(
            c, {
                'key': 'value',
                'this': 'that',
                'here': {
                    'with': 'me',
                    'without': 'you'
                },
                'other': {'magic', 'unicorn'}
            })
Пример #14
0
    def create(self, namespace_name, name, **kwargs):
        """
        Create resource quota for namespace
        """
        url = self.api("/namespaces/{}/resourcequotas".format(namespace_name))
        manifest = {
            "kind": "ResourceQuota",
            "apiVersion": "v1",
            "metadata": {
                "namespace": namespace_name,
                "name": name,
                "labels": {"app": namespace_name, "heritage": "deis"},
            },
            "spec": {},
        }

        data = dict_merge(manifest, kwargs.get("data", {}))
        response = self.http_post(url, json=data)
        if not response.status_code == 201:
            raise KubeHTTPException(response, "create quota {} for namespace {}".format(name, namespace_name))

        return response
Пример #15
0
    def create(self, namespace, name, **kwargs):
        # Ports and app type will be overwritten as required
        manifest = {
            'kind': 'Service',
            'apiVersion': 'v1',
            'metadata': {
                'name': name,
                'labels': {
                    'app': namespace,
                    'heritage': 'deis'
                },
                'annotations': {}
            },
            'spec': {
                'ports': [{
                    'name': 'http',
                    'port': 80,
                    'targetPort': 5000,
                    'protocol': 'TCP'
                }],
                'selector': {
                    'app': namespace,
                    'heritage': 'deis'
                }
            }
        }

        data = dict_merge(manifest, kwargs.get('data', {}))
        url = self.api("/namespaces/{}/services", namespace)
        response = self.http_post(url, json=data)
        if self.unhealthy(response.status_code):
            raise KubeHTTPException(
                response,
                'create Service "{}" in Namespace "{}"', namespace, namespace
            )

        return response
Пример #16
0
    def create(self, namespace, name, **kwargs):
        # Ports and app type will be overwritten as required
        manifest = {
            'kind': 'Service',
            'apiVersion': 'v1',
            'metadata': {
                'name': name,
                'labels': {
                    'app': namespace,
                    'heritage': 'drycc'
                },
                'annotations': {}
            },
            'spec': {
                'ports': [{
                    'name': 'http',
                    'port': 80,
                    'targetPort': 5000,
                    'protocol': 'TCP'
                }],
                'selector': {
                    'app': namespace,
                    'heritage': 'drycc'
                }
            }
        }

        data = dict_merge(manifest, kwargs.get('data', {}))
        url = self.api("/namespaces/{}/services", namespace)
        response = self.http_post(url, json=data)
        if self.unhealthy(response.status_code):
            raise KubeHTTPException(response,
                                    'create Service "{}" in Namespace "{}"',
                                    namespace, namespace)

        return response