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

« back to all changes in this revision

Viewing changes to nova/tests/api/openstack/v2/contrib/test_server_diagnostics.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
import unittest
 
18
 
 
19
from lxml import etree
 
20
 
 
21
from nova.api.openstack import v2
 
22
from nova.api.openstack.v2.contrib import server_diagnostics
 
23
from nova.api.openstack.v2 import extensions
 
24
from nova.api.openstack import wsgi
 
25
import nova.compute
 
26
from nova import test
 
27
from nova.tests.api.openstack import fakes
 
28
import nova.utils
 
29
 
 
30
 
 
31
def fake_get_diagnostics(self, _context, instance_uuid):
 
32
    return {'data': 'Some diagnostic info'}
 
33
 
 
34
 
 
35
def fake_instance_get(self, _context, instance_uuid):
 
36
    return {'uuid': instance_uuid}
 
37
 
 
38
 
 
39
class ServerDiagnosticsTest(test.TestCase):
 
40
 
 
41
    def setUp(self):
 
42
        super(ServerDiagnosticsTest, self).setUp()
 
43
        self.flags(allow_admin_api=True)
 
44
        self.flags(verbose=True)
 
45
        self.stubs.Set(nova.compute.API, 'get_diagnostics',
 
46
                       fake_get_diagnostics)
 
47
        self.stubs.Set(nova.compute.API, 'get', fake_instance_get)
 
48
        self.compute_api = nova.compute.API()
 
49
 
 
50
        self.router = v2.APIRouter()
 
51
        ext_middleware = extensions.ExtensionMiddleware(self.router)
 
52
        self.app = wsgi.LazySerializationMiddleware(ext_middleware)
 
53
 
 
54
    def test_get_diagnostics(self):
 
55
        uuid = nova.utils.gen_uuid()
 
56
        req = fakes.HTTPRequest.blank('/fake/servers/%s/diagnostics' % uuid)
 
57
        res = req.get_response(self.app)
 
58
        output = json.loads(res.body)
 
59
        self.assertEqual(output, {'data': 'Some diagnostic info'})
 
60
 
 
61
 
 
62
class TestServerDiagnosticsXMLSerializer(unittest.TestCase):
 
63
    namespace = wsgi.XMLNS_V11
 
64
 
 
65
    def _tag(self, elem):
 
66
        tagname = elem.tag
 
67
        self.assertEqual(tagname[0], '{')
 
68
        tmp = tagname.partition('}')
 
69
        namespace = tmp[0][1:]
 
70
        self.assertEqual(namespace, self.namespace)
 
71
        return tmp[2]
 
72
 
 
73
    def test_index_serializer(self):
 
74
        serializer = server_diagnostics.ServerDiagnosticsTemplate()
 
75
        exemplar = dict(diag1='foo', diag2='bar')
 
76
        text = serializer.serialize(exemplar)
 
77
 
 
78
        print text
 
79
        tree = etree.fromstring(text)
 
80
 
 
81
        self.assertEqual('diagnostics', self._tag(tree))
 
82
        self.assertEqual(len(tree), len(exemplar))
 
83
        for child in tree:
 
84
            tag = self._tag(child)
 
85
            self.assertTrue(tag in exemplar)
 
86
            self.assertEqual(child.text, exemplar[tag])