def setUp(self): super(BareMetalDriverWithDBTestCase, self).setUp() self.flags(**COMMON_FLAGS) self.flags(**BAREMETAL_FLAGS) fake_image.stub_out_image_service(self.stubs) self.context = utils.get_test_admin_context() self.driver = bm_driver.BareMetalDriver(None) self.node_info = bm_db_utils.new_bm_node( id=123, service_host='test_host', cpus=2, memory_mb=2048, ) self.nic_info = [ { 'address': '01:23:45:67:89:01', 'datapath_id': '0x1', 'port_no': 1 }, { 'address': '01:23:45:67:89:02', 'datapath_id': '0x2', 'port_no': 2 }, ] self.addCleanup(fake_image.FakeImageService_reset)
def test_loading_baremetal_drivers(self): from nova.virt.baremetal import fake drv = c.BareMetalDriver() self.assertTrue(isinstance(drv.baremetal_nodes, fake.Fake)) self.assertTrue(isinstance(drv._vif_driver, FakeVifDriver)) self.assertTrue(isinstance(drv._firewall_driver, FakeFirewallDriver)) self.assertTrue(isinstance(drv._volume_driver, FakeVolumeDriver))
def setUp(self): super(BareMetalDriverWithDBTestCase, self).setUp() self.flags(**COMMON_FLAGS) self.flags(**BAREMETAL_FLAGS) fake_image.stub_out_image_service(self.stubs) self.context = utils.get_test_admin_context() self.driver = bm_driver.BareMetalDriver(fake_virt.FakeVirtAPI()) self.addCleanup(fake_image.FakeImageService_reset)
def setUp(self): super(BareMetalDriverWithDBTestCase, self).setUp() self.config(**COMMON_CONFIG) self.config(**BAREMETAL_CONFIG) fake_image.stub_out_image_service(self.stubs) self.context = utils.get_test_admin_context() self.driver = bm_driver.BareMetalDriver(None) self.addCleanup(fake_image.FakeImageService_reset)
def test_get_host_stats(self): self.flags(instance_type_extra_specs=['cpu_arch:x86_64', 'x:123', 'y:456', ]) drv = c.BareMetalDriver() s = drv._get_host_stats() es = s['instance_type_extra_specs'] self.assertEqual(es['cpu_arch'], 'x86_64') self.assertEqual(es['x'], '123') self.assertEqual(es['y'], '456') self.assertEqual(es['hypervisor_type'], 'baremetal') self.assertEqual(es['baremetal_driver'], 'nova.virt.baremetal.fake.Fake') self.assertEqual(len(es), 5)
def test_get_host_stats(self): self.flags(instance_type_extra_specs=[ 'cpu_arch:x86_64', 'x:123', 'y:456', ]) drv = bm_driver.BareMetalDriver() cap_list = drv.get_host_stats() self.assertTrue(isinstance(cap_list, list)) self.assertEqual(len(cap_list), 1) cap = cap_list[0] self.assertEqual(cap['cpu_arch'], 'x86_64') self.assertEqual(cap['x'], '123') self.assertEqual(cap['y'], '456') self.assertEqual(cap['hypervisor_type'], 'baremetal') self.assertEqual(cap['baremetal_driver'], 'nova.virt.baremetal.fake.Fake')
def test_spawn(self): context = test_utils.get_test_admin_context() instance = test_utils.get_test_instance() instance['uuid'] = '12345' network_info = test_utils.get_test_network_info() block_device_info = None image_meta = test_utils.get_test_image_info(None, instance) drv = c.BareMetalDriver() drv.spawn(context, instance=instance, image_meta=image_meta, injected_files=[('/foo', 'bar'), ('/abc', 'xyz')], admin_password='******', network_info=network_info, block_device_info=block_device_info) n = bmdb.bm_node_get(context, self.node_id) self.assertEqual(n['instance_uuid'], instance['uuid']) self.assertEqual(n['task_state'], baremetal_states.ACTIVE)
def setUp(self): self.flags(**COMMON_FLAGS) utils.clear_tables() super(BaremetalDriverSpawnTestCase, self).setUp() fake_image.stub_out_image_service(self.stubs) self.context = test_utils.get_test_admin_context() self.instance = test_utils.get_test_instance() self.instance['uuid'] = '12345' self.network_info = test_utils.get_test_network_info() self.block_device_info = None self.image_meta = test_utils.get_test_image_info(None, self.instance) self.node = _create_baremetal_stuff() self.node_id = self.node['id'] self.driver = bm_driver.BareMetalDriver() self.kwargs = dict(context=self.context, instance=self.instance, image_meta=self.image_meta, injected_files=[('/foo', 'bar'), ('/abc', 'xyz')], admin_password='******', network_info=self.network_info, block_device_info=self.block_device_info)
def test_get_info(self): # Create the mock objects self.mox.StubOutWithMock(dom, 'read_domains') self.mox.StubOutWithMock(dom, 'write_domains') # Expected calls dom.read_domains('/tftpboot/' 'test_fake_dom_file').AndReturn(fake_domains) dom.write_domains('/tftpboot/test_fake_dom_file', fake_domains) self.mox.ReplayAll() # Code under test conn = driver.BareMetalDriver(True) # TODO(mikalstill): this is not a very good fake instance info = conn.get_info({'name': 'instance-00000001'}) # Expected values self.assertEquals(info['mem'], 16777216) self.assertEquals(info['state'], 1) self.assertEquals(info['num_cpu'], 1) self.assertEquals(info['cpu_time'], 100) self.assertEquals(info['max_mem'], 16777216)
def setUp(self): super(BareMetalDriverNoDBTestCase, self).setUp() self.flags(**COMMON_FLAGS) self.flags(**BAREMETAL_FLAGS) self.driver = bm_driver.BareMetalDriver(None)
def test_max_sum_baremetal_resources(self): N1 = new_bm_node(service_host="host1", cpus=1, memory_mb=1000, local_gb=10) N2 = new_bm_node(service_host="host1", cpus=1, memory_mb=1000, local_gb=20) N3 = new_bm_node(service_host="host1", cpus=10, memory_mb=1000, local_gb=20) N4 = new_bm_node(service_host="host1", cpus=1, memory_mb=2000, local_gb=20) ns = [N1, N2, N3, N4, ] context = test_utils.get_test_admin_context() self.stubs.Set(c, '_get_baremetal_nodes', lambda ctx: ns) drv = c.BareMetalDriver() dic = drv._max_baremetal_resources(context) self.assertEqual(dic.get('vcpus'), 1) self.assertEqual(dic.get('memory_mb'), 2000) self.assertEqual(dic.get('local_gb'), 20) self.assertEqual(dic.get('vcpus_used'), 0) self.assertEqual(dic.get('memory_mb_used'), 0) self.assertEqual(dic.get('local_gb_used'), 0) dic = drv._sum_baremetal_resources(context) self.assertEqual(dic.get('vcpus'), 13) self.assertEqual(dic.get('memory_mb'), 5000) self.assertEqual(dic.get('local_gb'), 70) self.assertEqual(dic.get('vcpus_used'), 0) self.assertEqual(dic.get('memory_mb_used'), 0) self.assertEqual(dic.get('local_gb_used'), 0) N4['instance_uuid'] = '1' dic = drv._max_baremetal_resources(context) self.assertEqual(dic.get('vcpus'), 10) self.assertEqual(dic.get('memory_mb'), 1000) self.assertEqual(dic.get('local_gb'), 20) self.assertEqual(dic.get('vcpus_used'), 0) self.assertEqual(dic.get('memory_mb_used'), 0) self.assertEqual(dic.get('local_gb_used'), 0) dic = drv._sum_baremetal_resources(context) self.assertEqual(dic.get('vcpus'), 13) self.assertEqual(dic.get('memory_mb'), 5000) self.assertEqual(dic.get('local_gb'), 70) self.assertEqual(dic.get('vcpus_used'), 1) self.assertEqual(dic.get('memory_mb_used'), 2000) self.assertEqual(dic.get('local_gb_used'), 20) N3['instance_uuid'] = '2' dic = drv._max_baremetal_resources(context) self.assertEqual(dic.get('vcpus'), 1) self.assertEqual(dic.get('memory_mb'), 1000) self.assertEqual(dic.get('local_gb'), 20) self.assertEqual(dic.get('vcpus_used'), 0) self.assertEqual(dic.get('memory_mb_used'), 0) self.assertEqual(dic.get('local_gb_used'), 0) dic = drv._sum_baremetal_resources(context) self.assertEqual(dic.get('vcpus'), 13) self.assertEqual(dic.get('memory_mb'), 5000) self.assertEqual(dic.get('local_gb'), 70) self.assertEqual(dic.get('vcpus_used'), 11) self.assertEqual(dic.get('memory_mb_used'), 3000) self.assertEqual(dic.get('local_gb_used'), 40) N2['instance_uuid'] = '3' dic = drv._max_baremetal_resources(context) self.assertEqual(dic.get('vcpus'), 1) self.assertEqual(dic.get('memory_mb'), 1000) self.assertEqual(dic.get('local_gb'), 10) self.assertEqual(dic.get('vcpus_used'), 0) self.assertEqual(dic.get('memory_mb_used'), 0) self.assertEqual(dic.get('local_gb_used'), 0) dic = drv._sum_baremetal_resources(context) self.assertEqual(dic.get('vcpus'), 13) self.assertEqual(dic.get('memory_mb'), 5000) self.assertEqual(dic.get('local_gb'), 70) self.assertEqual(dic.get('vcpus_used'), 12) self.assertEqual(dic.get('memory_mb_used'), 4000) self.assertEqual(dic.get('local_gb_used'), 60) N1['instance_uuid'] = '4' dic = drv._max_baremetal_resources(context) self.assertEqual(dic.get('vcpus'), 0) self.assertEqual(dic.get('memory_mb'), 0) self.assertEqual(dic.get('local_gb'), 0) self.assertEqual(dic.get('vcpus_used'), 0) self.assertEqual(dic.get('memory_mb_used'), 0) self.assertEqual(dic.get('local_gb_used'), 0) dic = drv._sum_baremetal_resources(context) self.assertEqual(dic.get('vcpus'), 13) self.assertEqual(dic.get('memory_mb'), 5000) self.assertEqual(dic.get('local_gb'), 70) self.assertEqual(dic.get('vcpus_used'), 13) self.assertEqual(dic.get('memory_mb_used'), 5000) self.assertEqual(dic.get('local_gb_used'), 70) N2['instance_uuid'] = None dic = drv._max_baremetal_resources(context) self.assertEqual(dic.get('vcpus'), 1) self.assertEqual(dic.get('memory_mb'), 1000) self.assertEqual(dic.get('local_gb'), 20) self.assertEqual(dic.get('vcpus_used'), 0) self.assertEqual(dic.get('memory_mb_used'), 0) self.assertEqual(dic.get('local_gb_used'), 0) dic = drv._sum_baremetal_resources(context) self.assertEqual(dic.get('vcpus'), 13) self.assertEqual(dic.get('memory_mb'), 5000) self.assertEqual(dic.get('local_gb'), 70) self.assertEqual(dic.get('vcpus_used'), 12) self.assertEqual(dic.get('memory_mb_used'), 4000) self.assertEqual(dic.get('local_gb_used'), 50)
def setUp(self): super(BareMetalDriverNoDBTestCase, self).setUp() self.config(**COMMON_CONFIG) self.config(**BAREMETAL_CONFIG) self.driver = bm_driver.BareMetalDriver(None)