~ubuntu-branches/ubuntu/raring/nova/raring-proposed

« back to all changes in this revision

Viewing changes to nova/tests/api/openstack/compute/contrib/test_hosts.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, James Page
  • Date: 2013-03-20 12:59:22 UTC
  • mfrom: (1.1.69)
  • Revision ID: package-import@ubuntu.com-20130320125922-ohvfav96lemn9wlz
Tags: 1:2013.1~rc1-0ubuntu1
[ Chuck Short ]
* New upstream release.
* debian/patches/avoid_setuptools_git_dependency.patch: Refreshed.
* debian/control: Clean up dependencies:
  - Dropped python-gflags no longer needed.
  - Dropped python-daemon no longer needed.
  - Dropped python-glance no longer needed.
  - Dropped python-lockfile no longer needed.
  - Dropped python-simplejson no longer needed.
  - Dropped python-tempita no longer needed.
  - Dropped python-xattr no longer needed.
  - Add sqlite3 required for the testsuite.

[ James Page ]
* d/watch: Update uversionmangle to deal with upstream versioning
  changes, remove tarballs.openstack.org. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (c) 2011 OpenStack, LLC.
 
1
# Copyright (c) 2011 OpenStack Foundation
2
2
# All Rights Reserved.
3
3
#
4
4
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
14
14
#    under the License.
15
15
 
16
16
from lxml import etree
 
17
import testtools
17
18
import webob.exc
18
19
 
19
20
from nova.api.openstack.compute.contrib import hosts as os_hosts
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
27
30
 
28
31
LOG = logging.getLogger(__name__)
29
32
 
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)
80
92
    return action
81
93
 
82
94
 
219
231
    def test_host_reboot_notimpl(self):
220
232
        self._test_host_power_action_notimpl(self.controller.reboot)
221
233
 
 
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
 
237
        dest = 'dummydest'
 
238
        with testtools.ExpectedException(webob.exc.HTTPNotFound,
 
239
                                         ".*%s.*" % dest):
 
240
            self.controller.update(self.req, dest, body={'status': 'enable'})
 
241
 
 
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
 
245
        dest = 'dummydest'
 
246
        with testtools.ExpectedException(webob.exc.HTTPNotFound,
 
247
                                         ".*%s.*" % dest):
 
248
            self.controller.update(self.req, dest,
 
249
                                   body={'maintenance_mode': 'enable'})
 
250
 
 
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
 
254
        dest = 'dummydest'
 
255
        with testtools.ExpectedException(webob.exc.HTTPNotFound,
 
256
                                         ".*%s.*" % dest):
 
257
            self.controller.reboot(self.req, dest)
 
258
 
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)
234
271
 
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)
239
276
 
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
254
291
 
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,
261
 
                          self.req, dest)
 
296
        with testtools.ExpectedException(webob.exc.HTTPNotFound,
 
297
                                         ".*%s.*" % dest):
 
298
            self.controller.show(self.req, dest)
262
299
 
263
300
    def _create_compute_service(self):
264
301
        """Create compute-manager(ComputeNode and Service record)."""
390
427
        result = self.deserializer.deserialize(intext)
391
428
 
392
429
        self.assertEqual(dict(body=exemplar), result)
 
430
 
 
431
    def test_corrupt_xml(self):
 
432
        self.assertRaises(
 
433
                exception.MalformedRequestBody,
 
434
                self.deserializer.deserialize,
 
435
                utils.killer_xml_body())