Skip to content

Commit e2ef53e

Browse files
committed
ROX-30630: run BPF bootstrap test in CI
With this change, we will start running our integration tests on GCP hosted VMs, allowing us to have better visibility into what is the compatibility of our code with different kernel versions. This is achieved by running a small bootstrap unit test that load our code into the kernel, exercising the verifier on it.
1 parent 827d14b commit e2ef53e

File tree

13 files changed

+288
-1
lines changed

13 files changed

+288
-1
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ jobs:
150150
base-image: ${{ needs.vars.outputs.image-name }}
151151
archs: ${{ env.ARCHS }}
152152

153+
unit-tests:
154+
uses: ./.github/workflows/unit-tests.yml
155+
secrets: inherit
156+
153157
integration-tests:
154158
needs:
155159
- vars

.github/workflows/unit-tests.yml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: Run unit tests
2+
on:
3+
workflow_call:
4+
inputs:
5+
version:
6+
description: The version of fact to be tested (commit SHA or tag)
7+
default: ${{ github.head_ref || github.ref_name }}
8+
type: string
9+
job-tag:
10+
description: Additional tag to prevent collision on GCP VM naming
11+
type: string
12+
default: '-ut'
13+
14+
jobs:
15+
unit-tests:
16+
runs-on: ubuntu-24.04
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
vm:
21+
- rhel
22+
- rhel-arm64
23+
- rhcos
24+
- rhcos-arm64
25+
- cos
26+
- cos-arm64
27+
- flatcar
28+
29+
steps:
30+
- uses: actions/checkout@v4
31+
with:
32+
path: fact
33+
- uses: actions/checkout@v4
34+
with:
35+
repository: stackrox/collector
36+
path: collector
37+
ref: master
38+
- uses: actions/setup-python@v5
39+
with:
40+
python-version: "3.10"
41+
42+
- name: Authenticate with GCP
43+
uses: 'google-github-actions/auth@v2'
44+
with:
45+
credentials_json: '${{ secrets.GOOGLE_CREDENTIALS_COLLECTOR_CI_VM_SVC_ACCT }}'
46+
47+
- name: Setup GCP
48+
uses: 'google-github-actions/setup-gcloud@v2'
49+
50+
- uses: ./collector/.github/actions/setup-vm-creds
51+
with:
52+
gcp-ssh-key: ${{ secrets.GCP_SSH_KEY }}
53+
gcp-ssh-key-pub: ${{ secrets.GCP_SSH_KEY_PUB }}
54+
s390x-ssh-key: ${{ secrets.IBM_CLOUD_S390X_SSH_PRIVATE_KEY }}
55+
ppc64le-ssh-key: ${{ secrets.IBM_CLOUD_POWER_SSH_PRIVATE_KEY }}
56+
ppc64le-ssh-key-pub: ${{ secrets.IBM_CLOUD_POWER_SSH_PUBLIC_KEY }}
57+
s390x-key: ${{ secrets.IBM_CLOUD_S390x_API_KEY }}
58+
ppc64le-key: ${{ secrets.IBM_CLOUD_POWER_API_KEY }}
59+
redhat-username: ${{ secrets.REDHAT_USERNAME }}
60+
redhat-password: ${{ secrets.REDHAT_PASSWORD }}
61+
vm-type: ${{ matrix.vm }}
62+
job-tag: ${{ inputs.job-tag }}
63+
workspace: ${{ github.workspace }}/collector
64+
65+
- name: Create vars.yml
66+
run: |
67+
cat << EOF > vars.yml
68+
---
69+
job_id: ${JOB_ID}
70+
fact:
71+
version: ${{ inputs.version }}
72+
workdir: ${{ github.workspace }}
73+
excluded_vms:
74+
- rhel-8
75+
- rhcos-412
76+
EOF
77+
78+
- name: Create Test VMs
79+
run: |
80+
ansible-playbook \
81+
make -C "./collector/ansible" create-ci-vms
82+
83+
- name: Run the tests
84+
run: |
85+
ansible-playbook \
86+
-i "${GITHUB_WORKSPACE}/collector/ansible/ci" \
87+
-e @vars.yml \
88+
"${GITHUB_WORKSPACE}/fact/ansible/run-unit-tests.yml"
89+
90+
- name: Teardown VMs
91+
if: always()
92+
run: |
93+
make -C "./collector/ansible" destroy-vms
94+
95+
- name: Store artifacts
96+
if: always()
97+
uses: actions/upload-artifact@v4
98+
with:
99+
name: ${{ matrix.vm }}-unit-test-logs
100+
path: |
101+
${{ github.workspace }}/unit-test-*.log
102+
if-no-files-found: ignore

ansible/group_vars/all.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
runtime_command: docker
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
runtime_command: podman
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
ansible_python_interpreter: /home/core/bin/python
3+
ansible_user: core
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
ansible_user: core
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
ansible_user: core
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
- name: Start test-runner
3+
community.docker.docker_container:
4+
name: test-runner
5+
image: quay.io/centos/centos:stream9
6+
interactive: true
7+
cgroupns_mode: host
8+
pid_mode: host
9+
privileged: true
10+
register:
11+
test_result
12+
13+
- name: Install dependencies
14+
community.docker.docker_container_exec:
15+
container: test-runner
16+
command: >
17+
dnf install --enablerepo=crb -y
18+
clang-19.1.7
19+
libbpf-devel
20+
protobuf-compiler
21+
protobuf-devel
22+
git
23+
24+
- name: Download rustup
25+
community.docker.docker_container_exec:
26+
container: test-runner
27+
command: curl --tlsv1.2 -sSf https://sh.rustup.rs -o rustup.sh
28+
29+
- name: Make rustup executable
30+
community.docker.docker_container_exec:
31+
container: test-runner
32+
command: chmod +x rustup.sh
33+
34+
- name: Install rust toolchain
35+
community.docker.docker_container_exec:
36+
container: test-runner
37+
command: ./rustup.sh -y --default-toolchain 1.84 --profile minimal
38+
39+
- name: Clone fact repo
40+
community.docker.docker_container_exec:
41+
container: test-runner
42+
command: >
43+
git clone -b "{{ fact.version }}"
44+
--recurse-submodules
45+
https://github.com/stackrox/fact
46+
register: clone_res
47+
48+
- name: Run unit tests
49+
block:
50+
- name: Run unit tests
51+
community.docker.docker_container_exec:
52+
container: test-runner
53+
env:
54+
PATH: /root/.cargo/bin:${PATH}
55+
FACT_LOGLEVEL: debug
56+
chdir: /fact
57+
command: cargo test --all-features
58+
register: test_result
59+
60+
always:
61+
- name: Dump logs
62+
ansible.builtin.include_tasks:
63+
file: dump-result.yml
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
- name: stderr dump
3+
ansible.builtin.debug:
4+
var: test_result.stderr_lines
5+
when: test_result.rc != 0
6+
7+
- name: Test result
8+
ansible.builtin.debug:
9+
var: test_result.stdout_lines
10+
when: test_result.rc != 0
11+
12+
- name: Write stdout to log
13+
copy:
14+
content: "{{ test_result.stdout }}"
15+
dest: "unit-test-{{ vm_config }}-stdout.log"
16+
delegate_to: localhost
17+
18+
- name: Write stderr to log
19+
copy:
20+
content: "{{ test_result.stderr }}"
21+
dest: "unit-test-{{ vm_config }}-stderr.log"
22+
delegate_to: localhost
23+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
- name: Run unit tests with docker
3+
include_tasks: docker.yml
4+
when: runtime_command == 'docker'
5+
6+
- name: Run unit tests with podman
7+
include_tasks: podman.yml
8+
when: runtime_command == 'podman'

0 commit comments

Comments
 (0)