~ubuntu-branches/ubuntu/precise/nova/precise-proposed

« back to all changes in this revision

Viewing changes to .pc/fix-pep8-errors.patch/nova/tests/api/openstack/compute/contrib/test_disk_config.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-06-05 09:50:59 UTC
  • mfrom: (1.1.55)
  • Revision ID: package-import@ubuntu.com-20120605095059-h16yl96dyy280wwd
Tags: 2012.1+stable~20120612-3ee026e-0ubuntu1
* New upstream snapshot. (LP: #1010473)
* Dropped, superseeded by new snapshot:
  - debian/patches/upstream/0001-fix-bug-where-nova-ignores-glance-host-in-imageref.patch
  - debian/patches/upstream/0002-Stop-libvirt-test-from-deleting-instances-dir.patch
  - debian/patches/upstream/0003-Allow-unprivileged-RADOS-users-to-access-rbd-volumes.patch
  - debian/patches/upstream/0004-Fixed-bug-962840-added-a-test-case.patch
  - debian/patches/upstream/0005-Populate-image-properties-with-project_id-again.patch
  - debian/patches/upstream/0006-Use-project_id-in-ec2.cloud._format_image.patc
  - debian/patches/CVE-2012-2101.patch
  - debian/patches/CVE-2012-2654.patch
* Resynchronize with stable/essex:
  - 3ee026e Only invoke .lower() on non-None protocols. (LP: #1010514)
  - f0a9f47 Create a utf8 version of the dns_domains table. (LP: #993663)
  - 84a43e1 Report memory correctly on Xen. (LP: #997014) 
  - 8c72924 Add libvirt get_console_output tests: pty and file. (LP: #990237)
  - 4e423cd Fix Multi_Scheduler to process host capabilities. (LP: #1000403)
  - 4aea7f1 Nail pep8 dependencies to 1.0.1
  - 2b3bbc4 handle updated qemu-img info output. (LP: #1000261)
  - 2d7d51c Fix type of snapshot_id column to match db. (LP: #962615)
  - ec70c69 Generate a Changelog for Nova
  - e5e890f Fix nova.tests.test_nova_rootwrap on Fedora 17. (LP: #992916)
  - 9e9a554 Ec2 handle strings with "0x" (LP: #983206)
  - 26dc6b7 QuantumManager will start dnsmasq during startup. Fixes (LP: #977759)
  - 7028d66 Introduced flag base_dir_name. (LP: #973194)
  - 76b525a Get unit tests functional in OS X.
  - facb936 Update KillFilter to handle 'deleted' exe's. (LP: #967931) 
  - 1209af4 Checks if value is string or not before decode. (LP: #952176)
  - 1209af4 Fix timeout in EC2 CloudController.create_image(). (LP: #989764)
  - 108e74b Re-add console_log from console_console_output(). (LP: #987335)
  - 48a0768 Don't leak RPC connections on timeouts or other exceptions. (LP: #968843)
  - 7c64de9 Cloudpipe tap vpn not always working. (LP: #975043)
  - 5ab5051 add libvirt_inject_key flag fix (LP: #971640)
  - 6c68ef5 Xen: Pass session to destroy_vdi. (LP: #988615)
  - 015744e Delete fixed_ips when network is deleted. (LP: #754900)
* Add debian/scripts/changelog.sh to help generate the changelog.
* Add debian/nova-common.docs:
  - Include changelog and README.rst
* debian/rules: Generate a tarball from git snapshot.
* debian/patches/fix-pep8-errors.patch: Fix pep8 errors due to pep8 upstream
  migration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
#
 
3
# Copyright 2011 OpenStack LLC.
 
4
# All Rights Reserved.
 
5
#
 
6
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
7
#    not use this file except in compliance with the License. You may obtain
 
8
#    a copy of the License at
 
9
#
 
10
#         http://www.apache.org/licenses/LICENSE-2.0
 
11
#
 
12
#    Unless required by applicable law or agreed to in writing, software
 
13
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
14
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
15
#    License for the specific language governing permissions and limitations
 
16
#    under the License.
 
17
 
 
18
import datetime
 
19
 
 
20
from nova.api.openstack  import compute
 
21
from nova.api.openstack.compute import extensions
 
22
from nova.api.openstack import wsgi
 
23
import nova.db.api
 
24
from nova import flags
 
25
import nova.rpc
 
26
from nova import test
 
27
from nova.tests.api.openstack import fakes
 
28
from nova import utils
 
29
 
 
30
 
 
31
MANUAL_INSTANCE_UUID = fakes.FAKE_UUID
 
32
AUTO_INSTANCE_UUID = fakes.FAKE_UUID.replace('a', 'b')
 
33
 
 
34
stub_instance = fakes.stub_instance
 
35
FLAGS = flags.FLAGS
 
36
 
 
37
 
 
38
API_DISK_CONFIG = 'OS-DCF:diskConfig'
 
39
 
 
40
 
 
41
def instance_addresses(context, instance_id):
 
42
    return None
 
43
 
 
44
 
 
45
class DiskConfigTestCase(test.TestCase):
 
46
 
 
47
    def setUp(self):
 
48
        super(DiskConfigTestCase, self).setUp()
 
49
        self.flags(verbose=True)
 
50
        fakes.stub_out_nw_api(self.stubs)
 
51
 
 
52
        FAKE_INSTANCES = [
 
53
            fakes.stub_instance(1,
 
54
                                uuid=MANUAL_INSTANCE_UUID,
 
55
                                auto_disk_config=False),
 
56
            fakes.stub_instance(2,
 
57
                                uuid=AUTO_INSTANCE_UUID,
 
58
                                auto_disk_config=True)
 
59
        ]
 
60
 
 
61
        def fake_instance_get(context, id_):
 
62
            for instance in FAKE_INSTANCES:
 
63
                if id_ == instance['id']:
 
64
                    return instance
 
65
 
 
66
        self.stubs.Set(nova.db, 'instance_get', fake_instance_get)
 
67
 
 
68
        def fake_instance_get_by_uuid(context, uuid):
 
69
            for instance in FAKE_INSTANCES:
 
70
                if uuid == instance['uuid']:
 
71
                    return instance
 
72
 
 
73
        self.stubs.Set(nova.db, 'instance_get_by_uuid',
 
74
                       fake_instance_get_by_uuid)
 
75
 
 
76
        def fake_instance_get_all(context, *args, **kwargs):
 
77
            return FAKE_INSTANCES
 
78
 
 
79
        self.stubs.Set(nova.db, 'instance_get_all', fake_instance_get_all)
 
80
        self.stubs.Set(nova.db, 'instance_get_all_by_filters',
 
81
                       fake_instance_get_all)
 
82
 
 
83
        def fake_instance_create(context, inst_, session=None):
 
84
            class FakeModel(dict):
 
85
                def save(self, session=None):
 
86
                    pass
 
87
 
 
88
            inst = FakeModel(**inst_)
 
89
            inst['id'] = 1
 
90
            inst['uuid'] = AUTO_INSTANCE_UUID
 
91
            inst['created_at'] = datetime.datetime(2010, 10, 10, 12, 0, 0)
 
92
            inst['updated_at'] = datetime.datetime(2010, 10, 10, 12, 0, 0)
 
93
            inst['progress'] = 0
 
94
            inst['name'] = 'instance-1'  # this is a property
 
95
 
 
96
            def fake_instance_get_for_create(context, id_, *args, **kwargs):
 
97
                return inst
 
98
 
 
99
            self.stubs.Set(nova.db, 'instance_get',
 
100
                          fake_instance_get_for_create)
 
101
            self.stubs.Set(nova.db, 'instance_update',
 
102
                          fake_instance_get_for_create)
 
103
 
 
104
            def fake_instance_get_all_for_create(context, *args, **kwargs):
 
105
                return [inst]
 
106
            self.stubs.Set(nova.db, 'instance_get_all',
 
107
                           fake_instance_get_all_for_create)
 
108
            self.stubs.Set(nova.db, 'instance_get_all_by_filters',
 
109
                           fake_instance_get_all_for_create)
 
110
 
 
111
            def fake_instance_add_security_group(context, instance_id,
 
112
                                                 security_group_id):
 
113
                pass
 
114
 
 
115
            self.stubs.Set(nova.db,
 
116
                           'instance_add_security_group',
 
117
                           fake_instance_add_security_group)
 
118
 
 
119
            return inst
 
120
 
 
121
        self.stubs.Set(nova.db, 'instance_create', fake_instance_create)
 
122
 
 
123
        self.app = compute.APIRouter()
 
124
 
 
125
    def assertDiskConfig(self, dict_, value):
 
126
        self.assert_(API_DISK_CONFIG in dict_)
 
127
        self.assertEqual(dict_[API_DISK_CONFIG], value)
 
128
 
 
129
    def test_show_server(self):
 
130
        req = fakes.HTTPRequest.blank(
 
131
            '/fake/servers/%s' % MANUAL_INSTANCE_UUID)
 
132
        res = req.get_response(self.app)
 
133
        server_dict = utils.loads(res.body)['server']
 
134
        self.assertDiskConfig(server_dict, 'MANUAL')
 
135
 
 
136
        req = fakes.HTTPRequest.blank(
 
137
            '/fake/servers/%s' % AUTO_INSTANCE_UUID)
 
138
        res = req.get_response(self.app)
 
139
        server_dict = utils.loads(res.body)['server']
 
140
        self.assertDiskConfig(server_dict, 'AUTO')
 
141
 
 
142
    def test_detail_servers(self):
 
143
        req = fakes.HTTPRequest.blank('/fake/servers/detail')
 
144
        res = req.get_response(self.app)
 
145
        server_dicts = utils.loads(res.body)['servers']
 
146
 
 
147
        expectations = ['MANUAL', 'AUTO']
 
148
        for server_dict, expected in zip(server_dicts, expectations):
 
149
            self.assertDiskConfig(server_dict, expected)
 
150
 
 
151
    def test_show_image(self):
 
152
        req = fakes.HTTPRequest.blank(
 
153
            '/fake/images/a440c04b-79fa-479c-bed1-0b816eaec379')
 
154
        res = req.get_response(self.app)
 
155
        image_dict = utils.loads(res.body)['image']
 
156
        self.assertDiskConfig(image_dict, 'MANUAL')
 
157
 
 
158
        req = fakes.HTTPRequest.blank(
 
159
            '/fake/images/70a599e0-31e7-49b7-b260-868f441e862b')
 
160
        res = req.get_response(self.app)
 
161
        image_dict = utils.loads(res.body)['image']
 
162
        self.assertDiskConfig(image_dict, 'AUTO')
 
163
 
 
164
    def test_detail_image(self):
 
165
        req = fakes.HTTPRequest.blank('/fake/images/detail')
 
166
        res = req.get_response(self.app)
 
167
        image_dicts = utils.loads(res.body)['images']
 
168
 
 
169
        expectations = ['MANUAL', 'AUTO']
 
170
        for image_dict, expected in zip(image_dicts, expectations):
 
171
            # NOTE(sirp): image fixtures 6 and 7 are setup for
 
172
            # auto_disk_config testing
 
173
            if image_dict['id'] in (6, 7):
 
174
                self.assertDiskConfig(image_dict, expected)
 
175
 
 
176
    def test_create_server_override_auto(self):
 
177
        req = fakes.HTTPRequest.blank('/fake/servers')
 
178
        req.method = 'POST'
 
179
        req.content_type = 'application/json'
 
180
        body = {'server': {
 
181
                  'name': 'server_test',
 
182
                  'imageRef': 'cedef40a-ed67-4d10-800e-17455edce175',
 
183
                  'flavorRef': '1',
 
184
                  API_DISK_CONFIG: 'AUTO'
 
185
               }}
 
186
 
 
187
        req.body = utils.dumps(body)
 
188
        res = req.get_response(self.app)
 
189
        server_dict = utils.loads(res.body)['server']
 
190
        self.assertDiskConfig(server_dict, 'AUTO')
 
191
 
 
192
    def test_create_server_override_manual(self):
 
193
        req = fakes.HTTPRequest.blank('/fake/servers')
 
194
        req.method = 'POST'
 
195
        req.content_type = 'application/json'
 
196
        body = {'server': {
 
197
                  'name': 'server_test',
 
198
                  'imageRef': 'cedef40a-ed67-4d10-800e-17455edce175',
 
199
                  'flavorRef': '1',
 
200
                  API_DISK_CONFIG: 'MANUAL'
 
201
               }}
 
202
 
 
203
        req.body = utils.dumps(body)
 
204
        res = req.get_response(self.app)
 
205
        server_dict = utils.loads(res.body)['server']
 
206
        self.assertDiskConfig(server_dict, 'MANUAL')
 
207
 
 
208
    def test_create_server_detect_from_image(self):
 
209
        """If user doesn't pass in diskConfig for server, use image metadata
 
210
        to specify AUTO or MANUAL.
 
211
        """
 
212
        req = fakes.HTTPRequest.blank('/fake/servers')
 
213
        req.method = 'POST'
 
214
        req.content_type = 'application/json'
 
215
        body = {'server': {
 
216
                  'name': 'server_test',
 
217
                  'imageRef': 'a440c04b-79fa-479c-bed1-0b816eaec379',
 
218
                  'flavorRef': '1',
 
219
               }}
 
220
 
 
221
        req.body = utils.dumps(body)
 
222
        res = req.get_response(self.app)
 
223
        server_dict = utils.loads(res.body)['server']
 
224
        self.assertDiskConfig(server_dict, 'MANUAL')
 
225
 
 
226
        req = fakes.HTTPRequest.blank('/fake/servers')
 
227
        req.method = 'POST'
 
228
        req.content_type = 'application/json'
 
229
        body = {'server': {
 
230
                  'name': 'server_test',
 
231
                  'imageRef': '70a599e0-31e7-49b7-b260-868f441e862b',
 
232
                  'flavorRef': '1',
 
233
               }}
 
234
 
 
235
        req.body = utils.dumps(body)
 
236
        res = req.get_response(self.app)
 
237
        server_dict = utils.loads(res.body)['server']
 
238
        self.assertDiskConfig(server_dict, 'AUTO')
 
239
 
 
240
    def test_update_server_invalid_disk_config(self):
 
241
        """Return BadRequest if user passes an invalid diskConfig value."""
 
242
        req = fakes.HTTPRequest.blank(
 
243
            '/fake/servers/%s' % MANUAL_INSTANCE_UUID)
 
244
        req.method = 'PUT'
 
245
        req.content_type = 'application/json'
 
246
        body = {'server': {API_DISK_CONFIG: 'server_test'}}
 
247
        req.body = utils.dumps(body)
 
248
        res = req.get_response(self.app)
 
249
        self.assertEqual(res.status_int, 400)
 
250
        expected_msg = ('{"badRequest": {"message": "%s must be either'
 
251
                        ' \'MANUAL\' or \'AUTO\'.", "code": 400}}' %
 
252
                        API_DISK_CONFIG)
 
253
        self.assertEqual(res.body, expected_msg)