Skip to content

Commit

Permalink
Merge pull request #34 from simondeziel/shellcheck
Browse files Browse the repository at this point in the history
Make tests shellcheck clean
  • Loading branch information
tomponline authored Oct 23, 2023
2 parents e67c205 + e2d3500 commit 326bba0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
2 changes: 1 addition & 1 deletion tests/pylxd
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ waitSnapdSeed

# Install LXD
snap remove lxd || true
snap install lxd --channel=${channel}
snap install lxd --channel="${channel}"
lxd waitready --timeout=300

# Run the pylxd tests
Expand Down
50 changes: 24 additions & 26 deletions tests/vm_nesting.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,59 +46,57 @@ instanceImage="ubuntu:22.04"
snapChannel="latest/edge"

function parallel() {
seq 1 $1 | xargs -P $1 -I "{}" "${@:2}"
seq "$1" | xargs -P "$1" -I "{}" "${@:2}"
}

function init() {
vm="${2:-}"
if [ -z "${vm}" ]
then
parallel $1 lxc init "${instanceImage}" "t{}" -s default -n lxdbr0
else
parallel $1 lxc init "${instanceImage}" "t{}" "${vm}" -s default -n lxdbr0
fi
vm="${2:-}"
if [ -z "${vm}" ]
then
parallel "$1" lxc init "${instanceImage}" "t{}" -s default -n lxdbr0
else
parallel "$1" lxc init "${instanceImage}" "t{}" "${vm}" -s default -n lxdbr0
fi
}

function conf() {
parallel $1 lxc config set "t{}" $2
parallel "$1" lxc config set "t{}" "$2"
}

function device_add() {
parallel $1 lxc config device add "t{}" $2 $3 $4
parallel "$1" lxc config device add "t{}" "$2" "$3" "$4"
}

function start() {
args=""

for i in $(seq 1 $1); do
args="t$i $args"
instances=()
for i in $(seq "$1"); do
instances["$i"]="t$i"
done

echo "Start $args"
lxc start $args
echo "Start ${instances[*]}"
lxc start -f "${instances[@]}"
}

function wait() {
parallel $1 bash -c "while true; do if lxc shell t{}; then break; fi; sleep 1; done"
parallel "$1" bash -c "while true; do if lxc shell t{}; then break; fi; sleep 1; done"
}

function copy() {
parallel $1 lxc file push $2 "t{}$3"
parallel "$1" lxc file push "$2" "t{}$3"
}

function cmd() {
parallel $1 lxc exec "t{}" -- bash -c "$2"
parallel "$1" lxc exec "t{}" -- bash -c "$2"
}

function delete() {
args=""

for i in $(seq 1 $1); do
args="t$i $args"
done
instances=()
for i in $(seq "$1"); do
instances["$i"]="t$i"
done

echo "Delete $args"
lxc delete -f $args
echo "Delete ${instances[*]}"
lxc delete -f "${instances[@]}"
}

# Test 10 VMs in parallel.
Expand Down

0 comments on commit 326bba0

Please sign in to comment.