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, '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}})
Exemple #2
0
    def test_update_load_balancer_instances(self):
        update_kwargs = copy.deepcopy(self.delete_kwargs)
        new_instance_uuids = ['a-uuid', 'd-uuid', 'e-uuid']
        update_kwargs['instance_uuids'] = new_instance_uuids

        self.mox.StubOutWithMock(db, 'load_balancer_get_by_uuid')
        self.mox.StubOutWithMock(
            db, 'load_balancer_instance_association_create')
        self.mox.StubOutWithMock(
            db, 'load_balancer_instance_association_destroy')
        self.mox.StubOutWithMock(db, 'load_balancer_update_state')

        load_balancer_ref = self.lb_ref
        for uuid in self.instance_uuids:
            association_values = {
                'load_balancer_id': load_balancer_ref.id,
                'instance_uuid': uuid,
            }
            association_ref = models.LoadBalancerInstanceAssociation()
            association_ref.update(association_values)
            load_balancer_ref.instances.append(association_ref)

        db.load_balancer_get_by_uuid(
            self.ctxt, self.uuid).AndReturn(load_balancer_ref)

        old_instance_uuids = map(lambda x: x['instance_uuid'],
                                 load_balancer_ref.instances)
        need_deleted_instances = filter(lambda x: x not in new_instance_uuids,
                                        old_instance_uuids)
        need_created_instances = filter(lambda x: x not in old_instance_uuids,
                                        new_instance_uuids)
        for instance_uuid in need_deleted_instances:
            db.load_balancer_instance_association_destroy(
                self.ctxt, load_balancer_ref.id, instance_uuid).AndReturn(None)
        for instance_uuid in need_created_instances:
            association_values = {
                'load_balancer_id': load_balancer_ref.id,
                'instance_uuid': instance_uuid,
            }
            db.load_balancer_instance_association_create(
                self.ctxt, association_values).AndReturn(None)
        db.load_balancer_update_state(
            self.ctxt, self.uuid, state.UPDATING).AndReturn(None)
        self.mox.ReplayAll()
        r = tcp.update_load_balancer_instances(self.ctxt, **update_kwargs)
        self.mox.VerifyAll()
        self.assertEqual(r, None)
Exemple #3
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 #4
0
            '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)
        if load_balancer_ref:
            db.load_balancer_destroy(context, load_balancer_ref.id)
        raise exception.CreateLoadBalancerFailed(msg=str(exp))

    return {'data': {'uuid': load_balancer_ref.uuid}}