summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-03-12 23:58:43 +0000
committerGerrit Code Review <review@openstack.org>2013-03-12 23:58:43 +0000
commit071719a3e16b747bc9c2cdadab829c3c1287eede (patch)
tree6d9f4781c400eca0385a5220072729e368f11c58
parent57231f485e3f35b270ef1313e037d9f8f7ca7575 (diff)
parent071a41f1d052bd01b181e4ae5d6e9aa5f0b39b8b (diff)
downloadnova-071719a3e16b747bc9c2cdadab829c3c1287eede.tar.gz
nova-071719a3e16b747bc9c2cdadab829c3c1287eede.tar.xz
nova-071719a3e16b747bc9c2cdadab829c3c1287eede.zip
Merge "Fix: nova-manage throws uncaught exception on invalid host/service"
-rwxr-xr-xbin/nova-manage24
-rw-r--r--nova/tests/test_nova_manage.py14
2 files changed, 28 insertions, 10 deletions
diff --git a/bin/nova-manage b/bin/nova-manage
index 274ae4640..96e4a4012 100755
--- a/bin/nova-manage
+++ b/bin/nova-manage
@@ -675,11 +675,13 @@ class ServiceCommands(object):
def enable(self, host, service):
"""Enable scheduling for a service."""
ctxt = context.get_admin_context()
- svc = db.service_get_by_args(ctxt, host, service)
- if not svc:
- print _("Unable to find service")
- return
- db.service_update(ctxt, svc['id'], {'disabled': False})
+ try:
+ svc = db.service_get_by_args(ctxt, host, service)
+ db.service_update(ctxt, svc['id'], {'disabled': False})
+ except exception.NotFound as ex:
+ print _("error: %s") % ex
+ sys.exit(2)
+ print _("Service %(service)s on host %(host)s enabled.") % locals()
@args('--host', dest='host', metavar='<host>', help='Host')
@args('--service', dest='service', metavar='<service>',
@@ -687,11 +689,13 @@ class ServiceCommands(object):
def disable(self, host, service):
"""Disable scheduling for a service."""
ctxt = context.get_admin_context()
- svc = db.service_get_by_args(ctxt, host, service)
- if not svc:
- print _("Unable to find service")
- return
- db.service_update(ctxt, svc['id'], {'disabled': True})
+ try:
+ svc = db.service_get_by_args(ctxt, host, service)
+ db.service_update(ctxt, svc['id'], {'disabled': True})
+ except exception.NotFound as ex:
+ print _("error: %s") % ex
+ sys.exit(2)
+ print _("Service %(service)s on host %(host)s disabled.") % locals()
@args('--host', dest='host', metavar='<host>', help='Host')
def describe_resource(self, host):
diff --git a/nova/tests/test_nova_manage.py b/nova/tests/test_nova_manage.py
index b1d1958f0..49f9f3256 100644
--- a/nova/tests/test_nova_manage.py
+++ b/nova/tests/test_nova_manage.py
@@ -382,3 +382,17 @@ class DBCommandsTestCase(test.TestCase):
def test_archive_deleted_rows_negative(self):
self.assertRaises(SystemExit,
self.commands.archive_deleted_rows, -1)
+
+
+class ServiceCommandsTestCase(test.TestCase):
+ def setUp(self):
+ super(ServiceCommandsTestCase, self).setUp()
+ self.commands = nova_manage.ServiceCommands()
+
+ def test_service_enable_invalid_params(self):
+ self.assertRaises(SystemExit,
+ self.commands.enable, 'nohost', 'noservice')
+
+ def test_service_disable_invalid_params(self):
+ self.assertRaises(SystemExit,
+ self.commands.disable, 'nohost', 'noservice')