This repository was archived by the owner on Feb 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Add atomic CLI tests #273
Merged
Merged
Add atomic CLI tests #273
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7e0055a
Add atomic CLI tests
mike-nguyen f17c869
fixup! Add atomic CLI tests
mike-nguyen 51de90f
fixup! Add atomic CLI tests
mike-nguyen 37a6a33
fixup! Add atomic CLI tests
mike-nguyen 5c685b9
fixup! Add atomic CLI tests
mike-nguyen d638c45
fixup! Add atomic CLI tests
mike-nguyen 184d3cf
fixup! Add atomic CLI tests
mike-nguyen 9d99904
fixup! Add atomic CLI tests
mike-nguyen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
allow_duplicates: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
# vim: set ft=ansible: | ||
# | ||
- name: Fail if acd_container is undefined | ||
fail: | ||
msg: "acd_container is undefined" | ||
when: acd_container is undefined | ||
|
||
- name: Remove container {{ acd_container }} | ||
command: atomic --assumeyes containers delete {{ acd_container }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
allow_duplicates: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
# vim: set ft=ansible: | ||
# | ||
# list containers and save to json | ||
# | ||
- name: List images with --json | ||
command: atomic containers list --json | ||
register: acl | ||
|
||
- name: Save JSON to variable | ||
set_fact: | ||
acl_json: "{{ acl.stdout | to_json | from_json }}" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
# vim: set ft=ansible: | ||
# | ||
dependencies: | ||
- role: atomic_containers_list | ||
|
||
allow_duplicates: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
--- | ||
# vim: set ft=ansible: | ||
# | ||
# This role verifies the values of an image from atomic containers list by | ||
# comparing the expected_values dictionary. The unique identifier for the | ||
# containers is image name | ||
# | ||
# Example calling this role: | ||
# - role: atomic_containers_list_verify | ||
# expected_values: | ||
# repo: docker.io/httpd | ||
# id: 21340928304932 | ||
# | ||
- name: Fail if expected_values or expected_values['image_name'] is undefined | ||
fail: | ||
msg: "expected_values or expected_values['image_name'] is undefined" | ||
when: expected_values is undefined or | ||
expected_values['image_name'] is undefined | ||
|
||
- name: Set role facts | ||
set_fact: | ||
aclv_expected: "{{ expected_values }}" | ||
aclv_em: "{{ expect_missing | default(false) | bool }}" | ||
aclv_acl_jq_match: "" | ||
|
||
# acl_json comes from the atomic_containers_list role which is a dependency | ||
# of this role in the meta directory | ||
- name: Get matching list entry | ||
set_fact: | ||
aclv_acl_jq_match: "{{ item }}" | ||
with_items: "{{ acl_json | json_query(query) }}" | ||
vars: | ||
query: "[?image_name=='{{ aclv_expected['image_name'] }}']" | ||
|
||
- name: Fail if no matching image entry | ||
fail: | ||
msg: "No matching container or container is in list when it is not supposed to be" | ||
when: (aclv_acl_jq_match == "" and not aclv_em) or | ||
(aclv_acl_jq_match != "" and aclv_em) | ||
|
||
# There is no way to skip the comparison in the next step if the container | ||
# is expected to not be in the containers list except setting the expected | ||
# dictionary to empty | ||
|
||
- name: Set expected for expected missing case | ||
set_fact: | ||
aclv_expected: {} | ||
when: aclv_em | ||
|
||
- name: Fail if values are incorrect | ||
fail: | ||
msg: "{{ item.key }} is incorrect or does not exist." | ||
when: aclv_acl_jq_match[item.key] is undefined or | ||
item.value not in aclv_acl_jq_match[item.key] | ||
with_dict: "{{ aclv_expected }}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
allow_duplicates: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
--- | ||
# vim: set ft=ansible: | ||
# | ||
# This role deletes specified container image through the atomic images | ||
# delete command | ||
# | ||
- name: Fail if image is undefined | ||
- name: Fail if aid_image is undefined | ||
fail: | ||
msg: "Image is undefined" | ||
when: image is undefined | ||
msg: "aid_image is undefined" | ||
when: aid_image is undefined | ||
|
||
- name: Set options | ||
set_fact: | ||
del_options: "{{ aid_options | default() }}" | ||
|
||
- name: Remove specified image | ||
command: atomic --debug --assumeyes images delete {{ image }} | ||
- name: Remove {{ aid_image }} | ||
command: atomic --assumeyes images delete {{ aid_image }} {{ del_options }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
allow_duplicates: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
# vim: set ft=ansible: | ||
# | ||
# list images and save to json | ||
# | ||
- name: Set options | ||
set_fact: | ||
images_list_options: "{{ ail_options | default() }}" | ||
|
||
- name: List images with --json | ||
command: atomic images list {{ images_list_options }} --json | ||
register: ail | ||
|
||
- name: Save JSON to variable | ||
set_fact: | ||
ail_json: "{{ ail.stdout | to_json | from_json }}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question about both filters here |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
# vim: set ft=ansible: | ||
# | ||
dependencies: | ||
- role: atomic_images_list | ||
|
||
allow_duplicates: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
--- | ||
# vim: set ft=ansible: | ||
# | ||
# This role verifies the values of an image from atomic images list by | ||
# comparing the expected_values dictionary. The entry in the list of | ||
# images is determined by the repo property. This role will assume the | ||
# latest tag unless a tag is passed to this role. | ||
# | ||
# Example calling this role: | ||
# - role: atomic_images_list_verify | ||
# expected: | ||
# repo: docker.io/httpd | ||
# | ||
- name: Fail if expected_values or expected_values['repo'] is undefined | ||
fail: | ||
msg: "expected_values or expected_values['repo'] is undefined" | ||
when: expected_values is undefined or | ||
expected_values['repo'] is undefined | ||
|
||
- name: Set facts for role | ||
set_fact: | ||
ailv_expected: "{{ expected_values }}" | ||
ailv_em: "{{ expect_missing | default(false) | bool }}" | ||
ailv_ail_jq_match: "" | ||
ailv_tag: "{{ expected_values['tag'] | default('latest') }}" | ||
|
||
- name: Setup queries | ||
set_fact: | ||
ailv_repo_query: "[?repo=='{{ ailv_expected['repo'] }}']" | ||
ailv_tag_query: "[?tag=='{{ ailv_tag }}']|[0]" | ||
|
||
- name: Get matching list entry | ||
set_fact: | ||
ailv_ail_jq_match: "{{ ail_json | json_query(ailv_repo_query) }}" | ||
|
||
- name: Check for tag in list of images that match the repo | ||
set_fact: | ||
ailv_match: "{{ ailv_ail_jq_match | json_query(ailv_tag_query) }}" | ||
|
||
- name: Fail if no matching image entry | ||
fail: | ||
msg: "No matching image entry or image is in list when it is not supposed to be" | ||
when: (ailv_match == True and ailv_em == True) or | ||
(ailv_match == False and ailv_em == False) | ||
|
||
# There is no way to skip the comparison in the next step if the container | ||
# is expected to not be in the containers list except setting the expected | ||
# dictionary to empty | ||
- name: Set expected for expected missing case | ||
set_fact: | ||
ailv_expected: {} | ||
when: ailv_em | ||
|
||
- name: Fail if values are incorrect | ||
fail: | ||
msg: "Got {{ item.key }}:{{ ailv_match[item.key]}}. Expected {{ item.key }}:{{ item.value }}" | ||
when: ailv_match[item.key] is undefined or | ||
item.value != ailv_match[item.key] | ||
with_dict: "{{ ailv_expected }}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
allow_duplicates: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
# vim: set ft=ansible: | ||
# | ||
# installs image with atomic cli | ||
# | ||
- name: Fail if ai_image is undefined | ||
fail: | ||
msg: "ai_image is not defined" | ||
when: ai_image is undefined | ||
|
||
- name: Set options | ||
set_fact: | ||
ai_options: "{{ ai_options | default() }}" | ||
|
||
- name: Install image | ||
command: atomic install {{ ai_image }} {{ ai_options }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
allow_duplicates: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,16 @@ | ||
--- | ||
# vim: set ft=ansible: | ||
# | ||
# This role pulls container image through the atomic pull | ||
# command | ||
# pulls image with atomic cli | ||
# | ||
- name: Fail if image is undefined | ||
- name: Fail if apl_image is undefined | ||
fail: | ||
msg: "Image is undefined" | ||
when: image is undefined | ||
msg: "apl_image is not defined" | ||
when: apl_image is undefined | ||
|
||
- name: Pull container image | ||
command: atomic --debug pull {{ image }} | ||
- name: Set options | ||
set_fact: | ||
pull_options: "{{ apl_options | default() }}" | ||
|
||
- name: Verify image exists | ||
command: atomic images list | ||
register: ail | ||
failed_when: image not in ail.stdout | ||
- name: Pull image | ||
command: atomic pull {{ apl_image }} {{ pull_options }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
allow_duplicates: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
# vim: set ft=ansible: | ||
# | ||
# Push image with atomic cli | ||
# | ||
- name: Fail if apsh_image is undefined | ||
fail: | ||
msg: "apsh_image is not defined" | ||
when: apsh_image is undefined | ||
|
||
- name: Set options | ||
set_fact: | ||
push_options: "{{ apsh_options | default() }}" | ||
|
||
- name: Push image | ||
command: atomic push {{ apsh_image }} {{ push_options }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
allow_duplicates: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
# vim: set ft=ansible: | ||
# | ||
# runs container with atomic cli | ||
# | ||
- name: Fail if ar_image is undefined | ||
fail: | ||
msg: "ar_image is not defined" | ||
when: ar_image is undefined | ||
|
||
- name: Run {{ ar_image }} | ||
command: atomic run {{ ar_image }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
allow_duplicates: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
# vim: set ft=ansible: | ||
# | ||
# stops running container with atomic cli | ||
# | ||
- name: Fail if as_container is undefined | ||
fail: | ||
msg: "as_container is not defined" | ||
when: as_container is undefined | ||
|
||
- name: Stop {{ as_container }} | ||
command: atomic stop {{ as_container }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
allow_duplicates: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
# vim: set ft=ansible: | ||
# | ||
# uninstalls image with atomic cli | ||
# | ||
- name: Fail if au_image is undefined | ||
fail: | ||
msg: "au_image is not defined" | ||
when: au_image is undefined | ||
|
||
- name: Set options | ||
set_fact: | ||
au_options: "{{ au_options | default() }}" | ||
|
||
- name: Uninstall image | ||
command: atomic uninstall {{ au_image }} {{ au_options }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
allow_duplicates: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
# | ||
# Commit a change to an image | ||
# | ||
|
||
- name: Fail if dc_commit or dc_image is not defined | ||
fail: | ||
msg: "dc_commit or dc_image is not defined" | ||
when: dc_commit is undefined or | ||
dc_image is undefined | ||
|
||
- name: Commit change | ||
command: docker commit {{ dc_commit }} {{ dc_image }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
allow_duplicates: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
# vim: set ft=ansible: | ||
# | ||
# list images with docker | ||
# | ||
- name: Set options | ||
set_fact: | ||
images_options: "{{ di_options | default() }}" | ||
|
||
- name: List images | ||
command: docker images {{ images_options }} | ||
register: di_images | ||
when: di_format is undefined | ||
|
||
# The docker format option uses go syntax that also uses double curly braces | ||
# that conflicts Ansibles variable substitution. A separate format option was | ||
# added to work around this. di_format should be in the form: | ||
# {% raw %}'{{.your_format}}'{% endraw %} | ||
- name: List images | ||
command: docker images {{ images_options }} --format={{ di_format }} | ||
register: di_images | ||
when: di_format is defined |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
allow_duplicates: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
# vim: set ft=ansible: | ||
# | ||
# pulls image with docker | ||
# | ||
- name: Fail if dp_image is undefined | ||
fail: | ||
msg: "dp_image is not defined" | ||
when: dp_image is undefined | ||
|
||
- name: Set options | ||
set_fact: | ||
pull_options: "{{ dp_options | default() }}" | ||
|
||
- name: Pull image | ||
command: docker pull {{ dp_image }} {{ pull_options }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
allow_duplicates: true |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is it necessary to use both filters? Seems like you should just be able to use
from_json
?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.
I don't need both. I'm not quite sure why I did that.