Skip to content
This repository was archived by the owner on Feb 7, 2023. It is now read-only.

Add atomic CLI tests #273

Merged
merged 8 commits into from
Dec 4, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions roles/atomic_containers_delete/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
allow_duplicates: true
10 changes: 10 additions & 0 deletions roles/atomic_containers_delete/tasks/main.yml
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 }}
2 changes: 2 additions & 0 deletions roles/atomic_containers_list/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
allow_duplicates: true
12 changes: 12 additions & 0 deletions roles/atomic_containers_list/tasks/main.yml
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 }}"
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

7 changes: 7 additions & 0 deletions roles/atomic_containers_list_verify/meta/main.yml
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
55 changes: 55 additions & 0 deletions roles/atomic_containers_list_verify/tasks/main.yml
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 }}"
2 changes: 2 additions & 0 deletions roles/atomic_images_delete/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
allow_duplicates: true
17 changes: 9 additions & 8 deletions roles/atomic_images_delete/tasks/main.yml
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 }}
2 changes: 2 additions & 0 deletions roles/atomic_images_list/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
allow_duplicates: true
16 changes: 16 additions & 0 deletions roles/atomic_images_list/tasks/main.yml
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 }}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same question about both filters here

7 changes: 7 additions & 0 deletions roles/atomic_images_list_verify/meta/main.yml
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
59 changes: 59 additions & 0 deletions roles/atomic_images_list_verify/tasks/main.yml
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 }}"
2 changes: 2 additions & 0 deletions roles/atomic_install/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
allow_duplicates: true
16 changes: 16 additions & 0 deletions roles/atomic_install/tasks/main.yml
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 }}
2 changes: 2 additions & 0 deletions roles/atomic_pull/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
allow_duplicates: true
20 changes: 9 additions & 11 deletions roles/atomic_pull/tasks/main.yml
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 }}
2 changes: 2 additions & 0 deletions roles/atomic_push/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
allow_duplicates: true
16 changes: 16 additions & 0 deletions roles/atomic_push/tasks/main.yml
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 }}
2 changes: 2 additions & 0 deletions roles/atomic_run/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
allow_duplicates: true
12 changes: 12 additions & 0 deletions roles/atomic_run/tasks/main.yml
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 }}
2 changes: 2 additions & 0 deletions roles/atomic_stop/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
allow_duplicates: true
12 changes: 12 additions & 0 deletions roles/atomic_stop/tasks/main.yml
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 }}
2 changes: 2 additions & 0 deletions roles/atomic_uninstall/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
allow_duplicates: true
16 changes: 16 additions & 0 deletions roles/atomic_uninstall/tasks/main.yml
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 }}
2 changes: 2 additions & 0 deletions roles/docker_commit/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
allow_duplicates: true
13 changes: 13 additions & 0 deletions roles/docker_commit/tasks/main.yml
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 }}
2 changes: 2 additions & 0 deletions roles/docker_images/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
allow_duplicates: true
22 changes: 22 additions & 0 deletions roles/docker_images/tasks/main.yml
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
2 changes: 2 additions & 0 deletions roles/docker_pull/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
allow_duplicates: true
16 changes: 16 additions & 0 deletions roles/docker_pull/tasks/main.yml
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 }}
2 changes: 2 additions & 0 deletions roles/docker_rmi/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
allow_duplicates: true
Loading