| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved | 2 # Copyright (c) 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved |
| 3 # | 3 # |
| 4 # Permission is hereby granted, free of charge, to any person obtaining a | 4 # Permission is hereby granted, free of charge, to any person obtaining a |
| 5 # copy of this software and associated documentation files (the | 5 # copy of this software and associated documentation files (the |
| 6 # "Software"), to deal in the Software without restriction, including | 6 # "Software"), to deal in the Software without restriction, including |
| 7 # without limitation the rights to use, copy, modify, merge, publish, dis- | 7 # without limitation the rights to use, copy, modify, merge, publish, dis- |
| 8 # tribute, sublicense, and/or sell copies of the Software, and to permit | 8 # tribute, sublicense, and/or sell copies of the Software, and to permit |
| 9 # persons to whom the Software is furnished to do so, subject to the fol- | 9 # persons to whom the Software is furnished to do so, subject to the fol- |
| 10 # lowing conditions: | 10 # lowing conditions: |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 from tests.unit import unittest | 26 from tests.unit import unittest |
| 27 from tests.unit import AWSMockServiceTestCase | 27 from tests.unit import AWSMockServiceTestCase |
| 28 | 28 |
| 29 from boto.ec2.autoscale import AutoScaleConnection | 29 from boto.ec2.autoscale import AutoScaleConnection |
| 30 from boto.ec2.autoscale.group import AutoScalingGroup | 30 from boto.ec2.autoscale.group import AutoScalingGroup |
| 31 from boto.ec2.autoscale.policy import ScalingPolicy | 31 from boto.ec2.autoscale.policy import ScalingPolicy |
| 32 from boto.ec2.autoscale.tag import Tag | 32 from boto.ec2.autoscale.tag import Tag |
| 33 | 33 |
| 34 from boto.ec2.blockdevicemapping import EBSBlockDeviceType, BlockDeviceMapping | 34 from boto.ec2.blockdevicemapping import EBSBlockDeviceType, BlockDeviceMapping |
| 35 | 35 |
| 36 from boto.ec2.autoscale import launchconfig | 36 from boto.ec2.autoscale import launchconfig, LaunchConfiguration |
| 37 | 37 |
| 38 class TestAutoScaleGroup(AWSMockServiceTestCase): | 38 class TestAutoScaleGroup(AWSMockServiceTestCase): |
| 39 connection_class = AutoScaleConnection | 39 connection_class = AutoScaleConnection |
| 40 | 40 |
| 41 def setUp(self): | 41 def setUp(self): |
| 42 super(TestAutoScaleGroup, self).setUp() | 42 super(TestAutoScaleGroup, self).setUp() |
| 43 | 43 |
| 44 def default_body(self): | 44 def default_body(self): |
| 45 return """ | 45 return """ |
| 46 <CreateLaunchConfigurationResponse> | 46 <CreateLaunchConfigurationResponse> |
| (...skipping 15 matching lines...) Expand all Loading... |
| 62 'Action': 'CreateAutoScalingGroup', | 62 'Action': 'CreateAutoScalingGroup', |
| 63 'AutoScalingGroupName': 'foo', | 63 'AutoScalingGroupName': 'foo', |
| 64 'LaunchConfigurationName': 'lauch_config', | 64 'LaunchConfigurationName': 'lauch_config', |
| 65 'MaxSize': 2, | 65 'MaxSize': 2, |
| 66 'MinSize': 1, | 66 'MinSize': 1, |
| 67 'TerminationPolicies.member.1': 'OldestInstance', | 67 'TerminationPolicies.member.1': 'OldestInstance', |
| 68 'TerminationPolicies.member.2': 'OldestLaunchConfiguration', | 68 'TerminationPolicies.member.2': 'OldestLaunchConfiguration', |
| 69 'InstanceId': 'test-id', | 69 'InstanceId': 'test-id', |
| 70 }, ignore_params_values=['Version']) | 70 }, ignore_params_values=['Version']) |
| 71 | 71 |
| 72 def test_autoscaling_group_single_vpc_zone_identifier(self): |
| 73 self.set_http_response(status_code=200) |
| 74 autoscale = AutoScalingGroup( |
| 75 name='foo', |
| 76 vpc_zone_identifier='vpc_zone_1') |
| 77 self.service_connection.create_auto_scaling_group(autoscale) |
| 78 self.assert_request_parameters({ |
| 79 'Action': 'CreateAutoScalingGroup', |
| 80 'AutoScalingGroupName': 'foo', |
| 81 'VPCZoneIdentifier': 'vpc_zone_1', |
| 82 }, ignore_params_values=['MaxSize', 'MinSize', 'LaunchConfigurationN
ame', 'Version']) |
| 83 |
| 84 def test_autoscaling_group_vpc_zone_identifier_list(self): |
| 85 self.set_http_response(status_code=200) |
| 86 autoscale = AutoScalingGroup( |
| 87 name='foo', |
| 88 vpc_zone_identifier=['vpc_zone_1', 'vpc_zone_2']) |
| 89 self.service_connection.create_auto_scaling_group(autoscale) |
| 90 self.assert_request_parameters({ |
| 91 'Action': 'CreateAutoScalingGroup', |
| 92 'AutoScalingGroupName': 'foo', |
| 93 'VPCZoneIdentifier': 'vpc_zone_1,vpc_zone_2', |
| 94 }, ignore_params_values=['MaxSize', 'MinSize', 'LaunchConfigurationN
ame', 'Version']) |
| 95 |
| 96 def test_autoscaling_group_vpc_zone_identifier_multi(self): |
| 97 self.set_http_response(status_code=200) |
| 98 autoscale = AutoScalingGroup( |
| 99 name='foo', |
| 100 vpc_zone_identifier='vpc_zone_1,vpc_zone_2') |
| 101 self.service_connection.create_auto_scaling_group(autoscale) |
| 102 self.assert_request_parameters({ |
| 103 'Action': 'CreateAutoScalingGroup', |
| 104 'AutoScalingGroupName': 'foo', |
| 105 'VPCZoneIdentifier': 'vpc_zone_1,vpc_zone_2', |
| 106 }, ignore_params_values=['MaxSize', 'MinSize', 'LaunchConfigurationN
ame', 'Version']) |
| 107 |
| 72 | 108 |
| 73 class TestAutoScaleGroupHonorCooldown(AWSMockServiceTestCase): | 109 class TestAutoScaleGroupHonorCooldown(AWSMockServiceTestCase): |
| 74 connection_class = AutoScaleConnection | 110 connection_class = AutoScaleConnection |
| 75 | 111 |
| 76 def default_body(self): | 112 def default_body(self): |
| 77 return """ | 113 return """ |
| 78 <SetDesiredCapacityResponse> | 114 <SetDesiredCapacityResponse> |
| 79 <ResponseMetadata> | 115 <ResponseMetadata> |
| 80 <RequestId>9fb7e2db-6998-11e2-a985-57c82EXAMPLE</RequestId> | 116 <RequestId>9fb7e2db-6998-11e2-a985-57c82EXAMPLE</RequestId> |
| 81 </ResponseMetadata> | 117 </ResponseMetadata> |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 """ | 256 """ |
| 221 | 257 |
| 222 def test_autoscaling_group_with_termination_policies(self): | 258 def test_autoscaling_group_with_termination_policies(self): |
| 223 self.set_http_response(status_code=200) | 259 self.set_http_response(status_code=200) |
| 224 response = self.service_connection.get_termination_policies() | 260 response = self.service_connection.get_termination_policies() |
| 225 self.assertListEqual( | 261 self.assertListEqual( |
| 226 response, | 262 response, |
| 227 ['ClosestToNextInstanceHour', 'Default', | 263 ['ClosestToNextInstanceHour', 'Default', |
| 228 'NewestInstance', 'OldestInstance', 'OldestLaunchConfiguration']) | 264 'NewestInstance', 'OldestInstance', 'OldestLaunchConfiguration']) |
| 229 | 265 |
| 266 class TestLaunchConfigurationDescribe(AWSMockServiceTestCase): |
| 267 connection_class = AutoScaleConnection |
| 268 |
| 269 def default_body(self): |
| 270 # This is a dummy response |
| 271 return """ |
| 272 <DescribeLaunchConfigurationsResponse> |
| 273 <DescribeLaunchConfigurationsResult> |
| 274 <LaunchConfigurations> |
| 275 <member> |
| 276 <AssociatePublicIpAddress>true</AssociatePublicIpAddress> |
| 277 <SecurityGroups/> |
| 278 <CreatedTime>2013-01-21T23:04:42.200Z</CreatedTime> |
| 279 <KernelId/> |
| 280 <LaunchConfigurationName>my-test-lc</LaunchConfigurationName> |
| 281 <UserData/> |
| 282 <InstanceType>m1.small</InstanceType> |
| 283 <LaunchConfigurationARN>arn:aws:autoscaling:us-east-1:8039819877
63:launchConfiguration:9dbbbf87-6141-428a-a409-0752edbe6cad:launchConfigurationN
ame/my-test-lc</LaunchConfigurationARN> |
| 284 <BlockDeviceMappings/> |
| 285 <ImageId>ami-514ac838</ImageId> |
| 286 <KeyName/> |
| 287 <RamdiskId/> |
| 288 <InstanceMonitoring> |
| 289 <Enabled>true</Enabled> |
| 290 </InstanceMonitoring> |
| 291 <EbsOptimized>false</EbsOptimized> |
| 292 </member> |
| 293 </LaunchConfigurations> |
| 294 </DescribeLaunchConfigurationsResult> |
| 295 <ResponseMetadata> |
| 296 <RequestId>d05a22f8-b690-11e2-bf8e-2113fEXAMPLE</RequestId> |
| 297 </ResponseMetadata> |
| 298 </DescribeLaunchConfigurationsResponse> |
| 299 """ |
| 300 |
| 301 def test_get_all_launch_configurations(self): |
| 302 self.set_http_response(status_code=200) |
| 303 |
| 304 response = self.service_connection.get_all_launch_configurations() |
| 305 self.assertTrue(isinstance(response, list)) |
| 306 self.assertEqual(len(response), 1) |
| 307 self.assertTrue(isinstance(response[0], LaunchConfiguration)) |
| 308 |
| 309 self.assertEqual(response[0].associate_public_ip_address, True) |
| 310 self.assertEqual(response[0].name, "my-test-lc") |
| 311 self.assertEqual(response[0].instance_type, "m1.small") |
| 312 self.assertEqual(response[0].launch_configuration_arn, "arn:aws:autoscal
ing:us-east-1:803981987763:launchConfiguration:9dbbbf87-6141-428a-a409-0752edbe6
cad:launchConfigurationName/my-test-lc") |
| 313 self.assertEqual(response[0].image_id, "ami-514ac838") |
| 314 self.assertTrue(isinstance(response[0].instance_monitoring, launchconfig
.InstanceMonitoring)) |
| 315 self.assertEqual(response[0].instance_monitoring.enabled, 'true') |
| 316 self.assertEqual(response[0].ebs_optimized, False) |
| 317 self.assertEqual(response[0].block_device_mappings, []) |
| 318 |
| 319 self.assert_request_parameters({ |
| 320 'Action': 'DescribeLaunchConfigurations', |
| 321 }, ignore_params_values=['Version']) |
| 322 |
| 323 def test_get_all_configuration_limited(self): |
| 324 self.set_http_response(status_code=200) |
| 325 |
| 326 response = self.service_connection.get_all_launch_configurations(max_rec
ords=10, names=["my-test1", "my-test2"]) |
| 327 self.assert_request_parameters({ |
| 328 'Action': 'DescribeLaunchConfigurations', |
| 329 'MaxRecords': 10, |
| 330 'LaunchConfigurationNames.member.1': 'my-test1', |
| 331 'LaunchConfigurationNames.member.2': 'my-test2' |
| 332 }, ignore_params_values=['Version']) |
| 333 |
| 230 class TestLaunchConfiguration(AWSMockServiceTestCase): | 334 class TestLaunchConfiguration(AWSMockServiceTestCase): |
| 231 connection_class = AutoScaleConnection | 335 connection_class = AutoScaleConnection |
| 232 | 336 |
| 233 def default_body(self): | 337 def default_body(self): |
| 234 # This is a dummy response | 338 # This is a dummy response |
| 235 return """ | 339 return """ |
| 236 <DescribeLaunchConfigurationsResponse> | 340 <DescribeLaunchConfigurationsResponse> |
| 237 </DescribeLaunchConfigurationsResponse> | 341 </DescribeLaunchConfigurationsResponse> |
| 238 """ | 342 """ |
| 239 | 343 |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 | 641 |
| 538 def test_autoscaling_group_put_notification_configuration(self): | 642 def test_autoscaling_group_put_notification_configuration(self): |
| 539 self.set_http_response(status_code=200) | 643 self.set_http_response(status_code=200) |
| 540 limits = self.service_connection.get_account_limits() | 644 limits = self.service_connection.get_account_limits() |
| 541 self.assert_request_parameters({ | 645 self.assert_request_parameters({ |
| 542 'Action': 'DescribeAccountLimits', | 646 'Action': 'DescribeAccountLimits', |
| 543 }, ignore_params_values=['Version']) | 647 }, ignore_params_values=['Version']) |
| 544 self.assertEqual(limits.max_autoscaling_groups, 6) | 648 self.assertEqual(limits.max_autoscaling_groups, 6) |
| 545 self.assertEqual(limits.max_launch_configurations, 3) | 649 self.assertEqual(limits.max_launch_configurations, 3) |
| 546 | 650 |
| 651 class TestGetAdjustmentTypes(AWSMockServiceTestCase): |
| 652 connection_class = AutoScaleConnection |
| 653 |
| 654 def setUp(self): |
| 655 super(TestGetAdjustmentTypes, self).setUp() |
| 656 |
| 657 def default_body(self): |
| 658 return """ |
| 659 <DescribeAdjustmentTypesResponse xmlns="http://autoscaling.amazonaws
.com/doc/201-01-01/"> |
| 660 <DescribeAdjustmentTypesResult> |
| 661 <AdjustmentTypes> |
| 662 <member> |
| 663 <AdjustmentType>ChangeInCapacity</AdjustmentType> |
| 664 </member> |
| 665 <member> |
| 666 <AdjustmentType>ExactCapacity</AdjustmentType> |
| 667 </member> |
| 668 <member> |
| 669 <AdjustmentType>PercentChangeInCapacity</AdjustmentType> |
| 670 </member> |
| 671 </AdjustmentTypes> |
| 672 </DescribeAdjustmentTypesResult> |
| 673 <ResponseMetadata> |
| 674 <RequestId>requestId</RequestId> |
| 675 </ResponseMetadata> |
| 676 </DescribeAdjustmentTypesResponse> |
| 677 """ |
| 678 def test_autoscaling_adjustment_types(self): |
| 679 self.set_http_response(status_code=200) |
| 680 response = self.service_connection.get_all_adjustment_types() |
| 681 self.assert_request_parameters({ |
| 682 'Action': 'DescribeAdjustmentTypes' |
| 683 }, ignore_params_values=['Version']) |
| 684 |
| 685 self.assertTrue(isinstance(response, list)) |
| 686 self.assertEqual(response[0].adjustment_type, "ChangeInCapacity") |
| 687 self.assertEqual(response[1].adjustment_type, "ExactCapacity") |
| 688 self.assertEqual(response[2].adjustment_type, "PercentChangeInCapacity") |
| 689 |
| 690 |
| 691 class TestLaunchConfigurationDescribeWithBlockDeviceTypes(AWSMockServiceTestCase
): |
| 692 connection_class = AutoScaleConnection |
| 693 |
| 694 def default_body(self): |
| 695 # This is a dummy response |
| 696 return """ |
| 697 <DescribeLaunchConfigurationsResponse> |
| 698 <DescribeLaunchConfigurationsResult> |
| 699 <LaunchConfigurations> |
| 700 <member> |
| 701 <AssociatePublicIpAddress>true</AssociatePublicIpAddress> |
| 702 <SecurityGroups/> |
| 703 <CreatedTime>2013-01-21T23:04:42.200Z</CreatedTime> |
| 704 <KernelId/> |
| 705 <LaunchConfigurationName>my-test-lc</LaunchConfigurationName> |
| 706 <UserData/> |
| 707 <InstanceType>m1.small</InstanceType> |
| 708 <LaunchConfigurationARN>arn:aws:autoscaling:us-east-1:8039819877
63:launchConfiguration:9dbbbf87-6141-428a-a409-0752edbe6cad:launchConfigurationN
ame/my-test-lc</LaunchConfigurationARN> |
| 709 <BlockDeviceMappings> |
| 710 <member> |
| 711 <DeviceName>/dev/xvdp</DeviceName> |
| 712 <Ebs> |
| 713 <SnapshotId>snap-1234abcd</SnapshotId> |
| 714 <Iops>1000</Iops> |
| 715 <DeleteOnTermination>true</DeleteOnTermination> |
| 716 <VolumeType>io1</VolumeType> |
| 717 <VolumeSize>100</VolumeSize> |
| 718 </Ebs> |
| 719 </member> |
| 720 <member> |
| 721 <VirtualName>ephemeral1</VirtualName> |
| 722 <DeviceName>/dev/xvdc</DeviceName> |
| 723 </member> |
| 724 <member> |
| 725 <VirtualName>ephemeral0</VirtualName> |
| 726 <DeviceName>/dev/xvdb</DeviceName> |
| 727 </member> |
| 728 <member> |
| 729 <DeviceName>/dev/xvdh</DeviceName> |
| 730 <Ebs> |
| 731 <Iops>2000</Iops> |
| 732 <DeleteOnTermination>false</DeleteOnTermination> |
| 733 <VolumeType>io1</VolumeType> |
| 734 <VolumeSize>200</VolumeSize> |
| 735 </Ebs> |
| 736 </member> |
| 737 </BlockDeviceMappings> |
| 738 <ImageId>ami-514ac838</ImageId> |
| 739 <KeyName/> |
| 740 <RamdiskId/> |
| 741 <InstanceMonitoring> |
| 742 <Enabled>true</Enabled> |
| 743 </InstanceMonitoring> |
| 744 <EbsOptimized>false</EbsOptimized> |
| 745 </member> |
| 746 </LaunchConfigurations> |
| 747 </DescribeLaunchConfigurationsResult> |
| 748 <ResponseMetadata> |
| 749 <RequestId>d05a22f8-b690-11e2-bf8e-2113fEXAMPLE</RequestId> |
| 750 </ResponseMetadata> |
| 751 </DescribeLaunchConfigurationsResponse> |
| 752 """ |
| 753 |
| 754 def test_get_all_launch_configurations_with_block_device_types(self): |
| 755 self.set_http_response(status_code=200) |
| 756 self.service_connection.use_block_device_types = True |
| 757 |
| 758 response = self.service_connection.get_all_launch_configurations() |
| 759 self.assertTrue(isinstance(response, list)) |
| 760 self.assertEqual(len(response), 1) |
| 761 self.assertTrue(isinstance(response[0], LaunchConfiguration)) |
| 762 |
| 763 self.assertEqual(response[0].associate_public_ip_address, True) |
| 764 self.assertEqual(response[0].name, "my-test-lc") |
| 765 self.assertEqual(response[0].instance_type, "m1.small") |
| 766 self.assertEqual(response[0].launch_configuration_arn, "arn:aws:autoscal
ing:us-east-1:803981987763:launchConfiguration:9dbbbf87-6141-428a-a409-0752edbe6
cad:launchConfigurationName/my-test-lc") |
| 767 self.assertEqual(response[0].image_id, "ami-514ac838") |
| 768 self.assertTrue(isinstance(response[0].instance_monitoring, launchconfig
.InstanceMonitoring)) |
| 769 self.assertEqual(response[0].instance_monitoring.enabled, 'true') |
| 770 self.assertEqual(response[0].ebs_optimized, False) |
| 771 |
| 772 self.assertEqual(response[0].block_device_mappings['/dev/xvdb'].ephemera
l_name, 'ephemeral0') |
| 773 |
| 774 self.assertEqual(response[0].block_device_mappings['/dev/xvdc'].ephemera
l_name, 'ephemeral1') |
| 775 |
| 776 self.assertEqual(response[0].block_device_mappings['/dev/xvdp'].snapshot
_id, 'snap-1234abcd') |
| 777 self.assertEqual(response[0].block_device_mappings['/dev/xvdp'].delete_o
n_termination, True) |
| 778 self.assertEqual(response[0].block_device_mappings['/dev/xvdp'].iops, 10
00) |
| 779 self.assertEqual(response[0].block_device_mappings['/dev/xvdp'].size, 10
0) |
| 780 self.assertEqual(response[0].block_device_mappings['/dev/xvdp'].volume_t
ype, 'io1') |
| 781 |
| 782 self.assertEqual(response[0].block_device_mappings['/dev/xvdh'].delete_o
n_termination, False) |
| 783 self.assertEqual(response[0].block_device_mappings['/dev/xvdh'].iops, 20
00) |
| 784 self.assertEqual(response[0].block_device_mappings['/dev/xvdh'].size, 20
0) |
| 785 self.assertEqual(response[0].block_device_mappings['/dev/xvdh'].volume_t
ype, 'io1') |
| 786 |
| 787 self.assert_request_parameters({ |
| 788 'Action': 'DescribeLaunchConfigurations', |
| 789 }, ignore_params_values=['Version']) |
| 790 |
| 791 def test_get_all_configuration_limited(self): |
| 792 self.set_http_response(status_code=200) |
| 793 |
| 794 response = self.service_connection.get_all_launch_configurations(max_rec
ords=10, names=["my-test1", "my-test2"]) |
| 795 self.assert_request_parameters({ |
| 796 'Action': 'DescribeLaunchConfigurations', |
| 797 'MaxRecords': 10, |
| 798 'LaunchConfigurationNames.member.1': 'my-test1', |
| 799 'LaunchConfigurationNames.member.2': 'my-test2' |
| 800 }, ignore_params_values=['Version']) |
| 801 |
| 547 | 802 |
| 548 if __name__ == '__main__': | 803 if __name__ == '__main__': |
| 549 unittest.main() | 804 unittest.main() |
| OLD | NEW |