-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #243 from mihalicyn/qemu-ext-snap-tests
Qemu external snap test
- Loading branch information
Showing
2 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/bin/sh | ||
set -eux | ||
|
||
architecture="$(uname -m)" | ||
if [ "${architecture}" != "x86_64" ]; then | ||
echo "Skipping test on ${architecture}" | ||
# shellcheck disable=SC2034 | ||
FAIL=0 | ||
exit 0 | ||
fi | ||
|
||
if ! echo "${LXD_SNAP_CHANNEL}" | grep -q '^latest/edge'; then | ||
echo "Skipping test as should only run on latest/edge" | ||
# shellcheck disable=SC2034 | ||
FAIL=0 | ||
exit 0 | ||
fi | ||
|
||
# Install LXD | ||
install_lxd | ||
|
||
# Configure LXD | ||
lxd init --auto | ||
|
||
# Get the source | ||
git clone --depth=1 "https://github.com/canonical/lxd-pkg-snap.git" -b "latest-edge" | ||
|
||
# Build qemu-for-lxd snap | ||
cd lxd-pkg-snap/lxd-qemu-snap | ||
|
||
CACHE_PATH="/home/runner/work/cache" | ||
mkdir "${CACHE_PATH}" || true | ||
|
||
# debug | ||
ls -la "${CACHE_PATH}/" | ||
|
||
LXD_QEMU_SNAP_FILE_NAME="qemu-for-lxd_1_amd64.snap" | ||
LXD_QEMU_SNAP_HASHSUM_FILE_PATH="${CACHE_PATH}/${LXD_QEMU_SNAP_FILE_NAME}.source-hash" | ||
LXD_QEMU_SNAP_CACHED_HASH_SUM="" | ||
[ -e "${LXD_QEMU_SNAP_HASHSUM_FILE_PATH}" ] && LXD_QEMU_SNAP_CACHED_HASH_SUM=$(cat "${LXD_QEMU_SNAP_HASHSUM_FILE_PATH}") | ||
LXD_QEMU_SNAP_HASH_SUM=$(find . -type f -print0 | sort -z | xargs -0 sha256sum | sha256sum | awk '{ print $1 }') | ||
|
||
if [ "${LXD_QEMU_SNAP_CACHED_HASH_SUM}" != "${LXD_QEMU_SNAP_HASH_SUM}" ]; then | ||
echo "==> Hash is changed (${LXD_QEMU_SNAP_CACHED_HASH_SUM} != ${LXD_QEMU_SNAP_HASH_SUM}). Rebuild is needed." | ||
|
||
# Install snapcraft | ||
snap install snapcraft --classic | ||
|
||
snapcraft # this should produce a qemu-for-lxd_1_amd64.snap file | ||
|
||
# save to cache | ||
mv "${LXD_QEMU_SNAP_FILE_NAME}" "${CACHE_PATH}/" | ||
echo "${LXD_QEMU_SNAP_HASH_SUM}" > "${LXD_QEMU_SNAP_HASHSUM_FILE_PATH}" | ||
fi | ||
|
||
SNAP_TO_INSTALL_PATH="${CACHE_PATH}/${LXD_QEMU_SNAP_FILE_NAME}" | ||
|
||
# debug | ||
ls -la "${CACHE_PATH}/" | ||
|
||
snap install "${SNAP_TO_INSTALL_PATH}" --dangerous | ||
|
||
# install gpu-2404 interface snap | ||
snap install mesa-2404 | ||
|
||
# connect snaps | ||
snap connect lxd:gpu-2404 mesa-2404:gpu-2404 | ||
snap connect lxd:qemu-external qemu-for-lxd:qemu-external | ||
|
||
# let LXD to reload | ||
sleep 5 | ||
lxd waitready --timeout=300 | ||
|
||
# check that qemu-external connect hook works properly | ||
journalctl --quiet --no-hostname --no-pager --boot=0 --unit=snap.lxd.daemon.service | grep "Setting up external QEMU snap integration" | ||
|
||
# check that qemu instance driver is activated and is in "external" mode | ||
lxc query /1.0 | jq '.environment.driver' | grep "qemu" | ||
lxc query /1.0 | jq '.environment.driver_version' | grep "(external)" | ||
|
||
# check that connection with mesa-2404 snap works | ||
serverPID="$(lxc query /1.0 | jq .environment.server_pid)" | ||
grep -aF LIBGL_DRIVERS "/proc/${serverPID}/environ" | ||
|
||
# shellcheck disable=SC2034 | ||
FAIL=0 |