Пример #1
0
 def test_delete_loadbalancer(self, *mocks):
     for mok in mocks[7:11]:
         mok.return_value = [{"dummy": '1'}, {"dummy": '2'}]
     mocks[12].return_value = {'id': 1}
     cmd.delete_loadbalancer(self.ctx, self.balancer)
     for mok in mocks:
         self.assertTrue(mok.called, "This mock didn't call %s"
                 % mok._mock_name)
Пример #2
0
 def test_delete_loadbalancer(self, mf1, mf2, mf3, mf4, mf5, mf6, mf7):
     cmd.delete_loadbalancer(self.ctx, self.balancer)
     self.assertTrue(mf1.called, "delete_vip not called")
     self.assertTrue(mf2.called, "delete_rserver_from_sf not called")
     self.assertTrue(mf3.called, "delete_rserver")
     self.assertTrue(mf5.called, "delete_probe not called")
     self.assertTrue(mf6.called, "remove_probe_from_server_farm not called")
     self.assertTrue(mf7.called, "delete_sticky not called")
     self.assertTrue(mf4.called, "delete_server_farm not called")
Пример #3
0
def update_lb(conf, tenant_id, lb_id, lb_body):
    lb_ref = db_api.loadbalancer_get(conf, lb_id, tenant_id=tenant_id)
    old_lb_ref = copy.deepcopy(lb_ref)
    db_api.pack_update(lb_ref, lb_body)
    lb_ref = db_api.loadbalancer_update(conf, lb_id, lb_ref)
    if (lb_ref['algorithm'] == old_lb_ref['algorithm'] and
        lb_ref['protocol'] == old_lb_ref['protocol']):
        LOG.debug("In LB %r algorithm and protocol have not changed, "
                     "nothing to do on the device %r.",
                     lb_ref['id'], lb_ref['device_id'])
        return

    sf_ref = db_api.serverfarm_get_all_by_lb_id(conf, lb_ref['id'])[0]
    if lb_ref['algorithm'] != old_lb_ref['algorithm']:
        predictor_ref = db_api.predictor_get_by_sf_id(conf, sf_ref['id'])
        db_api.predictor_update(conf, predictor_ref['id'],
                                {'type': lb_ref['algorithm']})

    vips = db_api.virtualserver_get_all_by_sf_id(conf, sf_ref['id'])
    if lb_ref['protocol'] != old_lb_ref['protocol']:
        vip_update_values = {'protocol': lb_ref['protocol']}
        for vip in vips:
            db_api.pack_update(vip, vip_update_values)
            db_api.virtualserver_update(conf, vip['id'], vip)

    servers = db_api.server_get_all_by_sf_id(conf, sf_ref['id'])
    probes = db_api.probe_get_all_by_sf_id(conf, sf_ref['id'])
    stickies = db_api.sticky_get_all_by_sf_id(conf, sf_ref['id'])

    device_ref = scheduler.reschedule(conf, lb_ref)
    if device_ref['id'] != lb_ref['device_id']:
        from_driver = drivers.get_device_driver(conf, lb_ref['device_id'])
        to_driver = drivers.get_device_driver(conf, device_ref['id'])
        lb_ref = db_api.loadbalancer_update(conf, lb_ref['id'],
                                            {'device_id': device_ref['id']})
    else:
        from_driver = drivers.get_device_driver(conf, device_ref['id'])
        to_driver = from_driver

    with from_driver.request_context() as ctx:
        try:
            commands.delete_loadbalancer(ctx, sf_ref, vips, servers, probes,
                                         stickies)
        except Exception:
            with utils.save_and_reraise_exception():
                db_api.loadbalancer_update(conf, lb_ref['id'],
                                           {'status': lb_status.ERROR})
    with to_driver.request_context() as ctx:
        try:
            commands.create_loadbalancer(ctx, sf_ref, vips, servers, probes,
                                         stickies)
        except Exception:
            with utils.save_and_reraise_exception():
                db_api.loadbalancer_update(conf, lb_ref['id'],
                                           {'status': lb_status.ERROR})
    db_api.loadbalancer_update(conf, lb_ref['id'],
                               {'status': lb_status.ACTIVE})
Пример #4
0
def delete_lb(conf, lb_id):
    balancer_instance = vserver.Balancer(conf)
    balancer_instance.loadFromDB(lb_id)

    #Step 1. Parse parameters came from request
    #bal_deploy.parseParams(params)

    #        #Step 2. Delete config in DB
    #        balancer_instance.removeFromDB()

    #Step 3. Destruct config at device
    device_id = balancer_instance.lb['device_id']
    device_driver = drivers.get_device_driver(conf, device_id)
    with device_driver.request_context() as ctx:
        commands.delete_loadbalancer(ctx, balancer_instance)

    balancer_instance.removeFromDB()
Пример #5
0
def delete_lb(conf, tenant_id, lb_id):
    lb_ref = db_api.loadbalancer_get(conf, lb_id, tenant_id=tenant_id)
    sf_ref = db_api.serverfarm_get_all_by_lb_id(conf, lb_ref['id'])[0]
    vips = db_api.virtualserver_get_all_by_sf_id(conf, sf_ref['id'])
    servers = db_api.server_get_all_by_sf_id(conf, sf_ref['id'])
    probes = db_api.probe_get_all_by_sf_id(conf, sf_ref['id'])
    stickies = db_api.sticky_get_all_by_sf_id(conf, sf_ref['id'])
    device_driver = drivers.get_device_driver(conf, lb_ref['device_id'])
    with device_driver.request_context() as ctx:
        commands.delete_loadbalancer(ctx, sf_ref, vips, servers, probes,
                                     stickies)
    db_api.probe_destroy_by_sf_id(conf, sf_ref['id'])
    db_api.sticky_destroy_by_sf_id(conf, sf_ref['id'])
    db_api.server_destroy_by_sf_id(conf, sf_ref['id'])
    db_api.virtualserver_destroy_by_sf_id(conf, sf_ref['id'])
    db_api.predictor_destroy_by_sf_id(conf, sf_ref['id'])
    db_api.serverfarm_destroy(conf, sf_ref['id'])
    db_api.loadbalancer_destroy(conf, lb_ref['id'])
Пример #6
0
 def test_delete_loadbalancer(self,
                              mock_delete_vip,
                              mock_remove_node_from_loadbalancer,
                              mock_remove_probe_from_loadbalancer,
                              mock_delete_sticky,
                              mock_delete_server_farm):
     cmd.delete_loadbalancer(self.ctx, 'fakesf',
                             ['fakevip'],
                             ['fakeserver'],
                             ['fakeprobe'],
                             ['fakesticky'])
     mock_delete_vip.assert_called_once_with(self.ctx, 'fakevip')
     mock_remove_node_from_loadbalancer.assert_called_once_with(self.ctx,
             'fakesf', 'fakeserver')
     mock_remove_probe_from_loadbalancer.assert_called_once_with(self.ctx,
             'fakesf', 'fakeprobe')
     mock_delete_sticky.assert_called_once_with(self.ctx, 'fakesticky')
     mock_delete_server_farm.assert_called_once_with(self.ctx, 'fakesf')
Пример #7
0
def delete_lb(conf, lb_id):
    lb = db_api.loadbalancer_get(conf, lb_id)
    device_driver = drivers.get_device_driver(conf, lb['device_id'])
    with device_driver.request_context() as ctx:
        commands.delete_loadbalancer(ctx, lb)