|
| 1 | +# support use cases: |
| 2 | +# * testing an image built locally in current environment (set pull variable to false) |
| 3 | +# * testing an image built locally inside a VM (supply vm_image variable) |
| 4 | +# * testing an image present in registry in current environment (set pull to true) |
| 5 | +# * testing an image present in registry inside a VM (set pull and vm_image variables) |
| 6 | +--- |
| 7 | +- name: Integration tests for tools container image executed in current environment |
| 8 | + hosts: localhost |
| 9 | + vars: |
| 10 | + # don't pull the test subject by default |
| 11 | + pull: false |
| 12 | + |
| 13 | + # don't set up the environment by default (instal and start container runtime) |
| 14 | + setup: false |
| 15 | + |
| 16 | + required_packages: |
| 17 | + - python3-conu |
| 18 | + - python3-pytest |
| 19 | + |
| 20 | + # tests to be invoked (this is utilized by basic standard test role) |
| 21 | + tests: |
| 22 | + # test suites = directories, where the tests live |
| 23 | + - integration |
| 24 | + |
| 25 | + # our test subject |
| 26 | + subject: "" |
| 27 | + |
| 28 | + # path where the test artifacts will be stored - logs |
| 29 | + artifacts: "{{ playbook_dir }}/artifacts/" |
| 30 | + |
| 31 | + tasks: |
| 32 | + - name: prepare the environment to run tests |
| 33 | + block: |
| 34 | + - name: Install the container engine |
| 35 | + package: |
| 36 | + name: docker |
| 37 | + state: present |
| 38 | + become: true |
| 39 | + - name: Start the container engine |
| 40 | + systemd: |
| 41 | + name: docker |
| 42 | + state: started |
| 43 | + become: true |
| 44 | + when: setup |
| 45 | + |
| 46 | + - name: Pull the test subject (=container image) |
| 47 | + command: docker pull {{ subject }} |
| 48 | + when: pull |
| 49 | + |
| 50 | + - name: Copy test subject from host inside the VM |
| 51 | + block: |
| 52 | + # FIXME: make this configurable |
| 53 | + - name: Create temporary directory for the image |
| 54 | + tempfile: |
| 55 | + state: directory |
| 56 | + register: tmp |
| 57 | + - name: Save the image to a file |
| 58 | + command: 'docker save -o {{ tmp.path + "/image.tar.gz" }} {{ subject }}' |
| 59 | + - name: Copy the image from host to the target |
| 60 | + # synchronize is so unreliable |
| 61 | + synchronize: |
| 62 | + src: '{{ tmp.path + "/image.tar.gz" }}' |
| 63 | + dest: '/tmp/' |
| 64 | + mode: push |
| 65 | + ssh_args: "-o UserKnownHostsFile=/dev/null -i {{ ansible_ssh_private_key_file }}" |
| 66 | + - file: |
| 67 | + state: absent |
| 68 | + path: "{{ tmp.path }}" |
| 69 | + when: not pull |
| 70 | + delegate_to: localhost |
| 71 | + |
| 72 | + - block: |
| 73 | + - name: Load the image on the target into dockerd |
| 74 | + command: 'docker load -i /tmp/image.tar.gz' |
| 75 | + - file: |
| 76 | + state: absent |
| 77 | + path: "/tmp/image.tar.gz" |
| 78 | + when: not pull |
| 79 | + |
| 80 | + - name: Execute the role which performs testing |
| 81 | + import_role: |
| 82 | + name: standard-test-basic |
0 commit comments