mirror of https://github.com/ansible/ansible.git
Add integration tests for docker_image options (#48574)
* Add integration tests for docker_image options
Tests for options in docker_image module
Signed-off-by: Akshay Gaikwad <akgaikwad001@gmail.com>
* Add force option tests
Signed-off-by: Akshay Gaikwad <akgaikwad001@gmail.com>
* Add repository option tests
Signed-off-by: Akshay Gaikwad <akgaikwad001@gmail.com>
* Modify test for option force
Signed-off-by: Akshay Gaikwad <akgaikwad001@gmail.com>
(cherry picked from commit 0493ef359a
)
pull/51556/head
parent
7b0c342dce
commit
03bc4be1c3
@ -0,0 +1,3 @@
|
||||
FROM busybox
|
||||
ENV foo /bar
|
||||
WORKDIR ${foo}
|
@ -0,0 +1,5 @@
|
||||
FROM alpine:3.7
|
||||
ENV INSTALL_PATH /newdata
|
||||
RUN mkdir -p $INSTALL_PATH
|
||||
|
||||
WORKDIR $INSTALL_PATH
|
@ -0,0 +1,240 @@
|
||||
---
|
||||
- name: Registering image name
|
||||
set_fact:
|
||||
iname: "{{ name_prefix ~ '-options' }}"
|
||||
iname_1: "{{ name_prefix ~ '-options-1' }}"
|
||||
|
||||
- name: Registering image name
|
||||
set_fact:
|
||||
inames: "{{ inames }} + [iname, iname_1]"
|
||||
|
||||
####################################################################
|
||||
## buildargs #######################################################
|
||||
####################################################################
|
||||
|
||||
- name: buildargs
|
||||
docker_image:
|
||||
path: "{{ role_path }}/files"
|
||||
name: "{{ iname }}"
|
||||
buildargs:
|
||||
TEST1: val1
|
||||
TEST2: val2
|
||||
TEST3: "True"
|
||||
register: buildargs_1
|
||||
|
||||
- name: buildargs (idempotency)
|
||||
docker_image:
|
||||
path: "{{ role_path }}/files"
|
||||
name: "{{ iname }}"
|
||||
buildargs:
|
||||
TEST1: val1
|
||||
TEST2: val2
|
||||
TEST3: "True"
|
||||
register: buildargs_2
|
||||
|
||||
- name: cleanup
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
state: absent
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- buildargs_1 is changed
|
||||
- buildargs_2 is not changed
|
||||
when: docker_py_version is version('1.6.0', '>=')
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- buildargs_1 is failed
|
||||
- buildargs_2 is failed
|
||||
when: docker_py_version is version('1.6.0', '<')
|
||||
|
||||
####################################################################
|
||||
## container_limits ################################################
|
||||
####################################################################
|
||||
|
||||
- name: container_limits (Failed due to min memory limit)
|
||||
docker_image:
|
||||
path: "{{ role_path }}/files"
|
||||
name: "{{ iname }}"
|
||||
container_limits:
|
||||
memory: 4000
|
||||
ignore_errors: yes
|
||||
register: container_limits_1
|
||||
|
||||
- name: container_limits
|
||||
docker_image:
|
||||
path: "{{ role_path }}/files"
|
||||
name: "{{ iname }}"
|
||||
container_limits:
|
||||
memory: 5000000
|
||||
memswap: 7000000
|
||||
register: container_limits_2
|
||||
|
||||
- name: cleanup
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
state: absent
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "('Minimum memory limit allowed is 4MB') in container_limits_1.msg"
|
||||
- container_limits_2 is changed
|
||||
|
||||
####################################################################
|
||||
## dockerfile ######################################################
|
||||
####################################################################
|
||||
|
||||
- name: dockerfile
|
||||
docker_image:
|
||||
path: "{{ role_path }}/files"
|
||||
name: "{{ iname }}"
|
||||
dockerfile: "MyDockerfile"
|
||||
register: dockerfile_1
|
||||
|
||||
- name: cleanup
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
state: absent
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- dockerfile_1 is changed
|
||||
- dockerfile_1['image']['Config']['WorkingDir'] == '/newdata'
|
||||
|
||||
####################################################################
|
||||
## repository ######################################################
|
||||
####################################################################
|
||||
|
||||
- name: Make sure image is not there
|
||||
docker_image:
|
||||
name: "{{ registry_address }}/test/{{ iname }}:latest"
|
||||
state: absent
|
||||
|
||||
- name: repository
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
path: "{{ role_path }}/files"
|
||||
repository: "{{ registry_address }}/test/{{ iname }}"
|
||||
register: repository_1
|
||||
|
||||
- name: repository (idempotent)
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
path: "{{ role_path }}/files"
|
||||
repository: "{{ registry_address }}/test/{{ iname }}"
|
||||
register: repository_2
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- repository_1 is changed
|
||||
- repository_2 is not changed
|
||||
|
||||
- name: Get facts of image
|
||||
docker_image_facts:
|
||||
name: "{{ registry_address }}/test/{{ iname }}:latest"
|
||||
register: facts_1
|
||||
|
||||
- name: cleanup
|
||||
docker_image:
|
||||
name: "{{ registry_address }}/test/{{ iname }}:latest"
|
||||
state: absent
|
||||
force: yes
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- facts_1.images | length == 1
|
||||
|
||||
####################################################################
|
||||
## force ###########################################################
|
||||
####################################################################
|
||||
|
||||
- name: Build an image
|
||||
docker_image:
|
||||
path: "{{ role_path }}/files"
|
||||
name: "{{ iname }}"
|
||||
|
||||
- name: force (changed)
|
||||
docker_image:
|
||||
path: "{{ role_path }}/files"
|
||||
name: "{{ iname }}"
|
||||
dockerfile: "MyDockerfile"
|
||||
force: yes
|
||||
register: force_1
|
||||
|
||||
- name: force (unchanged)
|
||||
docker_image:
|
||||
path: "{{ role_path }}/files"
|
||||
name: "{{ iname }}"
|
||||
dockerfile: "MyDockerfile"
|
||||
force: yes
|
||||
register: force_2
|
||||
|
||||
- name: cleanup
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
state: absent
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- force_1 is changed
|
||||
- force_2 is not changed
|
||||
|
||||
####################################################################
|
||||
## load path #######################################################
|
||||
####################################################################
|
||||
|
||||
- name: Archive image
|
||||
docker_image:
|
||||
name: "hello-world:latest"
|
||||
archive_path: image.tar
|
||||
register: archive_image
|
||||
|
||||
- name: remove image
|
||||
docker_image:
|
||||
name: "hello-world:latest"
|
||||
state: absent
|
||||
|
||||
- name: load image (changed)
|
||||
docker_image:
|
||||
name: "hello-world:latest"
|
||||
load_path: image.tar
|
||||
register: load_image
|
||||
|
||||
- name: load image (idempotency)
|
||||
docker_image:
|
||||
name: "hello-world:latest"
|
||||
load_path: image.tar
|
||||
register: load_image_1
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- load_image is changed
|
||||
- load_image_1 is not changed
|
||||
- archive_image['image']['Id'] == load_image['image']['Id']
|
||||
|
||||
####################################################################
|
||||
## path ############################################################
|
||||
####################################################################
|
||||
|
||||
- name: Build image
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
path: "{{ role_path }}/files"
|
||||
register: path_1
|
||||
|
||||
- name: Build image(idempotency)
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
path: "{{ role_path }}/files"
|
||||
register: path_2
|
||||
|
||||
- name: cleanup
|
||||
docker_image:
|
||||
name: "{{ iname }}"
|
||||
state: absent
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- path_1 is changed
|
||||
- path_2 is not changed
|
Loading…
Reference in New Issue