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

Correctly handle a situation when a repository has no description #195

Merged
merged 3 commits into from
Aug 19, 2020
Merged

Conversation

ichekaldin
Copy link
Contributor

SUMMARY

If a repository was created without a description, API call response
will not include 'repositoryDescription' attribute:

$ aws codecommit get-repository --repository-name test
{
    "repositoryMetadata": {
        "accountId": "123412341234",
        "repositoryId": "abcd1234-abcd-abcd-1234-abcd1234abc",
        "repositoryName": "test",
        "defaultBranch": "master",
        "lastModifiedDate": 1597770987.868,
        "creationDate": 1579544888.152,
        "cloneUrlHttp": "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/test",
        "cloneUrlSsh": "ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/test",
        "Arn": "arn:aws:codecommit:us-east-1:123412341234:test"
    }
}

The following module execution:

- name: Create CodeCommit repository
  community.aws.aws_codecommit:
    name: test
    state: present

will fail with the following stacktrace:

Traceback (most recent call last):
  File \"/root/.ansible/tmp/ansible-tmp-1597769457.193254-7427-16306174619296/AnsiballZ_aws_codecommit.py\", line 102, in <module>
    _ansiballz_main()
  File \"/root/.ansible/tmp/ansible-tmp-1597769457.193254-7427-16306174619296/AnsiballZ_aws_codecommit.py\", line 94, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File \"/root/.ansible/tmp/ansible-tmp-1597769457.193254-7427-16306174619296/AnsiballZ_aws_codecommit.py\", line 40, in invoke_module
    runpy.run_module(mod_name='ansible_collections.community.aws.plugins.modules.aws_codecommit', init_globals=None, run_name='__main__', alter_sys=True)
  File \"/root/.pyenv/versions/3.8.1/lib/python3.8/runpy.py\", line 206, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File \"/root/.pyenv/versions/3.8.1/lib/python3.8/runpy.py\", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File \"/root/.pyenv/versions/3.8.1/lib/python3.8/runpy.py\", line 86, in _run_code
    exec(code, run_globals)
  File \"/tmp/ansible_community.aws.aws_codecommit_payload_0zfnkbv7/ansible_community.aws.aws_codecommit_payload.zip/ansible_collections/community/aws/plugins/modules/aws_codecommit.py\", line 245, in <module>
  File \"/tmp/ansible_community.aws.aws_codecommit_payload_0zfnkbv7/ansible_community.aws.aws_codecommit_payload.zip/ansible_collections/community/aws/plugins/modules/aws_codecommit.py\", line 240, in main
  File \"/tmp/ansible_community.aws.aws_codecommit_payload_0zfnkbv7/ansible_community.aws.aws_codecommit_payload.zip/ansible_collections/community/aws/plugins/modules/aws_codecommit.py\", line 165, in process
KeyError: 'repositoryDescription'
ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

aws_codecommit.py

ADDITIONAL INFORMATION

If a repository was created without a description, API call response
will not include 'repositoryDescription' attribute:

```
$ aws codecommit get-repository --repository-name test
{
    "repositoryMetadata": {
        "accountId": "123412341234",
        "repositoryId": "abcd1234-abcd-abcd-1234-abcd1234abc",
        "repositoryName": "test",
        "defaultBranch": "master",
        "lastModifiedDate": 1597770987.868,
        "creationDate": 1579544888.152,
        "cloneUrlHttp": "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/test",
        "cloneUrlSsh": "ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/test",
        "Arn": "arn:aws:codecommit:us-east-1:123412341234:test"
    }
}
```

As a result, module execution fails with the following stacktrace:

```
Traceback (most recent call last):
  File \"/root/.ansible/tmp/ansible-tmp-1597769457.193254-7427-16306174619296/AnsiballZ_aws_codecommit.py\", line 102, in <module>
    _ansiballz_main()
  File \"/root/.ansible/tmp/ansible-tmp-1597769457.193254-7427-16306174619296/AnsiballZ_aws_codecommit.py\", line 94, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File \"/root/.ansible/tmp/ansible-tmp-1597769457.193254-7427-16306174619296/AnsiballZ_aws_codecommit.py\", line 40, in invoke_module
    runpy.run_module(mod_name='ansible_collections.community.aws.plugins.modules.aws_codecommit', init_globals=None, run_name='__main__', alter_sys=True)
  File \"/root/.pyenv/versions/3.8.1/lib/python3.8/runpy.py\", line 206, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File \"/root/.pyenv/versions/3.8.1/lib/python3.8/runpy.py\", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File \"/root/.pyenv/versions/3.8.1/lib/python3.8/runpy.py\", line 86, in _run_code
    exec(code, run_globals)
  File \"/tmp/ansible_community.aws.aws_codecommit_payload_0zfnkbv7/ansible_community.aws.aws_codecommit_payload.zip/ansible_collections/community/aws/plugins/modules/aws_codecommit.py\", line 245, in <module>
  File \"/tmp/ansible_community.aws.aws_codecommit_payload_0zfnkbv7/ansible_community.aws.aws_codecommit_payload.zip/ansible_collections/community/aws/plugins/modules/aws_codecommit.py\", line 240, in main
  File \"/tmp/ansible_community.aws.aws_codecommit_payload_0zfnkbv7/ansible_community.aws.aws_codecommit_payload.zip/ansible_collections/community/aws/plugins/modules/aws_codecommit.py\", line 165, in process
KeyError: 'repositoryDescription'
```
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.

Change looks sound 2 minor things:

  1. Please add a changelog (bugfix) fragment: https://docs.ansible.com/ansible/latest/community/development_process.html#changelogs-how-to
  2. To avoid the possibility of a regression, please add to the integration tests: tests/integration/targets/aws_codecommit/tasks/main.yml

Additional tests do the following:

- Create a new repository with no description
- Update a repository with no description
- Delete a repository
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.

LGTM

@tremble
Copy link
Contributor

tremble commented Aug 19, 2020

Thank you for taking the time to submit this patch, including adding a changelog fragment and integration tests. We're in the process of enabling the bot, so I'm going to wait and see if the bot automatically merges this. If not I'll merge tomorrow.

@tremble tremble merged commit afc1296 into ansible-collections:main Aug 19, 2020
@tremble
Copy link
Contributor

tremble commented Aug 19, 2020

Spoke to @jillr - automerge isn't enabled yet, so manually merged.

alinabuzachis pushed a commit to alinabuzachis/community.aws that referenced this pull request Jul 19, 2021
…sible-collections#195)

* Correctly handle a situation when a repository has no description

If a repository was created without a description, API call response
will not include 'repositoryDescription' attribute:

```
$ aws codecommit get-repository --repository-name test
{
    "repositoryMetadata": {
        "accountId": "123412341234",
        "repositoryId": "abcd1234-abcd-abcd-1234-abcd1234abc",
        "repositoryName": "test",
        "defaultBranch": "master",
        "lastModifiedDate": 1597770987.868,
        "creationDate": 1579544888.152,
        "cloneUrlHttp": "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/test",
        "cloneUrlSsh": "ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/test",
        "Arn": "arn:aws:codecommit:us-east-1:123412341234:test"
    }
}
```

As a result, module execution fails with the following stacktrace:

```
Traceback (most recent call last):
  File \"/root/.ansible/tmp/ansible-tmp-1597769457.193254-7427-16306174619296/AnsiballZ_aws_codecommit.py\", line 102, in <module>
    _ansiballz_main()
  File \"/root/.ansible/tmp/ansible-tmp-1597769457.193254-7427-16306174619296/AnsiballZ_aws_codecommit.py\", line 94, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File \"/root/.ansible/tmp/ansible-tmp-1597769457.193254-7427-16306174619296/AnsiballZ_aws_codecommit.py\", line 40, in invoke_module
    runpy.run_module(mod_name='ansible_collections.community.aws.plugins.modules.aws_codecommit', init_globals=None, run_name='__main__', alter_sys=True)
  File \"/root/.pyenv/versions/3.8.1/lib/python3.8/runpy.py\", line 206, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File \"/root/.pyenv/versions/3.8.1/lib/python3.8/runpy.py\", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File \"/root/.pyenv/versions/3.8.1/lib/python3.8/runpy.py\", line 86, in _run_code
    exec(code, run_globals)
  File \"/tmp/ansible_community.aws.aws_codecommit_payload_0zfnkbv7/ansible_community.aws.aws_codecommit_payload.zip/ansible_collections/community/aws/plugins/modules/aws_codecommit.py\", line 245, in <module>
  File \"/tmp/ansible_community.aws.aws_codecommit_payload_0zfnkbv7/ansible_community.aws.aws_codecommit_payload.zip/ansible_collections/community/aws/plugins/modules/aws_codecommit.py\", line 240, in main
  File \"/tmp/ansible_community.aws.aws_codecommit_payload_0zfnkbv7/ansible_community.aws.aws_codecommit_payload.zip/ansible_collections/community/aws/plugins/modules/aws_codecommit.py\", line 165, in process
KeyError: 'repositoryDescription'
```

* Add integration tests

Additional tests do the following:

- Create a new repository with no description
- Update a repository with no description
- Delete a repository

* Add change log fragment

Co-authored-by: Ivan Chekaldin <ivan.chekaldin@blackboard.com>
alinabuzachis pushed a commit to alinabuzachis/community.aws that referenced this pull request Jul 19, 2021
…sible-collections#195)

* Correctly handle a situation when a repository has no description

If a repository was created without a description, API call response
will not include 'repositoryDescription' attribute:

```
$ aws codecommit get-repository --repository-name test
{
    "repositoryMetadata": {
        "accountId": "123412341234",
        "repositoryId": "abcd1234-abcd-abcd-1234-abcd1234abc",
        "repositoryName": "test",
        "defaultBranch": "master",
        "lastModifiedDate": 1597770987.868,
        "creationDate": 1579544888.152,
        "cloneUrlHttp": "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/test",
        "cloneUrlSsh": "ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/test",
        "Arn": "arn:aws:codecommit:us-east-1:123412341234:test"
    }
}
```

As a result, module execution fails with the following stacktrace:

```
Traceback (most recent call last):
  File \"/root/.ansible/tmp/ansible-tmp-1597769457.193254-7427-16306174619296/AnsiballZ_aws_codecommit.py\", line 102, in <module>
    _ansiballz_main()
  File \"/root/.ansible/tmp/ansible-tmp-1597769457.193254-7427-16306174619296/AnsiballZ_aws_codecommit.py\", line 94, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File \"/root/.ansible/tmp/ansible-tmp-1597769457.193254-7427-16306174619296/AnsiballZ_aws_codecommit.py\", line 40, in invoke_module
    runpy.run_module(mod_name='ansible_collections.community.aws.plugins.modules.aws_codecommit', init_globals=None, run_name='__main__', alter_sys=True)
  File \"/root/.pyenv/versions/3.8.1/lib/python3.8/runpy.py\", line 206, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File \"/root/.pyenv/versions/3.8.1/lib/python3.8/runpy.py\", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File \"/root/.pyenv/versions/3.8.1/lib/python3.8/runpy.py\", line 86, in _run_code
    exec(code, run_globals)
  File \"/tmp/ansible_community.aws.aws_codecommit_payload_0zfnkbv7/ansible_community.aws.aws_codecommit_payload.zip/ansible_collections/community/aws/plugins/modules/aws_codecommit.py\", line 245, in <module>
  File \"/tmp/ansible_community.aws.aws_codecommit_payload_0zfnkbv7/ansible_community.aws.aws_codecommit_payload.zip/ansible_collections/community/aws/plugins/modules/aws_codecommit.py\", line 240, in main
  File \"/tmp/ansible_community.aws.aws_codecommit_payload_0zfnkbv7/ansible_community.aws.aws_codecommit_payload.zip/ansible_collections/community/aws/plugins/modules/aws_codecommit.py\", line 165, in process
KeyError: 'repositoryDescription'
```

* Add integration tests

Additional tests do the following:

- Create a new repository with no description
- Update a repository with no description
- Delete a repository

* Add change log fragment

Co-authored-by: Ivan Chekaldin <ivan.chekaldin@blackboard.com>
alinabuzachis pushed a commit to alinabuzachis/community.aws that referenced this pull request May 25, 2022
* ec2_ami - Flag device_name as required, it's needed the apis

* Add aws_retry decorator to most ec2_ami calls

* Add Retries to ec2_ami_info

* ec2_ami - Use waiter with retry

* changelog

* ec2_ami - mark integration tests stable...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants