-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: run the tests in travis using LXD containers (#1415)
- Loading branch information
1 parent
5d5d8f2
commit 8c9a38c
Showing
5 changed files
with
166 additions
and
12 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,55 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright (C) 2017 Canonical Ltd | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License version 3 as | ||
# published by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
# Start a lxc container to run jobs in travis. | ||
# Arguments: | ||
# name: The name of the container. | ||
|
||
set -ev | ||
|
||
if [ "$#" -lt 1 ]; then | ||
echo "Usage: "$0" <name>" | ||
exit 1 | ||
fi | ||
|
||
script_path="$(dirname "$0")" | ||
project_path="$(readlink -f "$script_path/../..")" | ||
name="$1" | ||
|
||
lxc="/snap/bin/lxc" | ||
|
||
echo "Start the LXC container." | ||
$lxc launch --ephemeral ubuntu:xenial "$name" | ||
# This is likely needed to wait for systemd in the container to start and get | ||
# an IP, configure DNS. First boot is always a bit slow because cloud-init | ||
# needs to run too. | ||
$lxc exec "$name" -- sh -c "for i in {1..50}; do ping -c1 www.ubuntu.com &> /dev/null && break; done" | ||
sleep 5 | ||
|
||
$lxc config set "$name" environment.TRAVIS_COMMIT_RANGE "$TRAVIS_COMMIT_RANGE" | ||
$lxc config set "$name" environment.TEST_USER_EMAIL "$TEST_USER_EMAIL" | ||
$lxc config set "$name" environment.TEST_USER_PASSWORD "$TEST_USER_PASSWORD" | ||
$lxc config set "$name" environment.TEST_STORE "$TEST_STORE" | ||
$lxc config set "$name" environment.TEST_SNAP_WITH_TRACKS "$TEST_SNAP_WITH_TRACKS" | ||
$lxc config set "$name" environment.GITHUB_TEST_USER_NAME "$GITHUB_TEST_USER_NAME" | ||
$lxc config set "$name" environment.GITHUB_TEST_PASSWORD "$GITHUB_TEST_PASSWORD" | ||
$lxc config set "$name" environment.SNAPCRAFT_AUTOPKGTEST_SECRET "$SNAPCRAFT_AUTOPKGTEST_SECRET" | ||
$lxc config set "$name" environment.SNAPCRAFT_TEST_MOCK_MACHINE "$SNAPCRAFT_TEST_MOCK_MACHINE" | ||
$lxc config set "$name" environment.GH_TOKEN "$GH_TOKEN" | ||
$lxc config set "$name" environment.CODECOV_TOKEN "$CODECOV_TOKEN" | ||
$lxc config set "$name" environment.LC_ALL "C.UTF-8" | ||
|
||
$lxc exec "$name" -- apt update |
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,55 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright (C) 2017 Canonical Ltd | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License version 3 as | ||
# published by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
# Start a LXD container to run jobs in travis. | ||
# Arguments: | ||
# name: The name of the container. | ||
|
||
set -ev | ||
|
||
if [ "$#" -lt 1 ]; then | ||
echo "Usage: "$0" <name>" | ||
exit 1 | ||
fi | ||
|
||
script_path="$(dirname "$0")" | ||
project_path="$(readlink -f "$script_path/../..")" | ||
name="$1" | ||
|
||
lxc="/snap/bin/lxc" | ||
|
||
echo "Starting the LXD container." | ||
$lxc launch --ephemeral ubuntu:xenial "$name" | ||
# This is likely needed to wait for systemd in the container to start and get | ||
# an IP, configure DNS. First boot is always a bit slow because cloud-init | ||
# needs to run too. | ||
$lxc exec "$name" -- sh -c "for i in {1..50}; do ping -c1 www.ubuntu.com &> /dev/null && break; done" | ||
sleep 5 | ||
|
||
$lxc config set "$name" environment.TRAVIS_COMMIT_RANGE "$TRAVIS_COMMIT_RANGE" | ||
$lxc config set "$name" environment.TEST_USER_EMAIL "$TEST_USER_EMAIL" | ||
$lxc config set "$name" environment.TEST_USER_PASSWORD "$TEST_USER_PASSWORD" | ||
$lxc config set "$name" environment.TEST_STORE "$TEST_STORE" | ||
$lxc config set "$name" environment.TEST_SNAP_WITH_TRACKS "$TEST_SNAP_WITH_TRACKS" | ||
$lxc config set "$name" environment.GITHUB_TEST_USER_NAME "$GITHUB_TEST_USER_NAME" | ||
$lxc config set "$name" environment.GITHUB_TEST_PASSWORD "$GITHUB_TEST_PASSWORD" | ||
$lxc config set "$name" environment.SNAPCRAFT_AUTOPKGTEST_SECRET "$SNAPCRAFT_AUTOPKGTEST_SECRET" | ||
$lxc config set "$name" environment.SNAPCRAFT_TEST_MOCK_MACHINE "$SNAPCRAFT_TEST_MOCK_MACHINE" | ||
$lxc config set "$name" environment.GH_TOKEN "$GH_TOKEN" | ||
$lxc config set "$name" environment.CODECOV_TOKEN "$CODECOV_TOKEN" | ||
$lxc config set "$name" environment.LC_ALL "C.UTF-8" | ||
|
||
$lxc exec "$name" -- apt update |
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,38 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright (C) 2017 Canonical Ltd | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License version 3 as | ||
# published by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
# Set up LXD in travis. | ||
|
||
set -ev | ||
|
||
apt-get update | ||
apt-get install --yes snapd | ||
# Use edge because the feature to copy links to the container has not yet been | ||
# released to stable: | ||
# https://github.com/lxc/lxd/commit/004e7c361e1d914795d3ba7582654622e32ff193 | ||
snap install lxd --edge | ||
# Wait while LXD first generates its keys. In a low entropy environment this | ||
# can take a while. | ||
|
||
# From LXD's CI. | ||
# shellcheck disable=SC2034 | ||
for i in $(seq 12); do | ||
lxd waitready --timeout=10 >/dev/null 2>&1 && break | ||
done | ||
|
||
/snap/bin/lxd init --auto | ||
/snap/bin/lxc network create testbr0 | ||
/snap/bin/lxc network attach-profile testbr0 default eth0 |