Merge "Fix exception during service update"
This commit is contained in:
commit
bd78839974
@ -451,7 +451,7 @@ class ServiceCommands(object):
|
|||||||
try:
|
try:
|
||||||
svc = objects.Service.get_by_args(ctxt, host_name, binary)
|
svc = objects.Service.get_by_args(ctxt, host_name, binary)
|
||||||
svc.destroy()
|
svc.destroy()
|
||||||
except exception.HostBinaryNotFound as e:
|
except exception.ServiceNotFound as e:
|
||||||
print(_("Host not found. Failed to remove %(service)s"
|
print(_("Host not found. Failed to remove %(service)s"
|
||||||
" on %(host)s.") %
|
" on %(host)s.") %
|
||||||
{'service': binary, 'host': host_name})
|
{'service': binary, 'host': host_name})
|
||||||
|
@ -438,7 +438,8 @@ def service_get_by_host_and_topic(context, host, topic):
|
|||||||
filter_by(topic=topic).\
|
filter_by(topic=topic).\
|
||||||
first()
|
first()
|
||||||
if not result:
|
if not result:
|
||||||
raise exception.ServiceNotFound(service_id=None)
|
raise exception.ServiceNotFound(service_id=topic,
|
||||||
|
host=host)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
@ -453,7 +454,8 @@ def service_get_by_args(context, host, binary):
|
|||||||
if host == result['host']:
|
if host == result['host']:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
raise exception.HostBinaryNotFound(host=host, binary=binary)
|
raise exception.ServiceNotFound(service_id=binary,
|
||||||
|
host=host)
|
||||||
|
|
||||||
|
|
||||||
@require_admin_context
|
@require_admin_context
|
||||||
|
@ -368,7 +368,14 @@ class ImageNotFound(NotFound):
|
|||||||
|
|
||||||
|
|
||||||
class ServiceNotFound(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):
|
class ServiceTooOld(Invalid):
|
||||||
@ -387,10 +394,6 @@ class SchedulerHostWeigherNotFound(NotFound):
|
|||||||
message = _("Scheduler Host Weigher %(weigher_name)s could not be found.")
|
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):
|
class InvalidReservationExpiration(Invalid):
|
||||||
message = _("Invalid reservation expiration %(expire)s.")
|
message = _("Invalid reservation expiration %(expire)s.")
|
||||||
|
|
||||||
|
@ -240,7 +240,7 @@ class DBAPIServiceTestCase(BaseTest):
|
|||||||
self._assertEqualObjects(services[1], service2)
|
self._assertEqualObjects(services[1], service2)
|
||||||
|
|
||||||
def test_service_get_by_args_not_found_exception(self):
|
def test_service_get_by_args_not_found_exception(self):
|
||||||
self.assertRaises(exception.HostBinaryNotFound,
|
self.assertRaises(exception.ServiceNotFound,
|
||||||
db.service_get_by_args,
|
db.service_get_by_args,
|
||||||
self.ctxt, 'non-exists-host', 'a')
|
self.ctxt, 'non-exists-host', 'a')
|
||||||
|
|
||||||
@ -282,7 +282,7 @@ class DBAPIServiceTestCase(BaseTest):
|
|||||||
service2 = db.service_get_by_args(self.ctxt, 'HOST', 'a')
|
service2 = db.service_get_by_args(self.ctxt, 'HOST', 'a')
|
||||||
self._assertEqualObjects(services[1], service2)
|
self._assertEqualObjects(services[1], service2)
|
||||||
|
|
||||||
self.assertRaises(exception.HostBinaryNotFound,
|
self.assertRaises(exception.ServiceNotFound,
|
||||||
db.service_get_by_args,
|
db.service_get_by_args,
|
||||||
self.ctxt, 'Host', 'a')
|
self.ctxt, 'Host', 'a')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user