示例#1
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}})
示例#2
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}})
示例#3
0
    def test_update_load_balancer_config(self):
        update_kwargs = copy.deepcopy(self.delete_kwargs)
        update_kwargs['config'] = self.config

        self.mox.StubOutWithMock(db, 'load_balancer_get_by_uuid')
        self.mox.StubOutWithMock(db, 'load_balancer_config_create')
        self.mox.StubOutWithMock(db, 'load_balancer_config_destroy')
        self.mox.StubOutWithMock(db, 'load_balancer_update_state')

        load_balancer_ref = self.lb_ref
        load_balancer_ref.config = self.config_ref
        db.load_balancer_get_by_uuid(
            self.ctxt, self.uuid).AndReturn(load_balancer_ref)
        db.load_balancer_config_destroy(
            self.ctxt, load_balancer_ref.config.id).AndReturn(None)
        db.load_balancer_config_create(
            self.ctxt, self.config).AndReturn(self.config_ref)
        db.load_balancer_update_state(
            self.ctxt, self.uuid, state.UPDATING).AndReturn(None)
        self.mox.ReplayAll()
        r = http.update_load_balancer_config(self.ctxt, **update_kwargs)
        self.mox.VerifyAll()
        self.assertEqual(r, None)
示例#4
0
文件: tcp.py 项目: ljjjustin/nozzle
        }
        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']:
            association = {
                'load_balancer_id': load_balancer_ref.id,
                'instance_uuid': uuid,
            }
            db.load_balancer_instance_association_create(context, association)
            associated_instances.append(uuid)
    except Exception, exp:
        if load_balancer_ref:
            for instance_uuid in associated_instances:
                db.load_balancer_instance_association_destroy(
                    context, load_balancer_ref.id, instance_uuid)
        if config_ref:
            db.load_balancer_config_destroy(context, config_ref.id)