Skip to content

Commit

Permalink
Rationalise lxd tests to call vm tests
Browse files Browse the repository at this point in the history
This rationalises the run-integration-tests-in-lxd to just set up the
containers for lxd and then run the 'run-integration-tests' in the lxd
container.

As a bonus, we can run both bionic and xenial lxd containers and run the
integration tests for both platforms.

Signed-off-by: Alex Kavanagh <[email protected]>
  • Loading branch information
ajkavanagh committed Sep 21, 2018
1 parent 4f3c4df commit 4200d34
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 47 deletions.
File renamed without changes.
66 changes: 19 additions & 47 deletions integration/run-integration-tests-in-lxd
Original file line number Diff line number Diff line change
Expand Up @@ -12,64 +12,36 @@
set -ex

_dir="$( cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd)"
_release=$(lsb_release -cs)

if [[ "${_release}" == "bionic" ]]; then
echo "Running Bionic (18:04) integration tests"
CONTAINER_IMAGE="ubuntu:18.04"
function _run_tests {
local _target=${1}
CONTAINER_NAME=pylxd-`uuidgen | cut -d"-" -f1`

# This creates a privileged container, because I was bumping into situations where it
# seemed that we had maxed out user namespaces (I haven't checked it out, but it's likely
# a bug in LXD).
lxc launch $CONTAINER_IMAGE $CONTAINER_NAME -c security.nesting=true -c security.privileged=true
sleep 5 # Wait for the network to come up
lxc exec $CONTAINER_NAME -- apt-get update
lxc exec $CONTAINER_NAME -- apt-get install -y tox python3-dev libssl-dev libffi-dev build-essential

lxc exec $CONTAINER_NAME -- lxc config set core.trust_password password
lxc exec $CONTAINER_NAME -- lxc config set core.https_address [::]
# force generation of client certificate to an address that doesn't work (http)
# generate an openssl certificate and key for the remote not verified test
lxc exec $CONTAINER_NAME -- mkdir -p /root/.config/lxc
openssl genrsa 1024 > ./$CONTAINER_NAME.key
lxc file push ./$CONTAINER_NAME.key $CONTAINER_NAME/root/.config/lxc/client.key
rm ./$CONTAINER_NAME.key
lxc exec $CONTAINER_NAME -- chmod 400 /root/.config/lxc/client.key
lxc exec $CONTAINER_NAME -- openssl req -new -x509 -nodes -sha1 -days 365 \
-key /root/.config/lxc/client.key -out /root/.config/lxc/client.crt \
-subj="/C=UK/ST=London/L=London/O=OrgName/OU=Test/CN=example.com"

# create a default dir storage pool for bionic
lxc exec $CONTAINER_NAME -- lxc storage create default dir
lxc exec $CONTAINER_NAME -- lxc profile device add default root disk path=/ pool=default

lxc exec $CONTAINER_NAME -- mkdir -p /opt/pylxd
# NOTE: rockstar (13 Sep 2016) - --recursive is not supported in lxd <2.1, so
# until we have pervasive support for that, we'll do this tar hack.
cd .. && tar cf - * .git | lxc exec $CONTAINER_NAME -- tar xf - -C /opt/pylxd
lxc exec $CONTAINER_NAME -- /bin/sh -c "cd /opt/pylxd && tox -eintegration"
lxc delete --force $CONTAINER_NAME
else
echo "Running Xenial (16:04) integration tests"
CONTAINER_IMAGE="ubuntu:16.04"
CONTAINER_NAME=pylxd-`uuidgen | cut -d"-" -f1`
if [[ "${_target}" == "bionic" ]]; then
echo "Running Bionic (18:04) integration tests"
CONTAINER_IMAGE="ubuntu:18.04"
else
echo "Running Xenial (16:04) integration tests"
CONTAINER_IMAGE="ubuntu:16.04"
fi

# This creates a privileged container, because I was bumping into situations where it
# seemed that we had maxed out user namespaces (I haven't checked it out, but it's likely
# a bug in LXD).
lxc launch $CONTAINER_IMAGE $CONTAINER_NAME -c security.nesting=true -c security.privileged=true
sleep 5 # Wait for the network to come up
lxc exec $CONTAINER_NAME -- apt-get update
lxc exec $CONTAINER_NAME -- apt-get install -y tox python3-dev libssl-dev libffi-dev build-essential

lxc exec $CONTAINER_NAME -- lxc config set core.trust_password password
lxc exec $CONTAINER_NAME -- lxc config set core.https_address [::]

lxc exec $CONTAINER_NAME -- mkdir -p /opt/pylxd
# NOTE: rockstar (13 Sep 2016) - --recursive is not supported in lxd <2.1, so
# until we have pervasive support for that, we'll do this tar hack.
cd .. && tar cf - ../* ../.git | lxc exec $CONTAINER_NAME -- tar xf - -C /opt/pylxd
lxc exec $CONTAINER_NAME -- /bin/sh -c "cd /opt/pylxd && tox -eintegration"
local ldir="${_dir}/.."
cd ${ldir} && tar cf - * .git | lxc exec $CONTAINER_NAME -- tar xf - -C /opt/pylxd
cd ${_dir}
lxc exec $CONTAINER_NAME -- /bin/sh -c "cd /opt/pylxd && integration/run-integration-tests"

lxc delete --force $CONTAINER_NAME
fi
}

# run xenial and then bionic integration tests
_run_tests xenial
_run_tests bionic

0 comments on commit 4200d34

Please sign in to comment.