Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: support running spread suite in autopkgtests #2188

Merged
merged 12 commits into from
Aug 9, 2018
Merged
24 changes: 18 additions & 6 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,30 @@ For manual exploratory testing, the team has one mac machine available.

Autopkgtests are tests for the project packaged as a deb. The unit tests are run during autopkgtests while the snapcraft deb is being built. Then the resulting deb is installed, and the integration and snaps suites are executed using the installed snapcraft.

To run them locally, the easiest way is to use a LXC container. Note however that snaps in LXC need squashfuse installed, which we need to do via the `--setup-commands` option. From the root of the project, run:

### How to run on Xenial

The easiest way is to use a LXC container. From the root of the project, run:

sudo apt install autopkgtest
adt-run --unbuilt-tree . --apt-upgrade --setup-commands="apt install squashfuse -y" --- lxd ubuntu:xenial
adt-run --unbuilt-tree . --apt-upgrade --- lxd ubuntu:xenial

It's possible to select only one of the suites using `--testname`, for example:

adt-run --unbuilt-tree . --apt-upgrade --testname=integrationtests --- lxd ubuntu:xenial

It's possible to select only one of the suites, with:

adt-run --unbuilt-tree . --apt-upgrade --setup-commands="apt install squashfuse -y" --testname=integrationtests --- lxd ubuntu:xenial
### How to run on Bionic

The easiest way is to use a LXC container. From the root of the project, run:

sudo apt install autopkgtest
autopkgtest . -U -- lxd ubuntu:xenial
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

autopkgtest instead of adt becuase the name changed in the archive?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, there is no adt-run now.


It's possible to select only one of the suites using `--test-name`, for example:

or:
autopkgtest . -U --test-name=integrationtests-spread -- lxd ubuntu:xenial

adt-run --unbuilt-tree . --apt-upgrade --setup-commands="apt install squashfuse -y" --testname=snapstests --- lxd ubuntu:xenial

## Spread tests for the snapcraft snap

Expand Down
5 changes: 4 additions & 1 deletion debian/tests/control
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ Tests: integrationtests-general,
integrationtests-plugins-java,
integrationtests-plugins-catkin,
integrationtests-snapd,
integrationtests-snapd-slow
integrationtests-snapd-slow,
integrationtests-spread
Restrictions: needs-root, allow-stderr, isolation-container, rw-build-tree
Depends: @,
bzr,
gcc,
git,
curl,
mercurial,
subversion,
libc6-dev,
lxd,
snapd (>= 2.15~),
squashfuse,
Expand Down
45 changes: 45 additions & 0 deletions debian/tests/integrationtests-spread
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/sh

set -ex

# required for the debian adt host
mkdir -p /etc/systemd/system/snapd.service.d/
if [ "${http_proxy:-}" != "" ]; then
cat <<-EOF | tee /etc/systemd/system/snapd.service.d/proxy.conf
[Service]
Environment=http_proxy=$http_proxy
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this be a harmless unit if $http_proxy is not defined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wouldn't be defined at all (see the if statement above).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duh, I completely missed that; my suggestion was going to be to gate it just like you did!

Environment=https_proxy=$http_proxy
EOF

# ensure environment is updated
echo "http_proxy=$http_proxy" >> /etc/environment
echo "https_proxy=$http_proxy" >> /etc/environment
fi
systemctl daemon-reload

# ensure we are not killed too easily
printf '%s\n' "-950" > /proc/$$/oom_score_adj || true

# see what mem we have (for debugging)
cat /proc/meminfo

# ensure we can do a connect to localhost
echo ubuntu:ubuntu | chpasswd
sed -i 's/\(PermitRootLogin\|PasswordAuthentication\)\>.*/\1 yes/' /etc/ssh/sshd_config
systemctl reload sshd.service

# Spread will only build with recent go
snap install --classic go

# and now run spread against localhost
# shellcheck disable=SC1091
. /etc/os-release
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe "source" instead of "."?

Copy link
Contributor Author

@kyrofa kyrofa Aug 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

source is a bashism, this is using dash.

export GOPATH=/tmp/go
/snap/bin/go get -u github.com/snapcore/spread/cmd/spread

export SNAPCRAFT_PACKAGE_TYPE="deb"
/tmp/go/bin/spread -v "autopkgtest:${ID}-${VERSION_ID}-$(dpkg --print-architecture)"

# store journal info for inspection
journalctl --sync
journalctl -ab > "$ADT_ARTIFACTS/journal.txt"
118 changes: 107 additions & 11 deletions spread.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ environment:
# FIXME: This variable is only used by the spread_tests/ suite.
SNAPCRAFT_FROM_SNAP: "1"

# If this variable is defined, spread will install snapcraft from that
# channel. Otherwise, it'll look for a snap in the source tree.
# This variable can be set to either "deb" or "snap". It defaults to "snap".
SNAPCRAFT_PACKAGE_TYPE: "$(HOST: echo ${SNAPCRAFT_PACKAGE_TYPE:-snap})"

# If SNAPCRAFT_PACKAGE_TYPE is "snap" and this variable is defined, spread
# will install snapcraft from that channel. Otherwise, it'll look for a snap
# in the source tree. If SNAPCRAFT_PACKAGE_TYPE is "deb" this variable does
# nothing.
SNAPCRAFT_CHANNEL: "$(HOST: echo ${SNAPCRAFT_CHANNEL})"

SETUP_DIR: /snapcraft/tests/spread/setup
Expand Down Expand Up @@ -34,6 +39,89 @@ backends:
workers: 2
- ubuntu-18.04-64:
workers: 2
autopkgtest:
type: adhoc
allocate: |
echo "Allocating ad-hoc $SPREAD_SYSTEM"
if [ -z "${ADT_ARTIFACTS}" ]; then
FATAL "adhoc only works inside autopkgtest"
exit 1
fi
echo 'ubuntu ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/99-spread-users
ADDRESS localhost:22
discard: echo "Discarding ad-hoc $SPREAD_SYSTEM"
systems:
# No Trusty systems since the deb doesn't exist there
# Xenial
- ubuntu-16.04-amd64:
username: ubuntu
password: ubuntu
- ubuntu-16.04-i386:
username: ubuntu
password: ubuntu
- ubuntu-16.04-ppc64el:
username: ubuntu
password: ubuntu
- ubuntu-16.04-armhf:
username: ubuntu
password: ubuntu
- ubuntu-16.04-s390x:
username: ubuntu
password: ubuntu
# Artful
- ubuntu-17.10-amd64:
username: ubuntu
password: ubuntu
- ubuntu-17.10-i386:
username: ubuntu
password: ubuntu
- ubuntu-17.10-ppc64el:
username: ubuntu
password: ubuntu
- ubuntu-17.10-armhf:
username: ubuntu
password: ubuntu
- ubuntu-17.10-s390x:
username: ubuntu
password: ubuntu
# Bionic
- ubuntu-18.04-amd64:
username: ubuntu
password: ubuntu
- ubuntu-18.04-i386:
username: ubuntu
password: ubuntu
- ubuntu-18.04-ppc64el:
username: ubuntu
password: ubuntu
- ubuntu-18.04-armhf:
username: ubuntu
password: ubuntu
- ubuntu-18.04-s390x:
username: ubuntu
password: ubuntu
- ubuntu-18.04-arm64:
username: ubuntu
password: ubuntu
# Cosmic
- ubuntu-18.10-amd64:
username: ubuntu
password: ubuntu
- ubuntu-18.10-i386:
username: ubuntu
password: ubuntu
- ubuntu-18.10-ppc64el:
username: ubuntu
password: ubuntu
- ubuntu-18.10-armhf:
username: ubuntu
password: ubuntu
- ubuntu-18.10-s390x:
username: ubuntu
password: ubuntu
- ubuntu-18.10-arm64:
username: ubuntu
password: ubuntu

exclude: [snaps-cache/]

Expand Down Expand Up @@ -66,18 +154,26 @@ prepare: |

apt install -y snapd

# If $SNAPCRAFT_CHANNEL is defined, install snapcraft from that channel.
# Otherwise, look for it in /snapcraft/.
if [ -z "$SNAPCRAFT_CHANNEL" ]; then
if stat /snapcraft/*.snap 2>/dev/null; then
snap install --classic --dangerous /snapcraft/*.snap
if [ "$SNAPCRAFT_PACKAGE_TYPE" = "deb" ]; then
Copy link
Collaborator

@sergiusens sergiusens Aug 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe not now, but this might be nice to have in helper scripts to be able to use shellcheck? Or did we discuss this already and am I going on in circles?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree 100%, sadly, see this comment for why it has to be this way.

apt install -y snapcraft
elif [ "$SNAPCRAFT_PACKAGE_TYPE" = "snap" ]; then
# If $SNAPCRAFT_CHANNEL is defined, install snapcraft from that channel.
# Otherwise, look for it in /snapcraft/.
if [ -z "$SNAPCRAFT_CHANNEL" ]; then
if stat /snapcraft/*.snap 2>/dev/null; then
snap install --classic --dangerous /snapcraft/*.snap
else
echo "Expected a snap to exist in /snapcraft/. If your intention"\
"was to install from the store, set \$SNAPCRAFT_CHANNEL."
exit 1
fi
else
echo "Expected a snap to exist in /snapcraft/. If your intention"\
"was to install from the store, set \$SNAPCRAFT_CHANNEL."
exit 1
snap install --classic snapcraft --channel="$SNAPCRAFT_CHANNEL"
fi
else
snap install --classic snapcraft --channel="$SNAPCRAFT_CHANNEL"
echo "'$SNAPCRAFT_PACKAGE_TYPE' is not a supported snapcraft package type."\
" Supported types are 'deb' and 'snap'."
exit 1
fi

restore: $SETUP_DIR/restore.sh
Expand Down