~ubuntu-branches/ubuntu/raring/nova/raring-proposed

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, Adam Gandelman, Yolanda Robla, James Page
  • Date: 2013-01-11 13:06:56 UTC
  • mfrom: (1.1.67)
  • Revision ID: package-import@ubuntu.com-20130111130656-7n7fkevy03stm3mv
Tags: 2013.1~g2-0ubuntu1
[ Chuck Short ]
* New upstream release.
* debian/patches/ubuntu-show-tests.patch: Dropped no longer needed.
* debian/nova-xcp-plugins.install: Fix xcp-plugins empty packages
* debian/control: Drop python-nose in favor or testrepository
* debian/control: Add python-coverage as a build dep.
* debian/rules, debian/control: Run pep8 tests.
* debian/*.init: Remove they are not needed and take up space
* debian/control, debian/nova-cells.{install, logrotate, upstart}: Add
  cells support.
* debian/patches/fix-ubuntu-tests.patch: temporarily disable failing tests.
* debian/control, debian/nova-baremetal.{install, logrotate, upstart}: Add
  nova baremetal support.
* debian/control: Remove python-support.

[ Adam Gandelman ]
* debian/*.manpages: Install Sphinx-generated manpages instead of
  our own.
* debian/nova-compute-*.conf: Specify the newly required compute_driver
  flag in addition to libvirt_type.
* debian/control:  Specify required python-webob and python-stevedore
  versions.

[ Yolanda Robla ]
* debian/*.upstart: Use start-stop-daemon instead of su for chuid
  (LP: #1086833).
* debian/rules: Remove override of dh_installinit for discriminating
  between Debian and Ubuntu.
* debian/nova-common.docs: Installing changelogs from rules
* debian/rules: Replacing perms in /etc/nova/logging.conf for 0644
* debian/control: adduser dependency on nova-compute.
* debian/control: added section oldlibs and priority extra on
  nova-ajax-console-proxy.
* debian/nova-xvpvncproxy.postrm: removing because of duplicates.

[ James Page ]
* d/control: Add ~ to python-sqlalchemy-ext versioned dependencies to
  make backporting easier.
* d/control: Updated nova-volume description and depdendencies to
  mark it as a transitional package, moved to oldlibs/extra.
* d/p/fix-libvirt-tests.patch: Dropped; accepted upstream.
* d/control: Added python-stevedore to BD's.
* d/*.postrm: Dropped postrm's that just run update-rc.d; this is not
  required when deploying upstart configurations only.
* d/nova-scheduler.manpages: Add man page for nova-rpc-zmq-receiver.
* d/rules: Install upstream changelog with a policy compliant name.
* d/control: Mark nova-compute-xcp as virtual package.
* d/control: nova-api-os-volume; Depend on cinder-api and mark as
  transitional package.
* d/nova-api-os-volume.lintian-overrides: Dropped - no longer required.

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.contrib import extended_availability_zone
20
 
from nova import availability_zones
21
 
from nova import compute
22
 
from nova import exception
23
 
from nova.openstack.common import jsonutils
24
 
from nova import test
25
 
from nova.tests.api.openstack import fakes
26
 
 
27
 
UUID1 = '00000000-0000-0000-0000-000000000001'
28
 
UUID2 = '00000000-0000-0000-0000-000000000002'
29
 
UUID3 = '00000000-0000-0000-0000-000000000003'
30
 
 
31
 
 
32
 
def fake_compute_get(*args, **kwargs):
33
 
    inst = fakes.stub_instance(1, uuid=UUID3, host="get-host")
34
 
    return inst
35
 
 
36
 
 
37
 
def fake_compute_get_all(*args, **kwargs):
38
 
    inst1 = fakes.stub_instance(1, uuid=UUID1, host="all-host")
39
 
    inst2 = fakes.stub_instance(2, uuid=UUID2, host="all-host")
40
 
    return [inst1, inst2]
41
 
 
42
 
 
43
 
def fake_get_host_availability_zone(context, host):
44
 
    return host
45
 
 
46
 
 
47
 
class ExtendedServerAttributesTest(test.TestCase):
48
 
    content_type = 'application/json'
49
 
    prefix = 'OS-EXT-AZ:'
50
 
 
51
 
    def setUp(self):
52
 
        super(ExtendedServerAttributesTest, self).setUp()
53
 
        fakes.stub_out_nw_api(self.stubs)
54
 
        self.stubs.Set(compute.api.API, 'get', fake_compute_get)
55
 
        self.stubs.Set(compute.api.API, 'get_all', fake_compute_get_all)
56
 
        self.stubs.Set(availability_zones, 'get_host_availability_zone',
57
 
                       fake_get_host_availability_zone)
58
 
 
59
 
        self.flags(
60
 
            osapi_compute_extension=[
61
 
                'nova.api.openstack.compute.contrib.select_extensions'],
62
 
            osapi_compute_ext_list=['Extended_availability_zone'])
63
 
 
64
 
    def _make_request(self, url):
65
 
        req = webob.Request.blank(url)
66
 
        req.headers['Accept'] = self.content_type
67
 
        res = req.get_response(fakes.wsgi_app(init_only=('servers',)))
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 assertServerAttributes(self, server, az):
77
 
        self.assertEqual(server.get('%savailability_zone' % self.prefix),
78
 
                         az)
79
 
 
80
 
    def test_show(self):
81
 
        url = '/v2/fake/servers/%s' % UUID3
82
 
        res = self._make_request(url)
83
 
 
84
 
        self.assertEqual(res.status_int, 200)
85
 
        self.assertServerAttributes(self._get_server(res.body), 'get-host')
86
 
 
87
 
    def test_detail(self):
88
 
        url = '/v2/fake/servers/detail'
89
 
        res = self._make_request(url)
90
 
 
91
 
        self.assertEqual(res.status_int, 200)
92
 
        for i, server in enumerate(self._get_servers(res.body)):
93
 
            self.assertServerAttributes(server, 'all-host')
94
 
 
95
 
    def test_no_instance_passthrough_404(self):
96
 
 
97
 
        def fake_compute_get(*args, **kwargs):
98
 
            raise exception.InstanceNotFound(instance_id='fake')
99
 
 
100
 
        self.stubs.Set(compute.api.API, 'get', fake_compute_get)
101
 
        url = '/v2/fake/servers/70f6db34-de8d-4fbd-aafb-4065bdfa6115'
102
 
        res = self._make_request(url)
103
 
 
104
 
        self.assertEqual(res.status_int, 404)
105
 
 
106
 
 
107
 
class ExtendedServerAttributesXmlTest(ExtendedServerAttributesTest):
108
 
    content_type = 'application/xml'
109
 
    prefix = '{%s}' % extended_availability_zone.\
110
 
                        Extended_availability_zone.namespace
111
 
 
112
 
    def _get_server(self, body):
113
 
        return etree.XML(body)
114
 
 
115
 
    def _get_servers(self, body):
116
 
        return etree.XML(body).getchildren()