[lxc-devel] [lxd/master] Select random storage backend for the second LXD instance in tests.
albertodonato on Github
lxc-bot at linuxcontainers.org
Wed Apr 19 15:11:14 UTC 2017
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 556 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170419/cd147e4b/attachment.bin>
-------------- next part --------------
From 8cd09b02db766b507d6381b121986f4c98d1b6b4 Mon Sep 17 00:00:00 2001
From: Alberto Donato <alberto.donato at canonical.com>
Date: Wed, 19 Apr 2017 13:03:19 +0200
Subject: [PATCH] Select random storage backend for the second LXD instance in
tests.
Signed-off-by: Alberto Donato <alberto.donato at canonical.com>
---
test/README.md | 1 +
test/backends/btrfs.sh | 5 ---
test/backends/lvm.sh | 4 ---
test/backends/zfs.sh | 4 ---
test/main.sh | 69 ++++++++++++++++++++++++++++++++---------
test/suites/backup.sh | 2 +-
test/suites/basic.sh | 2 +-
test/suites/database_update.sh | 2 +-
test/suites/fdleak.sh | 2 +-
test/suites/init.sh | 8 ++---
test/suites/migration.sh | 17 ++++++----
test/suites/pki.sh | 2 +-
test/suites/profiling.sh | 4 +--
test/suites/security.sh | 2 +-
test/suites/serverconfig.sh | 2 +-
test/suites/storage.sh | 2 +-
test/suites/storage_profiles.sh | 2 +-
17 files changed, 82 insertions(+), 48 deletions(-)
mode change 100644 => 100755 test/backends/btrfs.sh
mode change 100644 => 100755 test/backends/lvm.sh
mode change 100644 => 100755 test/backends/zfs.sh
mode change 100644 => 100755 test/suites/backup.sh
mode change 100644 => 100755 test/suites/basic.sh
mode change 100644 => 100755 test/suites/database_update.sh
mode change 100644 => 100755 test/suites/fdleak.sh
mode change 100644 => 100755 test/suites/init.sh
mode change 100644 => 100755 test/suites/migration.sh
mode change 100644 => 100755 test/suites/pki.sh
mode change 100644 => 100755 test/suites/profiling.sh
mode change 100644 => 100755 test/suites/security.sh
mode change 100644 => 100755 test/suites/serverconfig.sh
mode change 100644 => 100755 test/suites/storage.sh
mode change 100644 => 100755 test/suites/storage_profiles.sh
diff --git a/test/README.md b/test/README.md
index d0357e7..89963bf 100644
--- a/test/README.md
+++ b/test/README.md
@@ -13,6 +13,7 @@ To run only the integration tests, run from the test directory:
Name | Default | Description
:-- | :--- | :----------
LXD\_BACKEND | dir | What backend to test against (btrfs, dir, lvm or zfs)
+LXD\_BACKEND2 | random | Backend to test against for the second LXD instance (used for migration tests)
LXD\_CONCURRENT | 0 | Run concurency tests, very CPU intensive
LXD\_DEBUG | 0 | Run lxd, lxc and the shell in debug mode (very verbose)
LXD\_INSPECT | 0 | Don't teardown the test environment on failure
diff --git a/test/backends/btrfs.sh b/test/backends/btrfs.sh
old mode 100644
new mode 100755
index 457dbd1..ffae1cc
--- a/test/backends/btrfs.sh
+++ b/test/backends/btrfs.sh
@@ -7,11 +7,6 @@ btrfs_setup() {
LXD_DIR=$1
echo "==> Setting up btrfs backend in ${LXD_DIR}"
-
- if ! which btrfs >/dev/null 2>&1; then
- echo "Couldn't find the btrfs binary"; false
- fi
-
}
btrfs_configure() {
diff --git a/test/backends/lvm.sh b/test/backends/lvm.sh
old mode 100644
new mode 100755
index 81ddf20..4c8ee9f
--- a/test/backends/lvm.sh
+++ b/test/backends/lvm.sh
@@ -7,10 +7,6 @@ lvm_setup() {
LXD_DIR=$1
echo "==> Setting up lvm backend in ${LXD_DIR}"
-
- if ! which lvm >/dev/null 2>&1; then
- echo "Couldn't find the lvm binary"; false
- fi
}
lvm_configure() {
diff --git a/test/backends/zfs.sh b/test/backends/zfs.sh
old mode 100644
new mode 100755
index aa40e22..52bd0a8
--- a/test/backends/zfs.sh
+++ b/test/backends/zfs.sh
@@ -7,10 +7,6 @@ zfs_setup() {
LXD_DIR=$1
echo "==> Setting up ZFS backend in ${LXD_DIR}"
-
- if ! which zfs >/dev/null 2>&1; then
- echo "Couldn't find zfs binary"; false
- fi
}
zfs_configure() {
diff --git a/test/main.sh b/test/main.sh
index 63564a0..8741e09 100755
--- a/test/main.sh
+++ b/test/main.sh
@@ -47,15 +47,54 @@ local_tcp_port() {
done
}
-# import all the backends
-for backend in backends/*.sh; do
- # shellcheck disable=SC1090
- . "${backend}"
-done
+# return a list of available storage backends
+available_storage_backends() {
+ # shellcheck disable=2039
+ local backend backends
+
+ backends="dir"
+ for backend in btrfs lvm zfs; do
+ if which $backend >/dev/null 2>&1; then
+ backends="$backends $backend"
+ fi
+ done
+ echo "$backends"
+}
+
+# whether a storage backend is available
+storage_backend_available() {
+ # shellcheck disable=2039
+ local backends
+ backends="$(available_storage_backends)"
+ [ "${backends#*$1}" != "$backends" ]
+}
+
+# choose a random available backend, excluding LXD_BACKEND
+random_backend() {
+ # shellcheck disable=2046
+ shuf -e $(available_storage_backends | sed "s/\b$LXD_BACKEND\b//") | head -n 1
+}
if [ -z "${LXD_BACKEND:-}" ]; then
LXD_BACKEND=dir
fi
+# a second storage backend for cross-backend tests
+if [ -z "${LXD2_BACKEND:-}" ]; then
+ LXD2_BACKEND="$(random_backend)"
+fi
+
+echo "==> Available storage backends: $(available_storage_backends | sort)"
+if ! storage_backend_available "$LXD_BACKEND"; then
+ echo "Storage backage \"$LXD_BACKEND\" is not available"
+ exit 1
+fi
+
+# import storage backends
+for backend in $(available_storage_backends); do
+ # shellcheck disable=SC1090
+ . "backends/${backend}.sh"
+done
+
spawn_lxd() {
set +x
@@ -63,12 +102,12 @@ spawn_lxd() {
# overwrites the environment and we would lose LXD_DIR's value otherwise.
# shellcheck disable=2039
- local LXD_DIR
+ local LXD_DIR lxddir lxd_backend
lxddir=${1}
shift
- storage=${1}
+ lxd_backend=${1:-none}
shift
# Copy pre generated Certs
@@ -76,7 +115,8 @@ spawn_lxd() {
cp deps/server.key "${lxddir}"
# setup storage
- "$LXD_BACKEND"_setup "${lxddir}"
+ "$lxd_backend"_setup "${lxddir}"
+ echo "$lxd_backend" > "${lxddir}/lxd.backend"
echo "==> Spawning lxd in ${lxddir}"
# shellcheck disable=SC2086
@@ -112,9 +152,9 @@ spawn_lxd() {
LXD_DIR="${lxddir}" lxc network attach-profile lxdbr0 default eth0
fi
- if [ "${storage}" = true ]; then
+ if [ "${lxd_backend}" != "none" ]; then
echo "==> Configuring storage backend"
- "$LXD_BACKEND"_configure "${lxddir}"
+ "$lxd_backend"_configure "${lxddir}"
fi
}
@@ -241,12 +281,13 @@ kill_lxd() {
# overwrites the environment and we would lose LXD_DIR's value otherwise.
# shellcheck disable=2039
- local LXD_DIR
+ local LXD_DIR daemon_dir daemon_pid check_leftovers lxd_backend
daemon_dir=${1}
LXD_DIR=${daemon_dir}
daemon_pid=$(cat "${daemon_dir}/lxd.pid")
check_leftovers="false"
+ lxd_backend=$(cat "${daemon_dir}/lxd.backend")
echo "==> Killing LXD at ${daemon_dir}"
if [ -e "${daemon_dir}/unix.socket" ]; then
@@ -339,7 +380,7 @@ kill_lxd() {
fi
# teardown storage
- "$LXD_BACKEND"_teardown "${daemon_dir}"
+ "$lxd_backend"_teardown "${daemon_dir}"
# Wipe the daemon directory
wipe "${daemon_dir}"
@@ -517,14 +558,14 @@ export LXD_CONF
LXD_DIR=$(mktemp -d -p "${TEST_DIR}" XXX)
export LXD_DIR
chmod +x "${LXD_DIR}"
-spawn_lxd "${LXD_DIR}" true
+spawn_lxd "${LXD_DIR}" "$LXD_BACKEND"
LXD_ADDR=$(cat "${LXD_DIR}/lxd.addr")
export LXD_ADDR
# Setup the second LXD
LXD2_DIR=$(mktemp -d -p "${TEST_DIR}" XXX)
chmod +x "${LXD2_DIR}"
-spawn_lxd "${LXD2_DIR}" true
+spawn_lxd "${LXD2_DIR}" "$LXD2_BACKEND"
LXD2_ADDR=$(cat "${LXD2_DIR}/lxd.addr")
export LXD2_ADDR
diff --git a/test/suites/backup.sh b/test/suites/backup.sh
old mode 100644
new mode 100755
index 0f3bd33..8c3fdfa
--- a/test/suites/backup.sh
+++ b/test/suites/backup.sh
@@ -5,7 +5,7 @@ test_container_import() {
LXD_IMPORT_DIR=$(mktemp -d -p "${TEST_DIR}" XXX)
chmod +x "${LXD_IMPORT_DIR}"
- spawn_lxd "${LXD_IMPORT_DIR}" true
+ spawn_lxd "${LXD_IMPORT_DIR}" "$LXD_BACKEND"
(
lxc init testimage ctImport
lxc snapshot ctImport
diff --git a/test/suites/basic.sh b/test/suites/basic.sh
old mode 100644
new mode 100755
index e3c89ee..b9b06e2
--- a/test/suites/basic.sh
+++ b/test/suites/basic.sh
@@ -218,7 +218,7 @@ test_basic_usage() {
# Test activateifneeded/shutdown
LXD_ACTIVATION_DIR=$(mktemp -d -p "${TEST_DIR}" XXX)
chmod +x "${LXD_ACTIVATION_DIR}"
- spawn_lxd "${LXD_ACTIVATION_DIR}" true
+ spawn_lxd "${LXD_ACTIVATION_DIR}" "$LXD_BACKEND"
(
set -e
# shellcheck disable=SC2030
diff --git a/test/suites/database_update.sh b/test/suites/database_update.sh
old mode 100644
new mode 100755
index 018492a..aa8ca5c
--- a/test/suites/database_update.sh
+++ b/test/suites/database_update.sh
@@ -8,7 +8,7 @@ test_database_update(){
sqlite3 "${MIGRATE_DB}" > /dev/null < deps/schema1.sql
# Start an LXD demon in the tmp directory. This should start the updates.
- spawn_lxd "${LXD_MIGRATE_DIR}" true
+ spawn_lxd "${LXD_MIGRATE_DIR}" "$LXD_BACKEND"
# Assert there are enough tables.
expected_tables=23
diff --git a/test/suites/fdleak.sh b/test/suites/fdleak.sh
old mode 100644
new mode 100755
index 78c518f..24d3e3c
--- a/test/suites/fdleak.sh
+++ b/test/suites/fdleak.sh
@@ -3,7 +3,7 @@
test_fdleak() {
LXD_FDLEAK_DIR=$(mktemp -d -p "${TEST_DIR}" XXX)
chmod +x "${LXD_FDLEAK_DIR}"
- spawn_lxd "${LXD_FDLEAK_DIR}" true
+ spawn_lxd "${LXD_FDLEAK_DIR}" "$LXD_BACKEND"
pid=$(cat "${LXD_FDLEAK_DIR}/lxd.pid")
beforefds=$(/bin/ls "/proc/${pid}/fd" | wc -l)
diff --git a/test/suites/init.sh b/test/suites/init.sh
old mode 100644
new mode 100755
index 1e06b9a..8ba65c9
--- a/test/suites/init.sh
+++ b/test/suites/init.sh
@@ -12,7 +12,7 @@ test_lxd_autoinit() {
# lxd init --auto --storage-backend zfs --storage-pool <name>
LXD_INIT_DIR=$(mktemp -d -p "${TEST_DIR}" XXX)
chmod +x "${LXD_INIT_DIR}"
- spawn_lxd "${LXD_INIT_DIR}" false
+ spawn_lxd "${LXD_INIT_DIR}" none
configure_loop_device loop_file_1 loop_device_1
# shellcheck disable=SC2154
@@ -25,7 +25,7 @@ test_lxd_autoinit() {
# lxd init --auto --storage-backend zfs --storage-pool <name>/<non-existing-dataset>
LXD_INIT_DIR=$(mktemp -d -p "${TEST_DIR}" XXX)
chmod +x "${LXD_INIT_DIR}"
- spawn_lxd "${LXD_INIT_DIR}" false
+ spawn_lxd "${LXD_INIT_DIR}" none
# shellcheck disable=SC2154
configure_loop_device loop_file_1 loop_device_1
@@ -37,7 +37,7 @@ test_lxd_autoinit() {
# lxd init --auto --storage-backend zfs --storage-pool <name>/<existing-dataset>
LXD_INIT_DIR=$(mktemp -d -p "${TEST_DIR}" XXX)
chmod +x "${LXD_INIT_DIR}"
- spawn_lxd "${LXD_INIT_DIR}" false
+ spawn_lxd "${LXD_INIT_DIR}" none
zfs create -p -o mountpoint=none "lxdtest-$(basename "${LXD_DIR}")-pool1-existing-pool/existing-dataset"
LXD_DIR=${LXD_INIT_DIR} lxd init --auto --storage-backend zfs --storage-pool "lxdtest-$(basename "${LXD_DIR}")-pool1-existing-pool/existing-dataset"
@@ -49,7 +49,7 @@ test_lxd_autoinit() {
# lxd init --storage-backend zfs --storage-create-loop 1 --storage-pool <name> --auto
LXD_INIT_DIR=$(mktemp -d -p "${TEST_DIR}" XXX)
chmod +x "${LXD_INIT_DIR}"
- spawn_lxd "${LXD_INIT_DIR}" false
+ spawn_lxd "${LXD_INIT_DIR}" none
ZFS_POOL="lxdtest-$(basename "${LXD_DIR}")-init"
LXD_DIR=${LXD_INIT_DIR} lxd init --storage-backend zfs --storage-create-loop 1 --storage-pool "${ZFS_POOL}" --auto
diff --git a/test/suites/migration.sh b/test/suites/migration.sh
old mode 100644
new mode 100755
index bb4041f..150a968
--- a/test/suites/migration.sh
+++ b/test/suites/migration.sh
@@ -15,19 +15,24 @@ test_migration() {
if [ "${LXD_BACKEND}" = "lvm" ]; then
# Test that non-thinpool lvm backends work fine with migration.
- lxc_remote storage create l1:"lxdtest-$(basename "${LXD_DIR}")-non-thinpool-lvm-migration" lvm lvm.use_thinpool=false volume.size=25MB
- lxc_remote profile device set l1:default root pool "lxdtest-$(basename "${LXD_DIR}")-non-thinpool-lvm-migration"
- lxc_remote storage create l2:"lxdtest-$(basename "${LXD2_DIR}")-non-thinpool-lvm-migration" lvm lvm.use_thinpool=false volume.size=25MB
- lxc_remote profile device set l2:default root pool "lxdtest-$(basename "${LXD2_DIR}")-non-thinpool-lvm-migration"
+ # shellcheck disable=2039
+ local storage_pool1 storage_pool2
+ storage_pool1="lxdtest-$(baasename "${LXD_DIR}")-non-thinpool-lvm-migration"
+ storage_pool2="lxdtest-$(basename "${LXD2_DIR}")-non-thinpool-lvm-migration"
+ lxc_remote storage create l1:"$storage_pool1" lvm lvm.use_thinpool=false volume.size=25MB
+ lxc_remote profile device set l1:default root pool "$storage_pool1"
+
+ lxc_remote storage create l2:"$storage_pool2" lvm lvm.use_thinpool=false volume.size=25MB
+ lxc_remote profile device set l2:default root pool "$storage_pool2"
migration
lxc_remote profile device set l1:default root pool "lxdtest-$(basename "${LXD_DIR}")"
lxc_remote profile device set l2:default root pool "lxdtest-$(basename "${LXD2_DIR}")"
- lxc_remote storage delete l1:"lxdtest-$(basename "${LXD_DIR}")-non-thinpool-lvm-migration"
- lxc_remote storage delete l2:"lxdtest-$(basename "${LXD2_DIR}")-non-thinpool-lvm-migration"
+ lxc_remote storage delete l1:"$storage_pool1"
+ lxc_remote storage delete l2:"$storage_pool2"
fi
}
diff --git a/test/suites/pki.sh b/test/suites/pki.sh
old mode 100644
new mode 100755
index aad7ee0..2276567
--- a/test/suites/pki.sh
+++ b/test/suites/pki.sh
@@ -26,7 +26,7 @@ test_pki() {
cat "${TEST_DIR}/pki/keys/127.0.0.1.crt" "${TEST_DIR}/pki/keys/ca.crt" > "${LXD5_DIR}/server.crt"
cp "${TEST_DIR}/pki/keys/127.0.0.1.key" "${LXD5_DIR}/server.key"
cp "${TEST_DIR}/pki/keys/ca.crt" "${LXD5_DIR}/server.ca"
- spawn_lxd "${LXD5_DIR}" true
+ spawn_lxd "${LXD5_DIR}" "$LXD_BACKEND"
LXD5_ADDR=$(cat "${LXD5_DIR}/lxd.addr")
# Setup the client
diff --git a/test/suites/profiling.sh b/test/suites/profiling.sh
old mode 100644
new mode 100755
index c9ee794..8d8c96e
--- a/test/suites/profiling.sh
+++ b/test/suites/profiling.sh
@@ -3,7 +3,7 @@
test_cpu_profiling() {
LXD3_DIR=$(mktemp -d -p "${TEST_DIR}" XXX)
chmod +x "${LXD3_DIR}"
- spawn_lxd "${LXD3_DIR}" false --cpuprofile "${LXD3_DIR}/cpu.out"
+ spawn_lxd "${LXD3_DIR}" none --cpuprofile "${LXD3_DIR}/cpu.out"
lxdpid=$(cat "${LXD3_DIR}/lxd.pid")
kill -TERM "${lxdpid}"
wait "${lxdpid}" || true
@@ -21,7 +21,7 @@ test_cpu_profiling() {
test_mem_profiling() {
LXD4_DIR=$(mktemp -d -p "${TEST_DIR}" XXX)
chmod +x "${LXD4_DIR}"
- spawn_lxd "${LXD4_DIR}" false --memprofile "${LXD4_DIR}/mem"
+ spawn_lxd "${LXD4_DIR}" none --memprofile "${LXD4_DIR}/mem"
lxdpid=$(cat "${LXD4_DIR}/lxd.pid")
if [ -e "${LXD4_DIR}/mem" ]; then
diff --git a/test/suites/security.sh b/test/suites/security.sh
old mode 100644
new mode 100755
index 3483b56..240f739
--- a/test/suites/security.sh
+++ b/test/suites/security.sh
@@ -8,7 +8,7 @@ test_security() {
if [ "${LXD_BACKEND}" = "zfs" ]; then
LXD_INIT_DIR=$(mktemp -d -p "${TEST_DIR}" XXX)
chmod +x "${LXD_INIT_DIR}"
- spawn_lxd "${LXD_INIT_DIR}" false
+ spawn_lxd "${LXD_INIT_DIR}" none
ZFS_POOL="lxdtest-$(basename "${LXD_DIR}")-init"
LXD_DIR=${LXD_INIT_DIR} lxd init --storage-backend zfs --storage-create-loop 1 --storage-pool "${ZFS_POOL}" --auto
diff --git a/test/suites/serverconfig.sh b/test/suites/serverconfig.sh
old mode 100644
new mode 100755
index 8a75e78..7453cac
--- a/test/suites/serverconfig.sh
+++ b/test/suites/serverconfig.sh
@@ -2,7 +2,7 @@
test_server_config() {
LXD_SERVERCONFIG_DIR=$(mktemp -d -p "${TEST_DIR}" XXX)
- spawn_lxd "${LXD_SERVERCONFIG_DIR}" true
+ spawn_lxd "${LXD_SERVERCONFIG_DIR}" "$LXD_BACKEND"
lxc config set core.trust_password 123456
diff --git a/test/suites/storage.sh b/test/suites/storage.sh
old mode 100644
new mode 100755
index 3ddcc72..198b47d
--- a/test/suites/storage.sh
+++ b/test/suites/storage.sh
@@ -5,7 +5,7 @@ test_storage() {
LXD_STORAGE_DIR=$(mktemp -d -p "${TEST_DIR}" XXXXXXXXX)
chmod +x "${LXD_STORAGE_DIR}"
- spawn_lxd "${LXD_STORAGE_DIR}" false
+ spawn_lxd "${LXD_STORAGE_DIR}" none
(
set -e
# shellcheck disable=2030
diff --git a/test/suites/storage_profiles.sh b/test/suites/storage_profiles.sh
old mode 100644
new mode 100755
index 9631b80..83939f1
--- a/test/suites/storage_profiles.sh
+++ b/test/suites/storage_profiles.sh
@@ -5,7 +5,7 @@ test_storage_profiles() {
LXD_STORAGE_DIR=$(mktemp -d -p "${TEST_DIR}" XXXXXXXXX)
chmod +x "${LXD_STORAGE_DIR}"
- spawn_lxd "${LXD_STORAGE_DIR}" false
+ spawn_lxd "${LXD_STORAGE_DIR}" none
(
set -e
# shellcheck disable=2030
More information about the lxc-devel
mailing list