Skip to content

Commit 063a239

Browse files
many: run nested tests for UC22
Backported from #153
1 parent d0fb6de commit 063a239

5 files changed

Lines changed: 83 additions & 38 deletions

File tree

.github/workflows/tests.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@ jobs:
2323
mkdir "${{ github.workspace }}"
2424
- uses: actions/checkout@v2
2525

26-
- name: Build snap
26+
- name: x86 build
2727
run: |
2828
spread -artifacts=./artifacts google-nested:tests/spread/build/
2929
find ./artifacts -type f -name "*.artifact" -exec cp {} "${{ github.workspace }}" \;
3030
31+
- name: arm64 build
32+
run: |
33+
spread-arm -artifacts=./artifacts google-nested-arm:tests/spread/build/
34+
find ./artifacts -type f -name "*.artifact" -exec cp {} "${{ github.workspace }}" \;
35+
3136
- uses: actions/upload-artifact@v2
3237
with:
3338
name: core-snap
@@ -94,6 +99,9 @@ jobs:
9499
- name: Build image
95100
working-directory: '${{ github.workspace }}'
96101
run: |
102+
PROJECT_PATH=$PWD/core-base
103+
# For os.query and others
104+
PATH=$PATH:$PROJECT_PATH/tests/lib/external/snapd-testing-tools/tools/
97105
. "core-base/tests/lib/prepare-utils.sh"
98106
99107
echo "************* INSTALLING DEPS *************"

spread.yaml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ project: core22
33
environment:
44
SETUPDIR: /home/core22
55
PROJECT_PATH: $SETUPDIR
6-
PATH: $PATH:$PROJECT_PATH/tests/bin
6+
PATH: $PATH:$PROJECT_PATH/tests/bin:$PROJECT_PATH/tests/lib/external/snapd-testing-tools/tools/
77
TESTSLIB: $PROJECT_PATH/tests/lib
88
SNAP_BRANCH: "edge" # stable/edge/beta
99
UC_VERSION: 22
@@ -16,13 +16,26 @@ backends:
1616
type: google
1717
key: '$(HOST: echo "$SPREAD_GOOGLE_KEY")'
1818
location: snapd-spread/us-east1-b
19-
plan: n2-standard-2
19+
plan: n2-standard-4
2020
halt-timeout: 2h
2121
systems:
2222
- ubuntu-22.04-64:
23+
workers: 4
2324
image: ubuntu-2204-64-virt-enabled
2425
storage: 20G
2526

27+
google-nested-arm:
28+
type: google
29+
key: '$(HOST: echo "$SPREAD_GOOGLE_KEY")'
30+
location: snapd-spread/us-central1-a
31+
plan: t2a-standard-4
32+
halt-timeout: 2h
33+
systems:
34+
- ubuntu-22.04-arm-64:
35+
workers: 4
36+
image: ubuntu-2204-arm-64-virt-enabled
37+
storage: 25G
38+
2639
qemu-nested:
2740
type: qemu
2841
# TODO:UC22: uc22 needs 2G or grub will not loopback the kernel snap
@@ -83,7 +96,7 @@ prepare: |
8396
unset REBOOT
8497
8598
warn-timeout: 40m
86-
kill-timeout: 50m
99+
kill-timeout: 60m
87100

88101
suites:
89102
tests/spread/build/:

tests/lib/nested.sh

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ execute_remote(){
1111

1212
wait_for_ssh(){
1313
local service_name="$1"
14-
retry=800
14+
retry=1800
1515
wait=1
1616
while ! execute_remote true; do
1717
if ! systemctl is-active "$service_name"; then
@@ -54,7 +54,7 @@ cleanup_nested_core_vm(){
5454
# remove the swtpm
5555
# TODO: we could just remove/reset the swtpm instead of removing the snap
5656
# wholesale
57-
snap remove swtpm-mvo
57+
snap remove test-snapd-swtpm
5858
fi
5959

6060
# delete the image file
@@ -74,13 +74,10 @@ start_nested_core_vm_unit(){
7474
cp "${SETUPDIR}/pc.img" "${IMAGE_FILE}"
7575

7676
# use only 2G of RAM for qemu-nested
77-
if [ "${SPREAD_BACKEND}" = "google-nested" ]; then
78-
# Do not enable SMP on GCE as it will cause boot issues. There is most likely
79-
# a bug in the combination of the kernel version used in GCE images, combined with
80-
# a new qemu version (v6) and OVMF
81-
# TODO try again to enable more cores in the future to see if it is fixed
77+
if [ "${SPREAD_BACKEND}" = "google-nested" ] ||
78+
[ "${SPREAD_BACKEND}" = "google-nested-arm" ]; then
8279
PARAM_MEM="-m 4096"
83-
PARAM_SMP="-smp 1"
80+
PARAM_SMP="-smp 4"
8481
elif [ "${SPREAD_BACKEND}" = "lxd-nested" ]; then
8582
PARAM_MEM="-m 4096"
8683
PARAM_SMP="-smp 2"
@@ -103,40 +100,55 @@ start_nested_core_vm_unit(){
103100
PARAM_SERIAL="-serial file:${WORK_DIR}/serial.log"
104101
PARAM_TPM=""
105102

106-
ATTR_KVM=""
107-
if [ "$ENABLE_KVM" = "true" ]; then
108-
ATTR_KVM=",accel=kvm"
109-
# CPU can be defined just when kvm is enabled
110-
PARAM_CPU="-cpu host"
111-
fi
112-
113103
# TODO: enable ms key booting for i.e. nightly edge jobs ?
114-
OVMF_CODE=""
115-
OVMF_VARS=""
104+
VMF_CODE=""
105+
VMF_VARS=""
116106
if [ "${ENABLE_SECURE_BOOT:-false}" = "true" ]; then
117-
OVMF_CODE=".secboot"
107+
VMF_CODE=".ms"
118108
fi
119109
if [ "${ENABLE_OVMF_SNAKEOIL:-false}" = "true" ]; then
120-
OVMF_VARS=".snakeoil"
110+
VMF_VARS=".snakeoil"
121111
fi
122112

123113
mkdir -p "${WORK_DIR}/image/"
124-
cp -f "/usr/share/OVMF/OVMF_VARS${OVMF_VARS}.fd" "${WORK_DIR}/image/OVMF_VARS${OVMF_VARS}.fd"
125-
PARAM_BIOS="-drive file=/usr/share/OVMF/OVMF_CODE${OVMF_CODE}.fd,if=pflash,format=raw,unit=0,readonly=on -drive file=${WORK_DIR}/image/OVMF_VARS${OVMF_VARS}.fd,if=pflash,format=raw"
126-
PARAM_MACHINE="-machine q35${ATTR_KVM} -global ICH9-LPC.disable_s3=1"
114+
if os.query is-pc-amd64; then
115+
ATTR_KVM=""
116+
if [ "$ENABLE_KVM" = "true" ]; then
117+
ATTR_KVM=",accel=kvm"
118+
# CPU can be defined just when kvm is enabled
119+
PARAM_CPU="-cpu host"
120+
fi
121+
QEMU_BIN=qemu-system-x86_64
122+
PARAM_MACHINE="-machine q35${ATTR_KVM} -global ICH9-LPC.disable_s3=1"
123+
PARAM_BIOS="-drive file=/usr/share/OVMF/OVMF_CODE${VMF_CODE}.fd,if=pflash,format=raw,unit=0,readonly=on -drive file=${WORK_DIR}/image/OVMF_VARS${VMF_VARS}.fd,if=pflash,format=raw"
124+
TPM_DEVICE=tpm-tis
125+
cp -f "/usr/share/OVMF/OVMF_VARS${VMF_VARS}.fd" "${WORK_DIR}/image/OVMF_VARS${VMF_VARS}.fd"
126+
elif os.query is-arm64; then
127+
# Assume arm64
128+
# Unfortunately gce does not offer kvm enabled arm64 VMs
129+
PARAM_CPU="-cpu cortex-a57"
130+
QEMU_BIN=qemu-system-aarch64
131+
PARAM_MACHINE="-machine virt"
132+
PARAM_BIOS="-drive file=/usr/share/AAVMF/AAVMF_CODE${VMF_CODE}.fd,if=pflash,format=raw,unit=0,readonly=on -drive file=${WORK_DIR}/image/AAVMF_VARS${VMF_VARS}.fd,if=pflash,format=raw"
133+
TPM_DEVICE=tpm-tis-device
134+
cp -f "/usr/share/AAVMF/AAVMF_VARS${VMF_VARS}.fd" "${WORK_DIR}/image/AAVMF_VARS${VMF_VARS}.fd"
135+
else
136+
printf "ERROR: unsupported archtecture\n"
137+
exit 1
138+
fi
127139

128-
# Unfortunately the swtpm-mvo snap does not work correctly in lxd container. It's not possible
140+
# Unfortunately the test-snapd-swtpm snap does not work correctly in lxd container. It's not possible
129141
# for the socket to come up due to being containerized.
130142
if [ "${ENABLE_TPM:-false}" = "true" ]; then
131-
TPMSOCK_PATH="/var/snap/swtpm-mvo/current/swtpm-sock"
143+
TPMSOCK_PATH="/var/snap/test-snapd-swtpm/current/swtpm-sock"
132144
if [ "${SPREAD_BACKEND}" = "lxd-nested" ]; then
133145
mkdir -p /tmp/qtpm
134146
swtpm socket --tpmstate dir=/tmp/qtpm --ctrl type=unixio,path=/tmp/qtpm/sock --tpm2 -d -t
135147
TPMSOCK_PATH="/tmp/qtpm/sock"
136-
elif ! snap list swtpm-mvo > /dev/null; then
137-
snap install swtpm-mvo --beta
148+
elif ! snap list test-snapd-swtpm > /dev/null; then
149+
snap install test-snapd-swtpm --beta
138150
retry=60
139-
while ! test -S /var/snap/swtpm-mvo/current/swtpm-sock; do
151+
while ! test -S /var/snap/test-snapd-swtpm/current/swtpm-sock; do
140152
retry=$(( retry - 1 ))
141153
if [ $retry -le 0 ]; then
142154
echo "Timed out waiting for the swtpm socket. Aborting!"
@@ -145,14 +157,15 @@ start_nested_core_vm_unit(){
145157
sleep 1
146158
done
147159
fi
148-
PARAM_TPM="-chardev socket,id=chrtpm,path=${TPMSOCK_PATH} -tpmdev emulator,id=tpm0,chardev=chrtpm -device tpm-tis,tpmdev=tpm0"
160+
PARAM_TPM="-chardev socket,id=chrtpm,path=${TPMSOCK_PATH} -tpmdev emulator,id=tpm0,chardev=chrtpm -device $TPM_DEVICE,tpmdev=tpm0"
149161
fi
150162

151163
PARAM_IMAGE="-drive file=${IMAGE_FILE},cache=none,format=raw,id=disk1,if=none -device virtio-blk-pci,drive=disk1,bootindex=1"
152164

153165
SVC_NAME="nested-vm-$(systemd-escape "${SPREAD_JOB:-unknown}")"
166+
# shellcheck disable=SC2086
154167
if ! systemd-run --service-type=simple --unit="${SVC_NAME}" -- \
155-
qemu-system-x86_64 \
168+
"$QEMU_BIN" \
156169
${PARAM_SMP} \
157170
${PARAM_CPU} \
158171
${PARAM_MEM} \

tests/lib/prepare-utils.sh

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
set -e
4-
set -x
4+
set -x
55

66
SSH_PORT=${SSH_PORT:-8022}
77
MON_PORT=${MON_PORT:-8888}
@@ -114,9 +114,20 @@ start_snapd_core_vm() {
114114
nested_wait_for_snap_command
115115
}
116116

117+
get_arch() {
118+
if os.query is-pc-amd64; then
119+
printf amd64
120+
elif os.query is-arm64; then
121+
printf arm64
122+
else
123+
printf "ERROR: unsupported archtecture\n"
124+
exit 1
125+
fi
126+
}
127+
117128
get_core_snap_name() {
118129
printf -v date '%(%Y%m%d)T' -1
119-
echo "core22_${date}_amd64.snap"
130+
echo "core22_${date}_$(get_arch).snap"
120131
}
121132

122133
install_core22_deps() {
@@ -141,7 +152,7 @@ download_core22_snaps() {
141152
local snap_branch="$1"
142153

143154
# get the model
144-
curl -o ubuntu-core-amd64-dangerous.model https://raw.githubusercontent.com/snapcore/models/master/ubuntu-core-22-amd64-dangerous.model
155+
curl -o ubuntu-core-dangerous.model https://raw.githubusercontent.com/snapcore/models/master/ubuntu-core-22-$(get_arch)-dangerous.model
145156

146157
# download neccessary images
147158
snap download pc-kernel --channel=22/${snap_branch} --basename=upstream-pc-kernel
@@ -209,5 +220,5 @@ build_core22_image() {
209220
--snap upstream-snapd.snap \
210221
--snap upstream-pc-kernel.snap \
211222
--snap upstream-pc-gadget.snap \
212-
ubuntu-core-amd64-dangerous.model
223+
ubuntu-core-dangerous.model
213224
}

tests/spread/main/basic/task.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ prepare: |
44
# for various utilities
55
. "$TESTSLIB/nested.sh"
66
7-
# Start the nested UC20 VM
7+
# Start the nested UC VM
88
start_nested_core_vm_unit
99
1010
# At this point we are able to SSH to the nested VM, so things probably worked

0 commit comments

Comments
 (0)