File: issue_655__wait_for_connection_error.yml

package info (click to toggle)
python-mitogen 0.3.26-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,456 kB
  • sloc: python: 22,134; sh: 183; makefile: 74; perl: 19; ansic: 18
file content (112 lines) | stat: -rw-r--r-- 3,733 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# https://github.com/dw/mitogen/issues/655
# Spins up a Centos8 container and runs the wait_for_connection test inside of it
# Doing it this way because the shutdown command causes issues in our tests
#   since things are ran on localhost; Azure DevOps loses connection and fails
# TODO: do we want to install docker a different way to be able to do this for other tests too
---
- name: regression/issue_655__wait_for_connection_error.yml
  hosts: localhost
  gather_facts: yes
  become: no
  tasks:
    - meta: end_play
      when:
        # Podman versions available in Homebrew require macOS 13+ (Ventura).
        # https://formulae.brew.sh/formula/podman
        # See also
        #   - issue_766__get_with_context.yml
        - ansible_facts.system == 'Darwin'
        - ansible_facts.distribution_version is version('13.0', '<', strict=True)

    - meta: end_play
      when:
        # Ansible 10 (ansible-core 2.17+) require Python 3.7+ on targets.
        # On CentOS 8 /usr/libexec/platform-python is Python 3.6
        - ansible_version_major_minor is version('2.17', '>=', strict=True)

    - name: set up test container and run tests inside it
      block:
        - name: install deps
          homebrew:
            name:
              - podman
            state: present

        - name: start machine
          command:
            cmd: "{{ item.cmd }}"
          loop:
            - cmd: podman machine init
            - cmd: podman machine start
            - cmd: podman info
          timeout: 300
          register: podman_machine
          changed_when: true

        - debug:
            var: podman_machine

        # python bindings (docker_container) aren't working on this host, so gonna shell out
        - name: create container
          command:
            cmd: podman run --name testMitogen -d --rm centos:8 bash -c "sleep infinity & wait"
          changed_when: true

        - name: add container to inventory
          add_host:
            name: testMitogen
            ansible_connection: podman
            ansible_python_interpreter: /usr/libexec/platform-python  # Python 3.6
            ansible_user: root
          changed_when: false
          environment:
            PATH: /usr/local/bin/:{{ ansible_env.PATH }}

        - name: run tests
          block:
            # to repro the issue, will create /var/run/reboot-required
            - name: create test file
              file:
                path: /var/run/reboot-required
                mode: u=rw,go=r
                state: touch

            - name: Check if reboot is required
              stat:
                path: /var/run/reboot-required
              register: reboot_required

            - name: Reboot server
              shell: sleep 2 && shutdown -r now "Ansible updates triggered"
              async: 1
              poll: 0
              changed_when: true
              when:
                - reboot_required.stat.exists

            - name: Wait 300 seconds for server to become available
              wait_for_connection:
                delay: 30
                timeout: 300
              when:
                - reboot_required.stat.exists

            - name: cleanup test file
              file:
                path: /var/run/reboot-required
                state: absent
          delegate_to: testMitogen
          environment:
            PATH: /usr/local/bin/:{{ ansible_env.PATH }}

        - name: remove test container
          command:
            cmd: "{{ item.cmd }}"
          loop:
            - cmd: podman stop testMitogen
            - cmd: podman machine stop
          changed_when: true
      when:
        - ansible_facts.pkg_mgr in ['homebrew']
  tags:
    - issue_655