195
199
['ClosestToNextInstanceHour', 'Default',
196
200
'NewestInstance', 'OldestInstance', 'OldestLaunchConfiguration'])
202
class TestLaunchConfiguration(AWSMockServiceTestCase):
203
connection_class = AutoScaleConnection
205
def default_body(self):
206
# This is a dummy response
208
<DescribeLaunchConfigurationsResponse>
209
</DescribeLaunchConfigurationsResponse>
212
def test_launch_config(self):
213
# This unit test is based on #753 and #1343
214
self.set_http_response(status_code=200)
215
dev_sdf = EBSBlockDeviceType(snapshot_id='snap-12345')
216
dev_sdg = EBSBlockDeviceType(snapshot_id='snap-12346')
218
bdm = BlockDeviceMapping()
219
bdm['/dev/sdf'] = dev_sdf
220
bdm['/dev/sdg'] = dev_sdg
222
lc = launchconfig.LaunchConfiguration(
223
connection=self.service_connection,
224
name='launch_config',
226
instance_type = 'm1.large',
227
security_groups = ['group1', 'group2'],
229
block_device_mappings = [bdm]
232
response = self.service_connection.create_launch_configuration(lc)
234
self.assert_request_parameters({
235
'Action': 'CreateLaunchConfiguration',
236
'BlockDeviceMapping.1.DeviceName': '/dev/sdf',
237
'BlockDeviceMapping.1.Ebs.DeleteOnTermination': 'false',
238
'BlockDeviceMapping.1.Ebs.SnapshotId': 'snap-12345',
239
'BlockDeviceMapping.2.DeviceName': '/dev/sdg',
240
'BlockDeviceMapping.2.Ebs.DeleteOnTermination': 'false',
241
'BlockDeviceMapping.2.Ebs.SnapshotId': 'snap-12346',
242
'EbsOptimized': 'false',
243
'LaunchConfigurationName': 'launch_config',
245
'InstanceMonitoring.Enabled': 'false',
246
'InstanceType': 'm1.large',
247
'SecurityGroups.member.1': 'group1',
248
'SecurityGroups.member.2': 'group2',
249
'SpotPrice': 'price',
250
}, ignore_params_values=['Version'])
253
class TestCreateAutoScalePolicy(AWSMockServiceTestCase):
254
connection_class = AutoScaleConnection
257
super(TestCreateAutoScalePolicy, self).setUp()
259
def default_body(self):
261
<PutScalingPolicyResponse xmlns="http://autoscaling.amazonaws.com\
263
<PutScalingPolicyResult>
264
<PolicyARN>arn:aws:autoscaling:us-east-1:803981987763:scaling\
266
-02e6-4e31-9719-0675d0dc31ae:autoScalingGroupName/my-test-asg:\
268
eout-policy</PolicyARN>
269
</PutScalingPolicyResult>
271
<RequestId>3cfc6fef-c08b-11e2-a697-2922EXAMPLE</RequestId>
273
</PutScalingPolicyResponse>
276
def test_scaling_policy_with_min_adjustment_step(self):
277
self.set_http_response(status_code=200)
279
policy = ScalingPolicy(
280
name='foo', as_name='bar',
281
adjustment_type='PercentChangeInCapacity', scaling_adjustment=50,
282
min_adjustment_step=30)
283
self.service_connection.create_scaling_policy(policy)
285
self.assert_request_parameters({
286
'Action': 'PutScalingPolicy',
288
'AutoScalingGroupName': 'bar',
289
'AdjustmentType': 'PercentChangeInCapacity',
290
'ScalingAdjustment': 50,
291
'MinAdjustmentStep': 30
292
}, ignore_params_values=['Version'])
294
def test_scaling_policy_with_wrong_adjustment_type(self):
295
self.set_http_response(status_code=200)
297
policy = ScalingPolicy(
298
name='foo', as_name='bar',
299
adjustment_type='ChangeInCapacity', scaling_adjustment=50,
300
min_adjustment_step=30)
301
self.service_connection.create_scaling_policy(policy)
303
self.assert_request_parameters({
304
'Action': 'PutScalingPolicy',
306
'AutoScalingGroupName': 'bar',
307
'AdjustmentType': 'ChangeInCapacity',
308
'ScalingAdjustment': 50
309
}, ignore_params_values=['Version'])
311
def test_scaling_policy_without_min_adjustment_step(self):
312
self.set_http_response(status_code=200)
314
policy = ScalingPolicy(
315
name='foo', as_name='bar',
316
adjustment_type='PercentChangeInCapacity', scaling_adjustment=50)
317
self.service_connection.create_scaling_policy(policy)
319
self.assert_request_parameters({
320
'Action': 'PutScalingPolicy',
322
'AutoScalingGroupName': 'bar',
323
'AdjustmentType': 'PercentChangeInCapacity',
324
'ScalingAdjustment': 50
325
}, ignore_params_values=['Version'])
199
328
if __name__ == '__main__':