Skip to content

Commit 7bd4001

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 6e2c746 commit 7bd4001

File tree

13 files changed

+301
-1
lines changed

13 files changed

+301
-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: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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+
EOF
74+
75+
- name: Create Test VMs
76+
run: |
77+
make -C "./collector/ansible" create-ci-vms
78+
79+
- name: Run the tests
80+
run: |
81+
ansible-playbook \
82+
-i "${GITHUB_WORKSPACE}/collector/ansible/ci" \
83+
-e @vars.yml \
84+
"${GITHUB_WORKSPACE}/fact/ansible/run-unit-tests.yml"
85+
86+
- name: Teardown VMs
87+
if: always()
88+
run: |
89+
make -C "./collector/ansible" destroy-vms
90+
91+
- name: Store artifacts
92+
if: always()
93+
uses: actions/upload-artifact@v4
94+
with:
95+
name: ${{ matrix.vm }}-unit-test-logs
96+
path: |
97+
${{ github.workspace }}/unit-test-*.log
98+
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: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
gcc
19+
clang-19.1.7
20+
libbpf-devel
21+
protobuf-compiler
22+
protobuf-devel
23+
git
24+
25+
- name: Download rustup
26+
community.docker.docker_container_exec:
27+
container: test-runner
28+
command: curl --tlsv1.2 -sSf https://sh.rustup.rs -o rustup.sh
29+
30+
- name: Make rustup executable
31+
community.docker.docker_container_exec:
32+
container: test-runner
33+
command: chmod +x rustup.sh
34+
35+
- name: Install rust toolchain
36+
community.docker.docker_container_exec:
37+
container: test-runner
38+
command: ./rustup.sh -y --default-toolchain 1.84 --profile minimal
39+
40+
- name: Clone fact repo
41+
community.docker.docker_container_exec:
42+
container: test-runner
43+
command: >
44+
git clone -b "{{ fact.version }}"
45+
--recurse-submodules
46+
https://github.com/stackrox/fact
47+
register: clone_res
48+
49+
- name: Run unit tests
50+
block:
51+
- name: Run unit tests
52+
community.docker.docker_container_exec:
53+
container: test-runner
54+
env:
55+
PATH: /root/.cargo/bin:${PATH}
56+
FACT_LOGLEVEL: debug
57+
chdir: /fact
58+
command: cargo test --all-features
59+
register: test_result
60+
61+
always:
62+
- name: Dump logs
63+
ansible.builtin.include_tasks:
64+
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)