-
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 #37 from simondeziel/helper-functions
Helper functions
- Loading branch information
Showing
10 changed files
with
218 additions
and
269 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,82 @@ | ||
|
||
# waitSnapdSeed: wait for snapd to be seeded. | ||
waitSnapdSeed() ( | ||
set +x | ||
for i in $(seq 60); do # Wait up to 60s. | ||
if systemctl show snapd.seeded.service --value --property SubState | grep -qx exited; then | ||
return 0 # Success. | ||
fi | ||
|
||
sleep 1 | ||
done | ||
|
||
echo "snapd not seeded after ${i}s" | ||
return 1 # Failed. | ||
) | ||
|
||
# waitVMAgent: waits for the VM agent to be running. | ||
waitVMAgent() ( | ||
set +x | ||
vmName="${1}" | ||
for i in $(seq 90); do | ||
if lxc info "${vmName}" | grep -qF 127.0.0.1; then | ||
return 0 # Success. | ||
fi | ||
|
||
sleep 1 | ||
done | ||
|
||
echo "VM ${vmName} agent not running after ${i}s" | ||
return 1 # Failed. | ||
) | ||
|
||
|
||
# install_lxd: install LXD from a specific channel or `latest/edge` if none is provided. | ||
install_lxd() ( | ||
# Wait for snapd seeding | ||
waitSnapdSeed | ||
|
||
snap remove lxd || true | ||
snap install lxd --channel="${LXD_SNAP_CHANNEL:-"latest/edge"}" | ||
snap list lxd | ||
lxd waitready --timeout=300 | ||
) | ||
|
||
# hasNeededAPIExtension: check if LXD supports the needed extension. | ||
hasNeededAPIExtension() ( | ||
needed_extension="${1}" | ||
|
||
lxc info | sed -ne '/^api_extensions:/,/^[^-]/ s/^- //p' | grep -qxF "${needed_extension}" | ||
) | ||
|
||
# runsMinimumKernel: check if the running kernel is at least the minimum version. | ||
runsMinimumKernel() ( | ||
min_version="${1}" | ||
min_major="$(echo "${min_version}" | cut -d. -f1)" | ||
min_minor="$(echo "${min_version}" | cut -d. -f2)" | ||
running_version="$(uname -r | cut -d. -f 1,2)" | ||
running_major="$(echo "${running_version}" | cut -d. -f1)" | ||
running_minor="$(echo "${running_version}" | cut -d. -f2)" | ||
|
||
if [ "${running_major}" -lt "${min_major}" ]; then | ||
return 1 | ||
elif [ "${running_major}" -eq "${min_major}" ] && [ "${running_minor}" -lt "${min_minor}" ]; then | ||
return 1 | ||
fi | ||
return 0 | ||
) | ||
|
||
# cleanup: report if the test passed or not and return the appropriate return code. | ||
cleanup() { | ||
echo "" | ||
if [ "${FAIL}" = "1" ]; then | ||
echo "Test failed" | ||
exit 1 | ||
fi | ||
|
||
echo "Test passed" | ||
exit 0 | ||
} | ||
|
||
FAIL=1 | ||
trap cleanup EXIT HUP INT TERM |
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
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
Oops, something went wrong.