Remove instance disk - always use same sutom disk
diff --git a/ec2stack/configure.py b/ec2stack/configure.py
index 5c4ffee..cc2e6f6 100644
--- a/ec2stack/configure.py
+++ b/ec2stack/configure.py
@@ -168,16 +168,6 @@
@param profile: the profile to set the attribute in.
@return: configparser configuration.
"""
-
- configure_instance_disk = raw_input(
- 'Do you wish to input a second custom storage disk for instances? (Yes/No): '
- )
-
- if configure_instance_disk.lower() in ['yes', 'y']:
- config = _set_attribute_of_profile(
- config, profile, 'cloudstack_instance_custom_disk_offering', 'Cloudstack custom instance disk offering name', 'CustomInstance'
- )
-
configure_instance_type_mapings = raw_input(
'Do you wish to input instance type mappings? (Yes/No): '
)
diff --git a/ec2stack/providers/cloudstack/instances.py b/ec2stack/providers/cloudstack/instances.py
index 3e8115b..01d2127 100644
--- a/ec2stack/providers/cloudstack/instances.py
+++ b/ec2stack/providers/cloudstack/instances.py
@@ -178,14 +178,9 @@
if helpers.get('BlockDeviceMapping.1.Ebs.VolumeType') is not None:
disk_type = helpers.get('BlockDeviceMapping.1.Ebs.VolumeType')
if disk_type == 'gp2':
- if 'CLOUDSTACK_INSTANCE_CUSTOM_DISK_OFFERING' in current_app.config:
- args['diskofferingid'] = disk_offerings.get_disk_offering(
- current_app.config['CLOUDSTACK_INSTANCE_CUSTOM_DISK_OFFERING']
- )['id']
- else:
- errors.invalid_request(
- "Unable to configure secondary disk, please run ec2stack-configure and choose to "
- "configure an instance disk")
+ args['diskofferingid'] = disk_offerings.get_disk_offering(
+ current_app.config['CLOUDSTACK_CUSTOM_DISK_OFFERING']
+ )['id']
if helpers.get('BlockDeviceMapping.1.Ebs.VolumeSize') is None:
errors.invalid_request("VolumeSize not found in BlockDeviceMapping")
diff --git a/pylint.rc b/pylint.rc
index c45bc02..1819a65 100644
--- a/pylint.rc
+++ b/pylint.rc
@@ -236,7 +236,7 @@
max-returns=6
# Maximum number of branch for function / method body
-max-branchs=12
+max-branches=16
# Maximum number of statements in function / method body
max-statements=50
diff --git a/tests/instances_tests.py b/tests/instances_tests.py
index f1986c2..a53fa0b 100644
--- a/tests/instances_tests.py
+++ b/tests/instances_tests.py
@@ -315,6 +315,118 @@
self.assert_ok(response)
assert 'RunInstancesResponse' in response.data
+ def test_run_instance_gp2(self):
+ data = self.get_example_data()
+ data['Action'] = 'RunInstances'
+ data['ImageId'] = 'a32d70ee-95e4-11e3-b2e4-d19c9d3e5e1d'
+ data['MinCount'] = '0'
+ data['MaxCount'] = '0'
+ data['SecurityGroupId.1'] = 'example-security-group-id'
+ data['SecurityGroup.1'] = 'example-security-group-name'
+ data['KeyName'] = 'example-ssh-key-name'
+ data['UserData'] = 'example-user-data'
+ data['BlockDeviceMapping.1.Ebs.VolumeType'] = 'gp2'
+ data['BlockDeviceMapping.1.Ebs.VolumeSize'] = '20'
+ data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')
+
+ get = mock.Mock()
+ get.return_value.text = read_file(
+ 'tests/data/valid_run_instance.json'
+ )
+ get.return_value.status_code = 200
+
+ get_disk_offering = mock.Mock()
+ get_disk_offering.return_value = json.loads(read_file(
+ 'tests/data/disk_offering_search.json'
+ ))
+
+ get_service_offering = mock.Mock()
+ get_service_offering.return_value = json.loads(read_file(
+ 'tests/data/service_offering_search.json'
+ ))
+
+ get_zone = mock.Mock()
+ get_zone.return_value = json.loads(read_file(
+ 'tests/data/zones_search.json'
+ ))
+
+ with mock.patch('requests.get', get):
+ with mock.patch(
+ 'ec2stack.providers.cloudstack.disk_offerings.get_disk_offering',
+ get_disk_offering
+ ):
+ with mock.patch(
+ 'ec2stack.providers.cloudstack.service_offerings.get_service_offering',
+ get_service_offering
+ ):
+ with mock.patch(
+ 'ec2stack.providers.cloudstack.zones.get_zone',
+ get_zone
+ ):
+ response = self.post(
+ '/',
+ data=data
+ )
+
+ self.assert_ok(response)
+ assert 'RunInstancesResponse' in response.data
+
+ def test_run_instance_gp2_no_volume_size(self):
+ data = self.get_example_data()
+ data['Action'] = 'RunInstances'
+ data['ImageId'] = 'a32d70ee-95e4-11e3-b2e4-d19c9d3e5e1d'
+ data['MinCount'] = '0'
+ data['MaxCount'] = '0'
+ data['SecurityGroupId.1'] = 'example-security-group-id'
+ data['SecurityGroup.1'] = 'example-security-group-name'
+ data['KeyName'] = 'example-ssh-key-name'
+ data['UserData'] = 'example-user-data'
+ data['BlockDeviceMapping.1.Ebs.VolumeType'] = 'gp2'
+ data['Signature'] = generate_signature(data, 'POST', 'localhost', '/')
+
+ get = mock.Mock()
+ get.return_value.text = read_file(
+ 'tests/data/valid_run_instance.json'
+ )
+ get.return_value.status_code = 200
+
+ get_disk_offering = mock.Mock()
+ get_disk_offering.return_value = json.loads(read_file(
+ 'tests/data/disk_offering_search.json'
+ ))
+
+ get_service_offering = mock.Mock()
+ get_service_offering.return_value = json.loads(read_file(
+ 'tests/data/service_offering_search.json'
+ ))
+
+ get_zone = mock.Mock()
+ get_zone.return_value = json.loads(read_file(
+ 'tests/data/zones_search.json'
+ ))
+
+ with mock.patch('requests.get', get):
+ with mock.patch(
+ 'ec2stack.providers.cloudstack.disk_offerings.get_disk_offering',
+ get_disk_offering
+ ):
+ with mock.patch(
+ 'ec2stack.providers.cloudstack.service_offerings.get_service_offering',
+ get_service_offering
+ ):
+ with mock.patch(
+ 'ec2stack.providers.cloudstack.zones.get_zone',
+ get_zone
+ ):
+ response = self.post(
+ '/',
+ data=data
+ )
+
+ self.assert_bad_request(response)
+ assert 'VolumeSize not found in BlockDeviceMapping' in response.data
+
+
def test_run_instance_with_zone_and_type_(self):
data = self.get_example_data()
data['Action'] = 'RunInstances'