|
5 | 5 | FACT_IMAGE_NAME: "{{ fact.image | default(None) }}" |
6 | 6 |
|
7 | 7 | tasks: |
8 | | - - name: Install dependencies |
9 | | - become: true |
10 | | - community.general.rpm_ostree_pkg: |
11 | | - apply_live: true |
12 | | - name: |
13 | | - - make |
14 | | - - python3-packaging |
15 | | - - python3-requests |
16 | | - state: present |
17 | | - |
18 | | - - name: Login to quay.io |
19 | | - community.docker.docker_login: |
20 | | - registry_url: quay.io |
21 | | - username: "{{ quay.username }}" |
22 | | - password: "{{ quay.password }}" |
23 | | - |
24 | 8 | - name: Clone the repo |
25 | 9 | ansible.builtin.git: |
26 | 10 | repo: https://github.com/stackrox/fact |
27 | | - dest: ./fact |
| 11 | + dest: /tmp/fact |
28 | 12 | version: "{{ fact.version }}" |
29 | 13 | update: false |
30 | 14 |
|
31 | | - - name: Install python packages |
32 | | - ansible.builtin.pip: |
33 | | - requirements: ./fact/tests/requirements.txt |
34 | | - chdir: "{{ ansible_env.HOME }}" |
35 | | - virtualenv: ./fact/.venv |
36 | | - virtualenv_command: python3 -m venv |
| 15 | + - name: Log into quay.io |
| 16 | + become: true |
| 17 | + shell: |
| 18 | + cmd: "{{ runtime_command }} login -u {{ quay.username }} --password-stdin quay.io" |
| 19 | + stdin: "{{ quay.password }}" |
| 20 | + |
| 21 | + - name: Copy podman auth |
| 22 | + become: true |
| 23 | + shell: |
| 24 | + cmd: | |
| 25 | + mkdir -p ~/.docker/ |
| 26 | + if [[ -f "${XDG_RUNTIME_DIR:-}/containers/auth.json" ]]; then |
| 27 | + AUTH_FILE="${XDG_RUNTIME_DIR:-}/containers/auth.json" |
| 28 | + elif [[ -f "/run/containers/0/auth.json" ]]; then |
| 29 | + AUTH_FILE="/run/containers/0/auth.json" |
| 30 | + else |
| 31 | + echo &>2 "No valid auth.json file found" |
| 32 | + exit 1 |
| 33 | + fi |
| 34 | + cp "${AUTH_FILE}" ~/.docker/config.json |
| 35 | + creates: ~/.docker/config.json |
| 36 | + when: runtime_command == "podman" |
37 | 37 |
|
38 | 38 | - block: |
| 39 | + # There are some ansible modules that we could use to modularize |
| 40 | + # this next task, however they required some Python modules to be |
| 41 | + # installed on the managed VM that may not be available (like |
| 42 | + # python3-packaging), so we stick to a shell as ugly as it is. |
39 | 43 | - name: Run tests |
| 44 | + become: true |
| 45 | + environment: |
| 46 | + DOCKER_HOST: "{{ runtime_host }}" |
40 | 47 | ansible.builtin.shell: |
41 | 48 | cmd: | |
42 | | - cd "${HOME}/fact" |
43 | | - source ".venv/bin/activate" |
44 | | - make integration-tests |
| 49 | + set -euo pipefail |
| 50 | + cd "/tmp/fact/tests" |
| 51 | +
|
| 52 | + # Setup the virtual environment |
| 53 | + python3 -m venv .venv |
| 54 | + source .venv/bin/activate |
| 55 | + pip install -r requirements.txt |
| 56 | +
|
| 57 | + # Generate gRPC files |
| 58 | + python3 -m grpc_tools.protoc \ |
| 59 | + -I../third_party/stackrox/proto \ |
| 60 | + --python_out=. \ |
| 61 | + --pyi_out=. \ |
| 62 | + --grpc_python_out=. \ |
| 63 | + ../third_party/stackrox/proto/internalapi/sensor/collector.proto \ |
| 64 | + ../third_party/stackrox/proto/internalapi/sensor/sfa.proto \ |
| 65 | + ../third_party/stackrox/proto/internalapi/sensor/sfa_iservice.proto |
| 66 | +
|
| 67 | + # Run the tests |
| 68 | + pytest --image="${FACT_IMAGE_NAME}" --junit-xml=results.xml |
| 69 | +
|
45 | 70 | always: |
| 71 | + - name: Make logs directories |
| 72 | + ansible.builtin.file: |
| 73 | + state: directory |
| 74 | + path: /tmp/fact/tests/logs |
| 75 | + recurse: true |
| 76 | + delegate_to: localhost |
| 77 | + |
46 | 78 | - name: Retrieve results |
47 | 79 | ansible.builtin.fetch: |
48 | | - src: "{{ ansible_env.HOME }}/fact/tests/results.xml" |
49 | | - dest: ../tests/ |
| 80 | + src: /tmp/fact/tests/results.xml |
| 81 | + dest: "/tmp/fact/tests/{{ vm_config }}-results.xml" |
50 | 82 | flat: true |
51 | 83 |
|
52 | 84 | - name: Compress log files |
53 | 85 | community.general.archive: |
54 | | - path: "{{ ansible_env.HOME }}/fact/tests/logs" |
55 | | - dest: "{{ ansible_env.HOME }}/fact/tests/logs.tar.gz" |
| 86 | + path: /tmp/fact/tests/logs |
| 87 | + dest: "/tmp/fact/tests/{{ vm_config }}.tar.gz" |
56 | 88 |
|
57 | 89 | - name: Fetch log files |
58 | 90 | ansible.builtin.fetch: |
59 | | - src: "{{ ansible_env.HOME }}/fact/tests/logs.tar.gz" |
60 | | - dest: ../tests/logs.tar.gz |
| 91 | + src: "/tmp/fact/tests/{{ vm_config }}.tar.gz" |
| 92 | + dest: /tmp/fact/tests/logs/ |
| 93 | + validate_checksum: false |
61 | 94 | flat: true |
0 commit comments