def test_scheduler_no_cfg(self, dev_get_all):
     conf = cfg.ConfigOpts(default_config_files=[])
     conf._oparser = mock.Mock()
     conf._oparser.parse_args.return_value = mock.Mock(), None
     conf._oparser.parse_args.return_value[0].__dict__ = self.attrs
     conf()
     dev_get_all.return_value = self.devices
     res = scheduler.schedule(conf, self.lb_ref)
     self.assertTrue(dev_get_all.called)
     self.assertEqual({'id': 3}, res)
Beispiel #2
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']
 def test_scheduler_with_proper_devs(self, dev_get_all):
     dev_get_all.return_value = self.devices
     res = scheduler.schedule(self.conf, self.lb_ref)
     self.assertTrue(dev_get_all.called)
     self.assertEqual({'id': 3}, res)
 def test_scheduler_without_devices(self, dev_get_all):
     dev_get_all.return_value = []
     with self.assertRaises(exp.DeviceNotFound):
         scheduler.schedule(self.conf, self.lb_ref)
         self.assertTrue(dev_get_all.called)
 def test_scheduler_no_proper_devs(self, dev_get_all):
     dev_get_all.return_value = self.devices[:2]
     with self.assertRaises(exp.NoValidDevice):
         scheduler.schedule(self.conf, self.lb_ref)
         self.assertTrue(dev_get_all.called)