~ubuntu-branches/ubuntu/trusty/python-boto/trusty

« back to all changes in this revision

Viewing changes to tests/unit/ec2/autoscale/test_group.py

  • Committer: Package Import Robot
  • Author(s): Eric Evans
  • Date: 2013-08-13 13:56:47 UTC
  • mfrom: (1.1.12)
  • Revision ID: package-import@ubuntu.com-20130813135647-o43z7y15uid87fzl
Tags: 2.10.0-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
from boto.ec2.autoscale import AutoScaleConnection
30
30
from boto.ec2.autoscale.group import AutoScalingGroup
31
 
 
 
31
from boto.ec2.autoscale.policy import ScalingPolicy
 
32
 
 
33
from boto.ec2.blockdevicemapping import EBSBlockDeviceType, BlockDeviceMapping
 
34
 
 
35
from boto.ec2.autoscale import launchconfig
32
36
 
33
37
class TestAutoScaleGroup(AWSMockServiceTestCase):
34
38
    connection_class = AutoScaleConnection
195
199
            ['ClosestToNextInstanceHour', 'Default',
196
200
             'NewestInstance', 'OldestInstance', 'OldestLaunchConfiguration'])
197
201
 
 
202
class TestLaunchConfiguration(AWSMockServiceTestCase):
 
203
    connection_class = AutoScaleConnection
 
204
 
 
205
    def default_body(self):
 
206
        # This is a dummy response
 
207
        return """
 
208
        <DescribeLaunchConfigurationsResponse>
 
209
        </DescribeLaunchConfigurationsResponse>
 
210
        """
 
211
 
 
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')
 
217
 
 
218
        bdm = BlockDeviceMapping()
 
219
        bdm['/dev/sdf'] = dev_sdf
 
220
        bdm['/dev/sdg'] = dev_sdg
 
221
 
 
222
        lc = launchconfig.LaunchConfiguration(
 
223
                connection=self.service_connection,
 
224
                name='launch_config',
 
225
                image_id='123456',
 
226
                instance_type = 'm1.large',
 
227
                security_groups = ['group1', 'group2'],
 
228
                spot_price='price',
 
229
                block_device_mappings = [bdm]
 
230
                )
 
231
 
 
232
        response = self.service_connection.create_launch_configuration(lc)
 
233
 
 
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',
 
244
            'ImageId': '123456',
 
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'])
 
251
 
 
252
 
 
253
class TestCreateAutoScalePolicy(AWSMockServiceTestCase):
 
254
    connection_class = AutoScaleConnection
 
255
 
 
256
    def setUp(self):
 
257
        super(TestCreateAutoScalePolicy, self).setUp()
 
258
 
 
259
    def default_body(self):
 
260
        return """
 
261
            <PutScalingPolicyResponse xmlns="http://autoscaling.amazonaws.com\
 
262
            /doc/2011-01-01/">
 
263
              <PutScalingPolicyResult>
 
264
                <PolicyARN>arn:aws:autoscaling:us-east-1:803981987763:scaling\
 
265
                Policy:b0dcf5e8
 
266
            -02e6-4e31-9719-0675d0dc31ae:autoScalingGroupName/my-test-asg:\
 
267
            policyName/my-scal
 
268
            eout-policy</PolicyARN>
 
269
              </PutScalingPolicyResult>
 
270
              <ResponseMetadata>
 
271
                <RequestId>3cfc6fef-c08b-11e2-a697-2922EXAMPLE</RequestId>
 
272
              </ResponseMetadata>
 
273
            </PutScalingPolicyResponse>
 
274
        """
 
275
 
 
276
    def test_scaling_policy_with_min_adjustment_step(self):
 
277
        self.set_http_response(status_code=200)
 
278
 
 
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)
 
284
 
 
285
        self.assert_request_parameters({
 
286
            'Action': 'PutScalingPolicy',
 
287
            'PolicyName': 'foo',
 
288
            'AutoScalingGroupName': 'bar',
 
289
            'AdjustmentType': 'PercentChangeInCapacity',
 
290
            'ScalingAdjustment': 50,
 
291
            'MinAdjustmentStep': 30
 
292
        }, ignore_params_values=['Version'])
 
293
 
 
294
    def test_scaling_policy_with_wrong_adjustment_type(self):
 
295
        self.set_http_response(status_code=200)
 
296
 
 
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)
 
302
 
 
303
        self.assert_request_parameters({
 
304
            'Action': 'PutScalingPolicy',
 
305
            'PolicyName': 'foo',
 
306
            'AutoScalingGroupName': 'bar',
 
307
            'AdjustmentType': 'ChangeInCapacity',
 
308
            'ScalingAdjustment': 50
 
309
        }, ignore_params_values=['Version'])
 
310
 
 
311
    def test_scaling_policy_without_min_adjustment_step(self):
 
312
        self.set_http_response(status_code=200)
 
313
 
 
314
        policy = ScalingPolicy(
 
315
            name='foo', as_name='bar',
 
316
            adjustment_type='PercentChangeInCapacity', scaling_adjustment=50)
 
317
        self.service_connection.create_scaling_policy(policy)
 
318
 
 
319
        self.assert_request_parameters({
 
320
            'Action': 'PutScalingPolicy',
 
321
            'PolicyName': 'foo',
 
322
            'AutoScalingGroupName': 'bar',
 
323
            'AdjustmentType': 'PercentChangeInCapacity',
 
324
            'ScalingAdjustment': 50
 
325
        }, ignore_params_values=['Version'])
 
326
 
198
327
 
199
328
if __name__ == '__main__':
200
329
    unittest.main()