New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Register scalable target prior to creating/deleting a scaling policy #35632
Conversation
The test
The test
The test
The test
The test
|
ready_for_review |
@gurumaia , Could you please take a look at the changes? |
@@ -170,7 +178,56 @@ def delete_scaling_policy(connection, module): | |||
except Exception as e: | |||
module.fail_json(msg=str(e), exception=traceback.format_exc()) | |||
|
|||
module.exit_json(changed=changed) | |||
result = {"changed": changed} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could just return {'changed': changed}
def create_scalable_target(connection, module): | ||
changed = False | ||
|
||
scalable_targets = connection.describe_scalable_targets( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This call needs exception handling.
MinCapacity=module.params.get('minimum_tasks'), | ||
MaxCapacity=module.params.get('maximum_tasks') | ||
) | ||
except Exception as e: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the rest of the module is using except Exception
so you've probably done this for consistency, but it would be better to catch only the specific exceptions, which would be the botocore.exceptions ClientError and BotoCoreError. Same for the one below. At some point the other 'except Exception's need to be removed.
Guidelines on exception handling: https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/cloud/amazon/GUIDELINES.md#using-fail_json-and-avoiding-ansiblemodule_utilsawscore
else: | ||
snaked_response = {} | ||
|
||
result = {"changed": changed, "response": snaked_response} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could just return this dict, same below.
@@ -284,11 +344,19 @@ def main(): | |||
except botocore.exceptions.ProfileNotFound as e: | |||
module.fail_json(msg=str(e)) | |||
|
|||
# A scalable target must be registered prior to creating a scaling policy | |||
scalable_target_result = create_scalable_target(connection, module) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For backwards compatibility should there be a way to turn this on or off?
|
||
# return the scalable target result only if it has changed and there were no policy changes | ||
if scalable_target_result['changed'] is True and policy_result['changed'] is False: | ||
module.exit_json(**scalable_target_result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The contents of this needs to be added to the RETURN doc.
ready_for_review |
@s-hertel , thanks for the review and the comments. I've pushed the necessary fixes and some other enhancements. I'd really appreciate if you could give it another look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great @chenl87, thanks for the patience. Feel free to add yourself as an author, and then you'll get updates and be able to use the power of "shipit" to help get community contributions merged.
)) | ||
|
||
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) | ||
module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True) | ||
|
||
if not HAS_BOTO3: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AnsibleAWSModule checks this for you so you can remove this and the import.
|
||
if not HAS_BOTO3: | ||
module.fail_json(msg='boto3 is required.') | ||
module.fail_json_aws(msg='boto3 is required.') | ||
|
||
try: | ||
region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True) | ||
if not region: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
boto3_conn handles this for you. You can remove this, as well as the try/except around boto3_conn. It handles ProfileNotFound. Since you're using AnsibleAWSModule you can replace this entire try/except with: connection = module.client('application-autoscaling')
.
The test
The test
|
SUMMARY
Added essential step of creating scalable target registration before attempting to create (and delete)
a scaling policy.
up until now, this module has always failed with the following message (example message):
"An error occurred (ObjectNotFoundException) when calling the PutScalingPolicy operation: No scalable target registered for service namespace: ecs, resource ID: service/poc-pricing/test-as, scalable dimension: ecs:service:DesiredCount"
ISSUE TYPE
COMPONENT NAME
aws_application_scaling_policy
ADDITIONAL INFORMATION
From boto3 documentation:
"
Registers or updates a scalable target. A scalable target is a resource that Application Auto Scaling can scale out or scale in. After you have registered a scalable target, you can use this operation to update the minimum and maximum values for its scalable dimension.
After you register a scalable target, you can create and apply scaling policies using PutScalingPolicy
"
http://boto3.readthedocs.io/en/latest/reference/services/application-autoscaling.html#ApplicationAutoScaling.Client.register_scalable_target