Identify baremetal nodes by UUID.

- add a new 'uuid' column to 'bm_nodes' table
- provide a new db/api method for accessing nodes by their uuid
- return this to Nova as the nodename / hypervisor_hostname

In this way, a baremetal node is uniquely identified to the user,
whether they use a per-compute baremetal db or global baremetal db.

It will also allow for an instance to be booted on a specific baremetal
node using a means akin to the current force-hosts (TBD in later patch).

Also, creates two new Exceptions to disambiguate between
InstanceNotFound and NodeNotFound / NodeNotFoundByUUID.

Change-Id: I81105a201588fdef31cffabdae260bb43017bcd1
This commit is contained in:
Devananda van der Veen
2013-02-13 18:25:29 -08:00
committed by Vishvananda Ishaya
parent cd67c62b90
commit d68397ecd2
4 changed files with 30 additions and 13 deletions

View File

@@ -1050,6 +1050,14 @@ class InstanceNotFound(NotFound):
message = _("Instance %(instance_id)s could not be found.")
class NodeNotFound(NotFound):
message = _("Node %(node_id)s could not be found.")
class NodeNotFoundByUUID(NotFound):
message = _("Node with UUID %(node_uuid)s could not be found.")
class MarkerNotFound(NotFound):
message = _("Marker %(marker)s could not be found.")

View File

@@ -65,7 +65,7 @@ class BareMetalNodesTestCase(base.BMDBTestCase):
self.assertEquals(r['pm_address'], '1')
self.assertRaises(
exception.InstanceNotFound,
exception.NodeNotFound,
db.bm_node_get,
self.context, -1)
@@ -113,7 +113,7 @@ class BareMetalNodesTestCase(base.BMDBTestCase):
db.bm_node_destroy(self.context, self.ids[0])
self.assertRaises(
exception.InstanceNotFound,
exception.NodeNotFound,
db.bm_node_get,
self.context, self.ids[0])
@@ -147,7 +147,7 @@ class BareMetalNodesTestCase(base.BMDBTestCase):
self.assertEqual(self.ids[1], if_x['bm_node_id'])
self.assertRaises(
exception.InstanceNotFound,
exception.NodeNotFound,
db.bm_node_get,
self.context, self.ids[0])

View File

@@ -22,6 +22,7 @@ from nova.virt.baremetal.db.sqlalchemy import models as bm_models
def new_bm_node(**kwargs):
h = bm_models.BareMetalNode()
h.id = kwargs.pop('id', None)
h.uuid = kwargs.pop('uuid', None)
h.service_host = kwargs.pop('service_host', None)
h.instance_uuid = kwargs.pop('instance_uuid', None)
h.cpus = kwargs.pop('cpus', 1)

View File

@@ -111,7 +111,7 @@ class BareMetalDriverWithDBTestCase(bm_db_base.BMDBTestCase):
nic['port_no'],
)
result['instance'] = utils.get_test_instance()
result['instance']['node'] = result['node']['id']
result['instance']['node'] = result['node']['uuid']
result['spawn_params'] = dict(
admin_password='test_pass',
block_device_info=None,
@@ -139,7 +139,7 @@ class BareMetalDriverWithDBTestCase(bm_db_base.BMDBTestCase):
self.assertEqual(stats['cpu_arch'], 'test')
self.assertEqual(stats['test_spec'], 'test_value')
self.assertEqual(stats['hypervisor_type'], 'baremetal')
self.assertEqual(stats['hypervisor_hostname'], '123')
self.assertEqual(stats['hypervisor_hostname'], node['node']['uuid'])
self.assertEqual(stats['host'], 'test_host')
self.assertEqual(stats['vcpus'], 2)
self.assertEqual(stats['host_memory_total'], 2048)
@@ -153,7 +153,15 @@ class BareMetalDriverWithDBTestCase(bm_db_base.BMDBTestCase):
def test_macs_for_instance(self):
node = self._create_node()
expected = set(['01:23:45:67:89:01', '01:23:45:67:89:02'])
expected = set([nic['address'] for nic in node['nic_info']])
self.assertEqual(
expected, self.driver.macs_for_instance(node['instance']))
def test_macs_for_instance_after_spawn(self):
node = self._create_node()
self.driver.spawn(**node['spawn_params'])
expected = set([nic['address'] for nic in node['nic_info']])
self.assertEqual(
expected, self.driver.macs_for_instance(node['instance']))
@@ -184,12 +192,12 @@ class BareMetalDriverWithDBTestCase(bm_db_base.BMDBTestCase):
def test_spawn_node_not_found(self):
node = self._create_node()
db.bm_node_update(self.context, node['node']['id'],
{'id': 9876})
{'uuid': 'hide-this-node'})
self.assertRaises(exception.NovaException,
self.driver.spawn, **node['spawn_params'])
row = db.bm_node_get(self.context, 9876)
row = db.bm_node_get(self.context, node['node']['id'])
self.assertEqual(row['task_state'], None)
def test_spawn_fails(self):
@@ -247,18 +255,18 @@ class BareMetalDriverWithDBTestCase(bm_db_base.BMDBTestCase):
def test_get_available_resources(self):
node = self._create_node()
resources = self.driver.get_available_resource(node['node']['id'])
resources = self.driver.get_available_resource(node['node']['uuid'])
self.assertEqual(resources['memory_mb'],
node['node_info']['memory_mb'])
self.assertEqual(resources['memory_mb_used'], 0)
self.driver.spawn(**node['spawn_params'])
resources = self.driver.get_available_resource(node['node']['id'])
resources = self.driver.get_available_resource(node['node']['uuid'])
self.assertEqual(resources['memory_mb_used'],
node['node_info']['memory_mb'])
self.driver.destroy(**node['destroy_params'])
resources = self.driver.get_available_resource(node['node']['id'])
resources = self.driver.get_available_resource(node['node']['uuid'])
self.assertEqual(resources['memory_mb_used'], 0)
def test_get_available_nodes(self):
@@ -281,7 +289,7 @@ class BareMetalDriverWithDBTestCase(bm_db_base.BMDBTestCase):
]
node2 = self._create_node(node_info=node_info, nic_info=nic_info)
self.assertEqual(2, len(self.driver.get_available_nodes()))
self.assertEqual(['123', '456'],
self.assertEqual([node1['node']['uuid'], node2['node']['uuid']],
self.driver.get_available_nodes())
node1['instance']['hostname'] = 'test-host-1'
@@ -298,5 +306,5 @@ class BareMetalDriverWithDBTestCase(bm_db_base.BMDBTestCase):
self.driver.destroy(**node2['destroy_params'])
self.assertEqual(2, len(self.driver.get_available_nodes()))
self.assertEqual(['123', '456'],
self.assertEqual([node1['node']['uuid'], node2['node']['uuid']],
self.driver.get_available_nodes())