~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_manage.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
 
import webob
17
 
 
18
 
from nova.api.openstack.volume.contrib import types_manage
19
 
from nova import exception
20
 
from nova import test
21
 
from nova.tests.api.openstack import fakes
22
 
from nova.volume import volume_types
23
 
 
24
 
 
25
 
def stub_volume_type(id):
26
 
    specs = {
27
 
            "key1": "value1",
28
 
            "key2": "value2",
29
 
            "key3": "value3",
30
 
            "key4": "value4",
31
 
            "key5": "value5"}
32
 
    return dict(id=id, name='vol_type_%s' % str(id), extra_specs=specs)
33
 
 
34
 
 
35
 
def return_volume_types_get_volume_type(context, id):
36
 
    if id == "777":
37
 
        raise exception.VolumeTypeNotFound(volume_type_id=id)
38
 
    return stub_volume_type(int(id))
39
 
 
40
 
 
41
 
def return_volume_types_destroy(context, name):
42
 
    if name == "777":
43
 
        raise exception.VolumeTypeNotFoundByName(volume_type_name=name)
44
 
    pass
45
 
 
46
 
 
47
 
def return_volume_types_create(context, name, specs):
48
 
    pass
49
 
 
50
 
 
51
 
def return_volume_types_get_by_name(context, name):
52
 
    if name == "777":
53
 
        raise exception.VolumeTypeNotFoundByName(volume_type_name=name)
54
 
    return stub_volume_type(int(name.split("_")[2]))
55
 
 
56
 
 
57
 
class VolumeTypesManageApiTest(test.TestCase):
58
 
    def setUp(self):
59
 
        super(VolumeTypesManageApiTest, self).setUp()
60
 
        self.controller = types_manage.VolumeTypesManageController()
61
 
 
62
 
    def test_volume_types_delete(self):
63
 
        self.stubs.Set(volume_types, 'get_volume_type',
64
 
                       return_volume_types_get_volume_type)
65
 
        self.stubs.Set(volume_types, 'destroy',
66
 
                       return_volume_types_destroy)
67
 
 
68
 
        req = fakes.HTTPRequest.blank('/v1/fake/types/1')
69
 
        self.controller._delete(req, 1)
70
 
 
71
 
    def test_volume_types_delete_not_found(self):
72
 
        self.stubs.Set(volume_types, 'get_volume_type',
73
 
                       return_volume_types_get_volume_type)
74
 
        self.stubs.Set(volume_types, 'destroy',
75
 
                       return_volume_types_destroy)
76
 
 
77
 
        req = fakes.HTTPRequest.blank('/v1/fake/types/777')
78
 
        self.assertRaises(webob.exc.HTTPNotFound, self.controller._delete,
79
 
                          req, '777')
80
 
 
81
 
    def test_create(self):
82
 
        self.stubs.Set(volume_types, 'create',
83
 
                       return_volume_types_create)
84
 
        self.stubs.Set(volume_types, 'get_volume_type_by_name',
85
 
                       return_volume_types_get_by_name)
86
 
 
87
 
        body = {"volume_type": {"name": "vol_type_1",
88
 
                                "extra_specs": {"key1": "value1"}}}
89
 
        req = fakes.HTTPRequest.blank('/v1/fake/types')
90
 
        res_dict = self.controller._create(req, body)
91
 
 
92
 
        self.assertEqual(1, len(res_dict))
93
 
        self.assertEqual('vol_type_1', res_dict['volume_type']['name'])
94
 
 
95
 
 
96
 
class VolumeTypesUnprocessableEntityTestCase(test.TestCase):
97
 
 
98
 
    """
99
 
    Tests of places we throw 422 Unprocessable Entity from
100
 
    """
101
 
 
102
 
    def setUp(self):
103
 
        super(VolumeTypesUnprocessableEntityTestCase, self).setUp()
104
 
        self.controller = types_manage.VolumeTypesManageController()
105
 
 
106
 
    def _unprocessable_volume_type_create(self, body):
107
 
        req = fakes.HTTPRequest.blank('/v2/fake/types')
108
 
        req.method = 'POST'
109
 
 
110
 
        self.assertRaises(webob.exc.HTTPUnprocessableEntity,
111
 
                          self.controller._create, req, body)
112
 
 
113
 
    def test_create_no_body(self):
114
 
        self._unprocessable_volume_type_create(body=None)
115
 
 
116
 
    def test_create_missing_volume(self):
117
 
        body = {'foo': {'a': 'b'}}
118
 
        self._unprocessable_volume_type_create(body=body)
119
 
 
120
 
    def test_create_malformed_entity(self):
121
 
        body = {'volume_type': 'string'}
122
 
        self._unprocessable_volume_type_create(body=body)