Merge "objects: add ComputeNode.get_by_uuid method"
This commit is contained in:
@@ -49,7 +49,8 @@ class ComputeNode(base.NovaPersistentObject, base.NovaObject):
|
|||||||
# Version 1.15: Added uuid
|
# Version 1.15: Added uuid
|
||||||
# Version 1.16: Added disk_allocation_ratio
|
# Version 1.16: Added disk_allocation_ratio
|
||||||
# Version 1.17: Added mapped
|
# Version 1.17: Added mapped
|
||||||
VERSION = '1.17'
|
# Version 1.18: Added get_by_uuid().
|
||||||
|
VERSION = '1.18'
|
||||||
|
|
||||||
fields = {
|
fields = {
|
||||||
'id': fields.IntegerField(read_only=True),
|
'id': fields.IntegerField(read_only=True),
|
||||||
@@ -239,6 +240,14 @@ class ComputeNode(base.NovaPersistentObject, base.NovaObject):
|
|||||||
db_compute = db.compute_node_get(context, compute_id)
|
db_compute = db.compute_node_get(context, compute_id)
|
||||||
return cls._from_db_object(context, cls(), db_compute)
|
return cls._from_db_object(context, cls(), db_compute)
|
||||||
|
|
||||||
|
@base.remotable_classmethod
|
||||||
|
def get_by_uuid(cls, context, compute_uuid):
|
||||||
|
nodes = ComputeNodeList.get_all_by_uuids(context, [compute_uuid])
|
||||||
|
# We have a unique index on the uuid column so we can get back 0 or 1.
|
||||||
|
if not nodes:
|
||||||
|
raise exception.ComputeHostNotFound(host=compute_uuid)
|
||||||
|
return nodes[0]
|
||||||
|
|
||||||
# NOTE(hanlind): This is deprecated and should be removed on the next
|
# NOTE(hanlind): This is deprecated and should be removed on the next
|
||||||
# major version bump
|
# major version bump
|
||||||
@base.remotable_classmethod
|
@base.remotable_classmethod
|
||||||
|
@@ -164,6 +164,27 @@ class _TestComputeNodeObject(object):
|
|||||||
self.assertNotIn('uuid', compute.obj_what_changed())
|
self.assertNotIn('uuid', compute.obj_what_changed())
|
||||||
get_mock.assert_called_once_with(self.context, 123)
|
get_mock.assert_called_once_with(self.context, 123)
|
||||||
|
|
||||||
|
@mock.patch.object(compute_node.ComputeNodeList, 'get_all_by_uuids')
|
||||||
|
def test_get_by_uuid(self, get_all_by_uuids):
|
||||||
|
fake_node = copy.copy(fake_compute_node)
|
||||||
|
fake_node['stats'] = None
|
||||||
|
get_all_by_uuids.return_value = objects.ComputeNodeList(
|
||||||
|
objects=[objects.ComputeNode(**fake_node)])
|
||||||
|
compute = compute_node.ComputeNode.get_by_uuid(
|
||||||
|
self.context, uuidsentinel.fake_compute_node)
|
||||||
|
self.assertEqual(uuidsentinel.fake_compute_node, compute.uuid)
|
||||||
|
get_all_by_uuids.assert_called_once_with(
|
||||||
|
self.context, [uuidsentinel.fake_compute_node])
|
||||||
|
|
||||||
|
@mock.patch.object(compute_node.ComputeNodeList, 'get_all_by_uuids')
|
||||||
|
def test_get_by_uuid_not_found(self, get_all_by_uuids):
|
||||||
|
get_all_by_uuids.return_value = objects.ComputeNodeList()
|
||||||
|
self.assertRaises(exception.ComputeHostNotFound,
|
||||||
|
compute_node.ComputeNode.get_by_uuid,
|
||||||
|
self.context, uuidsentinel.fake_compute_node)
|
||||||
|
get_all_by_uuids.assert_called_once_with(
|
||||||
|
self.context, [uuidsentinel.fake_compute_node])
|
||||||
|
|
||||||
@mock.patch.object(db, 'compute_node_get')
|
@mock.patch.object(db, 'compute_node_get')
|
||||||
def test_get_without_mapped(self, get_mock):
|
def test_get_without_mapped(self, get_mock):
|
||||||
fake_node = copy.copy(fake_compute_node)
|
fake_node = copy.copy(fake_compute_node)
|
||||||
|
@@ -1072,7 +1072,7 @@ object_data = {
|
|||||||
'BuildRequestList': '1.0-cd95608eccb89fbc702c8b52f38ec738',
|
'BuildRequestList': '1.0-cd95608eccb89fbc702c8b52f38ec738',
|
||||||
'CellMapping': '1.0-7f1a7e85a22bbb7559fc730ab658b9bd',
|
'CellMapping': '1.0-7f1a7e85a22bbb7559fc730ab658b9bd',
|
||||||
'CellMappingList': '1.0-4ee0d9efdfd681fed822da88376e04d2',
|
'CellMappingList': '1.0-4ee0d9efdfd681fed822da88376e04d2',
|
||||||
'ComputeNode': '1.17-abc222ef5a707dcd3e3d32b48197c9e7',
|
'ComputeNode': '1.18-431fafd8ac4a5f3559bd9b1f1332cc22',
|
||||||
'ComputeNodeList': '1.17-52f3b0962b1c86b98590144463ebb192',
|
'ComputeNodeList': '1.17-52f3b0962b1c86b98590144463ebb192',
|
||||||
'DNSDomain': '1.0-7b0b2dab778454b6a7b6c66afe163a1a',
|
'DNSDomain': '1.0-7b0b2dab778454b6a7b6c66afe163a1a',
|
||||||
'DNSDomainList': '1.0-4ee0d9efdfd681fed822da88376e04d2',
|
'DNSDomainList': '1.0-4ee0d9efdfd681fed822da88376e04d2',
|
||||||
|
Reference in New Issue
Block a user