diff options
author | Dave Bendit <David@ibendit.com> | 2019-08-02 10:11:14 -0500 |
---|---|---|
committer | Felix Fontein <felix@fontein.de> | 2019-08-02 17:11:14 +0200 |
commit | fc558fb85f03d3864f159e3c156fe48ab3550026 (patch) | |
tree | 4662b5b4e8530ac8a335b71c3ebfe89e5c10d20e /test/integration/targets/docker_container | |
parent | a7573102bcbc7e88b8bf6de639be2696f1a5ad43 (diff) | |
download | ansible-fc558fb85f03d3864f159e3c156fe48ab3550026.tar.gz |
[docker_container] Adding support for `mounts` option (#49808)
* [WIP][docker_container] Adding support for `mounts` option
Fixes #42054
* Adjusting to current standards.
* Add changelog.
* Adjust types.
* Cleanup.
* Add idempotency checks for mounts.
* Improve diff for mounts.
* Linting.
* Python 2.6 compatibility.
* Fix error message formatting.
* Move mounts and volumes tests into own file.
* Add set of mount tests.
* Golang's omitempty for bool omits false values.
* Simplify sanity checks. Correct order of volume_options sanitization and usage.
* Fix key.
* Fix check.
* Add tests where both volumes and mounts show up.
* Add collision test.
Diffstat (limited to 'test/integration/targets/docker_container')
-rw-r--r-- | test/integration/targets/docker_container/tasks/tests/mounts-volumes.yml | 404 | ||||
-rw-r--r-- | test/integration/targets/docker_container/tasks/tests/options.yml | 191 |
2 files changed, 404 insertions, 191 deletions
diff --git a/test/integration/targets/docker_container/tasks/tests/mounts-volumes.yml b/test/integration/targets/docker_container/tasks/tests/mounts-volumes.yml new file mode 100644 index 0000000000..218caad65f --- /dev/null +++ b/test/integration/targets/docker_container/tasks/tests/mounts-volumes.yml @@ -0,0 +1,404 @@ +--- +- name: Registering container name + set_fact: + cname: "{{ cname_prefix ~ '-mounts' }}" + cname_h1: "{{ cname_prefix ~ '-mounts-h1' }}" + cname_h2: "{{ cname_prefix ~ '-mounts-h2' }}" +- name: Registering container name + set_fact: + cnames: "{{ cnames + [cname, cname_h1, cname_h2] }}" + +#################################################################### +## keep_volumes #################################################### +#################################################################### + +# TODO: - keep_volumes + +#################################################################### +## mounts ########################################################## +#################################################################### + +- name: mounts + docker_container: + image: alpine:3.8 + command: '/bin/sh -c "sleep 10m"' + name: "{{ cname }}" + state: started + mounts: + - source: /tmp + target: /tmp + type: bind + - source: / + target: /whatever + type: bind + read_only: no + register: mounts_1 + ignore_errors: yes + +- name: mounts (idempotency) + docker_container: + image: alpine:3.8 + command: '/bin/sh -c "sleep 10m"' + name: "{{ cname }}" + state: started + mounts: + - source: / + target: /whatever + type: bind + read_only: no + - source: /tmp + target: /tmp + type: bind + register: mounts_2 + ignore_errors: yes + +- name: mounts (less mounts) + docker_container: + image: alpine:3.8 + command: '/bin/sh -c "sleep 10m"' + name: "{{ cname }}" + state: started + mounts: + - source: /tmp + target: /tmp + type: bind + register: mounts_3 + ignore_errors: yes + +- name: mounts (more mounts) + docker_container: + image: alpine:3.8 + command: '/bin/sh -c "sleep 10m"' + name: "{{ cname }}" + state: started + mounts: + - source: /tmp + target: /tmp + type: bind + - source: /tmp + target: /somewhereelse + type: bind + read_only: yes + force_kill: yes + register: mounts_4 + ignore_errors: yes + +- name: mounts (different modes) + docker_container: + image: alpine:3.8 + command: '/bin/sh -c "sleep 10m"' + name: "{{ cname }}" + state: started + mounts: + - source: /tmp + target: /tmp + type: bind + - source: /tmp + target: /somewhereelse + type: bind + read_only: no + force_kill: yes + register: mounts_5 + ignore_errors: yes + +- name: cleanup + docker_container: + name: "{{ cname }}" + state: absent + force_kill: yes + diff: no + +- assert: + that: + - mounts_1 is changed + - mounts_2 is not changed + - mounts_3 is not changed + - mounts_4 is changed + - mounts_5 is changed + when: docker_py_version is version('2.6.0', '>=') +- assert: + that: + - mounts_1 is failed + - "('version is ' ~ docker_py_version ~ ' ') in mounts_1.msg" + - "'Minimum version required is 2.6.0 ' in mounts_1.msg" + when: docker_py_version is version('2.6.0', '<') + +#################################################################### +## mounts + volumes ################################################ +#################################################################### + +- name: mounts + volumes + docker_container: + image: alpine:3.8 + command: '/bin/sh -c "sleep 10m"' + name: "{{ cname }}" + state: started + mounts: + - source: / + target: /whatever + type: bind + read_only: yes + volumes: + - /tmp:/tmp + register: mounts_volumes_1 + ignore_errors: yes + +- name: mounts + volumes (idempotency) + docker_container: + image: alpine:3.8 + command: '/bin/sh -c "sleep 10m"' + name: "{{ cname }}" + state: started + mounts: + - source: / + target: /whatever + type: bind + read_only: yes + volumes: + - /tmp:/tmp + register: mounts_volumes_2 + ignore_errors: yes + +- name: mounts + volumes (switching) + docker_container: + image: alpine:3.8 + command: '/bin/sh -c "sleep 10m"' + name: "{{ cname }}" + state: started + mounts: + - source: /tmp + target: /tmp + type: bind + read_only: no + volumes: + - /:/whatever:ro + force_kill: yes + register: mounts_volumes_3 + ignore_errors: yes + +- name: mounts + volumes (collision, should fail) + docker_container: + image: alpine:3.8 + command: '/bin/sh -c "sleep 10m"' + name: "{{ cname }}" + state: started + mounts: + - source: /tmp + target: /tmp + type: bind + read_only: no + volumes: + - /tmp:/tmp + force_kill: yes + register: mounts_volumes_4 + ignore_errors: yes + +- name: cleanup + docker_container: + name: "{{ cname }}" + state: absent + force_kill: yes + diff: no + +- assert: + that: + - mounts_volumes_1 is changed + - mounts_volumes_2 is not changed + - mounts_volumes_3 is changed + - mounts_volumes_4 is failed + when: docker_py_version is version('2.6.0', '>=') +- assert: + that: + - mounts_volumes_1 is failed + - "('version is ' ~ docker_py_version ~ ' ') in mounts_1.msg" + - "'Minimum version required is 2.6.0 ' in mounts_1.msg" + when: docker_py_version is version('2.6.0', '<') + +#################################################################### +## volume_driver ################################################### +#################################################################### + +- name: volume_driver + docker_container: + image: alpine:3.8 + command: '/bin/sh -c "sleep 10m"' + name: "{{ cname }}" + volume_driver: local + state: started + register: volume_driver_1 + +- name: volume_driver (idempotency) + docker_container: + image: alpine:3.8 + command: '/bin/sh -c "sleep 10m"' + name: "{{ cname }}" + volume_driver: local + state: started + register: volume_driver_2 + +- name: volume_driver (change) + docker_container: + image: alpine:3.8 + command: '/bin/sh -c "sleep 10m"' + name: "{{ cname }}" + volume_driver: / + state: started + force_kill: yes + register: volume_driver_3 + +- name: cleanup + docker_container: + name: "{{ cname }}" + state: absent + force_kill: yes + diff: no + +- assert: + that: + - volume_driver_1 is changed + - volume_driver_2 is not changed + - volume_driver_3 is changed + +#################################################################### +## volumes ######################################################### +#################################################################### + +- name: volumes + docker_container: + image: alpine:3.8 + command: '/bin/sh -c "sleep 10m"' + name: "{{ cname }}" + state: started + volumes: + - "/tmp:/tmp" + - "/:/whatever:rw,z" + register: volumes_1 + +- name: volumes (idempotency) + docker_container: + image: alpine:3.8 + command: '/bin/sh -c "sleep 10m"' + name: "{{ cname }}" + state: started + volumes: + - "/:/whatever:rw,z" + - "/tmp:/tmp" + register: volumes_2 + +- name: volumes (less volumes) + docker_container: + image: alpine:3.8 + command: '/bin/sh -c "sleep 10m"' + name: "{{ cname }}" + state: started + volumes: + - "/tmp:/tmp" + register: volumes_3 + +- name: volumes (more volumes) + docker_container: + image: alpine:3.8 + command: '/bin/sh -c "sleep 10m"' + name: "{{ cname }}" + state: started + volumes: + - "/tmp:/tmp" + - "/tmp:/somewhereelse:ro,Z" + force_kill: yes + register: volumes_4 + +- name: volumes (different modes) + docker_container: + image: alpine:3.8 + command: '/bin/sh -c "sleep 10m"' + name: "{{ cname }}" + state: started + volumes: + - "/tmp:/tmp" + - "/tmp:/somewhereelse:ro" + force_kill: yes + register: volumes_5 + +- name: cleanup + docker_container: + name: "{{ cname }}" + state: absent + force_kill: yes + diff: no + +- assert: + that: + - volumes_1 is changed + - volumes_2 is not changed + - volumes_3 is not changed + - volumes_4 is changed + - volumes_5 is changed + +#################################################################### +## volumes_from #################################################### +#################################################################### + +- name: start helpers + docker_container: + image: alpine:3.8 + command: '/bin/sh -c "sleep 10m"' + name: "{{ container_name }}" + state: started + volumes: + - "{{ '/tmp:/tmp' if container_name == cname_h1 else '/:/whatever:ro' }}" + loop: + - "{{ cname_h1 }}" + - "{{ cname_h2 }}" + loop_control: + loop_var: container_name + +- name: volumes_from + docker_container: + image: alpine:3.8 + command: '/bin/sh -c "sleep 10m"' + name: "{{ cname }}" + state: started + volumes_from: "{{ cname_h1 }}" + register: volumes_from_1 + +- name: volumes_from (idempotency) + docker_container: + image: alpine:3.8 + command: '/bin/sh -c "sleep 10m"' + name: "{{ cname }}" + state: started + volumes_from: "{{ cname_h1 }}" + register: volumes_from_2 + +- name: volumes_from (change) + docker_container: + image: alpine:3.8 + command: '/bin/sh -c "sleep 10m"' + name: "{{ cname }}" + state: started + volumes_from: "{{ cname_h2 }}" + force_kill: yes + register: volumes_from_3 + +- name: cleanup + docker_container: + name: "{{ container_name }}" + state: absent + force_kill: yes + loop: + - "{{ cname }}" + - "{{ cname_h1 }}" + - "{{ cname_h2 }}" + loop_control: + loop_var: container_name + diff: no + +- assert: + that: + - volumes_from_1 is changed + - volumes_from_2 is not changed + - volumes_from_3 is changed + +#################################################################### +#################################################################### +#################################################################### diff --git a/test/integration/targets/docker_container/tasks/tests/options.yml b/test/integration/targets/docker_container/tasks/tests/options.yml index e594f46cf9..638286b0c6 100644 --- a/test/integration/targets/docker_container/tasks/tests/options.yml +++ b/test/integration/targets/docker_container/tasks/tests/options.yml @@ -3645,197 +3645,6 @@ avoid such warnings, please quote the value.' in log_options_2.warnings" when: docker_py_version is version('3.5.0', '<') #################################################################### -## keep_volumes #################################################### -#################################################################### - -# TODO: - keep_volumes - -#################################################################### -## volume_driver ################################################### -#################################################################### - -- name: volume_driver - docker_container: - image: alpine:3.8 - command: '/bin/sh -c "sleep 10m"' - name: "{{ cname }}" - volume_driver: local - state: started - register: volume_driver_1 - -- name: volume_driver (idempotency) - docker_container: - image: alpine:3.8 - command: '/bin/sh -c "sleep 10m"' - name: "{{ cname }}" - volume_driver: local - state: started - register: volume_driver_2 - -- name: volume_driver (change) - docker_container: - image: alpine:3.8 - command: '/bin/sh -c "sleep 10m"' - name: "{{ cname }}" - volume_driver: / - state: started - force_kill: yes - register: volume_driver_3 - -- name: cleanup - docker_container: - name: "{{ cname }}" - state: absent - force_kill: yes - diff: no - -- assert: - that: - - volume_driver_1 is changed - - volume_driver_2 is not changed - - volume_driver_3 is changed - -#################################################################### -## volumes ######################################################### -#################################################################### - -- name: volumes - docker_container: - image: alpine:3.8 - command: '/bin/sh -c "sleep 10m"' - name: "{{ cname }}" - state: started - volumes: - - "/tmp:/tmp" - - "/:/whatever:rw,z" - register: volumes_1 - -- name: volumes (idempotency) - docker_container: - image: alpine:3.8 - command: '/bin/sh -c "sleep 10m"' - name: "{{ cname }}" - state: started - volumes: - - "/:/whatever:rw,z" - - "/tmp:/tmp" - register: volumes_2 - -- name: volumes (less volumes) - docker_container: - image: alpine:3.8 - command: '/bin/sh -c "sleep 10m"' - name: "{{ cname }}" - state: started - volumes: - - "/tmp:/tmp" - register: volumes_3 - -- name: volumes (more volumes) - docker_container: - image: alpine:3.8 - command: '/bin/sh -c "sleep 10m"' - name: "{{ cname }}" - state: started - volumes: - - "/tmp:/tmp" - - "/tmp:/somewhereelse:ro,Z" - force_kill: yes - register: volumes_4 - -- name: volumes (different modes) - docker_container: - image: alpine:3.8 - command: '/bin/sh -c "sleep 10m"' - name: "{{ cname }}" - state: started - volumes: - - "/tmp:/tmp" - - "/tmp:/somewhereelse:ro" - force_kill: yes - register: volumes_5 - -- name: cleanup - docker_container: - name: "{{ cname }}" - state: absent - force_kill: yes - diff: no - -- assert: - that: - - volumes_1 is changed - - volumes_2 is not changed - - volumes_3 is not changed - - volumes_4 is changed - - volumes_5 is changed - -#################################################################### -## volumes_from #################################################### -#################################################################### - -- name: start helpers - docker_container: - image: alpine:3.8 - command: '/bin/sh -c "sleep 10m"' - name: "{{ container_name }}" - state: started - volumes: - - "{{ '/tmp:/tmp' if container_name == cname_h1 else '/:/whatever:ro' }}" - loop: - - "{{ cname_h1 }}" - - "{{ cname_h2 }}" - loop_control: - loop_var: container_name - -- name: volumes_from - docker_container: - image: alpine:3.8 - command: '/bin/sh -c "sleep 10m"' - name: "{{ cname }}" - state: started - volumes_from: "{{ cname_h1 }}" - register: volumes_from_1 - -- name: volumes_from (idempotency) - docker_container: - image: alpine:3.8 - command: '/bin/sh -c "sleep 10m"' - name: "{{ cname }}" - state: started - volumes_from: "{{ cname_h1 }}" - register: volumes_from_2 - -- name: volumes_from (change) - docker_container: - image: alpine:3.8 - command: '/bin/sh -c "sleep 10m"' - name: "{{ cname }}" - state: started - volumes_from: "{{ cname_h2 }}" - force_kill: yes - register: volumes_from_3 - -- name: cleanup - docker_container: - name: "{{ container_name }}" - state: absent - force_kill: yes - loop: - - "{{ cname }}" - - "{{ cname_h1 }}" - - "{{ cname_h2 }}" - loop_control: - loop_var: container_name - diff: no - -- assert: - that: - - volumes_from_1 is changed - - volumes_from_2 is not changed - - volumes_from_3 is changed - -#################################################################### ## working_dir ##################################################### #################################################################### |