Esempio n. 1
0
 def test_probe_get_all(self):
     values = get_fake_probe('1')
     probe_ref1 = db_api.probe_create(self.conf, values)
     probe_ref2 = db_api.probe_create(self.conf, values)
     probes = db_api.probe_get_all(self.conf)
     self.assertEqual([dict(probe.iteritems()) for probe in probes],
                      [dict(probe.iteritems()) for probe in [probe_ref1,
                                                             probe_ref2]])
Esempio n. 2
0
 def test_probe_destroy_by_sf_id(self):
     values1 = get_fake_probe('1')
     values2 = get_fake_probe('2')
     probe_ref1 = db_api.probe_create(self.conf, values1)
     probe_ref2 = db_api.probe_create(self.conf, values2)
     db_api.probe_destroy_by_sf_id(self.conf, '1')
     probes = db_api.probe_get_all(self.conf)
     self.assertEqual(len(probes), 1)
     self.assertEqual(probes[0]['id'], probe_ref2['id'])
 def test_probe_destroy_by_sf_id(self):
     values1 = get_fake_probe("1")
     values2 = get_fake_probe("2")
     probe_ref1 = db_api.probe_create(self.conf, values1)
     probe_ref2 = db_api.probe_create(self.conf, values2)
     db_api.probe_destroy_by_sf_id(self.conf, "1")
     probes = db_api.probe_get_all(self.conf)
     self.assertEqual(len(probes), 1)
     self.assertEqual(dict(probe_ref2.iteritems()), dict(probes[0].iteritems()))
 def test_probe_get_all_by_sf_id(self):
     values = get_fake_probe("1")
     pr1 = db_api.probe_create(self.conf, values)
     values = get_fake_probe("2")
     pr2 = db_api.probe_create(self.conf, values)
     probes1 = db_api.probe_get_all_by_sf_id(self.conf, "1")
     probes2 = db_api.probe_get_all_by_sf_id(self.conf, "2")
     self.assertEqual([dict(pr1.iteritems())], [dict(pr.iteritems()) for pr in probes1])
     self.assertEqual([dict(pr2.iteritems())], [dict(pr.iteritems()) for pr in probes2])
Esempio n. 5
0
 def test_probe_get_all_by_sf_id(self):
     values = get_fake_probe('1')
     pr1 = db_api.probe_create(self.conf, values)
     values = get_fake_probe('2')
     pr2 = db_api.probe_create(self.conf, values)
     probes1 = db_api.probe_get_all_by_sf_id(self.conf, '1')
     probes2 = db_api.probe_get_all_by_sf_id(self.conf, '2')
     self.assertEqual(len(probes1), 1)
     self.assertEqual(probes1[0]['id'], pr1['id'])
     self.assertEqual(len(probes2), 1)
     self.assertEqual(probes2[0]['id'], pr2['id'])
Esempio n. 6
0
def create_loadbalancer(ctx, balancer, nodes, probes, vips):
    lb = db_api.unpack_extra(balancer)
    sf = db_api.serverfarm_create(ctx.conf, {'lb_id': lb['id']})
    if 'algorithm' in lb:
        predictor_params = {'sf_id': sf['id'], 'type': lb['algorithm']}
    else:
        predictor_params = {'sf_id': sf['id']}
    db_api.predictor_create(ctx.conf, predictor_params)
    create_server_farm(ctx, sf)
    for node in nodes:
        node_values = db_api.server_pack_extra(node)
        node_values['sf_id'] = sf['id']
        rs_ref = db_api.server_create(ctx.conf, node_values)
        create_rserver(ctx, rs_ref)
        add_rserver_to_server_farm(ctx, sf, rs_ref)

    for probe in probes:
        probe_values = db_api.probe_pack_extra(probe)
        probe_values['lb_id'] = lb['id']
        probe_values['sf_id'] = sf['id']
        probe_ref = db_api.probe_create(ctx.conf, probe_values)
        create_probe(ctx,  probe_ref)
        add_probe_to_server_farm(ctx, sf, probe_ref)

    for vip in vips:
        vip_values = db_api.virtualserver_pack_extra(vip)
        vip_values['lb_id'] = lb['id']
        vip_values['sf_id'] = sf['id']
        vip_ref = db_api.virtualserver_create(ctx.conf, vip_values)
        create_vip(ctx, vip_ref, sf)
Esempio n. 7
0
 def test_probe_create(self):
     values = get_fake_probe('1')
     probe_ref = db_api.probe_create(self.conf, values)
     probe = dict(probe_ref.iteritems())
     self.assertIsNotNone(probe['id'])
     values['id'] = probe['id']
     self.assertEqual(probe, values)
Esempio n. 8
0
 def test_probe_destroy(self):
     values = get_fake_probe('1')
     probe = db_api.probe_create(self.conf, values)
     db_api.probe_destroy(self.conf, probe['id'])
     with self.assertRaises(exception.ProbeNotFound) as cm:
         db_api.probe_get(self.conf, probe['id'])
     err = cm.exception
     self.assertEqual(err.kwargs, {'probe_id': probe['id']})
 def test_probe_update(self):
     values = get_fake_probe("1")
     probe_ref = db_api.probe_create(self.conf, values)
     update = {"name": "test", "extra": {"delay": 20, "attemptsDeforeDeactivation": 5, "timeout": 15}}
     probe_ref = db_api.probe_update(self.conf, probe_ref["id"], update)
     probe = dict(probe_ref.iteritems())
     values.update(update)
     self.assertIsNotNone(probe["id"])
     values["id"] = probe["id"]
     self.assertEqual(probe, values)
Esempio n. 10
0
 def test_probe_update(self):
     values = get_fake_probe('1')
     probe_ref = db_api.probe_create(self.conf, values)
     update = {'name': 'test',
               'extra': {'delay': 20,
                         'attemptsDeforeDeactivation': 5,
                         'timeout': 15}}
     probe_ref = db_api.probe_update(self.conf, probe_ref['id'], update)
     probe = dict(probe_ref.iteritems())
     values.update(update)
     self.assertIsNotNone(probe['id'])
     values['id'] = probe['id']
     self.assertEqual(probe, values)
Esempio n. 11
0
def create_lb(conf, params):
    node_values = params.pop('nodes', [])
    probe_values = params.pop('healthMonitor', [])
    vip_values = params.pop('virtualIps', [])
    lb_values = db_api.loadbalancer_pack_extra(params)

    lb_ref = db_api.loadbalancer_create(conf, lb_values)
    sf_ref = db_api.serverfarm_create(conf, {'lb_id': lb_ref['id']})
    db_api.predictor_create(conf, {'sf_id': sf_ref['id'],
                                   'type': lb_ref['algorithm']})
    vip_update_values = {'protocol': lb_ref['protocol']}

    vips = []
    for vip in vip_values:
        vip = db_api.virtualserver_pack_extra(vip)
        db_api.pack_update(vip, vip_update_values)
        vip['lb_id'] = lb_ref['id']
        vip['sf_id'] = sf_ref['id']
        vips.append(db_api.virtualserver_create(conf, vip))

    servers = []
    for server in node_values:
        server = db_api.server_pack_extra(server)
        server['sf_id'] = sf_ref['id']
        servers.append(db_api.server_create(conf, server))

    probes = []
    for probe in probe_values:
        probe = db_api.probe_pack_extra(probe)
        probe['lb_id'] = lb_ref['id']
        probe['sf_id'] = sf_ref['id']
        probes.append(db_api.probe_create(conf, probe))

    device_ref = scheduler.schedule(conf, lb_ref)
    db_api.loadbalancer_update(conf, lb_ref['id'],
                               {'device_id': device_ref['id']})
    device_driver = drivers.get_device_driver(conf, device_ref['id'])
    with device_driver.request_context() as ctx:
        try:
            commands.create_loadbalancer(ctx, sf_ref, vips, servers, probes,
                                         [])
        except Exception:
            with utils.save_and_reraise_exception():
                db_api.loadbalancer_update(conf, lb_ref['id'],
                                           {'status': lb_status.ERROR,
                                            'deployed': False})
    db_api.loadbalancer_update(conf, lb_ref['id'],
                               {'status': lb_status.ACTIVE,
                                'deployed': True})
    return lb_ref['id']
Esempio n. 12
0
def lb_add_probe(conf, lb_id, probe_dict):
    logger.debug("Got new probe description %s" % probe_dict)
    # NOTE(akscram): historically strange validation, wrong place for it.
    if probe_dict['type'] is None:
        return

    lb_ref = db_api.loadbalancer_get(conf, lb_id)
    # NOTE(akscram): server farms are really only create problems than
    #                they solve multiply use of the virtual IPs.
    try:
        sf_ref = db_api.serverfarm_get_all_by_lb_id(conf, lb_ref['id'])[0]
    except IndexError:
        raise exc.ServerFarmNotFound

    values = db_api.probe_pack_extra(probe_dict)
    values['lb_id'] = lb_ref['id']
    values['sf_id'] = sf_ref['id']
    probe_ref = db_api.probe_create(conf, values)
    device_driver = drivers.get_device_driver(conf, lb_ref['device_id'])
    with device_driver.request_context() as ctx:
        commands.add_probe_to_loadbalancer(ctx, sf_ref, probe_ref)
    return db_api.unpack_extra(probe_ref)
Esempio n. 13
0
 def test_probe_get(self):
     values = get_fake_probe('1')
     probe_ref1 = db_api.probe_create(self.conf, values)
     probe_ref2 = db_api.probe_get(self.conf, probe_ref1['id'])
     self.assertEqual(dict(probe_ref1.iteritems()),
                      dict(probe_ref2.iteritems()))
Esempio n. 14
0
 def test_probe_get_all(self):
     values = get_fake_probe('1')
     db_api.probe_create(self.conf, values)
     db_api.probe_create(self.conf, values)
     probes = db_api.probe_get_all(self.conf)
     self.assertEqual(len(probes), 2)
Esempio n. 15
0
 def test_probe_get_with_tenant_fails(self):
     lb_id, sf_id = self._create_lb_and_sf('1', 'tenant1')
     probe_ref = db_api.probe_create(self.conf, get_fake_probe(sf_id))
     with self.assertRaises(exception.ProbeNotFound):
         db_api.probe_get(self.conf, probe_ref['id'], tenant_id='tenant2')
Esempio n. 16
0
    def savetoDB(self):
        try:
            lb_ref = db_api.loadbalancer_update(self.conf, self.lb['id'],
                                                self.lb)
        except exception.LoadBalancerNotFound:
            lb_ref = db_api.loadbalancer_create(self.conf, self.lb)

        self.sf['lb_id'] = lb_ref['id']
        try:
            sf_ref = db_api.serverfarm_update(self.conf, self.sf['id'],
                                              self.sf)
        except exception.ServerFarmNotFound:
            sf_ref = db_api.serverfarm_create(self.conf, self.sf)

        self.sf._predictor['sf_id'] = sf_ref['id']
        try:
            db_api.predictor_update(self.conf, self.sf._predictor['id'],
                                    self.sf._predictor)
        except exception.PredictorNotFound:
            db_api.predictor_create(self.conf, self.sf._predictor)

        stickies = self.sf._sticky
        vips = []

        self.sf = sf_ref
        self.sf._rservers = []
        self.sf._probes = []
        self.sf._sticky = []

        for rs in self.rs:
            rs['sf_id'] = sf_ref['id']
            try:
                rs_ref = db_api.server_update(self.conf, rs['id'], rs)
            except exception.ServerNotFound:
                rs_ref = db_api.server_create(self.conf, rs)
            self.sf._rservers.append(rs_ref)

        for pr in self.probes:
            pr['sf_id'] = sf_ref['id']
            try:
                pr_ref = db_api.probe_update(self.conf, pr['id'], pr)
            except exception.ProbeNotFound:
                pr_ref = db_api.probe_create(self.conf, pr)
            self.sf._probes.append(pr_ref)

        for vip in self.vips:
            vip['sf_id'] = sf_ref['id']
            vip['lb_id'] = lb_ref['id']
            try:
                vip_ref = db_api.virtualserver_update(self.conf, vip['id'],
                                                      vip)
            except exception.VirtualServerNotFound:
                vip_ref = db_api.virtualserver_create(self.conf, vip)
            vips.append(vip_ref)

        for st in stickies:
            st['sf_id'] = sf_ref['id']
            try:
                st_ref = db_api.sticky_update(self.conf, st['id'], st)
            except exception.StickyNotFound:
                st_ref = db_api.sticky_create(self.conf, st)
            self.sf._sticky.append(st_ref)

        self.rs = self.sf._rservers
        self.probes = self.sf._probes
        self.vips = vips