Skip to content
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

Fix idempotency and logic to update existing aggregator #645

Merged
merged 5 commits into from
Jul 2, 2022
Merged

Fix idempotency and logic to update existing aggregator #645

merged 5 commits into from
Jul 2, 2022

Conversation

ichekaldin
Copy link
Contributor

SUMMARY

describe_configuration_aggregators method returns output similar
to the following:

{
    "ConfigurationAggregators": [
        {
            "ConfigurationAggregatorName": "test-name",
            "ConfigurationAggregatorArn": "arn:aws:config:us-east-1:123412341234:config-aggregator/config-aggregator-xbxbvyq5",
            "OrganizationAggregationSource": {
                "RoleArn": "arn:aws:iam::123412341234:role/my-role",
                "AllAwsRegions": true
            },
            "CreationTime": 1619030767.047,
            "LastUpdatedTime": 1626463216.998
        }
    ]
}

As a result, lines 134-136 fail:

    del current_params['ConfigurationAggregatorArn']
    del current_params['CreationTime']
    del current_params['LastUpdatedTime']

as they try to delete attributes from the current_params as opposed
to current_params['ConfigurationAggregators'][0].

The error message is:

KeyError: 'ConfigurationAggregators'

Additionally, if no account_sources attribute is specified, the module
fails idempotency check, because in that case AccountAggregationSources
attribute is present in params, but not in current_params.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

aws_config_aggregator

ADDITIONAL INFORMATION

@ansibullbot
Copy link

@ansibullbot ansibullbot added bug This issue/PR relates to a bug community_review module module needs_triage plugins plugin (any type) labels Jul 16, 2021
@ichekaldin
Copy link
Contributor Author

I see that ansible/check failed two tests:

  • ansible-galaxy-importer - I can't clearly see what the error is.

  • ansible-test-cloud-integration-aws-py36_2 - the error is:

ERROR: The 1 integration test(s) listed below (out of 20) failed. See error output above for details:
ec2_vpc_endpoint_service_info

I haven't modified any files related to ec2_vpc_endpoint_service_info as part of this PR.

Am I missing anything obvious?

@alinabuzachis
Copy link
Contributor

recheck

@ichekaldin
Copy link
Contributor Author

@alinabuzachis It looks like the tests fail with the same errors.

@tremble
Copy link
Contributor

tremble commented Aug 10, 2021

@ichekaldin Sorry about that, the move to Zuul caused all sorts of fun.

@tremble
Copy link
Contributor

tremble commented Aug 10, 2021

@ichekaldin While they're not run in CI due to constraints with AWS Config (eg. you can't have multiple aggregators) There are some basic integration tests for aws_config (including the aggregator)

https://github.com/ansible-collections/community.aws/blob/main/tests/integration/targets/aws_config/tasks/main.yaml

Please could you update the tests to include idempotency tests and some regression tests for the issues you hit.

@ansibullbot ansibullbot added integration tests/integration tests tests labels Aug 10, 2021
@ichekaldin
Copy link
Contributor Author

@tremble I added a test to validate that specifying empty list of accounts and the organization source works:

    - name: test resource_type configuration_aggregator with organization_source parameter
      aws_config_aggregator:
        name: random_name
        state: present
        account_sources: []
        organization_source:
          all_aws_regions: true
          role_arn: "{{ config_iam_role.arn }}"
      register: output
      ignore_errors: true

Would that be sufficient?

@ichekaldin
Copy link
Contributor Author

@tremble Sorry to keep bumping this - I'd love for this fix to get merged before the next release. What do you think about the test I added?

Copy link
Contributor

@tremble tremble left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your submission.

account_sources and organization_source are both currently required parameters (line 167/168) so on its own this change doesn't make sense.

Additionally, the integration test resulted in exceptions when I tried to run it and I'm not sure it's the right test.

@@ -14,6 +14,7 @@
short_description: Manage AWS Config aggregations across multiple accounts
description:
- Module manages AWS Config resources
requirements: [ 'botocore', 'boto3' ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
requirements: [ 'botocore', 'boto3' ]

The botocore/boto3 requirements are automatically added.

assert:
that:
- output.failed
- 'output.msg.startswith("missing required arguments: organization_source")'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test looks wrong...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TASK [aws_config : test resource_type configuration_aggregator with organization_source parameter] ****************************************************************************************************************
task path: /root/ansible_collections/community/aws/tests/output/.tmp/integration/aws_config-z_x25kln-ÅÑŚÌβŁÈ/tests/integration/targets/aws_config/tasks/main.yaml:156
Using module file /root/ansible_collections/community/aws/plugins/modules/aws_config_aggregator.py
Pipelining is enabled.
<testhost> ESTABLISH LOCAL CONNECTION FOR USER: root
<testhost> EXEC /bin/sh -c 'ANSIBLE_DEBUG_BOTOCORE_LOGS=True /usr/bin/python3.10 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "<stdin>", line 121, in <module>
  File "<stdin>", line 113, in _ansiballz_main
  File "<stdin>", line 61, in invoke_module
  File "/usr/lib/python3.10/runpy.py", line 209, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.10/runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_aws_config_aggregator_payload_lfs1q8or/ansible_aws_config_aggregator_payload.zip/ansible_collections/community/aws/plugins/modules/aws_config_aggregator.py", line 228, in <module>
  File "/tmp/ansible_aws_config_aggregator_payload_lfs1q8or/ansible_aws_config_aggregator_payload.zip/ansible_collections/community/aws/plugins/modules/aws_config_aggregator.py", line 216, in main
  File "/tmp/ansible_aws_config_aggregator_payload_lfs1q8or/ansible_aws_config_aggregator_payload.zip/ansible_collections/community/aws/plugins/modules/aws_config_aggregator.py", line 119, in create_resource
KeyError: 'AccountAggregationSources'
fatal: [testhost]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"<stdin>\", line 121, in <module>\n  File \"<stdin>\", line 113, in _ansiballz_main\n  File \"<stdin>\", line 61, in invoke_module\n  File \"/usr/lib/python3.10/runpy.py\", line 209, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.10/runpy.py\", line 96, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib/python3.10/runpy.py\", line 86, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_aws_config_aggregator_payload_lfs1q8or/ansible_aws_config_aggregator_payload.zip/ansible_collections/community/aws/plugins/modules/aws_config_aggregator.py\", line 228, in <module>\n  File \"/tmp/ansible_aws_config_aggregator_payload_lfs1q8or/ansible_aws_config_aggregator_payload.zip/ansible_collections/community/aws/plugins/modules/aws_config_aggregator.py\", line 216, in main\n  File \"/tmp/ansible_aws_config_aggregator_payload_lfs1q8or/ansible_aws_config_aggregator_payload.zip/ansible_collections/community/aws/plugins/modules/aws_config_aggregator.py\", line 119, in create_resource\nKeyError: 'AccountAggregationSources'\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}
...ignoring

TASK [aws_config : assert failure when called with organization_source parameter] *********************************************************************************************************************************
task path: /root/ansible_collections/community/aws/tests/output/.tmp/integration/aws_config-z_x25kln-ÅÑŚÌβŁÈ/tests/integration/targets/aws_config/tasks/main.yaml:167
fatal: [testhost]: FAILED! => {
    "assertion": "output.msg.startswith(\"missing required arguments: organization_source\")",
    "changed": false,
    "evaluated_to": false,
    "msg": "Assertion failed"
}

@ansibullbot
Copy link

@ichekaldin this PR contains the following merge commits:

Please rebase your branch to remove these commits.

click here for bot help

@ansibullbot ansibullbot added merge_commit This PR contains at least one merge commit. Please resolve! needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html and removed community_review labels Oct 22, 2021
Comment on lines 170 to 171
- output.failed
- 'output.msg.startswith("missing required arguments: organization_source")'
- output.changed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The aggregator doesn't exist, so it'll refuse to create due to account_sources being empty

@ansibullbot ansibullbot added community_review and removed merge_commit This PR contains at least one merge commit. Please resolve! needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html labels Oct 22, 2021
@ichekaldin
Copy link
Contributor Author

@tremble Thank you! I made some changes to new vs existing parameters are compared.

alinabuzachis pushed a commit to alinabuzachis/community.aws that referenced this pull request May 25, 2022
)

[4.0.0] Bump minimum botocore version to 1.20.0

SUMMARY
With the next major version we can bump botocore/boto3 again.  Since 1.20.0 is now over a year old, we can bump the minimum version in preparation for 4.0.0.  CI should still test backports against the relevant versions for the backported release.
1.20.0 was released 2021-02-02.
1.21.0 was released 2021-07-15, hopefully we'll release 4.0.0 before July.
Should we release after mid-July we can always bump again.
(Mentioned in ansible-collections#645)
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
requirements.txt
ADDITIONAL INFORMATION
botocore] $ git show 1.20.0
tag 1.20.0
Tagger: aws-sdk-python-automation <[email protected]>
Date:   Tue Feb 2 19:11:44 2021 +0000

Tagging 1.20.0 release.

commit b7d27dc39aea82e22e2c11443fbd02a4904367cd (tag: 1.20.0)
Merge: cc497a593 27ebea65f
Author: aws-sdk-python-automation <[email protected]>
Date:   Tue Feb 2 19:11:44 2021 +0000

    Merge branch 'release-1.20.0'
    
    * release-1.20.0:
      Bumping version to 1.20.0
      Update to latest models
      Add changelog for custom endpoints and ARN resources
      Allow custom endpoints when addressing ARN resources
      Add changes for Python 3.4/3.5 removal
      Fall back to Transfer-Encoding 'chunked' if AWSRequest body is not seekable stream

boto3] $ git show 1.17.0
tag 1.17.0
Tagger: aws-sdk-python-automation <[email protected]>
Date:   Tue Feb 2 19:11:35 2021 +0000

Tagging 1.17.0 release.

commit 1a35ed1ab41f967ea43420650075f2693cbbe08b (tag: 1.17.0)
Merge: d77d24f9 35454bc5
Author: aws-sdk-python-automation <[email protected]>
Date:   Tue Feb 2 19:11:35 2021 +0000

    Merge branch 'release-1.17.0'
    
    * release-1.17.0:
      Bumping version to 1.17.0
      Add changelog entries from botocore
      Add S3 VPCE examples
      Add changes for Python 3.4/3.5 removal

Reviewed-by: Alina Buzachis <None>
`describe_configuration_aggregators` method returns output similar
to the following:

```
{
    "ConfigurationAggregators": [
        {
            "ConfigurationAggregatorName": "test-name",
            "ConfigurationAggregatorArn": "arn:aws:config:us-east-1:123412341234:config-aggregator/config-aggregator-xbxbvyq5",
            "OrganizationAggregationSource": {
                "RoleArn": "arn:aws:iam::123412341234:role/my-role",
                "AllAwsRegions": true
            },
            "CreationTime": 1619030767.047,
            "LastUpdatedTime": 1626463216.998
        }
    ]
}
```

As a result, lines 134-136 fail:

```
    del current_params['ConfigurationAggregatorArn']
    del current_params['CreationTime']
    del current_params['LastUpdatedTime']
```
as they try to delete attributes from the `current_params` as opposed
to `current_params['ConfigurationAggregators'][0]`.

The error message is:
```
KeyError: 'ConfigurationAggregators'
```

Additionally, if no `account_sources` attribute is specified, the module
fails idempotency check, because in that case `AccountAggregationSources`
attribute is present in `params`, but not in `current_params`.
Copy link
Contributor

@tremble tremble left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basic tests seem to show it's working

@tremble
Copy link
Contributor

tremble commented Jul 2, 2022

@ichekaldin Sorry it took so long to get back to this review.

@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded.

✔️ ansible-galaxy-importer SUCCESS in 4m 05s (non-voting)
✔️ build-ansible-collection SUCCESS in 4m 46s
✔️ ansible-test-sanity-docker-devel SUCCESS in 10m 36s (non-voting)
✔️ ansible-test-sanity-docker-milestone SUCCESS in 11m 36s
✔️ ansible-test-sanity-docker-stable-2.12 SUCCESS in 9m 26s
✔️ ansible-test-sanity-docker-stable-2.13 SUCCESS in 9m 03s
✔️ ansible-test-units-community-aws-python38 SUCCESS in 7m 00s
✔️ ansible-test-units-community-aws-python39 SUCCESS in 6m 45s
✔️ ansible-test-splitter SUCCESS in 2m 40s
✔️ integration-community.aws-1 SUCCESS in 6m 14s
⚠️ integration-community.aws-2 SKIPPED
⚠️ integration-community.aws-3 SKIPPED
⚠️ integration-community.aws-4 SKIPPED
⚠️ integration-community.aws-5 SKIPPED
⚠️ integration-community.aws-6 SKIPPED
⚠️ integration-community.aws-7 SKIPPED
⚠️ integration-community.aws-8 SKIPPED
⚠️ integration-community.aws-9 SKIPPED
⚠️ integration-community.aws-10 SKIPPED
⚠️ integration-community.aws-11 SKIPPED
⚠️ integration-community.aws-12 SKIPPED
⚠️ integration-community.aws-13 SKIPPED

@tremble tremble added mergeit Merge the PR (SoftwareFactory) backport-4 PR should be backported to the stable-4 branch backport-3 PR should be backported to the stable-3 branch labels Jul 2, 2022
@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded (gate pipeline).

✔️ ansible-galaxy-importer SUCCESS in 3m 51s (non-voting)
✔️ build-ansible-collection SUCCESS in 6m 00s
✔️ ansible-test-sanity-docker-devel SUCCESS in 9m 34s (non-voting)
✔️ ansible-test-sanity-docker-milestone SUCCESS in 12m 34s
✔️ ansible-test-sanity-docker-stable-2.12 SUCCESS in 11m 32s
✔️ ansible-test-sanity-docker-stable-2.13 SUCCESS in 8m 50s
✔️ ansible-test-units-community-aws-python38 SUCCESS in 5m 40s
✔️ ansible-test-units-community-aws-python39 SUCCESS in 7m 32s
✔️ ansible-test-splitter SUCCESS in 3m 12s
✔️ integration-community.aws-1 SUCCESS in 5m 08s
⚠️ integration-community.aws-2 SKIPPED
⚠️ integration-community.aws-3 SKIPPED
⚠️ integration-community.aws-4 SKIPPED
⚠️ integration-community.aws-5 SKIPPED
⚠️ integration-community.aws-6 SKIPPED
⚠️ integration-community.aws-7 SKIPPED
⚠️ integration-community.aws-8 SKIPPED
⚠️ integration-community.aws-9 SKIPPED
⚠️ integration-community.aws-10 SKIPPED
⚠️ integration-community.aws-11 SKIPPED
⚠️ integration-community.aws-12 SKIPPED
⚠️ integration-community.aws-13 SKIPPED

@softwarefactory-project-zuul softwarefactory-project-zuul bot merged commit 77d5813 into ansible-collections:main Jul 2, 2022
@patchback
Copy link

patchback bot commented Jul 2, 2022

Backport to stable-3: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-3/77d5813ace46ccfe54ea7cebd0d4ab7d2b487538/pr-645

Backported as #1296

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Jul 2, 2022
Fix idempotency and logic to update existing aggregator

SUMMARY

describe_configuration_aggregators method returns output similar
to the following:
{
    "ConfigurationAggregators": [
        {
            "ConfigurationAggregatorName": "test-name",
            "ConfigurationAggregatorArn": "arn:aws:config:us-east-1:123412341234:config-aggregator/config-aggregator-xbxbvyq5",
            "OrganizationAggregationSource": {
                "RoleArn": "arn:aws:iam::123412341234:role/my-role",
                "AllAwsRegions": true
            },
            "CreationTime": 1619030767.047,
            "LastUpdatedTime": 1626463216.998
        }
    ]
}

As a result, lines 134-136 fail:
    del current_params['ConfigurationAggregatorArn']
    del current_params['CreationTime']
    del current_params['LastUpdatedTime']

as they try to delete attributes from the current_params as opposed
to current_params['ConfigurationAggregators'][0].
The error message is:
KeyError: 'ConfigurationAggregators'

Additionally, if no account_sources attribute is specified, the module
fails idempotency check, because in that case AccountAggregationSources
attribute is present in params, but not in current_params.

ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME

aws_config_aggregator
ADDITIONAL INFORMATION

Reviewed-by: Mark Chappell <None>
(cherry picked from commit 77d5813)
@patchback
Copy link

patchback bot commented Jul 2, 2022

Backport to stable-4: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-4/77d5813ace46ccfe54ea7cebd0d4ab7d2b487538/pr-645

Backported as #1297

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Jul 2, 2022
Fix idempotency and logic to update existing aggregator

SUMMARY

describe_configuration_aggregators method returns output similar
to the following:
{
    "ConfigurationAggregators": [
        {
            "ConfigurationAggregatorName": "test-name",
            "ConfigurationAggregatorArn": "arn:aws:config:us-east-1:123412341234:config-aggregator/config-aggregator-xbxbvyq5",
            "OrganizationAggregationSource": {
                "RoleArn": "arn:aws:iam::123412341234:role/my-role",
                "AllAwsRegions": true
            },
            "CreationTime": 1619030767.047,
            "LastUpdatedTime": 1626463216.998
        }
    ]
}

As a result, lines 134-136 fail:
    del current_params['ConfigurationAggregatorArn']
    del current_params['CreationTime']
    del current_params['LastUpdatedTime']

as they try to delete attributes from the current_params as opposed
to current_params['ConfigurationAggregators'][0].
The error message is:
KeyError: 'ConfigurationAggregators'

Additionally, if no account_sources attribute is specified, the module
fails idempotency check, because in that case AccountAggregationSources
attribute is present in params, but not in current_params.

ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME

aws_config_aggregator
ADDITIONAL INFORMATION

Reviewed-by: Mark Chappell <None>
(cherry picked from commit 77d5813)
softwarefactory-project-zuul bot pushed a commit that referenced this pull request Jul 2, 2022
[PR #645/77d5813a backport][stable-3] Fix idempotency and logic to update existing aggregator

This is a backport of PR #645 as merged into main (77d5813).
SUMMARY

describe_configuration_aggregators method returns output similar
to the following:
{
    "ConfigurationAggregators": [
        {
            "ConfigurationAggregatorName": "test-name",
            "ConfigurationAggregatorArn": "arn:aws:config:us-east-1:123412341234:config-aggregator/config-aggregator-xbxbvyq5",
            "OrganizationAggregationSource": {
                "RoleArn": "arn:aws:iam::123412341234:role/my-role",
                "AllAwsRegions": true
            },
            "CreationTime": 1619030767.047,
            "LastUpdatedTime": 1626463216.998
        }
    ]
}

As a result, lines 134-136 fail:
    del current_params['ConfigurationAggregatorArn']
    del current_params['CreationTime']
    del current_params['LastUpdatedTime']

as they try to delete attributes from the current_params as opposed
to current_params['ConfigurationAggregators'][0].
The error message is:
KeyError: 'ConfigurationAggregators'

Additionally, if no account_sources attribute is specified, the module
fails idempotency check, because in that case AccountAggregationSources
attribute is present in params, but not in current_params.

ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

aws_config_aggregator
ADDITIONAL INFORMATION

Reviewed-by: Mark Chappell <None>
softwarefactory-project-zuul bot pushed a commit that referenced this pull request Jul 2, 2022
[PR #645/77d5813a backport][stable-4] Fix idempotency and logic to update existing aggregator

This is a backport of PR #645 as merged into main (77d5813).
SUMMARY

describe_configuration_aggregators method returns output similar
to the following:
{
    "ConfigurationAggregators": [
        {
            "ConfigurationAggregatorName": "test-name",
            "ConfigurationAggregatorArn": "arn:aws:config:us-east-1:123412341234:config-aggregator/config-aggregator-xbxbvyq5",
            "OrganizationAggregationSource": {
                "RoleArn": "arn:aws:iam::123412341234:role/my-role",
                "AllAwsRegions": true
            },
            "CreationTime": 1619030767.047,
            "LastUpdatedTime": 1626463216.998
        }
    ]
}

As a result, lines 134-136 fail:
    del current_params['ConfigurationAggregatorArn']
    del current_params['CreationTime']
    del current_params['LastUpdatedTime']

as they try to delete attributes from the current_params as opposed
to current_params['ConfigurationAggregators'][0].
The error message is:
KeyError: 'ConfigurationAggregators'

Additionally, if no account_sources attribute is specified, the module
fails idempotency check, because in that case AccountAggregationSources
attribute is present in params, but not in current_params.

ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

aws_config_aggregator
ADDITIONAL INFORMATION

Reviewed-by: Mark Chappell <None>
@ichekaldin ichekaldin deleted the aws_config_aggregator_idempotency branch July 2, 2022 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-3 PR should be backported to the stable-3 branch backport-4 PR should be backported to the stable-4 branch bug This issue/PR relates to a bug community_review integration tests/integration mergeit Merge the PR (SoftwareFactory) module module plugins plugin (any type) tests tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants