~gandelman-a/ubuntu/precise/nova/UCA_2012.2.1

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, Adam Gandelman
  • Date: 2012-06-22 12:39:57 UTC
  • mfrom: (1.1.57)
  • Revision ID: package-import@ubuntu.com-20120622123957-hbzwg84nt9rqwg8r
Tags: 2012.2~f2~20120621.14517-0ubuntu1
[ Chuck Short ]
* New upstream version.

[ Adam Gandelman ]
* debian/rules: Temporarily disable test suite while blocking
  tests are investigated. 
* debian/patches/kombu_tests_timeout.patch: Dropped.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
#    License for the specific language governing permissions and limitations
14
14
#    under the License.
15
15
 
16
 
import json
17
 
 
18
16
import webob
19
17
 
20
18
from nova import compute
21
19
from nova import exception
 
20
from nova.openstack.common import jsonutils
22
21
from nova import test
23
22
from nova.tests.api.openstack import fakes
24
23
 
29
28
 
30
29
def fake_get_vnc_console_invalid_type(self, _context,
31
30
                                      _instance, _console_type):
32
 
    raise exception.ConsoleTypeInvalid()
 
31
    raise exception.ConsoleTypeInvalid(console_type=_console_type)
 
32
 
 
33
 
 
34
def fake_get_vnc_console_not_found(self, _context, instance, _console_type):
 
35
    raise exception.InstanceNotFound(instance_id=instance["uuid"])
33
36
 
34
37
 
35
38
def fake_get(self, context, instance_uuid):
36
39
    return {'uuid': instance_uuid}
37
40
 
38
41
 
39
 
def fake_get_not_found(*args, **kwargs):
40
 
    raise exception.NotFound()
 
42
def fake_get_not_found(self, context, instance_uuid):
 
43
    raise exception.InstanceNotFound(instance_id=instance_uuid)
41
44
 
42
45
 
43
46
class ConsolesExtensionTest(test.TestCase):
52
55
        body = {'os-getVNCConsole': {'type': 'novnc'}}
53
56
        req = webob.Request.blank('/v2/fake/servers/1/action')
54
57
        req.method = "POST"
55
 
        req.body = json.dumps(body)
 
58
        req.body = jsonutils.dumps(body)
56
59
        req.headers["content-type"] = "application/json"
57
60
 
58
61
        res = req.get_response(fakes.wsgi_app())
59
 
        output = json.loads(res.body)
 
62
        output = jsonutils.loads(res.body)
60
63
        self.assertEqual(res.status_int, 200)
61
64
        self.assertEqual(output,
62
65
            {u'console': {u'url': u'http://fake', u'type': u'novnc'}})
63
66
 
64
67
    def test_get_vnc_console_no_type(self):
65
68
        self.stubs.Set(compute.API, 'get', fake_get)
 
69
        self.stubs.Set(compute.API, 'get_vnc_console',
 
70
                       fake_get_vnc_console_invalid_type)
66
71
        body = {'os-getVNCConsole': {}}
67
72
        req = webob.Request.blank('/v2/fake/servers/1/action')
68
73
        req.method = "POST"
69
 
        req.body = json.dumps(body)
 
74
        req.body = jsonutils.dumps(body)
70
75
        req.headers["content-type"] = "application/json"
71
76
 
72
77
        res = req.get_response(fakes.wsgi_app())
77
82
        body = {'os-getVNCConsole': {'type': 'novnc'}}
78
83
        req = webob.Request.blank('/v2/fake/servers/1/action')
79
84
        req.method = "POST"
80
 
        req.body = json.dumps(body)
 
85
        req.body = jsonutils.dumps(body)
81
86
        req.headers["content-type"] = "application/json"
82
87
 
83
88
        res = req.get_response(fakes.wsgi_app())
84
89
        self.assertEqual(res.status_int, 404)
85
90
 
86
91
    def test_get_vnc_console_no_instance_on_console_get(self):
87
 
        self.stubs.Set(compute.API, 'get_vnc_console', fake_get_not_found)
 
92
        self.stubs.Set(compute.API, 'get_vnc_console',
 
93
            fake_get_vnc_console_not_found)
88
94
        body = {'os-getVNCConsole': {'type': 'novnc'}}
89
95
        req = webob.Request.blank('/v2/fake/servers/1/action')
90
96
        req.method = "POST"
91
 
        req.body = json.dumps(body)
 
97
        req.body = jsonutils.dumps(body)
92
98
        req.headers["content-type"] = "application/json"
93
99
 
94
100
        res = req.get_response(fakes.wsgi_app())
101
107
                       fake_get_vnc_console_invalid_type)
102
108
        req = webob.Request.blank('/v2/fake/servers/1/action')
103
109
        req.method = "POST"
104
 
        req.body = json.dumps(body)
 
110
        req.body = jsonutils.dumps(body)
105
111
        req.headers["content-type"] = "application/json"
106
112
 
107
113
        res = req.get_response(fakes.wsgi_app())