| OLD | NEW |
| 1 # Copyright (c) 2011 Reza Lotun http://reza.lotun.name | 1 # Copyright (c) 2011 Reza Lotun http://reza.lotun.name |
| 2 # All rights reserved. | 2 # 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 | 26 |
| 27 import unittest | 27 import unittest |
| 28 import time | 28 import time |
| 29 from boto.ec2.autoscale import AutoScaleConnection | 29 from boto.ec2.autoscale import AutoScaleConnection |
| 30 from boto.ec2.autoscale.activity import Activity | 30 from boto.ec2.autoscale.activity import Activity |
| 31 from boto.ec2.autoscale.group import AutoScalingGroup, ProcessType | 31 from boto.ec2.autoscale.group import AutoScalingGroup, ProcessType |
| 32 from boto.ec2.autoscale.launchconfig import LaunchConfiguration | 32 from boto.ec2.autoscale.launchconfig import LaunchConfiguration |
| 33 from boto.ec2.autoscale.policy import AdjustmentType, MetricCollectionTypes, Sca
lingPolicy | 33 from boto.ec2.autoscale.policy import AdjustmentType, MetricCollectionTypes, Sca
lingPolicy |
| 34 from boto.ec2.autoscale.scheduled import ScheduledUpdateGroupAction | 34 from boto.ec2.autoscale.scheduled import ScheduledUpdateGroupAction |
| 35 from boto.ec2.autoscale.instance import Instance | 35 from boto.ec2.autoscale.instance import Instance |
| 36 from boto.ec2.autoscale.tag import Tag |
| 36 | 37 |
| 37 class AutoscaleConnectionTest(unittest.TestCase): | 38 class AutoscaleConnectionTest(unittest.TestCase): |
| 38 | 39 |
| 39 def test_basic(self): | 40 def test_basic(self): |
| 40 # NB: as it says on the tin these are really basic tests that only | 41 # NB: as it says on the tin these are really basic tests that only |
| 41 # (lightly) exercise read-only behaviour - and that's only if you | 42 # (lightly) exercise read-only behaviour - and that's only if you |
| 42 # have any autoscale groups to introspect. It's useful, however, to | 43 # have any autoscale groups to introspect. It's useful, however, to |
| 43 # catch simple errors | 44 # catch simple errors |
| 44 | 45 |
| 45 print '--- running %s tests ---' % self.__class__.__name__ | 46 print '--- running %s tests ---' % self.__class__.__name__ |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 85 |
| 85 # get adjustment types | 86 # get adjustment types |
| 86 adjustments = c.get_all_adjustment_types() | 87 adjustments = c.get_all_adjustment_types() |
| 87 for adjustment in adjustments: | 88 for adjustment in adjustments: |
| 88 self.assertTrue(type(adjustment), AdjustmentType) | 89 self.assertTrue(type(adjustment), AdjustmentType) |
| 89 | 90 |
| 90 # get metrics collection types | 91 # get metrics collection types |
| 91 types = c.get_all_metric_collection_types() | 92 types = c.get_all_metric_collection_types() |
| 92 self.assertTrue(type(types), MetricCollectionTypes) | 93 self.assertTrue(type(types), MetricCollectionTypes) |
| 93 | 94 |
| 95 # create the simplest possible AutoScale group |
| 96 # first create the launch configuration |
| 97 time_string = '%d' % int(time.time()) |
| 98 lc_name = 'lc-%s' % time_string |
| 99 lc = LaunchConfiguration(name=lc_name, image_id='ami-2272864b', |
| 100 instance_type='t1.micro') |
| 101 c.create_launch_configuration(lc) |
| 102 found = False |
| 103 lcs = c.get_all_launch_configurations() |
| 104 for lc in lcs: |
| 105 if lc.name == lc_name: |
| 106 found = True |
| 107 break |
| 108 assert found |
| 109 |
| 110 # now create autoscaling group |
| 111 group_name = 'group-%s' % time_string |
| 112 group = AutoScalingGroup(name=group_name, launch_config=lc, |
| 113 availability_zones=['us-east-1a'], |
| 114 min_size=1, max_size=1) |
| 115 c.create_auto_scaling_group(group) |
| 116 found = False |
| 117 groups = c.get_all_groups() |
| 118 for group in groups: |
| 119 if group.name == group_name: |
| 120 found = True |
| 121 break |
| 122 assert found |
| 123 |
| 124 # now create a tag |
| 125 tag = Tag(key='foo', value='bar', resource_id=group_name, |
| 126 propagate_at_launch=True) |
| 127 c.create_or_update_tags([tag]) |
| 128 |
| 129 found = False |
| 130 tags = c.get_all_tags() |
| 131 for tag in tags: |
| 132 if tag.resource_id == group_name and tag.key == 'foo': |
| 133 found = True |
| 134 break |
| 135 assert found |
| 136 |
| 137 c.delete_tags([tag]) |
| 138 |
| 139 # shutdown instances and wait for them to disappear |
| 140 group.shutdown_instances() |
| 141 instances = True |
| 142 while instances: |
| 143 time.sleep(5) |
| 144 groups = c.get_all_groups() |
| 145 for group in groups: |
| 146 if group.name == group_name: |
| 147 if not group.instances: |
| 148 instances = False |
| 149 |
| 150 group.delete() |
| 151 lc.delete() |
| 152 |
| 153 found = True |
| 154 while found: |
| 155 found = False |
| 156 time.sleep(5) |
| 157 tags = c.get_all_tags() |
| 158 for tag in tags: |
| 159 if tag.resource_id == group_name and tag.key == 'foo': |
| 160 found = True |
| 161 |
| 162 assert not found |
| 163 |
| 94 print '--- tests completed ---' | 164 print '--- tests completed ---' |
| 95 | 165 |
| 166 |
| OLD | NEW |