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

« back to all changes in this revision

Viewing changes to nova/tests/api/openstack/volume/contrib/test_types_extra_specs.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
 
# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
 
 
3
 
# Copyright (c) 2011 Zadara Storage Inc.
4
 
# Copyright (c) 2011 OpenStack LLC.
5
 
# Copyright 2011 University of Southern California
6
 
# All Rights Reserved.
7
 
#
8
 
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
9
 
#    not use this file except in compliance with the License. You may obtain
10
 
#    a copy of the License at
11
 
#
12
 
#         http://www.apache.org/licenses/LICENSE-2.0
13
 
#
14
 
#    Unless required by applicable law or agreed to in writing, software
15
 
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16
 
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17
 
#    License for the specific language governing permissions and limitations
18
 
#    under the License.
19
 
 
20
 
from lxml import etree
21
 
import webob
22
 
 
23
 
from nova.api.openstack.volume.contrib import types_extra_specs
24
 
from nova import test
25
 
from nova.tests.api.openstack import fakes
26
 
import nova.wsgi
27
 
 
28
 
 
29
 
def return_create_volume_type_extra_specs(context, volume_type_id,
30
 
                                          extra_specs):
31
 
    return stub_volume_type_extra_specs()
32
 
 
33
 
 
34
 
def return_volume_type_extra_specs(context, volume_type_id):
35
 
    return stub_volume_type_extra_specs()
36
 
 
37
 
 
38
 
def return_empty_volume_type_extra_specs(context, volume_type_id):
39
 
    return {}
40
 
 
41
 
 
42
 
def delete_volume_type_extra_specs(context, volume_type_id, key):
43
 
    pass
44
 
 
45
 
 
46
 
def stub_volume_type_extra_specs():
47
 
    specs = {
48
 
            "key1": "value1",
49
 
            "key2": "value2",
50
 
            "key3": "value3",
51
 
            "key4": "value4",
52
 
            "key5": "value5"}
53
 
    return specs
54
 
 
55
 
 
56
 
def volume_type_get(context, volume_type_id):
57
 
    pass
58
 
 
59
 
 
60
 
class VolumeTypesExtraSpecsTest(test.TestCase):
61
 
 
62
 
    def setUp(self):
63
 
        super(VolumeTypesExtraSpecsTest, self).setUp()
64
 
        self.stubs.Set(nova.db, 'volume_type_get', volume_type_get)
65
 
        self.api_path = '/v1/fake/os-volume-types/1/extra_specs'
66
 
        self.controller = types_extra_specs.VolumeTypeExtraSpecsController()
67
 
 
68
 
    def test_index(self):
69
 
        self.stubs.Set(nova.db, 'volume_type_extra_specs_get',
70
 
                       return_volume_type_extra_specs)
71
 
 
72
 
        req = fakes.HTTPRequest.blank(self.api_path)
73
 
        res_dict = self.controller.index(req, 1)
74
 
 
75
 
        self.assertEqual('value1', res_dict['extra_specs']['key1'])
76
 
 
77
 
    def test_index_no_data(self):
78
 
        self.stubs.Set(nova.db, 'volume_type_extra_specs_get',
79
 
                       return_empty_volume_type_extra_specs)
80
 
 
81
 
        req = fakes.HTTPRequest.blank(self.api_path)
82
 
        res_dict = self.controller.index(req, 1)
83
 
 
84
 
        self.assertEqual(0, len(res_dict['extra_specs']))
85
 
 
86
 
    def test_show(self):
87
 
        self.stubs.Set(nova.db, 'volume_type_extra_specs_get',
88
 
                       return_volume_type_extra_specs)
89
 
 
90
 
        req = fakes.HTTPRequest.blank(self.api_path + '/key5')
91
 
        res_dict = self.controller.show(req, 1, 'key5')
92
 
 
93
 
        self.assertEqual('value5', res_dict['key5'])
94
 
 
95
 
    def test_show_spec_not_found(self):
96
 
        self.stubs.Set(nova.db, 'volume_type_extra_specs_get',
97
 
                       return_empty_volume_type_extra_specs)
98
 
 
99
 
        req = fakes.HTTPRequest.blank(self.api_path + '/key6')
100
 
        self.assertRaises(webob.exc.HTTPNotFound, self.controller.show,
101
 
                          req, 1, 'key6')
102
 
 
103
 
    def test_delete(self):
104
 
        self.stubs.Set(nova.db, 'volume_type_extra_specs_delete',
105
 
                       delete_volume_type_extra_specs)
106
 
 
107
 
        req = fakes.HTTPRequest.blank(self.api_path + '/key5')
108
 
        self.controller.delete(req, 1, 'key5')
109
 
 
110
 
    def test_create(self):
111
 
        self.stubs.Set(nova.db,
112
 
                       'volume_type_extra_specs_update_or_create',
113
 
                       return_create_volume_type_extra_specs)
114
 
        body = {"extra_specs": {"key1": "value1"}}
115
 
 
116
 
        req = fakes.HTTPRequest.blank(self.api_path)
117
 
        res_dict = self.controller.create(req, 1, body)
118
 
 
119
 
        self.assertEqual('value1', res_dict['extra_specs']['key1'])
120
 
 
121
 
    def test_update_item(self):
122
 
        self.stubs.Set(nova.db,
123
 
                       'volume_type_extra_specs_update_or_create',
124
 
                       return_create_volume_type_extra_specs)
125
 
        body = {"key1": "value1"}
126
 
 
127
 
        req = fakes.HTTPRequest.blank(self.api_path + '/key1')
128
 
        res_dict = self.controller.update(req, 1, 'key1', body)
129
 
 
130
 
        self.assertEqual('value1', res_dict['key1'])
131
 
 
132
 
    def test_update_item_too_many_keys(self):
133
 
        self.stubs.Set(nova.db,
134
 
                       'volume_type_extra_specs_update_or_create',
135
 
                       return_create_volume_type_extra_specs)
136
 
        body = {"key1": "value1", "key2": "value2"}
137
 
 
138
 
        req = fakes.HTTPRequest.blank(self.api_path + '/key1')
139
 
        self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update,
140
 
                          req, 1, 'key1', body)
141
 
 
142
 
    def test_update_item_body_uri_mismatch(self):
143
 
        self.stubs.Set(nova.db,
144
 
                       'volume_type_extra_specs_update_or_create',
145
 
                       return_create_volume_type_extra_specs)
146
 
        body = {"key1": "value1"}
147
 
 
148
 
        req = fakes.HTTPRequest.blank(self.api_path + '/bad')
149
 
        self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update,
150
 
                          req, 1, 'bad', body)
151
 
 
152
 
 
153
 
class VolumeTypeExtraSpecsSerializerTest(test.TestCase):
154
 
    def test_index_create_serializer(self):
155
 
        serializer = types_extra_specs.VolumeTypeExtraSpecsTemplate()
156
 
 
157
 
        # Just getting some input data
158
 
        extra_specs = stub_volume_type_extra_specs()
159
 
        text = serializer.serialize(dict(extra_specs=extra_specs))
160
 
 
161
 
        print text
162
 
        tree = etree.fromstring(text)
163
 
 
164
 
        self.assertEqual('extra_specs', tree.tag)
165
 
        self.assertEqual(len(extra_specs), len(tree))
166
 
        seen = set(extra_specs.keys())
167
 
        for child in tree:
168
 
            self.assertTrue(child.tag in seen)
169
 
            self.assertEqual(extra_specs[child.tag], child.text)
170
 
            seen.remove(child.tag)
171
 
        self.assertEqual(len(seen), 0)
172
 
 
173
 
    def test_update_show_serializer(self):
174
 
        serializer = types_extra_specs.VolumeTypeExtraSpecTemplate()
175
 
 
176
 
        exemplar = dict(key1='value1')
177
 
        text = serializer.serialize(exemplar)
178
 
 
179
 
        print text
180
 
        tree = etree.fromstring(text)
181
 
 
182
 
        self.assertEqual('key1', tree.tag)
183
 
        self.assertEqual('value1', tree.text)
184
 
        self.assertEqual(0, len(tree))
185
 
 
186
 
 
187
 
class VolumeTypeExtraSpecsUnprocessableEntityTestCase(test.TestCase):
188
 
 
189
 
    """
190
 
    Tests of places we throw 422 Unprocessable Entity from
191
 
    """
192
 
 
193
 
    def setUp(self):
194
 
        super(VolumeTypeExtraSpecsUnprocessableEntityTestCase, self).setUp()
195
 
        self.controller = types_extra_specs.VolumeTypeExtraSpecsController()
196
 
 
197
 
    def _unprocessable_extra_specs_create(self, body):
198
 
        req = fakes.HTTPRequest.blank('/v2/fake/types/1/extra_specs')
199
 
        req.method = 'POST'
200
 
 
201
 
        self.assertRaises(webob.exc.HTTPUnprocessableEntity,
202
 
                          self.controller.create, req, '1', body)
203
 
 
204
 
    def test_create_no_body(self):
205
 
        self._unprocessable_extra_specs_create(body=None)
206
 
 
207
 
    def test_create_missing_volume(self):
208
 
        body = {'foo': {'a': 'b'}}
209
 
        self._unprocessable_extra_specs_create(body=body)
210
 
 
211
 
    def test_create_malformed_entity(self):
212
 
        body = {'extra_specs': 'string'}
213
 
        self._unprocessable_extra_specs_create(body=body)
214
 
 
215
 
    def _unprocessable_extra_specs_update(self, body):
216
 
        req = fakes.HTTPRequest.blank('/v2/fake/types/1/extra_specs')
217
 
        req.method = 'POST'
218
 
 
219
 
        self.assertRaises(webob.exc.HTTPUnprocessableEntity,
220
 
                          self.controller.update, req, '1', body)
221
 
 
222
 
    def test_update_no_body(self):
223
 
        self._unprocessable_extra_specs_update(body=None)
224
 
 
225
 
    def test_update_empty_body(self):
226
 
        self._unprocessable_extra_specs_update(body={})