Skip to content

Commit

Permalink
ecs_ecr - Fix RepositoryNotFoundException when creating Repositorie…
Browse files Browse the repository at this point in the history
…s in check mode (ansible-collections#1550)

ecs_ecr - Fix `RepositoryNotFoundException` when creating Repositories in check mode

SUMMARY
When trying to create a repository in check mode the module throws a RepositoryNotFoundException trying to access policy objects on the repositories
also fixes and re-enables basic integration tests
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
ecs_ecr
ADDITIONAL INFORMATION

Reviewed-by: Markus Bergholz <[email protected]>
  • Loading branch information
tremble authored Oct 7, 2022
1 parent 87af3ad commit 187649d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 29 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/1550-ecs_ecr-RepositoryNotFound.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- ecs_ecr - fix a ``RepositoryNotFound`` exception when trying to create repositories in check mode (https://github.com/ansible-collections/community.aws/pull/1550).
4 changes: 2 additions & 2 deletions plugins/modules/ecs_ecr.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def get_repository_policy(self, registry_id, name):
repositoryName=name, **build_kwargs(registry_id))
text = res.get('policyText')
return text and json.loads(text)
except is_boto3_error_code('RepositoryPolicyNotFoundException'):
except is_boto3_error_code(['RepositoryNotFoundException', 'RepositoryPolicyNotFoundException']):
return None

def create_repository(self, registry_id, name, image_tag_mutability):
Expand Down Expand Up @@ -334,7 +334,7 @@ def get_lifecycle_policy(self, registry_id, name):
repositoryName=name, **build_kwargs(registry_id))
text = res.get('lifecyclePolicyText')
return text and json.loads(text)
except is_boto3_error_code('LifecyclePolicyNotFoundException'):
except is_boto3_error_code(['LifecyclePolicyNotFoundException', 'RepositoryNotFoundException']):
return None

def put_lifecycle_policy(self, registry_id, name, policy_text):
Expand Down
3 changes: 0 additions & 3 deletions tests/integration/targets/ecs_ecr/aliases
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
# reason: boto2
unstable

cloud/aws
30 changes: 6 additions & 24 deletions tests/integration/targets/ecs_ecr/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@
ecs_ecr:
name: '{{ ecr_name }}'
register: result

- name: it should return the repo but without a policy and not create or change
assert:
that:
- result.repository
- not result.policy
- '"policy" not in result'
- not result.created
- not result.changed

Expand Down Expand Up @@ -136,11 +136,11 @@
ecs_ecr:
name: '{{ ecr_name }}'
register: result

- name: it should return the policy but not create or change
assert:
that:
- result.policy
- '"policy" in result'
- not result.created
- not result.changed

Expand All @@ -151,30 +151,12 @@
register: result
check_mode: yes

- name: it should skip, change but not create, have deprecations
assert:
that:
- result is skipped
- result is changed
- not result.created
- result.deprecations


- name: When in check mode, and purging a policy that exists
ecs_ecr:
name: '{{ ecr_name }}'
purge_policy: yes
register: result
check_mode: yes

- name: it should skip, change but not create, no deprecations
- name: it should skip, change but not create
assert:
that:
- result is skipped
- result is changed
- not result.created
- result.deprecations is not defined


- name: When purging a policy that exists
ecs_ecr:
Expand Down Expand Up @@ -290,7 +272,7 @@
that:
- result is changed
- not result.created
- result.lifecycle_policy is defined
- '"lifecycle_policy" in result'
- result.lifecycle_policy.rules|length == 1


Expand Down

0 comments on commit 187649d

Please sign in to comment.