File: container_test_tasks.yaml

package info (click to toggle)
python-ara 1.5.8-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 10,460 kB
  • sloc: python: 6,493; sh: 215; makefile: 15; javascript: 2
file content (92 lines) | stat: -rw-r--r-- 3,095 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
- name: Ensure volume directory exists
  file:
    path: "{{ ara_api_root_dir }}/server"
    state: directory
    recurse: yes

- name: "Build {{ item.name }}:{{ item.tag }} with {{ item.script }}"
  command: "{{ ara_api_source }}/contrib/container-images/{{ item.script }} {{ item.name }}:{{ item.tag }}"

- name: "Start {{ item.name }}:{{ item.tag }} with podman"
  command: |
    podman run --name api-server --detach --tty \
    --volume {{ ara_api_root_dir }}/server:/opt/ara:z -p 8000:8000 \
    -e ARA_LOG_LEVEL=DEBUG -e ARA_DEBUG=true \
    {{ item.name }}:{{ item.tag }}

- block:
    - name: Get the API root
      uri:
        url: "http://127.0.0.1:8000/api/"
        return_content: yes
        follow_redirects: none
        method: GET
      register: _get_root
      # Allow the server to settle from sql migrations
      until: _get_root.status == 200
      retries: 3
      delay: 5

    - name: Validate the API response
      assert:
        that:
          - "'gunicorn' in _get_root.server"
          - _get_root.json["kind"] == "ara"
          - _get_root.json["api"] == ["http://127.0.0.1:8000/api/v1/"]

    - name: Create a test playbook
      uri:
        url: "http://127.0.0.1:8000/api/v1/playbooks"
        return_content: yes
        follow_redirects: none
        method: POST
        status_code: 201
        body_format: json
        body:
          name: "Integration test playbook for {{ item.script }}"
          ansible_version: "9.0.0.1"
          started: "{{ ansible_date_time.iso8601_micro }}"
          status: running
          controller: localhost
          labels:
            - "{{ _get_root.json['version'] }}"
            - "{{ item.name }}:{{ item.tag }}"
            - "{{ item.script }}"
          path: "/tests/container_test_tasks.yaml"
      register: _post_playbook

    - name: Get the test playbook
      uri:
        url: "http://127.0.0.1:8000/api/v1/playbooks/{{ _post_playbook.json['id'] }}"
        return_content: yes
        follow_redirects: none
        method: GET
        status_code: 200
      register: _get_playbook

    - name: Assert the test playbook
      assert:
        that:
          - _get_playbook.json["id"] == _post_playbook.json["id"]
  always:
    - name: Recover container logs
      shell: podman logs -nt api-server | tee -a {{ ara_api_root_dir }}/server/container-{{ item.tag }}.log
      changed_when: false

    - name: Generate a static report
      command: podman exec -it api-server ara-manage generate /opt/ara/static-{{ item.tag }}
      ignore_errors: yes

    - name: Stop the container and remove it
      command: podman rm -f api-server

    # So they get re-generated by the container spinning up and at the same time
    # prevent sql migration issues because we're going back and forth between versions
    # when testing multiple containers back-to-back
    - name: Discard database and settings file
      file:
        path: "{{ item }}"
        state: absent
      loop:
        - "{{ ara_api_root_dir }}/server/ansible.sqlite"
        - "{{ ara_api_root_dir }}/server/settings.yaml"