OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved |
| 3 # |
| 4 # Permission is hereby granted, free of charge, to any person obtaining a |
| 5 # copy of this software and associated documentation files (the |
| 6 # "Software"), to deal in the Software without restriction, including |
| 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 |
| 9 # persons to whom the Software is furnished to do so, subject to the fol- |
| 10 # lowing conditions: |
| 11 # |
| 12 # The above copyright notice and this permission notice shall be included |
| 13 # in all copies or substantial portions of the Software. |
| 14 # |
| 15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 16 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- |
| 17 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT |
| 18 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 19 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 # IN THE SOFTWARE. |
| 22 # |
| 23 |
| 24 from tests.unit import unittest |
| 25 from tests.unit import AWSMockServiceTestCase |
| 26 |
| 27 from boto.ec2.autoscale import AutoScaleConnection |
| 28 from boto.ec2.autoscale.group import AutoScalingGroup |
| 29 |
| 30 |
| 31 class TestAutoScaleGroup(AWSMockServiceTestCase): |
| 32 connection_class = AutoScaleConnection |
| 33 |
| 34 def setUp(self): |
| 35 super(TestAutoScaleGroup, self).setUp() |
| 36 |
| 37 def default_body(self): |
| 38 return """ |
| 39 <CreateLaunchConfigurationResponse> |
| 40 <ResponseMetadata> |
| 41 <RequestId>requestid</RequestId> |
| 42 </ResponseMetadata> |
| 43 </CreateLaunchConfigurationResponse> |
| 44 """ |
| 45 |
| 46 def test_autoscaling_group_with_termination_policies(self): |
| 47 self.set_http_response(status_code=200) |
| 48 autoscale = AutoScalingGroup( |
| 49 name='foo', launch_config='lauch_config', |
| 50 min_size=1, max_size=2, |
| 51 termination_policies=['OldestInstance', 'OldestLaunchConfiguration']
) |
| 52 self.service_connection.create_auto_scaling_group(autoscale) |
| 53 self.assert_request_parameters({ |
| 54 'Action': 'CreateAutoScalingGroup', |
| 55 'AutoScalingGroupName': 'foo', |
| 56 'LaunchConfigurationName': 'lauch_config', |
| 57 'MaxSize': 2, |
| 58 'MinSize': 1, |
| 59 'TerminationPolicies.member.1': 'OldestInstance', |
| 60 'TerminationPolicies.member.2': 'OldestLaunchConfiguration', |
| 61 }, ignore_params_values=['Version']) |
| 62 |
| 63 |
| 64 class TestParseAutoScaleGroupResponse(AWSMockServiceTestCase): |
| 65 connection_class = AutoScaleConnection |
| 66 |
| 67 def default_body(self): |
| 68 return """ |
| 69 <DescribeAutoScalingGroupsResult> |
| 70 <AutoScalingGroups> |
| 71 <member> |
| 72 <Tags/> |
| 73 <SuspendedProcesses/> |
| 74 <AutoScalingGroupName>test_group</AutoScalingGroupName> |
| 75 <HealthCheckType>EC2</HealthCheckType> |
| 76 <CreatedTime>2012-09-27T20:19:47.082Z</CreatedTime> |
| 77 <EnabledMetrics/> |
| 78 <LaunchConfigurationName>test_launchconfig</LaunchConfiguration
Name> |
| 79 <Instances> |
| 80 <member> |
| 81 <HealthStatus>Healthy</HealthStatus> |
| 82 <AvailabilityZone>us-east-1a</AvailabilityZone> |
| 83 <InstanceId>i-z118d054</InstanceId> |
| 84 <LaunchConfigurationName>test_launchconfig</LaunchConfigura
tionName> |
| 85 <LifecycleState>InService</LifecycleState> |
| 86 </member> |
| 87 </Instances> |
| 88 <DesiredCapacity>1</DesiredCapacity> |
| 89 <AvailabilityZones> |
| 90 <member>us-east-1c</member> |
| 91 <member>us-east-1a</member> |
| 92 </AvailabilityZones> |
| 93 <LoadBalancerNames/> |
| 94 <MinSize>1</MinSize> |
| 95 <VPCZoneIdentifier/> |
| 96 <HealthCheckGracePeriod>0</HealthCheckGracePeriod> |
| 97 <DefaultCooldown>300</DefaultCooldown> |
| 98 <AutoScalingGroupARN>myarn</AutoScalingGroupARN> |
| 99 <TerminationPolicies> |
| 100 <member>OldestInstance</member> |
| 101 <member>OldestLaunchConfiguration</member> |
| 102 </TerminationPolicies> |
| 103 <MaxSize>2</MaxSize> |
| 104 </member> |
| 105 </AutoScalingGroups> |
| 106 </DescribeAutoScalingGroupsResult> |
| 107 """ |
| 108 |
| 109 def test_get_all_groups_is_parsed_correctly(self): |
| 110 self.set_http_response(status_code=200) |
| 111 response = self.service_connection.get_all_groups(names=['test_group']) |
| 112 self.assertEqual(len(response), 1, response) |
| 113 as_group = response[0] |
| 114 self.assertEqual(as_group.availability_zones, ['us-east-1c', 'us-east-1a
']) |
| 115 self.assertEqual(as_group.default_cooldown, 300) |
| 116 self.assertEqual(as_group.desired_capacity, 1) |
| 117 self.assertEqual(as_group.enabled_metrics, []) |
| 118 self.assertEqual(as_group.health_check_period, 0) |
| 119 self.assertEqual(as_group.health_check_type, 'EC2') |
| 120 self.assertEqual(as_group.launch_config_name, 'test_launchconfig') |
| 121 self.assertEqual(as_group.load_balancers, []) |
| 122 self.assertEqual(as_group.min_size, 1) |
| 123 self.assertEqual(as_group.max_size, 2) |
| 124 self.assertEqual(as_group.name, 'test_group') |
| 125 self.assertEqual(as_group.suspended_processes, []) |
| 126 self.assertEqual(as_group.tags, []) |
| 127 self.assertEqual(as_group.termination_policies, |
| 128 ['OldestInstance', 'OldestLaunchConfiguration']) |
| 129 |
| 130 |
| 131 class TestDescribeTerminationPolicies(AWSMockServiceTestCase): |
| 132 connection_class = AutoScaleConnection |
| 133 |
| 134 def default_body(self): |
| 135 return """ |
| 136 <DescribeTerminationPolicyTypesResponse> |
| 137 <DescribeTerminationPolicyTypesResult> |
| 138 <TerminationPolicyTypes> |
| 139 <member>ClosestToNextInstanceHour</member> |
| 140 <member>Default</member> |
| 141 <member>NewestInstance</member> |
| 142 <member>OldestInstance</member> |
| 143 <member>OldestLaunchConfiguration</member> |
| 144 </TerminationPolicyTypes> |
| 145 </DescribeTerminationPolicyTypesResult> |
| 146 <ResponseMetadata> |
| 147 <RequestId>requestid</RequestId> |
| 148 </ResponseMetadata> |
| 149 </DescribeTerminationPolicyTypesResponse> |
| 150 """ |
| 151 |
| 152 def test_autoscaling_group_with_termination_policies(self): |
| 153 self.set_http_response(status_code=200) |
| 154 response = self.service_connection.get_termination_policies() |
| 155 self.assertListEqual( |
| 156 response, |
| 157 ['ClosestToNextInstanceHour', 'Default', |
| 158 'NewestInstance', 'OldestInstance', 'OldestLaunchConfiguration']) |
| 159 |
| 160 |
| 161 if __name__ == '__main__': |
| 162 unittest.main() |
OLD | NEW |