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
"""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.") %
from cinder import exception
from cinder import test
from cinder.tests.unit.api import fakes
+from cinder.tests.unit import fake_service
def app():
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)
@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()
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 '