Пример #1
0
 def test_load_balancer_update_state(self):
     self.truncate_all_tables()
     db.load_balancer_create(self.context, self.configs)
     db.load_balancer_update_state(self.context,
                                   self.load_balancer_id, 'active')
     actual = db.load_balancer_get(self.context, self.load_balancer_id)
     self.assertEqual(actual.state, 'active')
Пример #2
0
    def test_create_load_balancer_failed_on_lb_create(self):
        def _raise_exception1(*args):
            raise exception.LoadBalancerNotFoundByName(
                load_balancer_name=self.create_kwargs['name'])

        def _raise_exception2(*args):
            raise Exception()

        self.mox.StubOutWithMock(db, 'load_balancer_create')
        self.mox.StubOutWithMock(db, 'load_balancer_get_by_name')
        self.mox.StubOutWithMock(utils, 'get_all_domain_names')
        self.mox.StubOutWithMock(utils, 'str_uuid')
        self.mox.StubOutWithMock(utils, 'gen_dns_prefix')
        db.load_balancer_get_by_name(
            self.ctxt, self.create_kwargs['name']).WithSideEffects(
                _raise_exception1).AndReturn(None)
        utils.get_all_domain_names().AndReturn(list())
        utils.str_uuid().AndReturn(self.uuid)
        utils.gen_dns_prefix().AndReturn(self.dns_prefix)
        db.load_balancer_create(
            self.ctxt, self.lb).WithSideEffects(
                _raise_exception2).AndReturn(None)
        self.mox.ReplayAll()
        self.assertRaises(exception.CreateLoadBalancerFailed,
                          http.create_load_balancer,
                          self.ctxt, **self.create_kwargs)
        self.mox.VerifyAll()
Пример #3
0
 def test_load_balancer_destroy(self):
     self.truncate_all_tables()
     db.load_balancer_create(self.context, self.configs)
     db.load_balancer_destroy(self.context, self.load_balancer_id)
     self.assertRaises(exception.LoadBalancerNotFound,
                       db.load_balancer_get,
                       self.context, self.load_balancer_id)
Пример #4
0
 def test_load_balancer_update_config(self):
     self.truncate_all_tables()
     db.load_balancer_create(self.context, self.configs)
     self.config['balancing_method'] = 'test_method'
     self.config['health_check_target_path'] = '/index.html'
     db.load_balancer_update_config(self.context,
                                    self.load_balancer_id, self.config)
     actual = db.load_balancer_get(self.context, self.load_balancer_id)
     config_ref = models.LoadBalancerConfig()
     config_ref.update(self.config)
     self.compare_records(actual.config, config_ref, skiped=['id'])
Пример #5
0
 def test_load_balancer_update_domains(self):
     self.truncate_all_tables()
     new_domains = [
         {'name': 'www.hao.com'},
         {'name': 'www.xyz.com'},
     ]
     db.load_balancer_create(self.context, self.configs)
     actual = db.load_balancer_get(self.context, self.load_balancer_id)
     db.load_balancer_update_domains(self.context,
                                     self.load_balancer_id, new_domains)
     actual = db.load_balancer_get(self.context, self.load_balancer_id)
     actual_domains = map(lambda x: x['name'], actual.domains)
     expect_domains = map(lambda x: x['name'], new_domains)
     self.assertEqual(expect_domains.sort(), actual_domains.sort())
Пример #6
0
    def test_create_load_balancer(self):
        def _raise_exception(*args):
            raise exception.LoadBalancerNotFoundByName(
                load_balancer_name=self.create_kwargs['name'])

        self.mox.StubOutWithMock(utils, 'get_all_domain_names')
        self.mox.StubOutWithMock(utils, 'str_uuid')
        self.mox.StubOutWithMock(utils, 'gen_dns_prefix')
        self.mox.StubOutWithMock(db, 'load_balancer_get_by_name')
        self.mox.StubOutWithMock(db, 'load_balancer_create')
        self.mox.StubOutWithMock(db, 'load_balancer_config_create')
        self.mox.StubOutWithMock(db, 'load_balancer_domain_create')
        self.mox.StubOutWithMock(
            db, 'load_balancer_instance_association_create')

        db.load_balancer_get_by_name(
            self.ctxt, self.create_kwargs['name']).WithSideEffects(
                _raise_exception).AndReturn(None)
        utils.get_all_domain_names().AndReturn(list())
        utils.str_uuid().AndReturn(self.uuid)
        utils.gen_dns_prefix().AndReturn(self.dns_prefix)
        db.load_balancer_create(self.ctxt, self.lb).AndReturn(self.lb_ref)
        db.load_balancer_config_create(
            self.ctxt, self.config).AndReturn(self.config_ref)
        for index, domain in enumerate(self.http_server_names):
            domain_values = {
                'load_balancer_id': self.load_balancer_id,
                'name': domain,
            }
            self.tmp = copy.deepcopy(domain_values)
            self.tmp['id'] = index + 1
            domain_ref = models.LoadBalancerDomain()
            domain_ref.update(self.tmp)
            db.load_balancer_domain_create(
                self.ctxt, domain_values).AndReturn(domain_ref)
        for uuid in self.create_kwargs['instance_uuids']:
            association_values = {
                'load_balancer_id': self.load_balancer_id,
                'instance_uuid': uuid,
            }
            association_ref = models.LoadBalancerInstanceAssociation()
            association_ref.update(association_values)
            db.load_balancer_instance_association_create(
                self.ctxt, association_values).AndReturn(association_ref)
        self.mox.ReplayAll()
        r = http.create_load_balancer(self.ctxt, **self.create_kwargs)
        self.mox.VerifyAll()
        self.assertEqual(r, {'data': {'uuid': self.uuid}})
Пример #7
0
 def test_load_balancer_update_instances(self):
     self.truncate_all_tables()
     new_instances = [
         {
             'instance_uuid': 'inst-1',
             'instance_ip': '192.168.1.1',
         },
         {
             'instance_uuid': 'inst-2',
             'instance_ip': '192.168.1.2',
         },
     ]
     db.load_balancer_create(self.context, self.configs)
     actual = db.load_balancer_get(self.context, self.load_balancer_id)
     db.load_balancer_update_instances(self.context,
                                       self.load_balancer_id, new_instances)
     actual = db.load_balancer_get(self.context, self.load_balancer_id)
     actual_instances = map(lambda x: x['instance_uuid'], actual.instances)
     expect_instances = map(lambda x: x['instance_uuid'], new_instances)
     self.assertEqual(expect_instances.sort(), actual_instances.sort())
Пример #8
0
    def test_create_load_balancer(self):
        def _raise_exception(*args):
            raise exception.LoadBalancerNotFoundByName(
                load_balancer_name=self.create_kwargs['name'])

        self.mox.StubOutWithMock(utils, 'str_uuid')
        self.mox.StubOutWithMock(utils, 'gen_dns_prefix')
        self.mox.StubOutWithMock(utils, 'allocate_listen_port')
        self.mox.StubOutWithMock(db, 'load_balancer_get_by_name')
        self.mox.StubOutWithMock(db, 'load_balancer_create')
        self.mox.StubOutWithMock(db, 'load_balancer_config_create')
        self.mox.StubOutWithMock(db, 'load_balancer_domain_create')
        self.mox.StubOutWithMock(
            db, 'load_balancer_instance_association_create')

        db.load_balancer_get_by_name(
            self.ctxt, self.create_kwargs['name']).WithSideEffects(
                _raise_exception).AndReturn(None)
        utils.str_uuid().AndReturn(self.uuid)
        utils.gen_dns_prefix().AndReturn(self.dns_prefix)
        utils.allocate_listen_port().AndReturn(self.listen_port)

        db.load_balancer_create(
            self.ctxt, self.lb_values).AndReturn(self.lb_ref)
        db.load_balancer_config_create(
            self.ctxt, self.config_values).AndReturn(self.config_ref)
        for uuid in self.create_kwargs['instance_uuids']:
            association_values = {
                'load_balancer_id': self.load_balancer_id,
                'instance_uuid': uuid,
            }
            association_ref = models.LoadBalancerInstanceAssociation()
            association_ref.update(association_values)
            db.load_balancer_instance_association_create(
                self.ctxt, association_values).AndReturn(association_ref)
        self.mox.ReplayAll()
        r = tcp.create_load_balancer(self.ctxt, **self.create_kwargs)
        self.mox.VerifyAll()
        self.assertEqual(r, {'data': {'uuid': self.uuid}})
Пример #9
0
    associated_instances = []

    try:
        load_balancer_values = {
            'name': kwargs['name'],
            'user_id': kwargs['user_id'],
            'project_id': kwargs['tenant_id'],
            'uuid': utils.str_uuid(),
            'free': kwargs['free'],
            'protocol': kwargs['protocol'],
            'state': state.CREATING,
            'dns_prefix': utils.gen_dns_prefix(),
            'listen_port': utils.allocate_listen_port(),
            'instance_port': kwargs['instance_port'],
        }
        load_balancer_ref = db.load_balancer_create(context,
                                                    load_balancer_values)

        config_values = {
            'load_balancer_id': load_balancer_ref.id,
            'balancing_method': config['balancing_method'],
            'health_check_timeout_ms': config['health_check_timeout_ms'],
            'health_check_interval_ms': config['health_check_interval_ms'],
            'health_check_target_path': '',
            'health_check_healthy_threshold':
            config['health_check_healthy_threshold'],
            'health_check_unhealthy_threshold':
            config['health_check_unhealthy_threshold'],
        }
        config_ref = db.load_balancer_config_create(context, config_values)
        # binding instances
        for uuid in kwargs['instance_uuids']:
Пример #10
0
 def test_load_balancer_create(self):
     self.truncate_all_tables()
     expect = db.load_balancer_create(self.context, self.configs)
     actual = db.load_balancer_get(self.context, expect.id)
     self.compare_records(expect, actual, skiped=['id'])