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()
51
52
fakes.stub_out_nw_api(self.stubs)
82
83
fake_instance_get_all)
84
85
def fake_instance_create(context, inst_, session=None):
85
class FakeModel(dict):
86
def save(self, session=None):
89
inst = FakeModel(**inst_)
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)
95
inst['name'] = 'instance-1' # this is a property
96
inst['task_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(**{
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),
92
'name': 'instance-1', # this is a property
95
'auto_disk_config': inst_['auto_disk_config'],
96
'security_groups': inst_['security_groups'],
103
99
def fake_instance_get_for_create(context, id_, *args, **kwargs):
104
100
return (inst, inst)
128
124
self.app = compute.APIRouter(init_only=('servers', 'images'))
126
def _setup_fake_image_service(self):
127
self.image_service = nova.tests.image.fake.stub_out_image_service(
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,
138
'container_format': 'ova',
139
'disk_format': 'vhd',
141
'properties': {'auto_disk_config': 'Disabled'}}
142
self.image_service.create(None, image)
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')
263
def test_create_server_detect_from_image_disabled_goes_to_manual(self):
264
req = fakes.HTTPRequest.blank('/fake/servers')
266
req.content_type = 'application/json'
268
'name': 'server_test',
269
'imageRef': '88580842-f50a-11e2-8d3a-f23c91aec05e',
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')
278
def test_create_server_errors_when_disabled_and_auto(self):
279
req = fakes.HTTPRequest.blank('/fake/servers')
281
req.content_type = 'application/json'
283
'name': 'server_test',
284
'imageRef': '88580842-f50a-11e2-8d3a-f23c91aec05e',
286
API_DISK_CONFIG: 'AUTO'
289
req.body = jsonutils.dumps(body)
290
res = req.get_response(self.app)
291
self.assertEqual(res.status_int, 400)
293
def test_create_server_when_disabled_and_manual(self):
294
req = fakes.HTTPRequest.blank('/fake/servers')
296
req.content_type = 'application/json'
298
'name': 'server_test',
299
'imageRef': '88580842-f50a-11e2-8d3a-f23c91aec05e',
301
API_DISK_CONFIG: 'MANUAL'
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')
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(