summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/api/openstack/compute/contrib/test_hosts.py47
1 files changed, 41 insertions, 6 deletions
diff --git a/nova/tests/api/openstack/compute/contrib/test_hosts.py b/nova/tests/api/openstack/compute/contrib/test_hosts.py
index 5678933dc..d10f97d28 100644
--- a/nova/tests/api/openstack/compute/contrib/test_hosts.py
+++ b/nova/tests/api/openstack/compute/contrib/test_hosts.py
@@ -14,6 +14,7 @@
# under the License.
from lxml import etree
+import testtools
import webob.exc
from nova.api.openstack.compute.contrib import hosts as os_hosts
@@ -52,6 +53,9 @@ def stub_set_host_enabled(context, host_name, enabled):
if host_name == "notimplemented":
# The vm driver for this host doesn't support this feature
raise NotImplementedError()
+ elif host_name == "dummydest":
+ # The host does not exist
+ raise exception.ComputeHostNotFound(host=host_name)
elif host_name == "host_c2":
# Simulate a failure
return results[not enabled]
@@ -68,6 +72,9 @@ def stub_set_host_maintenance(context, host_name, mode):
if host_name == "notimplemented":
# The vm driver for this host doesn't support this feature
raise NotImplementedError()
+ elif host_name == "dummydest":
+ # The host does not exist
+ raise exception.ComputeHostNotFound(host=host_name)
elif host_name == "host_c2":
# Simulate a failure
return results[not mode]
@@ -79,6 +86,9 @@ def stub_set_host_maintenance(context, host_name, mode):
def stub_host_power_action(context, host_name, action):
if host_name == "notimplemented":
raise NotImplementedError()
+ elif host_name == "dummydest":
+ # The host does not exist
+ raise exception.ComputeHostNotFound(host=host_name)
return action
@@ -221,6 +231,31 @@ class HostTestCase(test.TestCase):
def test_host_reboot_notimpl(self):
self._test_host_power_action_notimpl(self.controller.reboot)
+ def test_host_status_bad_host(self):
+ # A host given as an argument does not exist.
+ self.req.environ["nova.context"].is_admin = True
+ dest = 'dummydest'
+ with testtools.ExpectedException(webob.exc.HTTPNotFound,
+ ".*%s.*" % dest):
+ self.controller.update(self.req, dest, body={'status': 'enable'})
+
+ def test_host_maintenance_bad_host(self):
+ # A host given as an argument does not exist.
+ self.req.environ["nova.context"].is_admin = True
+ dest = 'dummydest'
+ with testtools.ExpectedException(webob.exc.HTTPNotFound,
+ ".*%s.*" % dest):
+ self.controller.update(self.req, dest,
+ body={'maintenance_mode': 'enable'})
+
+ def test_host_power_action_bad_host(self):
+ # A host given as an argument does not exist.
+ self.req.environ["nova.context"].is_admin = True
+ dest = 'dummydest'
+ with testtools.ExpectedException(webob.exc.HTTPNotFound,
+ ".*%s.*" % dest):
+ self.controller.reboot(self.req, dest)
+
def test_bad_status_value(self):
bad_body = {"status": "bad"}
self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update,
@@ -234,12 +269,12 @@ class HostTestCase(test.TestCase):
self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update,
self.req, "host_c1", bad_body)
- def test_bad_update_key_and_correct_udpate_key(self):
+ def test_bad_update_key_and_correct_update_key(self):
bad_body = {"status": "disable", "crazy": "bad"}
self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update,
self.req, "host_c1", bad_body)
- def test_good_udpate_keys(self):
+ def test_good_update_keys(self):
body = {"status": "disable", "maintenance_mode": "enable"}
result = self.controller.update(self.req, 'host_c1', body)
self.assertEqual(result["host"], "host_c1")
@@ -255,12 +290,12 @@ class HostTestCase(test.TestCase):
self.req.environ["nova.context"].is_admin = True
def test_show_host_not_exist(self):
- # A host given as an argument does not exists.
+ # A host given as an argument does not exist.
self.req.environ["nova.context"].is_admin = True
dest = 'dummydest'
- self.assertRaises(webob.exc.HTTPNotFound,
- self.controller.show,
- self.req, dest)
+ with testtools.ExpectedException(webob.exc.HTTPNotFound,
+ ".*%s.*" % dest):
+ self.controller.show(self.req, dest)
def _create_compute_service(self):
"""Create compute-manager(ComputeNode and Service record)."""