Use Service object instead of DB API directly

In cmd.manage and volume.api we had code accessing DB API directly.
This should be done through Service versioned object instead and this
commit fixes that.

Change-Id: I7c65323279b86c37fce7ffeb2b2626508842edfb
Closes-Bug: 1513806
This commit is contained in:
Michał Dulko 2015-11-06 12:37:23 +01:00
parent 91f1881440
commit 2e6a2872e8
4 changed files with 9 additions and 5 deletions

View File

@ -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.") %

View File

@ -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)

View File

@ -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()

View File

@ -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 '