Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(nri-resctrl-plugin): add integration tests #66

feat(nri-resctrl-plugin): add integration tests

feat(nri-resctrl-plugin): add integration tests #66

Workflow file for this run

name: test-resctrl
on:
workflow_dispatch:
inputs:
instance-type:
description: 'EC2 instance type to use'
required: false
default: 'm7i.metal-24xl'
type: string
image-type:
description: 'Runner AMI image type'
required: false
default: 'ubuntu-24.04'
type: string
pull_request:
paths:
- 'crates/resctrl/**'
- 'crates/nri-resctrl-plugin/**'
- '.github/actions/setup-k3s/**'
- '.github/workflows/test-resctrl.yaml'
- 'Cargo.toml'
push:
branches:
- 'main'
- '**'
paths:
- 'crates/resctrl/**'
- 'crates/nri-resctrl-plugin/**'
- '.github/actions/setup-k3s/**'
- '.github/workflows/test-resctrl.yaml'
- 'Cargo.toml'
permissions:
id-token: write
contents: read
actions: write
jobs:
build-and-unit-test:
name: Build + unit tests (GH hosted)
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Cache cargo registry and git index
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-resctrl-cargo-${{ hashFiles('Cargo.lock') }}
restore-keys: |
${{ runner.os }}-resctrl-cargo-
- name: Cache cargo build artifacts
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-resctrl-target-${{ hashFiles('Cargo.lock') }}
restore-keys: |
${{ runner.os }}-resctrl-target-
- name: Install Rust toolchain
run: |
rustc -V || curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
echo "source $HOME/.cargo/env" >> $HOME/.profile
source $HOME/.cargo/env
rustc -V
cargo -V
- name: Run unit tests (resctrl)
run: |
source $HOME/.cargo/env
# RESCTRL_E2E not set, so smoke test is skipped
RUST_TEST_THREADS=1 cargo test -p resctrl --release -- --nocapture --test-threads=1
- name: Run unit tests (nri-resctrl-plugin)
run: |
source $HOME/.cargo/env
RUST_TEST_THREADS=1 cargo test -p nri-resctrl-plugin --release -- --nocapture --test-threads=1
- name: Build test binaries (no-run)
run: |
source $HOME/.cargo/env
# Build only the hardware smoke integration test binary
cargo test -p resctrl --test smoke_test --release --no-run
- name: Build nri-resctrl-plugin integration tests (no-run)
run: |
source $HOME/.cargo/env
# Build all integration tests for nri-resctrl-plugin without running them
cargo test -p nri-resctrl-plugin --tests --release --no-run
- name: Collect smoke test binary
id: collect-bin
run: |
set -euxo pipefail
BIN=$(find target/release/deps -maxdepth 1 -type f -executable -name 'smoke_test-*' | head -n 1)
if [ -z "$BIN" ]; then
echo "Smoke test binary not found" >&2
exit 1
fi
file "$BIN" || true
ldd "$BIN" || true
cp "$BIN" resctrl-smoke
chmod +x resctrl-smoke
- name: Upload resctrl smoke binary
uses: actions/upload-artifact@v4
with:
name: resctrl-smoke-bin
path: resctrl-smoke
if-no-files-found: error
- name: Collect nri-resctrl-plugin e2e binary
id: collect-plugin-bin
run: |
set -euxo pipefail
P_BIN=$(find target/release/deps -maxdepth 1 -type f -executable -name 'integration_test-*' | head -n 1)
if [ -z "$P_BIN" ]; then
echo "nri-resctrl-plugin integration test binary not found" >&2
find target/release -maxdepth 2 -type f -name '*integration_test*' || true
exit 1
fi
file "$P_BIN" || true
ldd "$P_BIN" || true
cp "$P_BIN" nri-resctrl-plugin-e2e
chmod +x nri-resctrl-plugin-e2e
- name: Upload nri-resctrl-plugin e2e binary
uses: actions/upload-artifact@v4
with:
name: nri-resctrl-plugin-e2e
path: nri-resctrl-plugin-e2e
if-no-files-found: error
nri-resctrl-plugin-e2e:
name: NRI resctrl plugin full flow (k3s on EC2)
needs: [setup-runner, build-and-unit-test]
runs-on: ${{ needs.setup-runner.outputs.runner-label }}
timeout-minutes: 20
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup k3s
uses: ./.github/actions/setup-k3s
with:
kubeconfig_path: /etc/rancher/k3s/k3s.yaml
disable_packaged_addons: true
preflight_inotify: true
wait_kube_system: false
timeout_api_server_ready_seconds: 300
timeout_node_ready_seconds: 300
- name: Verify NRI socket
run: |
set -euo pipefail
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
echo "=== Waiting for NRI socket at /var/run/nri/nri.sock ==="
for i in $(seq 1 90); do
if sudo test -S /var/run/nri/nri.sock; then
echo "✓ NRI socket present"
sudo ls -la /var/run/nri/nri.sock
break
fi
sleep 1
done
if ! sudo test -S /var/run/nri/nri.sock; then
echo "✗ NRI socket not found after enabling on k3s"
sudo journalctl -u k3s --no-pager -n 200 || true
exit 1
fi
- name: Download nri-resctrl-plugin e2e binary
uses: actions/download-artifact@v4
with:
name: nri-resctrl-plugin-e2e
path: ./
- name: Prepare test binary
run: |
chmod +x ./nri-resctrl-plugin-e2e || true
- name: Run plugin integration tests (excluding capacity retry)
env:
NRI_SOCKET_PATH: /var/run/nri/nri.sock
RUST_LOG: info
KUBECONFIG: /etc/rancher/k3s/k3s.yaml
run: |
echo "Using prebuilt test binary: ./nri-resctrl-plugin-e2e"
NRI_SOCKET_PATH="/var/run/nri/nri.sock" sudo -E ./nri-resctrl-plugin-e2e --include-ignored --nocapture --test-threads=1 --skip test_capacity_retry_e2e
- name: Run plugin integration test (capacity retry)
env:
NRI_SOCKET_PATH: /var/run/nri/nri.sock
RUST_LOG: info
KUBECONFIG: /etc/rancher/k3s/k3s.yaml
run: |
echo "Using prebuilt test binary: ./nri-resctrl-plugin-e2e"
NRI_SOCKET_PATH="/var/run/nri/nri.sock" sudo -E ./nri-resctrl-plugin-e2e test_capacity_retry_e2e --include-ignored --nocapture --test-threads=1
- name: Cleanup k3s
if: always()
run: |
sudo /usr/local/bin/k3s-uninstall.sh || true
setup-runner:
name: Start EC2 runner (resctrl-capable)
needs: [build-and-unit-test]
runs-on: ubuntu-latest
outputs:
runner-label: ${{ steps.start-runner.outputs.runner-label }}
ec2-instance-id: ${{ steps.start-runner.outputs.ec2-instance-id }}
region: ${{ steps.start-runner.outputs.region }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Start AWS Runner
id: start-runner
uses: ./.github/actions/aws-runner
with:
github-token: ${{ secrets.REPO_ADMIN_TOKEN }}
aws-role-arn: ${{ secrets.AWS_ROLE_ARN }}
iam-role-name: github-actions-runner
instance-type: ${{ inputs.instance-type || 'm7i.metal-24xl' }}
image-type: ${{ inputs.image-type || 'ubuntu-24.04' }}
market-type: 'spot'
resctrl-e2e-smoke:
name: Run resctrl smoke test
needs: [build-and-unit-test, setup-runner]
runs-on: ${{ needs.setup-runner.outputs.runner-label }}
timeout-minutes: 20
env:
HOME: /root
steps:
- name: Prepare HOME
run: mkdir -p "$HOME"
- name: Download smoke binary
uses: actions/download-artifact@v4
with:
name: resctrl-smoke-bin
path: ./
- name: Run resctrl smoke test (hardware)
shell: bash
run: |
set -euxo pipefail
BIN=./resctrl-smoke
chmod +x "$BIN" || true
echo "Executing $BIN"
RESCTRL_E2E=1 "$BIN" --nocapture --test-threads=1
stop-runner:
name: Stop EC2 runner
needs: [setup-runner, resctrl-e2e-smoke, nri-resctrl-plugin-e2e]
runs-on: ubuntu-latest
if: always()
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Stop AWS Runner
uses: ./.github/actions/aws-runner/cleanup
with:
runner-label: ${{ needs.setup-runner.outputs.runner-label }}
ec2-instance-id: ${{ needs.setup-runner.outputs.ec2-instance-id }}
github-token: ${{ secrets.REPO_ADMIN_TOKEN }}
aws-role-arn: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ${{ needs.setup-runner.outputs.region }}