~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_server_action_list.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-05-24 13:12:53 UTC
  • mfrom: (1.1.55)
  • Revision ID: package-import@ubuntu.com-20120524131253-ommql08fg1en06ut
Tags: 2012.2~f1-0ubuntu1
* New upstream release.
* Prepare for quantal:
  - Dropped debian/patches/upstream/0006-Use-project_id-in-ec2.cloud._format_image.patch
  - Dropped debian/patches/upstream/0005-Populate-image-properties-with-project_id-again.patch
  - Dropped debian/patches/upstream/0004-Fixed-bug-962840-added-a-test-case.patch
  - Dropped debian/patches/upstream/0003-Allow-unprivileged-RADOS-users-to-access-rbd-volumes.patch
  - Dropped debian/patches/upstream/0002-Stop-libvirt-test-from-deleting-instances-dir.patch
  - Dropped debian/patches/upstream/0001-fix-bug-where-nova-ignores-glance-host-in-imageref.patch 
  - Dropped debian/patches/0001-fix-useexisting-deprecation-warnings.patch
* debian/control: Add python-keystone as a dependency. (LP: #907197)
* debian/patches/kombu_tests_timeout.patch: Refreshed.
* debian/nova.conf, debian/nova-common.postinst: Convert to new ini
  file configuration
* debian/patches/nova-manage_flagfile_location.patch: Refreshed

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 datetime
17
 
import json
18
 
import unittest
19
 
 
20
 
from lxml import etree
21
 
 
22
 
from nova.api.openstack import compute
23
 
from nova.api.openstack.compute import extensions
24
 
from nova.api.openstack.compute.contrib import server_action_list
25
 
from nova.api.openstack import wsgi
26
 
import nova.compute
27
 
from nova import test
28
 
from nova.tests.api.openstack import fakes
29
 
import nova.utils
30
 
 
31
 
 
32
 
dt = datetime.datetime.utcnow()
33
 
 
34
 
 
35
 
def fake_get_actions(self, _context, instance_uuid):
36
 
    return [
37
 
        {'action': 'rebuild', 'error': None, 'created_at': dt},
38
 
        {'action': 'reboot', 'error': 'Failed!', 'created_at': dt},
39
 
    ]
40
 
 
41
 
 
42
 
def fake_instance_get(self, _context, instance_uuid):
43
 
    return {'uuid': instance_uuid}
44
 
 
45
 
 
46
 
class ServerActionsTest(test.TestCase):
47
 
 
48
 
    def setUp(self):
49
 
        super(ServerActionsTest, self).setUp()
50
 
        self.flags(verbose=True)
51
 
        self.stubs.Set(nova.compute.API, 'get_actions', fake_get_actions)
52
 
        self.stubs.Set(nova.compute.API, 'get', fake_instance_get)
53
 
 
54
 
        self.router = compute.APIRouter()
55
 
 
56
 
    def test_get_actions(self):
57
 
        uuid = nova.utils.gen_uuid()
58
 
        req = fakes.HTTPRequest.blank('/fake/servers/%s/actions' % uuid)
59
 
        res = req.get_response(self.router)
60
 
        output = json.loads(res.body)
61
 
        expected = {'actions': [
62
 
            {'action': 'rebuild', 'error': None, 'created_at': str(dt)},
63
 
            {'action': 'reboot', 'error': 'Failed!', 'created_at': str(dt)},
64
 
        ]}
65
 
        self.assertEqual(output, expected)
66
 
 
67
 
 
68
 
class TestServerActionsXMLSerializer(unittest.TestCase):
69
 
    namespace = wsgi.XMLNS_V11
70
 
 
71
 
    def _tag(self, elem):
72
 
        tagname = elem.tag
73
 
        self.assertEqual(tagname[0], '{')
74
 
        tmp = tagname.partition('}')
75
 
        namespace = tmp[0][1:]
76
 
        self.assertEqual(namespace, self.namespace)
77
 
        return tmp[2]
78
 
 
79
 
    def test_index_serializer(self):
80
 
        serializer = server_action_list.ServerActionsTemplate()
81
 
        exemplar = [dict(
82
 
                created_at=datetime.datetime.now(),
83
 
                action='foo',
84
 
                error='quxx'),
85
 
                    dict(
86
 
                created_at=datetime.datetime.now(),
87
 
                action='bar',
88
 
                error='xxuq')]
89
 
        text = serializer.serialize(dict(actions=exemplar))
90
 
 
91
 
        print text
92
 
        tree = etree.fromstring(text)
93
 
 
94
 
        self.assertEqual('actions', self._tag(tree))
95
 
        self.assertEqual(len(tree), len(exemplar))
96
 
        for idx, child in enumerate(tree):
97
 
            self.assertEqual('action', self._tag(child))
98
 
            for field in ('created_at', 'action', 'error'):
99
 
                self.assertEqual(str(exemplar[idx][field]), child.get(field))