Example #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')
Example #2
0
 def test_delete_load_balancer(self):
     self.mox.StubOutWithMock(db, 'load_balancer_get_by_uuid')
     self.mox.StubOutWithMock(db, 'load_balancer_update_state')
     db.load_balancer_get_by_uuid(
         self.context, self.lb_uuid).AndReturn(self.lb_ref)
     db.load_balancer_update_state(
         self.context, self.lb_uuid, state.DELETING)
     self.mox.ReplayAll()
     r = api.delete_load_balancer(self.context, **self.kwargs)
     self.mox.VerifyAll()
     self.assertEqual(r, None)
Example #3
0
def delete_load_balancer(context, **kwargs):
    expect_keys = [
        'tenant_id', 'uuid',
    ]
    utils.check_input_parameters(expect_keys, **kwargs)

    uuid = kwargs['uuid']
    try:
        load_balancer_ref = db.load_balancer_get_by_uuid(context, uuid)
        db.load_balancer_update_state(context, uuid, state.DELETING)
        notify(context, load_balancer_ref, 'loadbalancer.delete.start')
    except Exception, exp:
        raise exception.DeleteLoadBalancerFailed(msg=str(exp))
Example #4
0
    def test_update_load_balancer_http_servers(self):
        kwargs = copy.deepcopy(self.delete_kwargs)
        new_http_servers = ['www.abc.com', 'www.123.com']
        kwargs['http_server_names'] = new_http_servers

        self.mox.StubOutWithMock(utils, 'get_all_domain_names')
        self.mox.StubOutWithMock(db, 'load_balancer_get_by_uuid')
        self.mox.StubOutWithMock(db, 'load_balancer_domain_create')
        self.mox.StubOutWithMock(db, 'load_balancer_domain_destroy')
        self.mox.StubOutWithMock(db, 'load_balancer_update_state')

        load_balancer_ref = self.lb_ref
        for index, domain in enumerate(self.http_server_names):
            domain_values = {
                'id': index + 1,
                'load_balancer_id': load_balancer_ref.id,
                'name': domain,
            }
            domain_ref = models.LoadBalancerDomain()
            domain_ref.update(domain_values)
            load_balancer_ref.domains.append(domain_ref)

        db.load_balancer_get_by_uuid(
            self.ctxt, self.uuid).AndReturn(load_balancer_ref)
        utils.get_all_domain_names().AndReturn(list())

        old_http_servers = map(lambda x: x['name'], load_balancer_ref.domains)
        need_deleted_domains = filter(lambda x: x not in new_http_servers,
                                      old_http_servers)
        need_created_domains = filter(lambda x: x not in old_http_servers,
                                      new_http_servers)

        for domain in load_balancer_ref.domains:
            if domain.name in need_deleted_domains:
                db.load_balancer_domain_destroy(
                    self.ctxt, domain.id).AndReturn(None)
        for domain in need_created_domains:
            domain_values = {
                'load_balancer_id': load_balancer_ref.id,
                'name': domain,
            }
            db.load_balancer_domain_create(
                self.ctxt, domain_values).AndReturn(None)
        db.load_balancer_update_state(
            self.ctxt, self.uuid, state.UPDATING).AndReturn(None)
        self.mox.ReplayAll()
        r = http.update_load_balancer_http_servers(self.ctxt, **kwargs)
        self.mox.VerifyAll()
        self.assertRaises(r, None)
Example #5
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)
Example #6
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)
Example #7
0
    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'],
    }
    try:
        db.load_balancer_config_destroy(context, load_balancer_ref.config.id)
        db.load_balancer_config_create(context, config_values)
        db.load_balancer_update_state(context, uuid, state.UPDATING)
    except Exception, exp:
        raise exception.UpdateLoadBalancerFailed(msg=str(exp))

    return None


def update_load_balancer_instances(context, **kwargs):
    expect_keys = [
        'user_id', 'tenant_id', 'protocol',
        'uuid', 'instance_uuids',
    ]
    utils.check_input_parameters(expect_keys, **kwargs)

    new_instance_uuids = kwargs['instance_uuids']
    if not new_instance_uuids:
Example #8
0
        db.load_balancer_destroy(context, load_balancer_ref.id)
    except Exception, exp:
        raise exception.DeleteLoadBalancerFailed(msg=str(exp))


def update_load_balancer_state(context, **kwargs):
    code = kwargs['code']
    uuid = kwargs['uuid']
    try:
        load_balancer_ref = db.load_balancer_get_by_uuid(context, uuid)
    except Exception, exp:
        raise exception.UpdateLoadBalancerFailed(msg=str(exp))

    if code == 200:
        if load_balancer_ref.state == state.DELETING:
            delete_load_balancer_hard(context, load_balancer_ref)
            notify(context, load_balancer_ref, 'loadbalancer.delete.end')
        elif load_balancer_ref.state == state.CREATING:
            db.load_balancer_update_state(context, uuid, state.ACTIVE)
            notify(context, load_balancer_ref, 'loadbalancer.create.end')
        elif load_balancer_ref.state == state.UPDATING:
            db.load_balancer_update_state(context, uuid, state.ACTIVE)
            notify(context, load_balancer_ref, 'loadbalancer.update.end')
    elif code == 500:
        if load_balancer_ref.state == state.CREATING:
            db.load_balancer_update_state(context, uuid, state.ERROR)
            notify(context, load_balancer_ref, 'loadbalancer.create.error')
        elif load_balancer_ref.state == state.UPDATING:
            db.load_balancer_update_state(context, uuid, state.ERROR)
            notify(context, load_balancer_ref, 'loadbalancer.update.error')