diff --git a/cinder/cmd/manage.py b/cinder/cmd/manage.py index cd5396c240d..f787db589c0 100644 --- a/cinder/cmd/manage.py +++ b/cinder/cmd/manage.py @@ -466,8 +466,8 @@ class ServiceCommands(object): """Completely removes a service.""" ctxt = context.get_admin_context() try: - svc = db.service_get_by_args(ctxt, host_name, binary) - db.service_destroy(ctxt, svc['id']) + svc = objects.Service.get_by_args(ctxt, host_name, binary) + svc.destroy() except exception.HostBinaryNotFound as e: print(_("Host not found. Failed to remove %(service)s" " on %(host)s.") % diff --git a/cinder/tests/unit/api/contrib/test_snapshot_manage.py b/cinder/tests/unit/api/contrib/test_snapshot_manage.py index 500c01a5ae6..9e36c6451e2 100644 --- a/cinder/tests/unit/api/contrib/test_snapshot_manage.py +++ b/cinder/tests/unit/api/contrib/test_snapshot_manage.py @@ -20,6 +20,7 @@ from cinder import context from cinder import exception from cinder import test from cinder.tests.unit.api import fakes +from cinder.tests.unit import fake_service def app(): @@ -77,6 +78,9 @@ class SnapshotManageTest(test.TestCase): called with the correct arguments, and that we return the correct HTTP code to the caller. """ + ctxt = context.RequestContext('admin', 'fake', True) + mock_db.return_value = fake_service.fake_service_obj(ctxt) + body = {'snapshot': {'volume_id': 'fake_volume_id', 'ref': 'fake_ref'}} res = self._get_resp(body) self.assertEqual(202, res.status_int, res) diff --git a/cinder/tests/unit/test_cmd.py b/cinder/tests/unit/test_cmd.py index da2a1179da3..7499e3fc7e7 100644 --- a/cinder/tests/unit/test_cmd.py +++ b/cinder/tests/unit/test_cmd.py @@ -802,7 +802,7 @@ class TestCinderManageCmd(test.TestCase): @mock.patch('cinder.db.service_destroy') @mock.patch('cinder.db.service_get_by_args', - return_value = {'id': 'volID'}) + return_value = {'id': '12'}) def test_remove_service_success(self, mock_get_by_args, mock_service_destroy): service_commands = cinder_manage.ServiceCommands() diff --git a/cinder/volume/api.py b/cinder/volume/api.py index aa71bb4832e..5da39e1a05d 100644 --- a/cinder/volume/api.py +++ b/cinder/volume/api.py @@ -1598,8 +1598,8 @@ class API(base.Base): metadata=None): host = volume_utils.extract_host(volume['host']) try: - self.db.service_get_by_host_and_topic( - context.elevated(), host, CONF.volume_topic) + objects.Service.get_by_host_and_topic(context.elevated(), host, + CONF.volume_topic) except exception.ServiceNotFound: with excutils.save_and_reraise_exception(): LOG.error(_LE('Unable to find service: %(service)s for '