~ubuntu-branches/ubuntu/saucy/nova/saucy-proposed

« back to all changes in this revision

Viewing changes to nova/tests/api/openstack/compute/plugins/v3/test_extended_status.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Adam Gandelman, James Page, Chuck Short
  • Date: 2013-07-19 09:15:03 UTC
  • mfrom: (1.1.73)
  • Revision ID: package-import@ubuntu.com-20130719091503-3khzpejd61moi5pf
Tags: 1:2013.2~b2-0ubuntu1
[ Adam Gandelman ]
* d/patches/requirements_drop_requests_vers_cap.patch: Remove
  upper version limit  on requests dependency, which was capped upstream
  to fix centos-related gating issues.
* debian/control:
  - Set version requirement python-kombu (>= 2.5.12).
  - Set version requirement python-pyparsing (>= 1.5.6).
  - Add websockify to nova-spiceproxy Depends.
  - Add spice-html5 to nova-spiceproxy Depends (LP: #1197119)
* Add nova-xvpvncproxy upstart (LP: #1197163)

[ James Page ]
* d/control: Update VCS fields for new branch locations. 

[ Chuck Short ]
* New upstream release.
* debian/patches/fix-requirements.patch: Combined several 
  patches into one.
* debian/control: Replace python-quantumclient with python-neutronclient.
* debian/patches/fix-sqlalchemy-0.7.9-usage.patch: Temporary patch to address a FTBFS
  with sqlalchemy 0.7.9.
* debian/patches/avoid-failing-test.patch: Skip failing test on buildds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2011 OpenStack Foundation
 
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
from lxml import etree
 
17
import webob
 
18
 
 
19
from nova.api.openstack.compute.plugins.v3 import extended_status
 
20
from nova import compute
 
21
from nova import db
 
22
from nova import exception
 
23
from nova.objects import instance as instance_obj
 
24
from nova.openstack.common import jsonutils
 
25
from nova import test
 
26
from nova.tests.api.openstack import fakes
 
27
 
 
28
UUID1 = '00000000-0000-0000-0000-000000000001'
 
29
UUID2 = '00000000-0000-0000-0000-000000000002'
 
30
UUID3 = '00000000-0000-0000-0000-000000000003'
 
31
 
 
32
 
 
33
def fake_compute_get(*args, **kwargs):
 
34
    return fakes.stub_instance(1, uuid=UUID3, task_state="kayaking",
 
35
            vm_state="slightly crunchy", power_state=1)
 
36
 
 
37
 
 
38
def fake_compute_get_all(*args, **kwargs):
 
39
    db_list = [
 
40
        fakes.stub_instance(1, uuid=UUID1, task_state="task-1",
 
41
                vm_state="vm-1", power_state=1),
 
42
        fakes.stub_instance(2, uuid=UUID2, task_state="task-2",
 
43
                vm_state="vm-2", power_state=2),
 
44
    ]
 
45
    fields = instance_obj.INSTANCE_DEFAULT_FIELDS
 
46
    return instance_obj._make_instance_list(args[1],
 
47
                                            instance_obj.InstanceList(),
 
48
                                            db_list, fields)
 
49
 
 
50
 
 
51
class ExtendedStatusTest(test.TestCase):
 
52
    content_type = 'application/json'
 
53
    prefix = 'os-extended-status:'
 
54
 
 
55
    def setUp(self):
 
56
        super(ExtendedStatusTest, self).setUp()
 
57
        fakes.stub_out_nw_api(self.stubs)
 
58
        self.stubs.Set(compute.api.API, 'get', fake_compute_get)
 
59
        self.stubs.Set(compute.api.API, 'get_all', fake_compute_get_all)
 
60
        self.stubs.Set(db, 'instance_get_by_uuid', fake_compute_get)
 
61
 
 
62
    def _make_request(self, url):
 
63
        req = webob.Request.blank(url)
 
64
        req.headers['Accept'] = self.content_type
 
65
        res = req.get_response(fakes.wsgi_app_v3(
 
66
            init_only=('servers',
 
67
                       'os-extended-status')))
 
68
        return res
 
69
 
 
70
    def _get_server(self, body):
 
71
        return jsonutils.loads(body).get('server')
 
72
 
 
73
    def _get_servers(self, body):
 
74
        return jsonutils.loads(body).get('servers')
 
75
 
 
76
    def assertServerStates(self, server, vm_state, power_state, task_state):
 
77
        self.assertEqual(server.get('%svm_state' % self.prefix), vm_state)
 
78
        self.assertEqual(int(server.get('%spower_state' % self.prefix)),
 
79
                         power_state)
 
80
        self.assertEqual(server.get('%stask_state' % self.prefix), task_state)
 
81
 
 
82
    def test_show(self):
 
83
        url = '/v3/servers/%s' % UUID3
 
84
        res = self._make_request(url)
 
85
 
 
86
        self.assertEqual(res.status_int, 200)
 
87
        self.assertServerStates(self._get_server(res.body),
 
88
                                vm_state='slightly crunchy',
 
89
                                power_state=1,
 
90
                                task_state='kayaking')
 
91
 
 
92
    def test_detail(self):
 
93
        url = '/v3/servers/detail'
 
94
        res = self._make_request(url)
 
95
 
 
96
        self.assertEqual(res.status_int, 200)
 
97
        for i, server in enumerate(self._get_servers(res.body)):
 
98
            self.assertServerStates(server,
 
99
                                    vm_state='vm-%s' % (i + 1),
 
100
                                    power_state=(i + 1),
 
101
                                    task_state='task-%s' % (i + 1))
 
102
 
 
103
    def test_no_instance_passthrough_404(self):
 
104
 
 
105
        def fake_compute_get(*args, **kwargs):
 
106
            raise exception.InstanceNotFound(instance_id='fake')
 
107
 
 
108
        self.stubs.Set(compute.api.API, 'get', fake_compute_get)
 
109
        url = '/v3/servers/70f6db34-de8d-4fbd-aafb-4065bdfa6115'
 
110
        res = self._make_request(url)
 
111
 
 
112
        self.assertEqual(res.status_int, 404)
 
113
 
 
114
 
 
115
class ExtendedStatusXmlTest(ExtendedStatusTest):
 
116
    content_type = 'application/xml'
 
117
    prefix = '{%s}' % extended_status.ExtendedStatus.namespace
 
118
 
 
119
    def _get_server(self, body):
 
120
        return etree.XML(body)
 
121
 
 
122
    def _get_servers(self, body):
 
123
        return etree.XML(body).getchildren()