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
This commit is contained in:
parent
0c78519f00
commit
de9c02c093
|
@ -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)
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue