コード例 #1
0
 def test_host_in_hc(self):
     cls = cook_cluster()
     self.assertEqual(
         variant_host(cls, {
             'predicate': 'in_hc',
             'args': None
         }), [])
     service = cook_service(cls)
     comp1 = cook_component(cls, service, 'Server')
     provider, hp = cook_provider()
     h1 = add_host(hp, provider, 'h10')
     h2 = add_host(hp, provider, 'h11')
     add_host_to_cluster(cls, h1)
     add_host_to_cluster(cls, h2)
     self.assertEqual(
         variant_host(cls, {
             'predicate': 'in_hc',
             'args': None
         }), [])
     self.add_hc(cluster=cls, service=service, component=comp1, host=h2)
     self.assertEqual(
         variant_host(cls, {
             'predicate': 'in_hc',
             'args': None
         }), ['h11'])
コード例 #2
0
    def test_host_in_service(self):
        cls = cook_cluster()
        service = cook_service(cls)
        comp = cook_component(cls, service, 'Server')
        provider, hp = cook_provider()
        h1 = add_host(hp, provider, 'h10')
        add_host_to_cluster(cls, h1)
        self.add_hc(cluster=cls, service=service, component=comp, host=h1)
        with self.assertRaises(AdcmEx) as e:
            variant_host(cls, {'predicate': 'in_service', 'args': {}})
        self.assertEqual(e.exception.msg,
                         'no "service" argument for predicate "in_service"')
        with self.assertRaises(AdcmEx) as e:
            variant_host(cls, {
                'predicate': 'in_service',
                'args': {
                    'service': 'qwe'
                }
            })
        self.assertTrue('ClusterObject {' in e.exception.msg)
        self.assertTrue('} does not exist' in e.exception.msg)

        args = {'predicate': 'in_service', 'args': {'service': 'UBER'}}
        hosts = variant_host(cls, args)
        self.assertEqual(hosts, ['h10'])
コード例 #3
0
 def test_no_host_in_cluster(self):
     cls = cook_cluster()
     hosts = variant_host(cls, {'predicate': 'in_cluster', 'args': None})
     self.assertEqual(hosts, [])
     hosts = variant_host(cls, {'predicate': 'in_cluster', 'args': []})
     self.assertEqual(hosts, [])
     hosts = variant_host(cls, {'predicate': 'in_cluster', 'args': {}})
     self.assertEqual(hosts, [])
コード例 #4
0
    def test_host_and(self):
        cls = cook_cluster()
        service = cook_service(cls)
        comp1 = cook_component(cls, service, 'Server')
        comp2 = cook_component(cls, service, 'Node')
        provider, hp = cook_provider()
        h1 = add_host(hp, provider, 'h10')
        h2 = add_host(hp, provider, 'h11')
        h3 = add_host(hp, provider, 'h12')
        add_host_to_cluster(cls, h1)
        add_host_to_cluster(cls, h2)
        add_host_to_cluster(cls, h3)
        self.add_hc(cluster=cls, service=service, component=comp1, host=h1)
        self.add_hc(cluster=cls, service=service, component=comp2, host=h2)
        self.add_hc(cluster=cls, service=service, component=comp2, host=h3)
        with self.assertRaises(AdcmEx) as e:
            variant_host(cls, {'predicate': 'and', 'args': 123})
        self.assertEqual(e.exception.msg,
                         'arguments of solver should be a list or a map')
        with self.assertRaises(AdcmEx) as e:
            variant_host(cls, {'predicate': 'and', 'args': [123]})
        self.assertEqual(e.exception.msg, 'predicte item should be a map')
        with self.assertRaises(AdcmEx) as e:
            args = {
                'predicate': 'and',
                'args': [{
                    'predicate': 'qwe',
                    'args': 123
                }]
            }
            variant_host(cls, args)
        self.assertEqual(e.exception.msg, 'no "qwe" in list of host functions')

        self.assertEqual(variant_host(cls, {
            'predicate': 'and',
            'args': []
        }), [])
        args = {
            'predicate':
            'and',
            'args': [
                {
                    'predicate': 'in_service',
                    'args': {
                        'service': 'UBER'
                    }
                },
                {
                    'predicate': 'in_component',
                    'args': {
                        'service': 'UBER',
                        'component': 'Node'
                    }
                },
            ],
        }
        hosts = variant_host(cls, args)
        self.assertEqual(hosts, ['h11', 'h12'])
コード例 #5
0
 def test_host_in_cluster(self):
     cls = cook_cluster()
     provider, hp = cook_provider()
     h1 = add_host(hp, provider, 'h10')
     add_host_to_cluster(cls, h1)
     hosts = variant_host(cls, {'predicate': 'in_cluster', 'args': []})
     self.assertEqual(hosts, ['h10'])
コード例 #6
0
    def test_host_not_in_component(self):
        cls = cook_cluster()
        service = cook_service(cls)
        comp1 = cook_component(cls, service, 'Server')
        comp2 = cook_component(cls, service, 'Node')
        service2 = cook_service(cls, 'Gett')
        comp3 = cook_component(cls, service2, 'Server')
        provider, hp = cook_provider()
        h1 = add_host(hp, provider, 'h10')
        h2 = add_host(hp, provider, 'h11')
        h3 = add_host(hp, provider, 'h12')
        h4 = add_host(hp, provider, 'h13')
        add_host(hp, provider, 'h14')
        add_host_to_cluster(cls, h1)
        add_host_to_cluster(cls, h2)
        add_host_to_cluster(cls, h3)
        add_host_to_cluster(cls, h4)
        self.add_hc(cluster=cls, service=service, component=comp1, host=h1)
        self.add_hc(cluster=cls, service=service, component=comp2, host=h2)
        self.add_hc(cluster=cls, service=service2, component=comp3, host=h3)
        with self.assertRaises(AdcmEx) as e:
            variant_host(cls, {'predicate': 'not_in_component', 'args': []})
        self.assertEqual(
            e.exception.msg,
            'no "service" argument for predicate "not_in_component"')
        with self.assertRaises(AdcmEx) as e:
            variant_host(cls, {
                'predicate': 'not_in_component',
                'args': {
                    'service': 'qwe'
                }
            })
        self.assertTrue('ClusterObject {' in e.exception.msg)
        self.assertTrue('} does not exist' in e.exception.msg)
        with self.assertRaises(AdcmEx) as e:
            args = {
                'predicate': 'not_in_component',
                'args': {
                    'service': 'UBER',
                    'component': 'asd'
                },
            }
            variant_host(cls, args)
        self.assertTrue('ServiceComponent {' in e.exception.msg)
        self.assertTrue('} does not exist' in e.exception.msg)

        args = {
            'predicate': 'not_in_component',
            'args': {
                'service': 'UBER',
                'component': 'Node'
            }
        }
        self.assertEqual(variant_host(cls, args), ['h10', 'h12', 'h13'])
        args = {
            'predicate': 'not_in_component',
            'args': {
                'service': 'UBER',
                'component': 'Server'
            }
        }
        self.assertEqual(variant_host(cls, args), ['h11', 'h12', 'h13'])
        args = {
            'predicate': 'not_in_component',
            'args': {
                'service': 'Gett',
                'component': 'Server'
            }
        }
        self.assertEqual(variant_host(cls, args), ['h10', 'h11', 'h13'])
コード例 #7
0
    def test_host_in_component(self):
        cls = cook_cluster()
        service = cook_service(cls)
        comp1 = cook_component(cls, service, 'Server')
        comp2 = cook_component(cls, service, 'Node')
        provider, hp = cook_provider()
        h1 = add_host(hp, provider, 'h10')
        h2 = add_host(hp, provider, 'h11')
        add_host_to_cluster(cls, h1)
        add_host_to_cluster(cls, h2)
        self.add_hc(cluster=cls, service=service, component=comp1, host=h1)
        self.add_hc(cluster=cls, service=service, component=comp2, host=h2)
        with self.assertRaises(AdcmEx) as e:
            variant_host(cls, {'predicate': 'in_component'})
        self.assertEqual(e.exception.msg, 'no "args" key in solver args')
        with self.assertRaises(AdcmEx) as e:
            variant_host(cls, {'predicate': 'in_component', 'args': 123})
        self.assertEqual(e.exception.msg,
                         'arguments of solver should be a list or a map')
        with self.assertRaises(AdcmEx) as e:
            variant_host(cls, {'predicate': 'in_component', 'args': []})
        self.assertEqual(e.exception.msg,
                         'no "service" argument for predicate "in_component"')
        with self.assertRaises(AdcmEx) as e:
            variant_host(cls, {
                'predicate': 'in_component',
                'args': {
                    'service': 'qwe'
                }
            })
        self.assertTrue('ClusterObject {' in e.exception.msg)
        self.assertTrue('} does not exist' in e.exception.msg)
        with self.assertRaises(AdcmEx) as e:
            args = {
                'predicate': 'in_component',
                'args': {
                    'service': 'UBER',
                    'component': 'asd'
                }
            }
            variant_host(cls, args)
        self.assertTrue('ServiceComponent {' in e.exception.msg)
        self.assertTrue('} does not exist' in e.exception.msg)

        args = {
            'predicate': 'in_component',
            'args': {
                'service': 'UBER',
                'component': 'Node'
            }
        }
        hosts = variant_host(cls, args)
        self.assertEqual(hosts, ['h11'])
コード例 #8
0
    def test_solver(self):
        cls = cook_cluster()
        with self.assertRaises(AdcmEx) as e:
            self.assertEqual(variant_host(cls, {'any': 'dict'}),
                             {'any': 'dict'})
        self.assertEqual(
            e.exception.msg,
            'no "predicate" key in variant host function arguments')

        with self.assertRaises(AdcmEx) as e:
            self.assertEqual(variant_host(cls, {}), {})
        self.assertEqual(
            e.exception.msg,
            'no "predicate" key in variant host function arguments')
        with self.assertRaises(AdcmEx) as e:
            self.assertEqual(variant_host(cls, []), [])
        self.assertEqual(e.exception.msg,
                         'arguments of variant host function should be a map')
        with self.assertRaises(AdcmEx) as e:
            variant_host(cls, 42)
        self.assertEqual(e.exception.msg,
                         'arguments of variant host function should be a map')
        with self.assertRaises(AdcmEx) as e:
            variant_host(cls, 'qwe')
        self.assertEqual(e.exception.msg,
                         'arguments of variant host function should be a map')
        with self.assertRaises(AdcmEx) as e:
            variant_host(cls, {'predicate': 'qwe'})
        self.assertEqual(e.exception.msg, 'no "qwe" in list of host functions')
        with self.assertRaises(AdcmEx) as e:
            variant_host(cls, {'predicate': 'inline_list'})
        self.assertEqual(e.exception.msg, 'no "args" key in solver args')
        with self.assertRaises(AdcmEx) as e:
            var_host_solver(cls, VARIANT_HOST_FUNC, [{"qwe": 1}])
        self.assertEqual(e.exception.msg, 'no "predicate" key in solver args')
        with self.assertRaises(AdcmEx) as e:
            var_host_solver(cls, VARIANT_HOST_FUNC, [{"predicate": 'qwe'}])
        self.assertEqual(e.exception.msg, 'no "args" key in solver args')
        with self.assertRaises(AdcmEx) as e:
            var_host_solver(cls, VARIANT_HOST_FUNC, [{
                "predicate": 'qwe',
                'args': {}
            }])
        self.assertEqual(e.exception.msg, 'no "qwe" in list of host functions')

        args = {'predicate': 'inline_list', 'args': {'list': [1, 2, 3]}}
        self.assertEqual(variant_host(cls, args), [1, 2, 3])
        args = {
            'predicate':
            'and',
            'args': [
                {
                    'predicate': 'inline_list',
                    'args': {
                        'list': [1, 2, 3]
                    }
                },
                {
                    'predicate': 'inline_list',
                    'args': {
                        'list': [2, 3, 4]
                    }
                },
            ],
        }
        self.assertEqual(variant_host(cls, args), [2, 3])
        args = {
            'predicate':
            'or',
            'args': [
                {
                    'predicate': 'inline_list',
                    'args': {
                        'list': [1, 2, 3]
                    }
                },
                {
                    'predicate': 'inline_list',
                    'args': {
                        'list': [2, 3, 4]
                    }
                },
            ],
        }
        self.assertEqual(variant_host(cls, args), [1, 2, 3, 4])
        args = {
            'predicate': 'or',
            'args': [
                {
                    'predicate': 'inline_list',
                    'args': {
                        'list': [1, 2, 3]
                    }
                },
            ],
        }
        self.assertEqual(variant_host(cls, args), [1, 2, 3])