Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2694 from weaveworks/2647-testing-mvp
Browse files Browse the repository at this point in the history
Testing MVP

Fixes #2647
  • Loading branch information
brb authored Feb 8, 2017
2 parents dea2755 + c026579 commit dff5b6d
Show file tree
Hide file tree
Showing 26 changed files with 726 additions and 543 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@ test/tls/*.pem
test/coverage
test/coverage.*
*qemu-*-static
terraform.tfstate
terraform.tfstate.backup
25 changes: 22 additions & 3 deletions .lintignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
# IMPORTANT: Please only use GLOBs to ignore files and directories.

# Do not lint any bash script in Weave Net, in order to
# Do not lint the below bash scripts in Weave Net, in order to
# avoid breaking the build on make lint:
*.sh
bin/*
bin/circle-deploy-issues
bin/circle-deploy-master
bin/circle-teardown-pre
bin/circle-test-teardown
bin/circle-test-unit
bin/install-wordepress
bin/multiweave
bin/publish-site
bin/release
build/build.sh
prog/weave-kube/launch.sh
prog/weaveexec/symlink
test/*_test.sh
test/600_proxy_docker_py.sh
test/assert.sh
test/config.sh
test/gce.sh
test/gen_coverage_reports.sh
test/run_all.sh
test/sanity_check.sh
test/setup.sh
vendor/*.sh
weave
19 changes: 18 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ tests:
./tools/test -no-go-get -netgo -timeout 8m

lint:
./tools/lint -nocomment -notestpackage .
./tools/lint -nocomment -notestpackage

endif

Expand Down Expand Up @@ -359,3 +359,20 @@ build:

run-smoketests: all testrunner
cd test && ./setup.sh && ./run_all.sh

integration-tests: all testrunner
# Usage:
# $ make \
# NAME="<prefix used to name VMs and other resources>" \
# PROVIDER="<provider among {vagrant|gcp|aws|do}>" \
# NUM_HOSTS="<# test machines>" \
# PLAYBOOK="<filename>" \
# RUNNER_ARGS="<...>" \
# TESTS="<...>" \ # Can be set to only run one or a few tests instead of the full test suite.
# DOCKER_VERSION=<...> \
# KUBERNETES_VERSION=<...> \
# KUBERNETES_CNI_VERSION=<...> \
# <...> # See also run-integration-test.sh for all variables and individual functions.
# integration-tests
#
RUNNER_ARGS="-parallel" ./test/run-integration-tests.sh
39 changes: 15 additions & 24 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,45 +1,36 @@
VAGRANTFILE_API_VERSION = "2"

require './vagrant-common.rb'
require File.expand_path(File.join(File.dirname(__FILE__), 'vagrant-common.rb'))

vm_ip = "172.16.0.3" # arbitrary private IP

pkgs = %w(
docker-engine=1.10.2-0~wily
aufs-tools
build-essential
ethtool
iputils-arping
libpcap-dev
git
mercurial
bc
jq
)

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

config.vm.box = "ubuntu/wily64"
config.vm.box = VAGRANT_IMAGE

config.vm.network "private_network", ip: vm_ip
config.vm.provider :virtualbox do |vb|
vb.memory = 2048
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "off"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "off"]
configure_nat_dns(vb)
end

# Disable default Vagrant shared folder, which we don't need:
config.vm.synced_folder ".", "/vagrant", disabled: true
# Keep Weave Net sources' in sync:
config.vm.synced_folder ".", "/home/vagrant/src/github.com/weaveworks/weave"
# Create a convenience symlink to $HOME/src/github.com/weaveworks/weave
config.vm.provision :shell, :inline => 'ln -sf ~vagrant/src/github.com/weaveworks/weave ~vagrant/'

# Set SSH keys up to be able to run smoke tests straightaway:
config.vm.provision "file", source: "~/.vagrant.d/insecure_private_key", destination: "/home/vagrant/src/github.com/weaveworks/weave/test/insecure_private_key"

install_build_deps config.vm, pkgs
install_go_toochain config.vm
tweak_user_env config.vm
tweak_docker_daemon config.vm
# Grant permissions on sources:
config.vm.provision :shell, :inline => 'sudo chown -R vagrant:vagrant ~vagrant/src', :privileged => false
cleanup config.vm

config.vm.provision 'ansible' do |ansible|
ansible.playbook = 'tools/config_management/setup_weave-net_dev.yml'
ansible.extra_vars = {
go_version: GO_VERSION
}
end
end

begin
Expand Down
41 changes: 6 additions & 35 deletions bin/circle-dependencies-post
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,16 @@

set -e

echo "TEST_AND_PUBLISH=1" > "$STATE"

# Avoid doing a full build if we can. Note if the PR doesn't exist
# when the build is kicked off, we can't run this check so we do a
# full build. Subsequent pushes to the same branch will have the desired behaviour
if [ -n "$CI_PULL_REQUEST" -a "$CI_PULL_REQUEST" = "$CI_PULL_REQUESTS" ] ; then
if PR=$(echo "$CI_PULL_REQUEST" | grep -oP '(?<=^https://github.com/weaveworks/weave/pull/)[0-9]+$') ; then
echo "GH_PR=$PR" >> "$STATE"
if FILES=$(curl -s https://api.github.com/repos/weaveworks/weave/pulls/$PR/files | jq -r '.[]|.filename') ; then
echo "PR touches [$FILES]"
if ! echo "$FILES" | grep -v ^site/ ; then
echo "PR contains site changes only - skipping tests"
echo "TEST_AND_PUBLISH=" >> "$STATE"
else
echo "PR contains non-site changes - running tests"
fi
else
echo "Unable to get files for PR $PR" >&2
fi
else
echo "Unable to extract PR number from $CI_PULL_REQUEST" >&2
fi
fi

source "$STATE"

mkdir -p $(dirname $SRCDIR) && cp -r $(pwd)/ $SRCDIR

if [ -n "$TEST_AND_PUBLISH" ] ; then
[ -z "$SECRET_PASSWORD" ] || bin/setup-circleci-secrets "$SECRET_PASSWORD"
cd $SRCDIR; git submodule update --init
if [ "$CIRCLE_NODE_INDEX" = "0" -a -n "$SECRET_PASSWORD" ] ; then
cd $SRCDIR/test; ./gce.sh make_template
fi
cd $SRCDIR/build
if [ -n "$TEST_AND_PUBLISH" ]; then
cd "$SRCDIR"
git submodule update --init
cd "$SRCDIR/build"
../tools/rebuild-image weaveworks/weavebuild . Dockerfile build.sh
touch $SRCDIR/.build.uptodate
touch "$SRCDIR/.build.uptodate"
sudo chown -R ubuntu /usr/local/go
cd $SRCDIR
cd "$SRCDIR"
make testrunner
make COVERAGE=true RM= exes all
fi
36 changes: 36 additions & 0 deletions bin/circle-dependencies-post-sources
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

set -e

echo "TEST_AND_PUBLISH=1" >"$STATE"

# Avoid doing a full build if we can. Note if the PR doesn't exist
# when the build is kicked off, we can't run this check so we do a
# full build. Subsequent pushes to the same branch will have the desired behaviour
if [ -n "$CI_PULL_REQUEST" -a "$CI_PULL_REQUEST" = "$CI_PULL_REQUESTS" ]; then
if PR=$(echo "$CI_PULL_REQUEST" | grep -oP '(?<=^https://github.com/weaveworks/weave/pull/)[0-9]+$'); then
echo "GH_PR=$PR" >>"$STATE"
if FILES=$(curl -s "https://api.github.com/repos/weaveworks/weave/pulls/$PR/files" | jq -r '.[]|.filename'); then
echo "PR touches [$FILES]"
if ! echo "$FILES" | grep -v ^site/; then
echo "PR contains site changes only - skipping tests"
echo "TEST_AND_PUBLISH=" >>"$STATE"
else
echo "PR contains non-site changes - running tests"
fi
else
echo "Unable to get files for PR $PR" >&2
fi
else
echo "Unable to extract PR number from $CI_PULL_REQUEST" >&2
fi
fi

source "$STATE"

mkdir -p "$(dirname "$SRCDIR")" && cp -r "$(pwd)/" "$SRCDIR"

if [ -n "$TEST_AND_PUBLISH" ]; then
cd "$SRCDIR"
git submodule update --init
fi
26 changes: 23 additions & 3 deletions bin/circle-test-pre
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,29 @@

set -e

# Signal failures in lock file, in order to fail fast:
function signal_failure() {
echo "KO" >"$TEST_VMS_READY_LOCK_FILE"
exit 1
}
trap signal_failure ERR

source "$STATE"
source "$(dirname "$0")/wait_for.sh"

if [ -n "$TEST_AND_PUBLISH" ]; then
[ -n "$SECRET_KEY" ] || {
echo "Cannot run smoke tests: no secret key"
exit 1
}

# Provisioning from image typically take 90 seconds,
# but if we are creating a GCP image, it can take more than 10 minutes:
wait_for 900 "$TEST_VMS_PROV_AND_CONF_LOCK_FILE"

if [ -n "$TEST_AND_PUBLISH" ] ; then
cd $SRCDIR/test
[ -z "$SECRET_PASSWORD" ] || (./gce.sh setup && eval $(./gce.sh hosts) && ./setup.sh)
# Upload built binaries to testing VMs:
cd "$SRCDIR/test" # Ensures we generate Terraform state files in the right folder, for later use by integration tests.
./run-integration-tests.sh setup >>"$TEST_VMS_SETUP_OUTPUT_FILE" 2>&1
echo "OK" >"$TEST_VMS_READY_LOCK_FILE"
echo "Test VMs now ready. $(date)." >>"$TEST_VMS_SETUP_OUTPUT_FILE"
fi
19 changes: 14 additions & 5 deletions bin/circle-test-smoke
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@
set -e

source "$STATE"
source "$(dirname "$0")/wait_for.sh"

if [ -n "$TEST_AND_PUBLISH" ] ; then
[ -n "$SECRET_PASSWORD" ] || { echo "Cannot run smoke tests: no secret key"; exit 1; }
cd $SRCDIR/test
eval $(./gce.sh hosts)
if [ -n "$TEST_AND_PUBLISH" ]; then
[ -n "$SECRET_KEY" ] || {
echo "Cannot run smoke tests: no secret key"
exit 1
}

# Provisioning from image typically take 90 seconds,
# but if we are creating a GCP image, it can take more than 10 minutes:
wait_for 900 "$TEST_VMS_READY_LOCK_FILE"

# Run integration tests:
export COVERAGE=true
export WEAVE_NET_SANITY_CHECKS_FILES="$CIRCLE_ARTIFACTS/weave_net_sanity_check_*.log"
./run_all.sh
cd "$SRCDIR/test" # Ensures we generate code coverage files in the right folder, and use the Terraform state of previously provisionned VMs.
./run-integration-tests.sh test
fi
1 change: 0 additions & 1 deletion bin/circle-test-teardown
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ source "$STATE"

if [ -n "$TEST_AND_PUBLISH" ] ; then
cd $SRCDIR/test
[ -z "$SECRET_PASSWORD" ] || ./gce.sh destroy
test "$CIRCLE_NODE_INDEX" != "0" || (cd $SRCDIR/test; ./gen_coverage_reports.sh)
fi
41 changes: 41 additions & 0 deletions bin/provision_test_vms.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

set -e

# Signal failures in lock file, in order to fail fast:
function signal_failure() {
echo "KO" >"$TEST_VMS_PROV_AND_CONF_LOCK_FILE"
exit 1
}
trap signal_failure ERR

source "$STATE"

function install_terraform() {
curl -fsS https://releases.hashicorp.com/terraform/0.8.5/terraform_0.8.5_linux_amd64.zip | gunzip >terraform && chmod +x terraform && sudo mv terraform /usr/bin
}

function install_ansible() {
sudo apt-get update || true
sudo apt-get install -qq -y python-pip python-dev libffi-dev libssl-dev && pip install --user -U cffi && pip install --user ansible
export PATH="$PATH:$HOME/.local/bin"
}

if [ -n "$TEST_AND_PUBLISH" ]; then
[ -n "$SECRET_KEY" ] || {
echo "Cannot run smoke tests: no secret key"
exit 1
}

install_terraform >>"$TEST_VMS_SETUP_OUTPUT_FILE" 2>&1
install_ansible >>"$TEST_VMS_SETUP_OUTPUT_FILE" 2>&1

# Only attempt to create GCP image in first container, wait for it to be created otherwise:
[ "$CIRCLE_NODE_INDEX" != "0" ] && export CREATE_IMAGE=0

# Provision and configure testing VMs:
cd "$SRCDIR/test" # Ensures we generate Terraform state files in the right folder, for later use by integration tests.
./run-integration-tests.sh configure >>"$TEST_VMS_SETUP_OUTPUT_FILE" 2>&1
echo "OK" >"$TEST_VMS_PROV_AND_CONF_LOCK_FILE"
echo "Test VMs now provisioned and configured. $(date)." >>"$TEST_VMS_SETUP_OUTPUT_FILE"
fi
Loading

0 comments on commit dff5b6d

Please sign in to comment.