Skip to content

Commit 3d419b8

Browse files
committed
Remove instance disk - always use same sutom disk
1 parent 9335852 commit 3d419b8

File tree

4 files changed

+116
-19
lines changed

4 files changed

+116
-19
lines changed

ec2stack/configure.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,6 @@ def _set_optional_attributes_of_profile(config, profile):
168168
@param profile: the profile to set the attribute in.
169169
@return: configparser configuration.
170170
"""
171-
172-
configure_instance_disk = raw_input(
173-
'Do you wish to input a second custom storage disk for instances? (Yes/No): '
174-
)
175-
176-
if configure_instance_disk.lower() in ['yes', 'y']:
177-
config = _set_attribute_of_profile(
178-
config, profile, 'cloudstack_instance_custom_disk_offering', 'Cloudstack custom instance disk offering name', 'CustomInstance'
179-
)
180-
181171
configure_instance_type_mapings = raw_input(
182172
'Do you wish to input instance type mappings? (Yes/No): '
183173
)

ec2stack/providers/cloudstack/instances.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,9 @@ def _run_instance_request():
178178
if helpers.get('BlockDeviceMapping.1.Ebs.VolumeType') is not None:
179179
disk_type = helpers.get('BlockDeviceMapping.1.Ebs.VolumeType')
180180
if disk_type == 'gp2':
181-
if 'CLOUDSTACK_INSTANCE_CUSTOM_DISK_OFFERING' in current_app.config:
182-
args['diskofferingid'] = disk_offerings.get_disk_offering(
183-
current_app.config['CLOUDSTACK_INSTANCE_CUSTOM_DISK_OFFERING']
184-
)['id']
185-
else:
186-
errors.invalid_request(
187-
"Unable to configure secondary disk, please run ec2stack-configure and choose to "
188-
"configure an instance disk")
181+
args['diskofferingid'] = disk_offerings.get_disk_offering(
182+
current_app.config['CLOUDSTACK_CUSTOM_DISK_OFFERING']
183+
)['id']
189184

190185
if helpers.get('BlockDeviceMapping.1.Ebs.VolumeSize') is None:
191186
errors.invalid_request("VolumeSize not found in BlockDeviceMapping")

pylint.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ max-locals=20
236236
max-returns=6
237237

238238
# Maximum number of branch for function / method body
239-
max-branchs=12
239+
max-branches=16
240240

241241
# Maximum number of statements in function / method body
242242
max-statements=50

tests/instances_tests.py

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,118 @@ def test_run_instance(self):
315315
self.assert_ok(response)
316316
assert 'RunInstancesResponse' in response.data
317317

318+
def test_run_instance_gp2(self):
319+
data = self.get_example_data()
320+
data['Action'] = 'RunInstances'
321+
data['ImageId'] = 'a32d70ee-95e4-11e3-b2e4-d19c9d3e5e1d'
322+
data['MinCount'] = '0'
323+
data['MaxCount'] = '0'
324+
data['SecurityGroupId.1'] = 'example-security-group-id'
325+
data['SecurityGroup.1'] = 'example-security-group-name'
326+
data['KeyName'] = 'example-ssh-key-name'
327+
data['UserData'] = 'example-user-data'
328+
data['BlockDeviceMapping.1.Ebs.VolumeType'] = 'gp2'
329+
data['BlockDeviceMapping.1.Ebs.VolumeSize'] = '20'
330+
data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')
331+
332+
get = mock.Mock()
333+
get.return_value.text = read_file(
334+
'tests/data/valid_run_instance.json'
335+
)
336+
get.return_value.status_code = 200
337+
338+
get_disk_offering = mock.Mock()
339+
get_disk_offering.return_value = json.loads(read_file(
340+
'tests/data/disk_offering_search.json'
341+
))
342+
343+
get_service_offering = mock.Mock()
344+
get_service_offering.return_value = json.loads(read_file(
345+
'tests/data/service_offering_search.json'
346+
))
347+
348+
get_zone = mock.Mock()
349+
get_zone.return_value = json.loads(read_file(
350+
'tests/data/zones_search.json'
351+
))
352+
353+
with mock.patch('requests.get', get):
354+
with mock.patch(
355+
'ec2stack.providers.cloudstack.disk_offerings.get_disk_offering',
356+
get_disk_offering
357+
):
358+
with mock.patch(
359+
'ec2stack.providers.cloudstack.service_offerings.get_service_offering',
360+
get_service_offering
361+
):
362+
with mock.patch(
363+
'ec2stack.providers.cloudstack.zones.get_zone',
364+
get_zone
365+
):
366+
response = self.post(
367+
'/',
368+
data=data
369+
)
370+
371+
self.assert_ok(response)
372+
assert 'RunInstancesResponse' in response.data
373+
374+
def test_run_instance_gp2_no_volume_size(self):
375+
data = self.get_example_data()
376+
data['Action'] = 'RunInstances'
377+
data['ImageId'] = 'a32d70ee-95e4-11e3-b2e4-d19c9d3e5e1d'
378+
data['MinCount'] = '0'
379+
data['MaxCount'] = '0'
380+
data['SecurityGroupId.1'] = 'example-security-group-id'
381+
data['SecurityGroup.1'] = 'example-security-group-name'
382+
data['KeyName'] = 'example-ssh-key-name'
383+
data['UserData'] = 'example-user-data'
384+
data['BlockDeviceMapping.1.Ebs.VolumeType'] = 'gp2'
385+
data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')
386+
387+
get = mock.Mock()
388+
get.return_value.text = read_file(
389+
'tests/data/valid_run_instance.json'
390+
)
391+
get.return_value.status_code = 200
392+
393+
get_disk_offering = mock.Mock()
394+
get_disk_offering.return_value = json.loads(read_file(
395+
'tests/data/disk_offering_search.json'
396+
))
397+
398+
get_service_offering = mock.Mock()
399+
get_service_offering.return_value = json.loads(read_file(
400+
'tests/data/service_offering_search.json'
401+
))
402+
403+
get_zone = mock.Mock()
404+
get_zone.return_value = json.loads(read_file(
405+
'tests/data/zones_search.json'
406+
))
407+
408+
with mock.patch('requests.get', get):
409+
with mock.patch(
410+
'ec2stack.providers.cloudstack.disk_offerings.get_disk_offering',
411+
get_disk_offering
412+
):
413+
with mock.patch(
414+
'ec2stack.providers.cloudstack.service_offerings.get_service_offering',
415+
get_service_offering
416+
):
417+
with mock.patch(
418+
'ec2stack.providers.cloudstack.zones.get_zone',
419+
get_zone
420+
):
421+
response = self.post(
422+
'/',
423+
data=data
424+
)
425+
426+
self.assert_bad_request(response)
427+
assert 'VolumeSize not found in BlockDeviceMapping' in response.data
428+
429+
318430
def test_run_instance_with_zone_and_type_(self):
319431
data = self.get_example_data()
320432
data['Action'] = 'RunInstances'

0 commit comments

Comments
 (0)