Exemplo n.º 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'])
Exemplo n.º 2
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'])
Exemplo n.º 3
0
def cook_hosts():
    b = Bundle.obj.create(name='ssh', version='1.0')
    hpp = Prototype.obj.create(bundle=b, type='provider', name='Cloud')
    provider = HostProvider.obj.create(name='Fort', prototype=hpp)
    hp = Prototype.obj.create(bundle=b, type='host', name='Simple')

    host1 = api.add_host(hp, provider, 'host1.net')
    host2 = api.add_host(hp, provider, 'host2.net')
    host3 = api.add_host(hp, provider, 'host3.net')

    return (provider, host1, host2, host3)
Exemplo n.º 4
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'])
Exemplo n.º 5
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'])
Exemplo n.º 6
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'])
Exemplo n.º 7
0
 def test_host_in_cluster(self):
     cls = cook_cluster()
     provider, hp = cook_provider()
     h1 = add_host(hp, provider, 'h10')
     limits = {"source": {"type": "builtin", "name": "host_in_cluster"}}
     self.assertEqual(get_variant(cls, None, limits), [])
     add_host_to_cluster(cls, h1)
     self.assertEqual(get_variant(cls, None, limits), ['h10'])
Exemplo n.º 8
0
 def test_host_in_cluster_service(self):
     cls = cook_cluster()
     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')
     limits = {"source": {"type": "builtin", "name": "host_in_cluster"}}
     self.assertEqual(get_variant(cls, None, limits), [])
     add_host_to_cluster(cls, h1)
     add_host_to_cluster(cls, h2)
     self.assertEqual(get_variant(cls, None, limits), ['h10', 'h11'])
     limits['source']['args'] = {'service': 'QWE'}
     self.assertEqual(get_variant(cls, None, limits), [])
     self.add_hc(cluster=cls, service=service, component=comp1, host=h2)
     self.assertEqual(get_variant(cls, None, limits), [])
     limits['source']['args']['service'] = 'UBER'
     self.assertEqual(get_variant(cls, None, limits), ['h11'])
Exemplo n.º 9
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'])