def test_show_host_resources_works_correctly(self): """Show_host_resources() works correctly as expected.""" scheduler = manager.SchedulerManager() ctxt = context.get_admin_context() s_ref = self._create_compute_service() i_ref1 = self._create_instance(project_id='p-01', host=s_ref['host']) i_ref2 = self._create_instance(project_id='p-02', vcpus=3, host=s_ref['host']) result = scheduler.show_host_resources(ctxt, s_ref['host']) c1 = ('resource' in result and 'usage' in result) compute_node = s_ref['compute_node'][0] c2 = self._dic_is_equal(result['resource'], compute_node) c3 = result['usage'].keys() == ['p-01', 'p-02'] keys = ['vcpus', 'memory_mb', 'local_gb'] c4 = self._dic_is_equal(result['usage']['p-01'], i_ref1, keys) c5 = self._dic_is_equal(result['usage']['p-02'], i_ref2, keys) self.assertTrue(c1 and c2 and c3 and c4 and c5) db.service_destroy(ctxt, s_ref['id']) db.instance_destroy(ctxt, i_ref1['id']) db.instance_destroy(ctxt, i_ref2['id'])
def test_with_two_zones(self): scheduler = manager.SchedulerManager() ctxt = context.get_admin_context() service_list = [ self._create_service_model(id=1, host='host1', zone='zone1'), self._create_service_model(id=2, host='host2', zone='zone2'), self._create_service_model(id=3, host='host3', zone='zone2'), self._create_service_model(id=4, host='host4', zone='zone2'), self._create_service_model(id=5, host='host5', zone='zone2') ] self.mox.StubOutWithMock(db, 'service_get_all_by_topic') arg = IgnoreArg() db.service_get_all_by_topic(arg, arg).AndReturn(service_list) self.mox.StubOutWithMock(rpc, 'cast', use_mock_anything=True) rpc.cast( ctxt, 'compute.host1', { 'method': 'run_instance', 'args': { 'instance_id': 'i-ffffffff', 'availability_zone': 'zone1' } }) self.mox.ReplayAll() scheduler.run_instance(ctxt, 'compute', instance_id='i-ffffffff', availability_zone='zone1')
def test_show_host_resources_host_not_exit(self): """A host given as an argument does not exists.""" scheduler = manager.SchedulerManager() dest = 'dummydest' ctxt = context.get_admin_context() self.assertRaises(exception.NotFound, scheduler.show_host_resources, ctxt, dest)
def test_fallback(self): scheduler = manager.SchedulerManager() self.mox.StubOutWithMock(rpc, 'cast', use_mock_anything=True) ctxt = context.get_admin_context() rpc.cast(ctxt, 'topic.fallback_host', {'method': 'noexist', 'args': {'num': 7}}) self.mox.ReplayAll() scheduler.noexist(ctxt, 'topic', num=7)
def test_show_host_resources_host_not_exit(self): """A host given as an argument does not exists.""" scheduler = manager.SchedulerManager() dest = 'dummydest' ctxt = context.get_admin_context() try: scheduler.show_host_resources(ctxt, dest) except exception.NotFound, e: c1 = (e.message.find(_("does not exist or is not a " "compute node.")) >= 0)
def setUp(self): super(SimpleDriverTestCase, self).setUp() self.flags(connection_type='fake', stub_network=True, max_cores=4, max_gigabytes=4, network_manager='nova.network.manager.FlatManager', volume_driver='nova.volume.driver.FakeISCSIDriver', scheduler_driver='nova.scheduler.simple.SimpleScheduler') self.scheduler = manager.SchedulerManager() self.context = context.get_admin_context() self.user_id = 'fake' self.project_id = 'fake'
def test_show_host_resources_no_project(self): """No instance are running on the given host.""" scheduler = manager.SchedulerManager() ctxt = context.get_admin_context() s_ref = self._create_compute_service() result = scheduler.show_host_resources(ctxt, s_ref['host']) # result checking c1 = ('resource' in result and 'usage' in result) compute_node = s_ref['compute_node'][0] c2 = self._dic_is_equal(result['resource'], compute_node) c3 = result['usage'] == {} self.assertTrue(c1 and c2 and c3) db.service_destroy(ctxt, s_ref['id'])
def setUp(self): super(SchedulerV3PassthroughTestCase, self).setUp() self.manager = manager.SchedulerManager() self.proxy = manager._SchedulerManagerV3Proxy(self.manager)
def setUp(self, mock_init_agg, mock_init_inst): super(SchedulerV21PassthroughTestCase, self).setUp() self.manager = manager.SchedulerManager() self.proxy = manager._SchedulerManagerV3Proxy(self.manager)