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

« back to all changes in this revision

Viewing changes to nova/tests/api/openstack/volume/test_types.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Adam Gandelman, Chuck Short
  • Date: 2012-11-23 09:04:58 UTC
  • mfrom: (1.1.66)
  • Revision ID: package-import@ubuntu.com-20121123090458-91565o7aev1i1h71
Tags: 2013.1~g1-0ubuntu1
[ Adam Gandelman ]
* debian/control: Ensure novaclient is upgraded with nova,
  require python-keystoneclient >= 1:2.9.0. (LP: #1073289)
* debian/patches/{ubuntu/*, rbd-security.patch}: Dropped, applied
  upstream.
* debian/control: Add python-testtools to Build-Depends.

[ Chuck Short ]
* New upstream version.
* Refreshed debian/patches/avoid_setuptools_git_dependency.patch.
* debian/rules: FTBFS if missing binaries.
* debian/nova-scheudler.install: Add missing rabbit-queues and
  nova-rpc-zmq-receiver.
* Remove nova-volume since it doesnt exist anymore, transition to cinder-*.
* debian/rules: install apport hook in the right place.
* debian/patches/ubuntu-show-tests.patch: Display test failures.
* debian/control: Add depends on genisoimage
* debian/control: Suggest guestmount.
* debian/control: Suggest websockify. (LP: #1076442)
* debian/nova.conf: Disable nova-volume service.
* debian/control: Depend on xen-system-* rather than the hypervisor.
* debian/control, debian/mans/nova-conductor.8, debian/nova-conductor.init,
  debian/nova-conductor.install, debian/nova-conductor.logrotate
  debian/nova-conductor.manpages, debian/nova-conductor.postrm
  debian/nova-conductor.upstart.in: Add nova-conductor service.
* debian/control: Add python-fixtures as a build deps.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2011 OpenStack LLC.
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.volume import types
20
 
from nova.api.openstack.volume.views import types as views_types
21
 
from nova import exception
22
 
from nova.openstack.common import timeutils
23
 
from nova import test
24
 
from nova.tests.api.openstack import fakes
25
 
from nova.volume import volume_types
26
 
 
27
 
 
28
 
def stub_volume_type(id):
29
 
    specs = {
30
 
            "key1": "value1",
31
 
            "key2": "value2",
32
 
            "key3": "value3",
33
 
            "key4": "value4",
34
 
            "key5": "value5"}
35
 
    return dict(id=id, name='vol_type_%s' % str(id), extra_specs=specs)
36
 
 
37
 
 
38
 
def return_volume_types_get_all_types(context):
39
 
    return dict(vol_type_1=stub_volume_type(1),
40
 
                vol_type_2=stub_volume_type(2),
41
 
                vol_type_3=stub_volume_type(3))
42
 
 
43
 
 
44
 
def return_empty_volume_types_get_all_types(context):
45
 
    return {}
46
 
 
47
 
 
48
 
def return_volume_types_get_volume_type(context, id):
49
 
    if id == "777":
50
 
        raise exception.VolumeTypeNotFound(volume_type_id=id)
51
 
    return stub_volume_type(int(id))
52
 
 
53
 
 
54
 
def return_volume_types_get_by_name(context, name):
55
 
    if name == "777":
56
 
        raise exception.VolumeTypeNotFoundByName(volume_type_name=name)
57
 
    return stub_volume_type(int(name.split("_")[2]))
58
 
 
59
 
 
60
 
class VolumeTypesApiTest(test.TestCase):
61
 
    def setUp(self):
62
 
        super(VolumeTypesApiTest, self).setUp()
63
 
        self.controller = types.VolumeTypesController()
64
 
 
65
 
    def test_volume_types_index(self):
66
 
        self.stubs.Set(volume_types, 'get_all_types',
67
 
                       return_volume_types_get_all_types)
68
 
 
69
 
        req = fakes.HTTPRequest.blank('/v1/fake/types')
70
 
        res_dict = self.controller.index(req)
71
 
 
72
 
        self.assertEqual(3, len(res_dict['volume_types']))
73
 
 
74
 
        expected_names = ['vol_type_1', 'vol_type_2', 'vol_type_3']
75
 
        actual_names = map(lambda e: e['name'], res_dict['volume_types'])
76
 
        self.assertEqual(set(actual_names), set(expected_names))
77
 
        for entry in res_dict['volume_types']:
78
 
            self.assertEqual('value1', entry['extra_specs']['key1'])
79
 
 
80
 
    def test_volume_types_index_no_data(self):
81
 
        self.stubs.Set(volume_types, 'get_all_types',
82
 
                       return_empty_volume_types_get_all_types)
83
 
 
84
 
        req = fakes.HTTPRequest.blank('/v1/fake/types')
85
 
        res_dict = self.controller.index(req)
86
 
 
87
 
        self.assertEqual(0, len(res_dict['volume_types']))
88
 
 
89
 
    def test_volume_types_show(self):
90
 
        self.stubs.Set(volume_types, 'get_volume_type',
91
 
                       return_volume_types_get_volume_type)
92
 
 
93
 
        req = fakes.HTTPRequest.blank('/v1/fake/types/1')
94
 
        res_dict = self.controller.show(req, 1)
95
 
 
96
 
        self.assertEqual(1, len(res_dict))
97
 
        self.assertEqual('1', res_dict['volume_type']['id'])
98
 
        self.assertEqual('vol_type_1', res_dict['volume_type']['name'])
99
 
 
100
 
    def test_volume_types_show_not_found(self):
101
 
        self.stubs.Set(volume_types, 'get_volume_type',
102
 
                       return_volume_types_get_volume_type)
103
 
 
104
 
        req = fakes.HTTPRequest.blank('/v1/fake/types/777')
105
 
        self.assertRaises(webob.exc.HTTPNotFound, self.controller.show,
106
 
                          req, '777')
107
 
 
108
 
    def test_view_builder_show(self):
109
 
        view_builder = views_types.ViewBuilder()
110
 
 
111
 
        now = timeutils.isotime()
112
 
        raw_volume_type = dict(name='new_type',
113
 
                               deleted=False,
114
 
                               created_at=now,
115
 
                               updated_at=now,
116
 
                               extra_specs={},
117
 
                               deleted_at=None,
118
 
                               id=42)
119
 
 
120
 
        request = fakes.HTTPRequest.blank("/v1")
121
 
        output = view_builder.show(request, raw_volume_type)
122
 
 
123
 
        self.assertTrue('volume_type' in output)
124
 
        expected_volume_type = dict(name='new_type',
125
 
                                    extra_specs={},
126
 
                                    id=42)
127
 
        self.assertDictMatch(output['volume_type'], expected_volume_type)
128
 
 
129
 
    def test_view_builder_list(self):
130
 
        view_builder = views_types.ViewBuilder()
131
 
 
132
 
        now = timeutils.isotime()
133
 
        raw_volume_types = []
134
 
        for i in range(0, 10):
135
 
            raw_volume_types.append(dict(name='new_type',
136
 
                                         deleted=False,
137
 
                                         created_at=now,
138
 
                                         updated_at=now,
139
 
                                         extra_specs={},
140
 
                                         deleted_at=None,
141
 
                                         id=42 + i))
142
 
 
143
 
        request = fakes.HTTPRequest.blank("/v1")
144
 
        output = view_builder.index(request, raw_volume_types)
145
 
 
146
 
        self.assertTrue('volume_types' in output)
147
 
        for i in range(0, 10):
148
 
            expected_volume_type = dict(name='new_type',
149
 
                                        extra_specs={},
150
 
                                        id=42 + i)
151
 
            self.assertDictMatch(output['volume_types'][i],
152
 
                                 expected_volume_type)
153
 
 
154
 
 
155
 
class VolumeTypesSerializerTest(test.TestCase):
156
 
    def _verify_volume_type(self, vtype, tree):
157
 
        self.assertEqual('volume_type', tree.tag)
158
 
        self.assertEqual(vtype['name'], tree.get('name'))
159
 
        self.assertEqual(str(vtype['id']), tree.get('id'))
160
 
        self.assertEqual(1, len(tree))
161
 
        extra_specs = tree[0]
162
 
        self.assertEqual('extra_specs', extra_specs.tag)
163
 
        seen = set(vtype['extra_specs'].keys())
164
 
        for child in extra_specs:
165
 
            self.assertTrue(child.tag in seen)
166
 
            self.assertEqual(vtype['extra_specs'][child.tag], child.text)
167
 
            seen.remove(child.tag)
168
 
        self.assertEqual(len(seen), 0)
169
 
 
170
 
    def test_index_serializer(self):
171
 
        serializer = types.VolumeTypesTemplate()
172
 
 
173
 
        # Just getting some input data
174
 
        vtypes = return_volume_types_get_all_types(None)
175
 
        text = serializer.serialize({'volume_types': vtypes.values()})
176
 
 
177
 
        tree = etree.fromstring(text)
178
 
 
179
 
        self.assertEqual('volume_types', tree.tag)
180
 
        self.assertEqual(len(vtypes), len(tree))
181
 
        for child in tree:
182
 
            name = child.get('name')
183
 
            self.assertTrue(name in vtypes)
184
 
            self._verify_volume_type(vtypes[name], child)
185
 
 
186
 
    def test_voltype_serializer(self):
187
 
        serializer = types.VolumeTypeTemplate()
188
 
 
189
 
        vtype = stub_volume_type(1)
190
 
        text = serializer.serialize(dict(volume_type=vtype))
191
 
 
192
 
        tree = etree.fromstring(text)
193
 
 
194
 
        self._verify_volume_type(vtype, tree)