Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

Commit

Permalink
Merge pull request #2506 from flynn/test-script-updates
Browse files Browse the repository at this point in the history
Test script updates
  • Loading branch information
lmars committed Mar 1, 2016
2 parents e48aad4 + 4cc11e5 commit 67ccdce
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 41 deletions.
13 changes: 2 additions & 11 deletions test/README.md
Expand Up @@ -78,19 +78,10 @@ sudo ./flynn-test \

## CI

### Dependencies

```text
apt-add-repository 'deb http://ppa.launchpad.net/titanous/tup/ubuntu trusty main'
apt-key adv --keyserver keyserver.ubuntu.com --recv 27947298A222DFA46E207200B34FBCAA90EA7F4E
apt-get update
apt-get install -y zerofree qemu qemu-kvm tup
```

### Install the runner

Check out the Flynn git repo and run the following to install the runner
into `/opt/flynn-test`:
Install Git if not already installed, then check out the Flynn git repo and run
the following to install the runner into `/opt/flynn-test`:

```
sudo test/scripts/install
Expand Down
42 changes: 22 additions & 20 deletions test/arg/arg.go
Expand Up @@ -7,26 +7,27 @@ import (
)

type Args struct {
BootConfig cluster.BootConfig
CLI string
FlynnHost string
RootFS string
Flynnrc string
RouterIP string
Build bool
Debug bool
Stream bool
Kill bool
BuildRootFS bool
DBPath string
ListenAddr string
TLSCert string
TLSKey string
AssetsDir string
Run string
Gist bool
ClusterAPI string
Concurrency int
BootConfig cluster.BootConfig
CLI string
FlynnHost string
RootFS string
Flynnrc string
RouterIP string
Build bool
Debug bool
Stream bool
Kill bool
BuildRootFS bool
DBPath string
ListenAddr string
TLSCert string
TLSKey string
AssetsDir string
Run string
Gist bool
ClusterAPI string
Concurrency int
ConcurrentBuilds int
}

func Parse() *Args {
Expand Down Expand Up @@ -56,6 +57,7 @@ func Parse() *Args {
flag.BoolVar(&args.BuildRootFS, "build-rootfs", false, "just build the rootfs (leaving it behind for future use) without running tests")
flag.BoolVar(&args.Gist, "gist", false, "upload debug info to a gist")
flag.IntVar(&args.Concurrency, "concurrency", 5, "max number of concurrent tests")
flag.IntVar(&args.ConcurrentBuilds, "concurrent-builds", 5, "max number of concurrent builds")
flag.Parse()

return args
Expand Down
26 changes: 26 additions & 0 deletions test/rootfs/setup.sh
Expand Up @@ -4,8 +4,10 @@ set -e -x
# init environment
export LC_ALL=C
mount -t proc none /proc
mount -t sysfs sysfs /sys

cleanup() {
umount /sys
umount /proc
}
trap cleanup EXIT
Expand All @@ -16,6 +18,30 @@ ln -s /bin/true /sbin/initctl
echo $'#!/bin/sh\nexit 101' > /usr/sbin/policy-rc.d
chmod +x /usr/sbin/policy-rc.d

# NOTE: chfn & chpasswd must be run in a network namespace to avoid PAM related
# errors (see https://github.com/docker/docker/issues/5704), but we can't
# just run the whole script in a network namespace (because then we would
# have no network!), so hack just those programs to run in a namespace.
#
# This behaviour was witnessed with kernel 3.13.0-77-generic, so when CI
# is running on a more recent kernel, try removing this hack.
ip netns add rootfs
mv /usr/bin/chfn{,.orig}
mv /usr/sbin/chpasswd{,.orig}
echo -e '#!/bin/bash\nip netns exec rootfs $0.orig "$@"' > /usr/bin/netns-hack
chmod +x /usr/bin/netns-hack
ln -s /usr/bin/netns-hack /usr/bin/chfn
ln -s /usr/bin/netns-hack /usr/sbin/chpasswd
apt-mark hold passwd
netns_cleanup() {
apt-mark unhold passwd
rm /usr/bin/netns-hack
mv /usr/bin/chfn{.orig,}
mv /usr/sbin/chpasswd{.orig,}
ip netns delete rootfs
}
trap netns_cleanup EXIT

# set up ubuntu user
addgroup docker
addgroup fuse
Expand Down
6 changes: 2 additions & 4 deletions test/runner/runner.go
Expand Up @@ -120,8 +120,6 @@ type Runner struct {

var args *arg.Args

const maxConcurrentBuilds = 1

func init() {
args = arg.Parse()
log.SetFlags(log.Lshortfile)
Expand All @@ -133,7 +131,7 @@ func main() {
bc: args.BootConfig,
events: make(chan Event),
networks: make(map[string]struct{}),
buildCh: make(chan struct{}, maxConcurrentBuilds),
buildCh: make(chan struct{}, args.ConcurrentBuilds),
clusters: make(map[string]*cluster.Cluster),
ircMsgs: make(chan string),
}
Expand Down Expand Up @@ -186,7 +184,7 @@ func (r *Runner) start() error {
return fmt.Errorf("could not create builds bucket: %s", err)
}

for i := 0; i < maxConcurrentBuilds; i++ {
for i := 0; i < args.ConcurrentBuilds; i++ {
r.buildCh <- struct{}{}
}

Expand Down
30 changes: 30 additions & 0 deletions test/scripts/cleanup.sh
@@ -0,0 +1,30 @@
#!/bin/bash

for pid in $(ps faux | grep '/opt/flynn-test/build/vmlinuz \-append' | grep -v grep | awk '{print $2}'); do
echo killing $pid
kill $pid
done

sleep 1

for tap in $(ifconfig | grep flynntap | awk '{print $1}'); do
echo removing $tap
sudo ip tuntap del mode tap $tap
done

for br in $(ifconfig | grep flynnbr | awk '{print $1}'); do
echo removing $br
sudo ip link set $br down
sudo ip link del $br
done

for br in $(sudo ip link | grep flynnbr | awk '{print $2}' | cut -d : -f 1); do
echo deleting $br
sudo brctl delbr
done

rm -rf /opt/flynn-test/build/rootfs-*
rm -rf /opt/flynn-test/build/netfs-*
rm -rf /opt/flynn-test/build/build-log*

echo done
51 changes: 45 additions & 6 deletions test/scripts/install
Expand Up @@ -2,6 +2,9 @@

set -e

RAMDISK_SIZE="448G"
GO_VERSION="1.6"

ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
source "${ROOT}/script/lib/ui.sh"

Expand All @@ -11,6 +14,9 @@ main() {
local src_dir="${dir}/src/github.com/flynn/flynn"
local build_dir="${dir}/build"

info "installing dependencies"
apt-get install -y build-essential zerofree qemu qemu-kvm

info "creating ${user} user"
if ! id "${user}" &>/dev/null; then
useradd --system --home "${dir}" --user-group --groups "kvm" -M "${user}"
Expand All @@ -23,8 +29,12 @@ main() {
fi

info "mounting build directory"
if ! mount | grep -q "tmpfs on ${build_dir}"; then
mount_tmpfs "${build_dir}"
mkdir -p "${build_dir}"
if ! grep -qF "${build_dir}" /etc/fstab; then
echo "tmpfs ${build_dir} tmpfs defaults,size=${RAMDISK_SIZE} 0 0" >> /etc/fstab
fi
if ! mount | grep -q "${build_dir}"; then
mount "${build_dir}"
fi

info "fixing permissions"
Expand All @@ -34,16 +44,45 @@ main() {
cp "${src_dir}/test/scripts/upstart.conf" "/etc/init/flynn-test.conf"
initctl reload-configuration

info "installing Go ${GO_VERSION}"
install_go

info "installing jchroot"
install_jchroot

info
info "install finished!"
info "you should add credentials to ${dir}/.credentials then start flynn-test (sudo start flynn-test)"
}

mount_tmpfs() {
local dir=$1
local size="32G"
install_go() {
if go version 2>&1 | grep -qF "go${GO_VERSION}"; then
return
fi

local tmp="$(mktemp --directory)"
trap "rm -rf ${tmp}" EXIT
pushd "${tmp}" &>/dev/null
wget --quiet "https://godeb.s3.amazonaws.com/godeb-amd64.tar.gz"
tar xzf "godeb-amd64.tar.gz"
./godeb install "${GO_VERSION}"
popd &>/dev/null
}

install_jchroot() {
local target="/usr/local/bin/jchroot"

if [[ -s "${target}" ]]; then
return
fi

mount -t tmpfs -o "size=${size}" tmpfs "${dir}"
local tmp="$(mktemp --directory)"
trap "rm -rf ${tmp}" EXIT
git clone "https://github.com/vincentbernat/jchroot.git" "${tmp}/jchroot"
pushd "${tmp}/jchroot" &>/dev/null
make
mv "jchroot" "${target}"
popd &>/dev/null
}

main $@
3 changes: 3 additions & 0 deletions test/scripts/upstart.conf
Expand Up @@ -27,6 +27,9 @@ script
git checkout --force --quiet origin/master
GOPATH="${dir}" go build -race -o test/bin/flynn-test-runner ./test/runner

# run the cleanup script
"${src_dir}/test/scripts/cleanup.sh"

if ! test -f "${dir}/build/rootfs.img"; then
"${src_dir}/test/rootfs/build.sh" "${dir}/build"
chown -R "flynn-test:flynn-test" "${dir}/build"
Expand Down

0 comments on commit 67ccdce

Please sign in to comment.