diff options
author | rlotun <rlotun@gmail.com> | 2011-03-31 16:51:07 +0100 |
---|---|---|
committer | rlotun <rlotun@gmail.com> | 2011-03-31 16:51:07 +0100 |
commit | e80a70c8003a679c3bfb6f8704fbbd8bfbfeb6af (patch) | |
tree | 007a283c1525dcbca144fad7b929673b31b978d7 | |
parent | f6b020f703ae48968313ac3335ca005bbafb69d7 (diff) | |
download | boto-e80a70c8003a679c3bfb6f8704fbbd8bfbfeb6af.tar.gz |
Simple autoscale unit tests and fixes.
-rw-r--r-- | boto/ec2/autoscale/__init__.py | 23 | ||||
-rw-r--r-- | boto/ec2/autoscale/launchconfig.py | 2 | ||||
-rw-r--r-- | boto/ec2/autoscale/policy.py | 6 | ||||
-rw-r--r-- | boto/ec2/autoscale/scheduled.py | 2 | ||||
-rw-r--r-- | tests/autoscale/__init__.py | 21 | ||||
-rw-r--r-- | tests/autoscale/test_connection.py | 90 | ||||
-rwxr-xr-x | tests/test.py | 8 |
7 files changed, 127 insertions, 25 deletions
diff --git a/boto/ec2/autoscale/__init__.py b/boto/ec2/autoscale/__init__.py index 8adc4585..7f155f8d 100644 --- a/boto/ec2/autoscale/__init__.py +++ b/boto/ec2/autoscale/__init__.py @@ -1,4 +1,4 @@ -# Copyright (c) 2009-2010 Reza Lotun http://reza.lotun.name/ +# Copyright (c) 2009-2011 Reza Lotun http://reza.lotun.name/ # Copyright (c) 2011 Jann Kleen # # Permission is hereby granted, free of charge, to any person obtaining a @@ -32,8 +32,9 @@ from boto.ec2.autoscale.request import Request from boto.ec2.autoscale.launchconfig import LaunchConfiguration from boto.ec2.autoscale.group import AutoScalingGroup from boto.ec2.autoscale.activity import Activity -from boto.ec2.autoscale.policy import AdjustmentTypes, MetricCollectionTypes, ScalingPolicy +from boto.ec2.autoscale.policy import AdjustmentType, MetricCollectionTypes, ScalingPolicy from boto.ec2.autoscale.instance import Instance +from boto.ec2.autoscale.scheduled import ScheduledUpdateGroupAction class AutoScaleConnection(AWSQueryConnection): @@ -303,19 +304,6 @@ class AutoScaleConnection(AWSQueryConnection): self.build_list_params(params, activity_ids, 'ActivityIds') return self.get_list('DescribeScalingActivities', params, [('member', Activity)]) - def get_all_scheduled_actions(self, autoscale_group=None, scheduled_actions=None, - start_time=None, end_time=None, max_records=None, next_token=None): - """ - Lists all the actions scheduled for your Auto Scaling group that haven't been executed. - """ - params = {} - # XXX - if autoscale_group: - params['AutoScalingGroupName'] = autoscale_group - if max_records: - params['MaxRecords'] = max_records - if next_token: - params['NextToken'] = next_token def delete_scheduled_action(self, scheduled_action_name, autoscale_group=None): params = { @@ -342,7 +330,7 @@ class AutoScaleConnection(AWSQueryConnection): return self.get_status('DeletePolicy', params) def get_all_adjustment_types(self): - return self.get_list('DescribeAdjustmentTypes', {}, [('member', AdjustmentTypes)]) + return self.get_list('DescribeAdjustmentTypes', {}, [('member', AdjustmentType)]) def get_all_autoscaling_instances(self, instance_ids=None, max_records=None, next_token=None): """ @@ -412,8 +400,7 @@ class AutoScaleConnection(AWSQueryConnection): params['MaxRecords'] = max_records if next_token: params['NextToken'] = next_token - #XXX - return self.get_object('DescribeScheduledActions', params, {}) + return self.get_list('DescribeScheduledActions', params, [('member', ScheduledUpdateGroupAction)]) def disable_metrics_collection(self, as_group, metrics=None): """ diff --git a/boto/ec2/autoscale/launchconfig.py b/boto/ec2/autoscale/launchconfig.py index 0c0c1cf3..fe19e1be 100644 --- a/boto/ec2/autoscale/launchconfig.py +++ b/boto/ec2/autoscale/launchconfig.py @@ -132,7 +132,7 @@ class LaunchConfiguration(object): return self.security_groups elif name == 'BlockDeviceMappings': self.block_device_mappings = ResultSet([('member', BlockDeviceMapping)]) - return self.instances + return self.block_device_mappings def endElement(self, name, value, connection): if name == 'InstanceType': diff --git a/boto/ec2/autoscale/policy.py b/boto/ec2/autoscale/policy.py index 8f870c86..f30eb6cb 100644 --- a/boto/ec2/autoscale/policy.py +++ b/boto/ec2/autoscale/policy.py @@ -45,16 +45,16 @@ class Alarm(object): setattr(self, name, value) -class AdjustmentTypes(object): +class AdjustmentType(object): def __init__(self, connection=None): self.connection = connection self.adjustment_types = ListElement([]) def __repr__(self): - return 'AdjustmentTypes:%s' % self.adjustment_types + return 'AdjustmentType:%s' % self.adjustment_types def startElement(self, name, attrs, connection): - if name == 'AdjustmentTypes': + if name == 'AdjustmentType': return self.adjustment_types def endElement(self, name, value, connection): diff --git a/boto/ec2/autoscale/scheduled.py b/boto/ec2/autoscale/scheduled.py index 66d716c9..a2bc2d15 100644 --- a/boto/ec2/autoscale/scheduled.py +++ b/boto/ec2/autoscale/scheduled.py @@ -40,7 +40,7 @@ class ScheduledUpdateGroupAction(object): def endElement(self, name, value, connection): if name == 'DesiredCapacity': self.desired_capacity = value - elif name = 'ScheduledActionName': + elif name == 'ScheduledActionName': self.name = value elif name == 'MaxSize': self.max_size = int(value) diff --git a/tests/autoscale/__init__.py b/tests/autoscale/__init__.py new file mode 100644 index 00000000..4a55c4b7 --- /dev/null +++ b/tests/autoscale/__init__.py @@ -0,0 +1,21 @@ +# Copyright (c) 2011 Reza Lotun http://reza.lotun.name +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, dis- +# tribute, sublicense, and/or sell copies of the Software, and to permit +# persons to whom the Software is furnished to do so, subject to the fol- +# lowing conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- +# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. + diff --git a/tests/autoscale/test_connection.py b/tests/autoscale/test_connection.py new file mode 100644 index 00000000..e837c2b9 --- /dev/null +++ b/tests/autoscale/test_connection.py @@ -0,0 +1,90 @@ +# Copyright (c) 2011 Reza Lotun http://reza.lotun.name +# All rights reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, dis- +# tribute, sublicense, and/or sell copies of the Software, and to permit +# persons to whom the Software is furnished to do so, subject to the fol- +# lowing conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- +# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. + +""" +Some unit tests for the AutoscaleConnection +""" + +import unittest +import time +from boto.ec2.autoscale import AutoScaleConnection +from boto.ec2.autoscale.activity import Activity +from boto.ec2.autoscale.group import AutoScalingGroup +from boto.ec2.autoscale.launchconfig import LaunchConfiguration +from boto.ec2.autoscale.policy import AdjustmentType, MetricCollectionTypes, ScalingPolicy +from boto.ec2.autoscale.scheduled import ScheduledUpdateGroupAction +from boto.ec2.autoscale.instance import Instance + +class AutoscaleConnectionTest(unittest.TestCase): + + def test_basic(self): + # NB: as it says on the tin these are really basic tests that only + # (lightly) exercise read-only behaviour - and that's only if you + # have any autoscale groups to introspect. It's useful, however, to + # catch simple errors + + print '--- running %s tests ---' % self.__class__.__name__ + c = AutoScaleConnection() + + self.assertTrue(repr(c).startswith('AutoScaleConnection')) + + groups = c.get_all_groups() + for group in groups: + self.assertTrue(type(group), AutoScalingGroup) + + # get activities + activities = group.get_activities() + + for activity in activities: + self.assertEqual(type(activity), Activity) + + # get launch configs + configs = c.get_all_launch_configurations() + for config in configs: + self.assertTrue(type(config), LaunchConfiguration) + + # get policies + policies = c.get_all_policies() + for policy in policies: + self.assertTrue(type(policy), ScalingPolicy) + + # get scheduled actions + actions = c.get_all_scheduled_actions() + for action in actions: + self.assertTrue(type(action), ScheduledUpdateGroupAction) + + # get instances + instances = c.get_all_autoscaling_instances() + for instance in instances: + self.assertTrue(type(instance), Instance) + + # get adjustment types + adjustments = c.get_all_adjustment_types() + for adjustment in adjustments: + self.assertTrue(type(adjustment), AdjustmentType) + + # get metrics collection types + types = c.get_all_metric_collection_types() + self.assertTrue(type(types), MetricCollectionTypes) + + print '--- tests completed ---' + diff --git a/tests/test.py b/tests/test.py index 5d38ad70..387f3b60 100755 --- a/tests/test.py +++ b/tests/test.py @@ -15,7 +15,7 @@ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. @@ -33,13 +33,14 @@ from s3.test_connection import S3ConnectionTest from s3.test_versioning import S3VersionTest from s3.test_gsconnection import GSConnectionTest from ec2.test_connection import EC2ConnectionTest +from autoscale.test_connection import AutoscaleConnectionTest from sdb.test_connection import SDBConnectionTest def usage(): print 'test.py [-t testsuite] [-v verbosity]' print ' -t run specific testsuite (s3|s3ver|s3nover|gs|sqs|ec2|sdb|all)' print ' -v verbosity (0|1|2)' - + def main(): try: opts, args = getopt.getopt(sys.argv[1:], 'ht:v:', @@ -66,6 +67,7 @@ def main(): suite.addTest(unittest.makeSuite(S3ConnectionTest)) suite.addTest(unittest.makeSuite(EC2ConnectionTest)) suite.addTest(unittest.makeSuite(SDBConnectionTest)) + suite.addTest(unittest.makeSuite(AutoscaleConnectionTest)) elif testsuite == 's3': suite.addTest(unittest.makeSuite(S3ConnectionTest)) suite.addTest(unittest.makeSuite(S3VersionTest)) @@ -79,6 +81,8 @@ def main(): suite.addTest(unittest.makeSuite(SQSConnectionTest)) elif testsuite == 'ec2': suite.addTest(unittest.makeSuite(EC2ConnectionTest)) + elif testsuite == 'autoscale': + suite.addTest(unittest.makeSuite(AutoscaleConnectionTest)) elif testsuite == 'sdb': suite.addTest(unittest.makeSuite(SDBConnectionTest)) else: |