def test_find_suitable_baremetal_node_about_memory(self): h1 = bmdb_utils.new_bm_node(id=1, memory_mb=512, service_host="host1") h2 = bmdb_utils.new_bm_node(id=2, memory_mb=2048, service_host="host1") h3 = bmdb_utils.new_bm_node(id=3, memory_mb=1024, service_host="host1") hosts = [h1, h2, h3] self.stubs.Set(c, '_get_baremetal_nodes', lambda self: hosts) inst = {'vcpus': 1} inst['memory_mb'] = 1 result = c._find_suitable_baremetal_node("context", inst) self.assertEqual(result['id'], 1) inst['memory_mb'] = 512 result = c._find_suitable_baremetal_node("context", inst) self.assertEqual(result['id'], 1) inst['memory_mb'] = 513 result = c._find_suitable_baremetal_node("context", inst) self.assertEqual(result['id'], 3) inst['memory_mb'] = 1024 result = c._find_suitable_baremetal_node("context", inst) self.assertEqual(result['id'], 3) inst['memory_mb'] = 1025 result = c._find_suitable_baremetal_node("context", inst) self.assertEqual(result['id'], 2) inst['memory_mb'] = 2048 result = c._find_suitable_baremetal_node("context", inst) self.assertEqual(result['id'], 2) inst['memory_mb'] = 2049 result = c._find_suitable_baremetal_node("context", inst) self.assertTrue(result is None)
def test_find_suitable_baremetal_node_about_cpu(self): n1 = bmdb_utils.new_bm_node(id=1, cpus=1, memory_mb=512, service_host="host1") n2 = bmdb_utils.new_bm_node(id=2, cpus=2, memory_mb=512, service_host="host1") n3 = bmdb_utils.new_bm_node(id=3, cpus=3, memory_mb=512, service_host="host1") nodes = [n1, n2, n3] self.stubs.Set(c, '_get_baremetal_nodes', lambda self: nodes) inst = {'memory_mb': 512} inst['vcpus'] = 1 result = c._find_suitable_baremetal_node("context", inst) self.assertEqual(result['id'], 1) inst['vcpus'] = 2 result = c._find_suitable_baremetal_node("context", inst) self.assertEqual(result['id'], 2) inst['vcpus'] = 3 result = c._find_suitable_baremetal_node("context", inst) self.assertEqual(result['id'], 3) inst['vcpus'] = 4 result = c._find_suitable_baremetal_node("context", inst) self.assertTrue(result is None)
def test_get_power_manager(self): n1 = bmdb_utils.new_bm_node( pm_address='10.1.1.1', id='1') pm1 = tilera_pdu.Pdu(n1) self.assertEqual(pm1._address, '10.1.1.1') self.assertEqual(pm1._node_id, '1') n2 = bmdb_utils.new_bm_node( pm_address='10.2.2.2', id='2') pm2 = tilera_pdu.Pdu(n2) self.assertEqual(pm2._address, '10.2.2.2') self.assertEqual(pm2._node_id, '2')
def test_find_suitable_baremetal_node_verify(self): n1 = bmdb_utils.new_bm_node(id=1, memory_mb=512, service_host="host1") n2 = bmdb_utils.new_bm_node(id=2, memory_mb=2048, service_host="host1") n3 = bmdb_utils.new_bm_node(id=3, memory_mb=1024, service_host="host1") hosts = [n1, n2, n3] inst = {} inst['vcpus'] = 1 inst['memory_mb'] = 1024 self.mox.StubOutWithMock(c, '_get_baremetal_nodes') c._get_baremetal_nodes("context").AndReturn(hosts) self.mox.ReplayAll() result = c._find_suitable_baremetal_node("context", inst) self.mox.VerifyAll() self.assertEqual(result['id'], 3)
def test_exec_ipmitool(self): H = 'address' U = 'user' P = 'password' I = 'lanplus' F = 'password_file' n1 = bmdb_utils.new_bm_node( pm_address=H, pm_user=U, pm_password=P) self.mox.StubOutWithMock(ipmi, '_make_password_file') self.mox.StubOutWithMock(utils, 'execute') self.mox.StubOutWithMock(ipmi, '_unlink_without_raise') ipmi._make_password_file(P).AndReturn(F) args = [ 'ipmitool', '-I', I, '-H', H, '-U', U, '-f', F, 'A', 'B', 'C', ] utils.execute(*args, attempts=3).AndReturn(('', '')) ipmi._unlink_without_raise(F).AndReturn(None) self.mox.ReplayAll() i = ipmi.Ipmi(n1) i._exec_ipmitool('A B C') self.mox.VerifyAll()
def _create_hosts(self): h1 = new_bm_node(service_host="host1") h2 = new_bm_node(service_host="host2") h3 = new_bm_node(service_host="host2") h1_ref = bmdb.bm_node_create(self.context, h1) self.assertTrue(h1_ref['id'] is not None) h2_ref = bmdb.bm_node_create(self.context, h2) self.assertTrue(h2_ref['id'] is not None) h3_ref = bmdb.bm_node_create(self.context, h3) self.assertTrue(h3_ref['id'] is not None) self.h1 = h1_ref self.h2 = h2_ref self.h3 = h3_ref
def _create_hosts(self): h1 = new_bm_node(service_host="host1") h2 = new_bm_node(service_host="host2") h3 = new_bm_node(service_host="host2") h1_ref = bmdb.bm_node_create(self.context, h1) self.assertTrue(h1_ref['id'] is not None) h2_ref = bmdb.bm_node_create(self.context, h2) self.assertTrue(h2_ref['id'] is not None) h3_ref = bmdb.bm_node_create(self.context, h3) self.assertTrue(h3_ref['id'] is not None) self.h1 = h1_ref self.h2 = h2_ref self.h3 = h3_ref
def test_ipmi(self): n1 = bmdb_utils.new_bm_node( pm_address='10.1.1.1', pm_user='******', pm_password='******') pm1 = ipmi.Ipmi(n1) self.assertEqual(pm1._address, '10.1.1.1') self.assertEqual(pm1._user, 'n1_user') self.assertEqual(pm1._password, 'n1_password') n2 = bmdb_utils.new_bm_node( pm_address='10.2.2.2', pm_user='******', pm_password='******') pm2 = ipmi.Ipmi(n2) self.assertEqual(pm2._address, '10.2.2.2') self.assertEqual(pm2._user, 'n2_user') self.assertEqual(pm2._password, 'n2_password')
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)
class FakeVifDriver(object): def plug(self, instance, vif): pass def unplug(self, instance, vif): pass FakeFirewallDriver = NoopFirewallDriver class FakeVolumeDriver(object): pass NODE = bmdb_utils.new_bm_node(cpus=2, memory_mb=4096, service_host="host1") NICS = [ {'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, }, ] def class_path(class_): return class_.__module__ + '.' + class_.__name__ class BaremetalDriverTestCase(test.TestCase): def setUp(self): super(BaremetalDriverTestCase, self).setUp() self.flags(baremetal_sql_connection='sqlite:///:memory:',
def test_bm_pxe_ip_associate(self): self._create_pxe_ip() node = bmdb.bm_node_create(self.context, new_bm_node()) ip_id = bmdb.bm_pxe_ip_associate(self.context, node['id']) ref = bmdb.bm_pxe_ip_get(self.context, ip_id) self.assertEqual(ref['bm_node_id'], node['id'])