Beispiel #1
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()
Beispiel #2
0
    def test_create_load_balancer_with_duplicate_name(self):
        def _raise_exception(*args):
            raise Exception()

        self.mox.StubOutWithMock(db, 'load_balancer_get_by_name')
        db.load_balancer_get_by_name(
            self.ctxt, self.create_kwargs['name']).WithSideEffects(
                _raise_exception).AndReturn(None)
        self.mox.ReplayAll()
        self.assertRaises(Exception, http.create_load_balancer,
                          self.ctxt, **self.create_kwargs)
        self.mox.VerifyAll()
Beispiel #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, '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}})
Beispiel #4
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}})
Beispiel #5
0
def get_msg_to_worker(context, method, **kwargs):
    result = dict()
    message = dict()
    load_balancer_ref = None
    if method == 'delete_load_balancer':
        result['cmd'] = 'delete_lb'
        message['user_id'] = kwargs['user_id']
        message['tenant_id'] = kwargs['tenant_id']
        message['uuid'] = kwargs['uuid']
        message['protocol'] = kwargs['protocol']
    elif method == 'create_load_balancer':
        result['cmd'] = 'create_lb'
        load_balancer_ref = db.load_balancer_get_by_name(context,
                                                         kwargs['name'])
        message = format_msg_to_worker(load_balancer_ref)
    elif method.startswith('update_load_balancer'):
        result['cmd'] = 'update_lb'
        load_balancer_ref = db.load_balancer_get_by_uuid(context,
                                                         kwargs['uuid'])
        message = format_msg_to_worker(load_balancer_ref)
    else:
        return None
    result['args'] = message
    return result
Beispiel #6
0
        raise exception.InvalidParameter(
            msg='Healthy check healthy threshold out of rage, 1~10')
    if not 1 <= config['health_check_unhealthy_threshold'] <= 10:
        raise exception.InvalidParameter(
            msg='Healthy check unhealthy threshold out of rage, 1~10')

    try:
        free = kwargs['free']
    except KeyError:
        kwargs['free'] = False
    except Exception, e:
        raise exception.CreateLoadBalancerFailed(msg='unknown error!')

    # check if load balancer already exists
    try:
        db.load_balancer_get_by_name(context, kwargs['name'])
    except exception.LoadBalancerNotFoundByName:
        pass
    except Exception, exp:
        raise exception.CreateLoadBalancerFailed(msg=str(exp))
    else:
        raise exception.CreateLoadBalancerFailed(msg='already exists!')

    # create load balancer
    config_ref = None
    load_balancer_ref = None
    associated_instances = []

    try:
        load_balancer_values = {
            'name': kwargs['name'],