~ubuntu-cloud-archive/ubuntu/precise/nova/trunk

« back to all changes in this revision

Viewing changes to nova/tests/api/openstack/v2/contrib/test_console_output.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, Adam Gandleman
  • Date: 2012-01-13 09:51:10 UTC
  • mfrom: (1.1.40)
  • Revision ID: package-import@ubuntu.com-20120113095110-ffd6163drcg77wez
Tags: 2012.1~e3~20120113.12049-0ubuntu1
[Chuck Short]
* New upstream version.
* debian/nova_sudoers, debian/nova-common.install, 
  Switch out to nova-rootwrap. (LP: #681774)
* Add "get-origsource-git" which allows developers to 
  generate a tarball from github, by doing:
  fakeroot debian/rules get-orig-source-git
* debian/debian/nova-objectstore.logrotate: Dont determine
  if we are running Debian or Ubuntu. (LP: #91379)

[Adam Gandleman]
* Removed python-nova.postinst, let dh_python2 generate instead since
  python-support is not a dependency. (LP: #907543)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2011 Eldar Nugaev
 
2
# All Rights Reserved.
 
3
#
 
4
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
5
#    not use this file except in compliance with the License. You may obtain
 
6
#    a copy of the License at
 
7
#
 
8
#         http://www.apache.org/licenses/LICENSE-2.0
 
9
#
 
10
#    Unless required by applicable law or agreed to in writing, software
 
11
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
12
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
13
#    License for the specific language governing permissions and limitations
 
14
#    under the License.
 
15
 
 
16
import json
 
17
 
 
18
import webob
 
19
 
 
20
from nova import compute
 
21
from nova import exception
 
22
from nova import test
 
23
from nova.tests.api.openstack import fakes
 
24
 
 
25
 
 
26
def fake_get_console_output(self, _context, _instance, tail_length):
 
27
    fixture = [str(i) for i in range(5)]
 
28
 
 
29
    if tail_length is None:
 
30
        pass
 
31
    elif tail_length == 0:
 
32
        fixture = []
 
33
    else:
 
34
        fixture = fixture[-int(tail_length):]
 
35
 
 
36
    return '\n'.join(fixture)
 
37
 
 
38
 
 
39
def fake_get(self, context, instance_uuid):
 
40
    return {'uuid': instance_uuid}
 
41
 
 
42
 
 
43
def fake_get_not_found(self, context, instance_uuid):
 
44
    raise exception.NotFound()
 
45
 
 
46
 
 
47
class ConsoleOutputExtensionTest(test.TestCase):
 
48
 
 
49
    def setUp(self):
 
50
        super(ConsoleOutputExtensionTest, self).setUp()
 
51
        self.stubs.Set(compute.API, 'get_console_output',
 
52
                       fake_get_console_output)
 
53
        self.stubs.Set(compute.API, 'get', fake_get)
 
54
 
 
55
    def test_get_text_console_instance_action(self):
 
56
        body = {'os-getConsoleOutput': {}}
 
57
        req = webob.Request.blank('/v2/fake/servers/1/action')
 
58
        req.method = "POST"
 
59
        req.body = json.dumps(body)
 
60
        req.headers["content-type"] = "application/json"
 
61
 
 
62
        res = req.get_response(fakes.wsgi_app())
 
63
        output = json.loads(res.body)
 
64
        self.assertEqual(res.status_int, 200)
 
65
        self.assertEqual(output, {'output': '0\n1\n2\n3\n4'})
 
66
 
 
67
    def test_get_console_output_with_tail(self):
 
68
        body = {'os-getConsoleOutput': {'length': 3}}
 
69
        req = webob.Request.blank('/v2/fake/servers/1/action')
 
70
        req.method = "POST"
 
71
        req.body = json.dumps(body)
 
72
        req.headers["content-type"] = "application/json"
 
73
        res = req.get_response(fakes.wsgi_app())
 
74
        output = json.loads(res.body)
 
75
        self.assertEqual(res.status_int, 200)
 
76
        self.assertEqual(output, {'output': '2\n3\n4'})
 
77
 
 
78
    def test_get_text_console_no_instance(self):
 
79
        self.stubs.Set(compute.API, 'get', fake_get_not_found)
 
80
        body = {'os-getConsoleOutput': {}}
 
81
        req = webob.Request.blank('/v2/fake/servers/1/action')
 
82
        req.method = "POST"
 
83
        req.body = json.dumps(body)
 
84
        req.headers["content-type"] = "application/json"
 
85
 
 
86
        res = req.get_response(fakes.wsgi_app())
 
87
        self.assertEqual(res.status_int, 404)
 
88
 
 
89
    def test_get_text_console_bad_body(self):
 
90
        body = {}
 
91
        req = webob.Request.blank('/v2/fake/servers/1/action')
 
92
        req.method = "POST"
 
93
        req.body = json.dumps(body)
 
94
        req.headers["content-type"] = "application/json"
 
95
 
 
96
        res = req.get_response(fakes.wsgi_app())
 
97
        self.assertEqual(res.status_int, 400)