Skip to content

Commit fce199e

Browse files
author
Yi He
committed
ci: add ci workflow
Signed-off-by: Yi He <[email protected]>
1 parent 3481ae3 commit fce199e

File tree

7 files changed

+506
-0
lines changed

7 files changed

+506
-0
lines changed

.github/workflows/integration.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
name: CI Test
3+
4+
on:
5+
pull_request_target:
6+
types: [opened, synchronize, reopened]
7+
8+
jobs:
9+
check-pull-request:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Query author repository permissions
13+
uses: octokit/[email protected]
14+
id: user_permission
15+
with:
16+
route: GET /repos/${{ github.repository }}/collaborators/${{ github.event.sender.login }}/permission
17+
env:
18+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19+
20+
- name: Check if user does have correct permissions
21+
if: contains('admin write', fromJson(steps.user_permission.outputs.data).permission)
22+
id: check_user_perm
23+
run: |
24+
echo "User '${{ github.event.sender.login }}' has permission '${{ fromJson(steps.user_permission.outputs.data).permission }}' allowed values: 'admin', 'write'"
25+
echo "allowed_user=true" >> $GITHUB_OUTPUT
26+
27+
- name: Get information for pull request
28+
uses: octokit/[email protected]
29+
id: pr-api
30+
with:
31+
route: GET /repos/${{ github.repository }}/pulls/${{ github.event.number }}
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
35+
outputs:
36+
allowed_user: ${{ steps.check_user_perm.outputs.allowed_user }}
37+
sha: ${{ fromJson(steps.pr-api.outputs.data).head.sha }}
38+
ref: ${{ fromJson(steps.pr-api.outputs.data).head.ref }}
39+
repo_url: ${{ fromJson(steps.pr-api.outputs.data).head.repo.html_url }}
40+
41+
fedora-43-bootc:
42+
needs: check-pull-request
43+
if: ${{ needs.check-pull-request.outputs.allowed_user == 'true' }}
44+
continue-on-error: true
45+
runs-on: ubuntu-latest
46+
47+
steps:
48+
- name: Run the tests
49+
uses: sclorg/[email protected]
50+
with:
51+
compose: Fedora-43
52+
api_key: ${{ secrets.TF_API_KEY }}
53+
git_url: ${{ needs.check-pull-request.outputs.repo_url }}
54+
git_ref: ${{ needs.check-pull-request.outputs.ref }}
55+
update_pull_request_status: true
56+
pull_request_status_name: fedora-43-bootc
57+
tmt_context: "arch=x86_64;distro=fedora-43"
58+
tmt_path: "./test/fmf"
59+
tmt_plan_regex: bootc-iso
60+
tf_scope: private
61+
variables: "ARCH=x86_64"
62+
timeout: 60
63+
64+

test/fmf/plans/integration.fmf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
summary: fdo server test plan
2+
discover:
3+
how: fmf
4+
test: integration
5+
execute:
6+
how: tmt
7+
provision:
8+
hardware:
9+
virtualization:
10+
is-supported: true
11+
cpu:
12+
processors: ">= 2"
13+
memory: ">= 6 GB"
14+
15+
/bootc-iso:
16+
summary: Test go fdo server with bootc iso image
17+
environment+:
18+
TEST_CASE: bootc-iso
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
#!/usr/bin/env bash
2+
set -euox pipefail
3+
4+
# Color definitions
5+
RED='\033[0;31m'
6+
GREEN='\033[0;32m'
7+
BLUE='\033[0;34m'
8+
NC='\033[0m' # No Color
9+
10+
# Logging functions
11+
log_info() { echo -e "${BLUE}[INFO]${NC} $*"; }
12+
log_success() { echo -e "${GREEN}[SUCCESS]${NC} $*"; }
13+
14+
# Network configuration
15+
NETWORK_NAME="integration"
16+
NETWORK_UUID="1c8fe98c-b53a-4ca4-bbdb-deb0f26b3579"
17+
NETWORK_BRIDGE="integration"
18+
NETWORK_SUBNET="192.168.100.0/24"
19+
NETWORK_GATEWAY="192.168.100.1"
20+
21+
# Package management
22+
install_packages() {
23+
log_info "Installing required packages"
24+
25+
packages=(
26+
make golang podman jq qemu-img httpd firewalld
27+
qemu-kvm libvirt-client libvirt-daemon-kvm
28+
libvirt-daemon virt-install ansible-core
29+
cargo lorax lsof
30+
)
31+
32+
dnf install -y "${packages[@]}"
33+
}
34+
35+
# Function to check and fix key permissions
36+
check_key_permissions() {
37+
local key_path="key/ostree_key"
38+
39+
if [[ -f "${key_path}" ]]; then
40+
local key_perms
41+
key_perms=$(stat -L -c "%a" "${key_path}")
42+
43+
if [[ "${key_perms}" != "600" ]]; then
44+
log_info "File permissions too open (${key_perms}), changing to 600"
45+
chmod 600 "${key_path}"
46+
fi
47+
else
48+
log_info "Key file not found: ${key_path}"
49+
fi
50+
}
51+
52+
# Function to configure services
53+
configure_services() {
54+
log_info "Configuring services"
55+
56+
# Enable and start services
57+
sudo systemctl enable --now httpd.service
58+
sudo systemctl enable --now firewalld
59+
60+
# Configure libvirt permissions
61+
log_info "Configuring libvirt permissions"
62+
sudo tee /etc/polkit-1/rules.d/50-libvirt.rules > /dev/null << 'EOF'
63+
polkit.addRule(function(action, subject) {
64+
if (action.id == "org.libvirt.unix.manage" &&
65+
subject.isInGroup("adm")) {
66+
return polkit.Result.YES;
67+
}
68+
});
69+
EOF
70+
71+
# Start libvirtd
72+
log_info "Starting libvirt daemon"
73+
sudo systemctl start libvirtd
74+
75+
# Verify libvirt is working
76+
if ! sudo virsh list --all > /dev/null; then
77+
echo "Failed to connect to libvirt" >&2
78+
return 1
79+
fi
80+
}
81+
82+
# Function to setup libvirt network
83+
setup_libvirt_network() {
84+
local network_xml="/tmp/integration.xml"
85+
86+
log_info "Setting up libvirt network"
87+
88+
# Create network configuration
89+
sudo tee "${network_xml}" > /dev/null << 'EOF'
90+
<network xmlns:dnsmasq='http://libvirt.org/schemas/network/dnsmasq/1.0'>
91+
<name>integration</name>
92+
<uuid>1c8fe98c-b53a-4ca4-bbdb-deb0f26b3579</uuid>
93+
<forward mode='nat'>
94+
<nat>
95+
<port start='1024' end='65535'/>
96+
</nat>
97+
</forward>
98+
<bridge name='integration' zone='trusted' stp='on' delay='0'/>
99+
<mac address='52:54:00:36:46:ef'/>
100+
<ip address='192.168.100.1' netmask='255.255.255.0'>
101+
<dhcp>
102+
<range start='192.168.100.2' end='192.168.100.254'/>
103+
<host mac='34:49:22:B0:83:30' name='vm-1' ip='192.168.100.50'/>
104+
<host mac='34:49:22:B0:83:31' name='vm-2' ip='192.168.100.51'/>
105+
<host mac='34:49:22:B0:83:32' name='vm-3' ip='192.168.100.52'/>
106+
</dhcp>
107+
</ip>
108+
<dnsmasq:options>
109+
<dnsmasq:option value='dhcp-vendorclass=set:efi-http,HTTPClient:Arch:00016'/>
110+
<dnsmasq:option value='dhcp-option-force=tag:efi-http,60,HTTPClient'/>
111+
<dnsmasq:option value='dhcp-boot=tag:efi-http,&quot;http://192.168.100.1/httpboot/EFI/BOOT/BOOTX64.EFI&quot;'/>
112+
</dnsmasq:options>
113+
</network>
114+
EOF
115+
116+
# Define network if it doesn't exist
117+
if ! sudo virsh net-info integration > /dev/null 2>&1; then
118+
sudo virsh net-define "${network_xml}"
119+
fi
120+
121+
# Start network if not active
122+
if [[ $(sudo virsh net-info integration | awk '/Active/ {print $2}') == "no" ]]; then
123+
sudo virsh net-start integration
124+
fi
125+
}
126+
127+
# Function to check and free port 8081 if needed
128+
check_port_8081() {
129+
log_info "Checking port 8081 availability"
130+
131+
if lsof -Pi :8081 -sTCP:LISTEN -t >/dev/null; then
132+
log_info "Port 8081 is in use, attempting to free it"
133+
sudo fuser -k 8081/tcp || true
134+
sleep 2
135+
fi
136+
}
137+
138+
139+
log_info "Starting CI environment setup"
140+
141+
# Get OS data
142+
source /etc/os-release
143+
log_info "Detected OS: ${ID} ${VERSION_ID}"
144+
145+
# Install required packages
146+
install_packages
147+
148+
# Check and fix key permissions
149+
check_key_permissions
150+
151+
# Configure services
152+
configure_services
153+
154+
# Setup libvirt network
155+
setup_libvirt_network
156+
157+
# Check port 8081
158+
check_port_8081
159+
160+
log_success "CI environment setup completed successfully"

test/fmf/tests/integration.fmf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
test: ./integration.sh
2+
duration: 60m

0 commit comments

Comments
 (0)