|
| 1 | +# https://github.com/dw/mitogen/issues/655 |
| 2 | +# Spins up a Centos8 container and runs the wait_for_connection test inside of it |
| 3 | +# Doing it this way because the shutdown command causes issues in our tests |
| 4 | +# since things are ran on localhost; Azure DevOps loses connection and fails |
| 5 | +# TODO: do we want to install docker a different way to be able to do this for other tests too |
| 6 | +--- |
| 7 | +# this should only run on our Mac hosts |
| 8 | +- hosts: target |
| 9 | + any_errors_fatal: True |
| 10 | + gather_facts: yes |
| 11 | + become: no |
| 12 | + tasks: |
| 13 | + - name: set up test container and run tests inside it |
| 14 | + block: |
| 15 | + - name: install deps |
| 16 | + block: |
| 17 | + - name: install docker |
| 18 | + shell: | |
| 19 | + # NOTE: for tracking purposes: https://github.com/docker/for-mac/issues/2359 |
| 20 | + # using docker for mac CI workaround: https://github.com/drud/ddev/pull/1748/files#diff-19288f650af2dabdf1dcc5b354d1f245 |
| 21 | + DOCKER_URL=https://download.docker.com/mac/stable/31259/Docker.dmg && |
| 22 | + curl -O -sSL $DOCKER_URL && |
| 23 | + open -W Docker.dmg && cp -r /Volumes/Docker/Docker.app /Applications |
| 24 | + sudo /Applications/Docker.app/Contents/MacOS/Docker --quit-after-install --unattended && |
| 25 | + ln -s /Applications/Docker.app/Contents/Resources/bin/docker /usr/local/bin/docker && |
| 26 | + nohup /Applications/Docker.app/Contents/MacOS/Docker --unattended & |
| 27 | + # wait 2 min for docker to come up |
| 28 | + counter=0 && |
| 29 | + while ! /usr/local/bin/docker ps 2>/dev/null ; do |
| 30 | + if [ $counter -lt 24 ]; then |
| 31 | + let counter=counter+1 |
| 32 | + else |
| 33 | + exit 1 |
| 34 | + fi |
| 35 | + sleep 5 |
| 36 | + done |
| 37 | +
|
| 38 | + # python bindings (docker_container) aren't working on this host, so gonna shell out |
| 39 | + - name: create docker container |
| 40 | + shell: /usr/local/bin/docker run --name testMitogen -d --rm centos:8 bash -c "sleep infinity & wait" |
| 41 | + |
| 42 | + - name: add container to inventory |
| 43 | + add_host: |
| 44 | + name: testMitogen |
| 45 | + ansible_connection: docker |
| 46 | + ansible_user: root |
| 47 | + changed_when: false |
| 48 | + environment: |
| 49 | + PATH: /usr/local/bin/:{{ ansible_env.PATH }} |
| 50 | + |
| 51 | + - name: run tests |
| 52 | + block: |
| 53 | + # to repro the issue, will create /var/run/reboot-required |
| 54 | + - name: create test file |
| 55 | + file: |
| 56 | + path: /var/run/reboot-required |
| 57 | + state: touch |
| 58 | + |
| 59 | + - name: Check if reboot is required |
| 60 | + stat: |
| 61 | + path: /var/run/reboot-required |
| 62 | + register: reboot_required |
| 63 | + |
| 64 | + - name: Reboot server |
| 65 | + shell: sleep 2 && shutdown -r now "Ansible updates triggered" |
| 66 | + async: 1 |
| 67 | + poll: 0 |
| 68 | + when: reboot_required.stat.exists == True |
| 69 | + |
| 70 | + - name: Wait 300 seconds for server to become available |
| 71 | + wait_for_connection: |
| 72 | + delay: 30 |
| 73 | + timeout: 300 |
| 74 | + when: reboot_required.stat.exists == True |
| 75 | + |
| 76 | + - name: cleanup test file |
| 77 | + file: |
| 78 | + path: /var/run/reboot-required |
| 79 | + state: absent |
| 80 | + delegate_to: testMitogen |
| 81 | + environment: |
| 82 | + PATH: /usr/local/bin/:{{ ansible_env.PATH }} |
| 83 | + |
| 84 | + - name: remove test container |
| 85 | + shell: /usr/local/bin/docker stop testMitogen |
0 commit comments