From de9c02c09327327dff18f1d87e5164e316c3e3f5 Mon Sep 17 00:00:00 2001 From: Jon Bernard Date: Mon, 5 Mar 2018 17:59:49 -0800 Subject: [PATCH] OVO: support query for disabled services Add a additional parameter to get_by_host_and_topic() to query for disabled (or not) services. This defaults to False so remains transparent to existing callers. This is needed for the coming replication promotion patch where services are required to be disable prior to promotion. If this is the case, I must be able to access the disabled services in order to correctly perform the promotion operation. Change-Id: I8fc93c55546e6d4a582beaea9caebcbc9f18d98b --- cinder/objects/service.py | 4 ++-- cinder/tests/unit/objects/test_service.py | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/cinder/objects/service.py b/cinder/objects/service.py index 90a6a96bfb4..15f4a214d08 100644 --- a/cinder/objects/service.py +++ b/cinder/objects/service.py @@ -142,8 +142,8 @@ class Service(base.CinderPersistentObject, base.CinderObject, self.obj_reset_changes(fields=(attrname,)) @classmethod - def get_by_host_and_topic(cls, context, host, topic): - db_service = db.service_get(context, disabled=False, host=host, + def get_by_host_and_topic(cls, context, host, topic, disabled=False): + db_service = db.service_get(context, disabled=disabled, host=host, topic=topic) return cls._from_db_object(context, cls(context), db_service) diff --git a/cinder/tests/unit/objects/test_service.py b/cinder/tests/unit/objects/test_service.py index 7a709aed159..67289818312 100644 --- a/cinder/tests/unit/objects/test_service.py +++ b/cinder/tests/unit/objects/test_service.py @@ -13,6 +13,7 @@ # under the License. import datetime +import ddt import mock from oslo_utils import timeutils import pytz @@ -25,6 +26,7 @@ from cinder.tests.unit import fake_service from cinder.tests.unit import objects as test_objects +@ddt.ddt class TestService(test_objects.BaseObjectsTestCase): @mock.patch('cinder.db.sqlalchemy.api.service_get') @@ -35,15 +37,17 @@ class TestService(test_objects.BaseObjectsTestCase): self._compare(self, db_service, service) service_get.assert_called_once_with(self.context, 1) + @ddt.data(True, False) @mock.patch('cinder.db.service_get') - def test_get_by_host_and_topic(self, service_get): + def test_get_by_host_and_topic(self, show_disabled, service_get): db_service = fake_service.fake_db_service() service_get.return_value = db_service service = objects.Service.get_by_host_and_topic( - self.context, 'fake-host', 'fake-topic') + self.context, 'fake-host', 'fake-topic', disabled=show_disabled) self._compare(self, db_service, service) service_get.assert_called_once_with( - self.context, disabled=False, host='fake-host', topic='fake-topic') + self.context, disabled=show_disabled, host='fake-host', + topic='fake-topic') @mock.patch('cinder.db.service_get') def test_get_by_args(self, service_get):