Skip to content

Commit db596fc

Browse files
Create sev library manual pr test on self-hosted runner
Signed-off-by: Harika Nittala <[email protected]>
1 parent 0dfe735 commit db596fc

File tree

1 file changed

+138
-0
lines changed

1 file changed

+138
-0
lines changed

.github/workflows/manual-pr-test.yaml

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
name: Manual sev PR test
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
command:
7+
type: choice
8+
description: 'Select the command to execute'
9+
required: true
10+
default: 'test-sev-on-host'
11+
options:
12+
- install-snp-on-the-host
13+
- reboot-host
14+
- verify-snp-on-host
15+
- test-sev-on-host
16+
- test-sev-on-guest
17+
pr_number:
18+
description: 'Test PR number'
19+
required: true
20+
default: '1'
21+
pr_branch:
22+
description: 'Test PR branch name'
23+
required: true
24+
default: 'main'
25+
jobs:
26+
snp_tests:
27+
runs-on: self-hosted
28+
steps:
29+
- name: Checkout Repository
30+
uses: actions/checkout@v2
31+
32+
# Commented these, as these are already installed on self-hosted runner
33+
# - name: Install Dependencies
34+
# run: |
35+
# sudo dnf update -y
36+
# sudo dnf clean packages -y
37+
# sudo dnf install -y wget git curl
38+
39+
- name: Execute Command
40+
run: |
41+
case "${{ github.event.inputs.command }}" in
42+
install-snp-on-the-host)
43+
echo "Installing SNP on the host..."
44+
wget https://raw.githubusercontent.com/LakshmiSaiHarika/sev-utils/Fedora-Latest-SNP-kernel-Upstream/tools/snp.sh
45+
chmod +x snp.sh
46+
./snp.sh setup-host
47+
echo "The host must be rebooted for changes to take effect."
48+
;;
49+
50+
reboot-host)
51+
echo "Rebooting the host..."
52+
sudo reboot
53+
;;
54+
55+
verify-snp-on-host)
56+
echo "Verifying SNP on the host..."
57+
if ! sudo dmesg | grep -i "SEV-SNP enabled" 2>&1 >/dev/null; then
58+
echo "SEV-SNP not enabled on the host."
59+
exit 1
60+
fi
61+
echo "SEV-SNP is enabled on the host."
62+
;;
63+
64+
test-sev-on-host)
65+
echo "Testing SEV on the host..."
66+
67+
# Give user access to /dev/sev to run cargo tests w/o permission issues
68+
sudo usermod -a -G kvm virtee
69+
sudo setfacl -m g:kvm:rw /dev/sev
70+
71+
git clone https://github.com/virtee/sev.git
72+
cd sev
73+
git fetch origin pull/${{ github.event.inputs.pr_number }}/head:${{ github.event.inputs.pr_branch }}
74+
git switch ${{ github.event.inputs.pr_branch }}
75+
source "${HOME}/.cargo/env" 2>/dev/null || true
76+
77+
if ! command -v rustc &> /dev/null; then
78+
echo "Installing Rust..."
79+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -sSf | sh -s -- -y
80+
source "${HOME}/.cargo/env" 2>/dev/null
81+
fi
82+
83+
cargo test -- --skip snp
84+
;;
85+
86+
test-sev-on-guest)
87+
echo "Testing SEV on the guest..."
88+
wget https://raw.githubusercontent.com/LakshmiSaiHarika/sev-utils/Fedora-Latest-SNP-kernel-Upstream/tools/snp.sh
89+
chmod +x snp.sh
90+
./snp.sh launch-guest
91+
92+
# SSH guest commands
93+
GUEST_SSH_KEY_PATH="${HOME}/snp/launch/snp-guest-key"
94+
if [ ! -f "${GUEST_SSH_KEY_PATH}" ]; then
95+
echo "SSH key not present, cannot verify guest SNP enabled."
96+
exit 1
97+
fi
98+
99+
ssh_guest_command() {
100+
command="$1"
101+
ssh -p 10022 -i "${GUEST_SSH_KEY_PATH}" -o "StrictHostKeyChecking no" -o "PasswordAuthentication=no" -o ConnectTimeout=1 amd@localhost "${command}"
102+
}
103+
104+
verify_snp_guest() {
105+
local snp_enabled=$(ssh_guest_command "sudo dmesg | grep 'Memory Encryption Features active:.*SEV-SNP'")
106+
if [[ -n "${snp_enabled}" ]]; then
107+
echo "SNP is Enabled"
108+
else
109+
echo "SNP is NOT Enabled"
110+
exit 1
111+
fi
112+
}
113+
114+
verify_snp_guest
115+
116+
# Install sev dependencies as a root user
117+
ssh_guest_command "sudo su - <<EOF
118+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -sSf | sh -s -- -y
119+
source "${HOME}/.cargo/env" 2>/dev/null
120+
sudo dnf install -y git gcc
121+
EOF"
122+
123+
# Clean up previous sev, clone and perform PR test on sev library as root user to fix OS permission denied issues
124+
ssh_guest_command "sudo su - <<EOF
125+
rm -rf ~/sev
126+
git clone https://github.com/virtee/sev.git
127+
cd ~/sev
128+
git fetch origin pull/${{ github.event.inputs.pr_number }}/head:${{ github.event.inputs.pr_branch }}
129+
git switch ${{ github.event.inputs.pr_branch }}
130+
cargo test
131+
EOF"
132+
;;
133+
134+
*)
135+
echo "Unsupported Command: [${{ github.event.inputs.command }}]"
136+
exit 1
137+
;;
138+
esac

0 commit comments

Comments
 (0)