Repository: boto/boto

Issue:
set_desired_capacity doesn't work if honor_cooldown parameter set to True.
Hi,
Function set_desired_capacity throws NameError exception if honor_cooldown is True:

> Traceback (most recent call last):
>   File "./ag-desired-capacity.py", line 131, in <module>
>     honor_cooldown = True)
>   File "/usr/lib/python2.6/site-packages/boto-2.13.3-py2.6.egg/boto/ec2/autoscale/**init**.py", line 752, in set_desired_capacity
>     params['HonorCooldown'] = json.dumps('True')
> NameError: global name 'json' is not defined

At first look it seems that import is missing: 'from boto.compat import json'
But after I added it I've got following response:

> File "./ag-desired-capacity.py", line 131, in <module>
>     honor_cooldown = True)
>   File "/usr/lib/python2.6/site-packages/boto-2.13.3-py2.6.egg/boto/ec2/autoscale/**init**.py", line 755, in set_desired_capacity
>     return self.get_status('SetDesiredCapacity', params)
>   File "/usr/lib/python2.6/site-packages/boto-2.13.3-py2.6.egg/boto/connection.py", line 1121, in get_status
>     raise self.ResponseError(response.status, response.reason, body)
> boto.exception.BotoServerError: BotoServerError: 400 Bad Request
> <ErrorResponse xmlns="http://autoscaling.amazonaws.com/doc/2011-01-01/">
>   <Error>
>     <Type>Sender</Type>
>     <Code>MalformedInput</Code>
>     <Message>boolean must follow xsd1.1 definition</Message>
>   </Error>
>   <RequestId>e4385ca2-5df0-11e3-ad1b-ad22a2f241c5</RequestId>
> </ErrorResponse>

Following fix to 'boto/ec2/autoscale/**init**.py' works for me:

> params['HonorCooldown'] = 'true'

Thanks,
Oleg.



Discussion:

Resolving patch:
diff --git a/boto/ec2/autoscale/__init__.py b/boto/ec2/autoscale/__init__.py
--- a/boto/ec2/autoscale/__init__.py
+++ b/boto/ec2/autoscale/__init__.py
@@ -785,7 +785,7 @@ def set_desired_capacity(self, group_name, desired_capacity, honor_cooldown=Fals
         params = {'AutoScalingGroupName': group_name,
                   'DesiredCapacity': desired_capacity}
         if honor_cooldown:
-            params['HonorCooldown'] = json.dumps('True')
+            params['HonorCooldown'] = 'true'
 
         return self.get_status('SetDesiredCapacity', params)
 


Test patch:
diff --git a/tests/unit/ec2/autoscale/test_group.py b/tests/unit/ec2/autoscale/test_group.py
--- a/tests/unit/ec2/autoscale/test_group.py
+++ b/tests/unit/ec2/autoscale/test_group.py
@@ -67,6 +67,29 @@ def test_autoscaling_group_with_termination_policies(self):
             'TerminationPolicies.member.2': 'OldestLaunchConfiguration',
         }, ignore_params_values=['Version'])
 
+
+class TestAutoScaleGroupHonorCooldown(AWSMockServiceTestCase):
+    connection_class = AutoScaleConnection
+
+    def default_body(self):
+        return """
+            <SetDesiredCapacityResponse>
+              <ResponseMetadata>
+                <RequestId>9fb7e2db-6998-11e2-a985-57c82EXAMPLE</RequestId>
+              </ResponseMetadata>
+            </SetDesiredCapacityResponse>
+        """
+
+    def test_honor_cooldown(self):
+        self.set_http_response(status_code=200)
+        self.service_connection.set_desired_capacity('foo', 10, True)
+        self.assert_request_parameters({
+            'Action': 'SetDesiredCapacity',
+            'AutoScalingGroupName': 'foo',
+            'DesiredCapacity': 10,
+            'HonorCooldown': 'true',
+        }, ignore_params_values=['Version'])
+
 class TestScheduledGroup(AWSMockServiceTestCase):
     connection_class = AutoScaleConnection