]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix exception during service update
authorLisaLi <xiaoyan.li@intel.com>
Mon, 29 Feb 2016 07:12:18 +0000 (15:12 +0800)
committerLisaLi <xiaoyan.li@intel.com>
Wed, 2 Mar 2016 05:25:42 +0000 (13:25 +0800)
The function objects.Service.get_by_args raises HostBinaryNotFound
exception, but in service update function, it catches ServiceNotFound
exception by mistake.

This patch is to remove HostBinaryNotFound and use ServiceNotFound to make
things simple and consistent.

Change-Id: Ic2ef79ca03393f3b1eb5bb89d4ffcf92d76460c6
Closes-bug: #1551101

cinder/cmd/manage.py
cinder/db/sqlalchemy/api.py
cinder/exception.py
cinder/tests/unit/test_db_api.py

index 5c8ab2bcb8426bd3ba520193d85aa21dece34ce4..2f25e1463368bece3727cf8d0d5e7be9c70a5c0c 100644 (file)
@@ -450,7 +450,7 @@ class ServiceCommands(object):
         try:
             svc = objects.Service.get_by_args(ctxt, host_name, binary)
             svc.destroy()
-        except exception.HostBinaryNotFound as e:
+        except exception.ServiceNotFound as e:
             print(_("Host not found. Failed to remove %(service)s"
                     " on %(host)s.") %
                   {'service': binary, 'host': host_name})
index 407c4999c4c8ac857b6d616c1e4f724d91550bae..da554c249aeab1b642140d6d7330c4e4b6f3f20a 100644 (file)
@@ -426,7 +426,8 @@ def service_get_by_host_and_topic(context, host, topic):
         filter_by(topic=topic).\
         first()
     if not result:
-        raise exception.ServiceNotFound(service_id=None)
+        raise exception.ServiceNotFound(service_id=topic,
+                                        host=host)
     return result
 
 
@@ -441,7 +442,8 @@ def service_get_by_args(context, host, binary):
         if host == result['host']:
             return result
 
-    raise exception.HostBinaryNotFound(host=host, binary=binary)
+    raise exception.ServiceNotFound(service_id=binary,
+                                    host=host)
 
 
 @require_admin_context
index 9f5a50e0bd096f70dfe80829d19e33e99438c44b..75d071a56bd6f4c0c588d0d7e7d6e9d327488146 100644 (file)
@@ -362,7 +362,14 @@ class ImageNotFound(NotFound):
 
 
 class ServiceNotFound(NotFound):
-    message = _("Service %(service_id)s could not be found.")
+
+    def __init__(self, message=None, **kwargs):
+        if kwargs.get('host', None):
+            self.message = _("Service %(service_id)s could not be "
+                             "found on host %(host)s.")
+        else:
+            self.message = _("Service %(service_id)s could not be found.")
+        super(ServiceNotFound, self).__init__(None, **kwargs)
 
 
 class ServiceTooOld(Invalid):
@@ -381,10 +388,6 @@ class SchedulerHostWeigherNotFound(NotFound):
     message = _("Scheduler Host Weigher %(weigher_name)s could not be found.")
 
 
-class HostBinaryNotFound(NotFound):
-    message = _("Could not find binary %(binary)s on host %(host)s.")
-
-
 class InvalidReservationExpiration(Invalid):
     message = _("Invalid reservation expiration %(expire)s.")
 
index daa3eaf0d4aeefad87133a20974471673d406b7b..02f3359ef1085a5ae8a549554dd2c9b902708e35 100644 (file)
@@ -240,7 +240,7 @@ class DBAPIServiceTestCase(BaseTest):
         self._assertEqualObjects(services[1], service2)
 
     def test_service_get_by_args_not_found_exception(self):
-        self.assertRaises(exception.HostBinaryNotFound,
+        self.assertRaises(exception.ServiceNotFound,
                           db.service_get_by_args,
                           self.ctxt, 'non-exists-host', 'a')
 
@@ -282,7 +282,7 @@ class DBAPIServiceTestCase(BaseTest):
         service2 = db.service_get_by_args(self.ctxt, 'HOST', 'a')
         self._assertEqualObjects(services[1], service2)
 
-        self.assertRaises(exception.HostBinaryNotFound,
+        self.assertRaises(exception.ServiceNotFound,
                           db.service_get_by_args,
                           self.ctxt, 'Host', 'a')