Exemple #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, '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}})
Exemple #2
0
    # create load balancer
    config_ref = None
    load_balancer_ref = None
    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'],