21
22
from nova.compute import vm_states
22
23
from nova import context as context_maker
23
24
from nova import db
25
from nova import exception
24
26
from nova.openstack.common import log as logging
25
27
from nova import test
26
28
from nova.tests import fake_hosts
29
from nova.tests import utils
28
31
LOG = logging.getLogger(__name__)
50
53
if host_name == "notimplemented":
51
54
# The vm driver for this host doesn't support this feature
52
55
raise NotImplementedError()
56
elif host_name == "dummydest":
57
# The host does not exist
58
raise exception.ComputeHostNotFound(host=host_name)
53
59
elif host_name == "host_c2":
54
60
# Simulate a failure
55
61
return results[not enabled]
66
72
if host_name == "notimplemented":
67
73
# The vm driver for this host doesn't support this feature
68
74
raise NotImplementedError()
75
elif host_name == "dummydest":
76
# The host does not exist
77
raise exception.ComputeHostNotFound(host=host_name)
69
78
elif host_name == "host_c2":
70
79
# Simulate a failure
71
80
return results[not mode]
77
86
def stub_host_power_action(context, host_name, action):
78
87
if host_name == "notimplemented":
79
88
raise NotImplementedError()
89
elif host_name == "dummydest":
90
# The host does not exist
91
raise exception.ComputeHostNotFound(host=host_name)
219
231
def test_host_reboot_notimpl(self):
220
232
self._test_host_power_action_notimpl(self.controller.reboot)
234
def test_host_status_bad_host(self):
235
# A host given as an argument does not exist.
236
self.req.environ["nova.context"].is_admin = True
238
with testtools.ExpectedException(webob.exc.HTTPNotFound,
240
self.controller.update(self.req, dest, body={'status': 'enable'})
242
def test_host_maintenance_bad_host(self):
243
# A host given as an argument does not exist.
244
self.req.environ["nova.context"].is_admin = True
246
with testtools.ExpectedException(webob.exc.HTTPNotFound,
248
self.controller.update(self.req, dest,
249
body={'maintenance_mode': 'enable'})
251
def test_host_power_action_bad_host(self):
252
# A host given as an argument does not exist.
253
self.req.environ["nova.context"].is_admin = True
255
with testtools.ExpectedException(webob.exc.HTTPNotFound,
257
self.controller.reboot(self.req, dest)
222
259
def test_bad_status_value(self):
223
260
bad_body = {"status": "bad"}
224
261
self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update,
232
269
self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update,
233
270
self.req, "host_c1", bad_body)
235
def test_bad_update_key_and_correct_udpate_key(self):
272
def test_bad_update_key_and_correct_update_key(self):
236
273
bad_body = {"status": "disable", "crazy": "bad"}
237
274
self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update,
238
275
self.req, "host_c1", bad_body)
240
def test_good_udpate_keys(self):
277
def test_good_update_keys(self):
241
278
body = {"status": "disable", "maintenance_mode": "enable"}
242
279
result = self.controller.update(self.req, 'host_c1', body)
243
280
self.assertEqual(result["host"], "host_c1")
253
290
self.req.environ["nova.context"].is_admin = True
255
292
def test_show_host_not_exist(self):
256
# A host given as an argument does not exists.
293
# A host given as an argument does not exist.
257
294
self.req.environ["nova.context"].is_admin = True
258
295
dest = 'dummydest'
259
self.assertRaises(webob.exc.HTTPNotFound,
260
self.controller.show,
296
with testtools.ExpectedException(webob.exc.HTTPNotFound,
298
self.controller.show(self.req, dest)
263
300
def _create_compute_service(self):
264
301
"""Create compute-manager(ComputeNode and Service record)."""
390
427
result = self.deserializer.deserialize(intext)
392
429
self.assertEqual(dict(body=exemplar), result)
431
def test_corrupt_xml(self):
433
exception.MalformedRequestBody,
434
self.deserializer.deserialize,
435
utils.killer_xml_body())