~ubuntu-branches/ubuntu/saucy/nova/saucy-proposed

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2013-09-09 13:11:11 UTC
  • mfrom: (1.1.74)
  • Revision ID: package-import@ubuntu.com-20130909131111-aw02ice50wac9tma
Tags: 1:2013.2~b3-0ubuntu1
* New usptream release. 
* debian/patches/avoid_requirements_cheetah.patch: Dropped
* debian/patches/fix-sqlalchemy-0.7.9-usage.patch: Dropped
* debian/patches/fix-requirements.patch: Refreshed.
* debian/patches/path-to-the-xenhost.conf-fixup.patch: Refreshed
* debian/control: Add python-jinja2
* debian/control: Dropped python-cheetah

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
import nova.openstack.common.rpc
24
24
from nova import test
25
25
from nova.tests.api.openstack import fakes
 
26
from nova.tests import fake_instance
26
27
import nova.tests.image.fake
27
28
 
28
29
 
46
47
            osapi_compute_extension=[
47
48
                'nova.api.openstack.compute.contrib.select_extensions'],
48
49
            osapi_compute_ext_list=['Disk_config'])
49
 
        nova.tests.image.fake.stub_out_image_service(self.stubs)
 
50
        self._setup_fake_image_service()
50
51
 
51
52
        fakes.stub_out_nw_api(self.stubs)
52
53
 
82
83
                       fake_instance_get_all)
83
84
 
84
85
        def fake_instance_create(context, inst_, session=None):
85
 
            class FakeModel(dict):
86
 
                def save(self, session=None):
87
 
                    pass
88
 
 
89
 
            inst = FakeModel(**inst_)
90
 
            inst['id'] = 1
91
 
            inst['uuid'] = AUTO_INSTANCE_UUID
92
 
            inst['created_at'] = datetime.datetime(2010, 10, 10, 12, 0, 0)
93
 
            inst['updated_at'] = datetime.datetime(2010, 10, 10, 12, 0, 0)
94
 
            inst['progress'] = 0
95
 
            inst['name'] = 'instance-1'  # this is a property
96
 
            inst['task_state'] = ''
97
 
            inst['vm_state'] = ''
98
 
            # NOTE(vish): db create translates security groups into model
99
 
            #             objects. Translate here so tests pass
100
 
            inst['security_groups'] = [{'name': group}
101
 
                                       for group in inst['security_groups']]
 
86
            inst = fake_instance.fake_db_instance(**{
 
87
                    'id': 1,
 
88
                    'uuid': AUTO_INSTANCE_UUID,
 
89
                    'created_at': datetime.datetime(2010, 10, 10, 12, 0, 0),
 
90
                    'updated_at': datetime.datetime(2010, 10, 10, 12, 0, 0),
 
91
                    'progress': 0,
 
92
                    'name': 'instance-1',  # this is a property
 
93
                    'task_state': '',
 
94
                    'vm_state': '',
 
95
                    'auto_disk_config': inst_['auto_disk_config'],
 
96
                    'security_groups': inst_['security_groups'],
 
97
                    })
102
98
 
103
99
            def fake_instance_get_for_create(context, id_, *args, **kwargs):
104
100
                return (inst, inst)
127
123
 
128
124
        self.app = compute.APIRouter(init_only=('servers', 'images'))
129
125
 
 
126
    def _setup_fake_image_service(self):
 
127
        self.image_service = nova.tests.image.fake.stub_out_image_service(
 
128
                self.stubs)
 
129
        timestamp = datetime.datetime(2011, 1, 1, 1, 2, 3)
 
130
        image = {'id': '88580842-f50a-11e2-8d3a-f23c91aec05e',
 
131
                 'name': 'fakeimage7',
 
132
                 'created_at': timestamp,
 
133
                 'updated_at': timestamp,
 
134
                 'deleted_at': None,
 
135
                 'deleted': False,
 
136
                 'status': 'active',
 
137
                 'is_public': False,
 
138
                 'container_format': 'ova',
 
139
                 'disk_format': 'vhd',
 
140
                 'size': '74185822',
 
141
                 'properties': {'auto_disk_config': 'Disabled'}}
 
142
        self.image_service.create(None, image)
 
143
 
130
144
    def tearDown(self):
131
145
        super(DiskConfigTestCase, self).tearDown()
132
146
        nova.tests.image.fake.FakeImageService_reset()
246
260
        server_dict = jsonutils.loads(res.body)['server']
247
261
        self.assertDiskConfig(server_dict, 'AUTO')
248
262
 
 
263
    def test_create_server_detect_from_image_disabled_goes_to_manual(self):
 
264
        req = fakes.HTTPRequest.blank('/fake/servers')
 
265
        req.method = 'POST'
 
266
        req.content_type = 'application/json'
 
267
        body = {'server': {
 
268
                  'name': 'server_test',
 
269
                  'imageRef': '88580842-f50a-11e2-8d3a-f23c91aec05e',
 
270
                  'flavorRef': '1',
 
271
               }}
 
272
 
 
273
        req.body = jsonutils.dumps(body)
 
274
        res = req.get_response(self.app)
 
275
        server_dict = jsonutils.loads(res.body)['server']
 
276
        self.assertDiskConfig(server_dict, 'MANUAL')
 
277
 
 
278
    def test_create_server_errors_when_disabled_and_auto(self):
 
279
        req = fakes.HTTPRequest.blank('/fake/servers')
 
280
        req.method = 'POST'
 
281
        req.content_type = 'application/json'
 
282
        body = {'server': {
 
283
                  'name': 'server_test',
 
284
                  'imageRef': '88580842-f50a-11e2-8d3a-f23c91aec05e',
 
285
                  'flavorRef': '1',
 
286
                  API_DISK_CONFIG: 'AUTO'
 
287
               }}
 
288
 
 
289
        req.body = jsonutils.dumps(body)
 
290
        res = req.get_response(self.app)
 
291
        self.assertEqual(res.status_int, 400)
 
292
 
 
293
    def test_create_server_when_disabled_and_manual(self):
 
294
        req = fakes.HTTPRequest.blank('/fake/servers')
 
295
        req.method = 'POST'
 
296
        req.content_type = 'application/json'
 
297
        body = {'server': {
 
298
                  'name': 'server_test',
 
299
                  'imageRef': '88580842-f50a-11e2-8d3a-f23c91aec05e',
 
300
                  'flavorRef': '1',
 
301
                  API_DISK_CONFIG: 'MANUAL'
 
302
               }}
 
303
 
 
304
        req.body = jsonutils.dumps(body)
 
305
        res = req.get_response(self.app)
 
306
        server_dict = jsonutils.loads(res.body)['server']
 
307
        self.assertDiskConfig(server_dict, 'MANUAL')
 
308
 
249
309
    def test_update_server_invalid_disk_config(self):
250
310
        # Return BadRequest if user passes an invalid diskConfig value.
251
311
        req = fakes.HTTPRequest.blank(