]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Use Service object instead of DB API directly
authorMichał Dulko <michal.dulko@intel.com>
Fri, 6 Nov 2015 11:37:23 +0000 (12:37 +0100)
committerMichał Dulko <michal.dulko@intel.com>
Fri, 6 Nov 2015 14:06:55 +0000 (15:06 +0100)
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

cinder/cmd/manage.py
cinder/tests/unit/api/contrib/test_snapshot_manage.py
cinder/tests/unit/test_cmd.py
cinder/volume/api.py

index cd5396c240ddfa47f9c168eeb99c32503cd83163..f787db589c047caa4befd619c816e1528f4cee46 100644 (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.") %
index 500c01a5ae6d9294a073075d6de0e6c946f41aa0..9e36c6451e239b38f3251fbcc13026a5bee2821b 100644 (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)
index da2a1179da30fa1c8a33cc234f68704f46b21194..7499e3fc7e788aaebfb7b4a6be2674a39b9bc3e6 100644 (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()
index aa71bb4832e5afa67b71453c92275789a7ebc4a7..5da39e1a05deedd547705ce4b853b2ce26ae08f1 100644 (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 '