diff --git a/nova/objects/service.py b/nova/objects/service.py index 42088b7bfcea..7b08d184712a 100644 --- a/nova/objects/service.py +++ b/nova/objects/service.py @@ -130,7 +130,8 @@ class Service(base.NovaPersistentObject, base.NovaObject, # Version 1.19: Added get_minimum_version() # Version 1.20: Added get_minimum_version_multi() # Version 1.21: Added uuid - VERSION = '1.21' + # Version 1.22: Added get_by_uuid() + VERSION = '1.22' fields = { 'id': fields.IntegerField(read_only=True), @@ -266,6 +267,11 @@ class Service(base.NovaPersistentObject, base.NovaObject, db_service = db.service_get(context, service_id) return cls._from_db_object(context, cls(), db_service) + @base.remotable_classmethod + def get_by_uuid(cls, context, service_uuid): + db_service = db.service_get_by_uuid(context, service_uuid) + return cls._from_db_object(context, cls(), db_service) + @base.remotable_classmethod def get_by_host_and_topic(cls, context, host, topic): db_service = db.service_get_by_host_and_topic(context, host, topic) diff --git a/nova/tests/unit/objects/test_objects.py b/nova/tests/unit/objects/test_objects.py index 757fcffb0072..45e9e121ec37 100644 --- a/nova/tests/unit/objects/test_objects.py +++ b/nova/tests/unit/objects/test_objects.py @@ -1157,7 +1157,7 @@ object_data = { 'SecurityGroupList': '1.0-dc8bbea01ba09a2edb6e5233eae85cbc', 'SecurityGroupRule': '1.1-ae1da17b79970012e8536f88cb3c6b29', 'SecurityGroupRuleList': '1.2-0005c47fcd0fb78dd6d7fd32a1409f5b', - 'Service': '1.21-4ff88e4cd40f3b3ce923805f29d84ee0', + 'Service': '1.22-8a740459ab9bf258a19c8fcb875c2d9a', 'ServiceList': '1.19-5325bce13eebcbf22edc9678285270cc', 'TaskLog': '1.0-78b0534366f29aa3eebb01860fbe18fe', 'TaskLogList': '1.0-cc8cce1af8a283b9d28b55fcd682e777', diff --git a/nova/tests/unit/objects/test_service.py b/nova/tests/unit/objects/test_service.py index 6632e5273a68..efaf87b30fae 100644 --- a/nova/tests/unit/objects/test_service.py +++ b/nova/tests/unit/objects/test_service.py @@ -99,6 +99,10 @@ class _TestServiceObject(object): def test_get_by_id(self): self._test_query('service_get', 'get_by_id', 123) + def test_get_by_uuid(self): + self._test_query('service_get_by_uuid', 'get_by_uuid', + uuidsentinel.service_uuid) + def test_get_by_host_and_topic(self): self._test_query('service_get_by_host_and_topic', 'get_by_host_and_topic', 'fake-host', 'fake-topic')