Fix various linter issues

Found via shellcheck.
This commit is contained in:
Iago López Galeiras
2017-01-09 16:20:24 +01:00
parent ec0b6dd8d0
commit 43d9f38c5e
34 changed files with 268 additions and 227 deletions

View File

@@ -1,16 +1,17 @@
#! /bin/bash
. ./config.sh
# shellcheck disable=SC1091
./config.sh
start_suite "Launch scope and check it boots"
weave_on $HOST1 launch
scope_on $HOST1 launch
weave_on "$HOST1" launch
scope_on "$HOST1" launch
wait_for_containers $HOST1 60 weave weaveproxy weavescope
wait_for_containers "$HOST1" 60 weave weaveproxy weavescope
has_container $HOST1 weave
has_container $HOST1 weaveproxy
has_container $HOST1 weavescope
has_container "$HOST1" weave
has_container "$HOST1" weaveproxy
has_container "$HOST1" weavescope
scope_end_suite

View File

@@ -1,15 +1,16 @@
#! /bin/bash
# shellcheck disable=SC1091
. ./config.sh
start_suite "Launch scope (without weave installed) and check it boots"
scope_on $HOST1 launch
scope_on "$HOST1" launch
wait_for_containers $HOST1 60 weavescope
wait_for_containers "$HOST1" 60 weavescope
has_container $HOST1 weave 0
has_container $HOST1 weaveproxy 0
has_container $HOST1 weavescope
has_container "$HOST1" weave 0
has_container "$HOST1" weaveproxy 0
has_container "$HOST1" weavescope
scope_end_suite

View File

@@ -1,13 +1,14 @@
#! /bin/bash
# shellcheck disable=SC1091
. ./config.sh
start_suite "Launch scope and check it boots, with a spurious host arg"
scope_on $HOST1 launch noatrealhost.foo
scope_on "$HOST1" launch noatrealhost.foo
wait_for_containers $HOST1 60 weavescope
wait_for_containers "$HOST1" 60 weavescope
has_container $HOST1 weavescope
has_container "$HOST1" weavescope
scope_end_suite

View File

@@ -1,12 +1,13 @@
#! /bin/bash
# shellcheck disable=SC1091
. ./config.sh
start_suite "Check scope exits cleanly within 5 seconds"
scope_on $HOST1 launch
scope_on "$HOST1" launch
sleep 5
scope_on $HOST1 stop
scope_on "$HOST1" stop
sleep 5

View File

@@ -1,21 +1,25 @@
#! /bin/bash
# shellcheck disable=SC1091
. ./config.sh
start_suite "Test some key topologies are not empty"
scope_on $HOST1 launch
scope_on "$HOST1" launch
wait_for_containers $HOST1 60 weavescope
wait_for_containers "$HOST1" 60 weavescope
topology_is_not_empty() {
local host="$1"
local topology="$2"
local timeout="${5:-60}"
for i in $(seq $timeout); do
local report="$(curl -s http://$host:4040/api/report)"
local count=$(echo "$report" | jq -r ".$topology.nodes | length > 0" 2>/dev/null)
for _ in $(seq "$timeout"); do
local report
local count
report="$(curl -s "http://$host:4040/api/report")"
count=$(echo "$report" | jq -r ".$topology.nodes | length > 0" 2>/dev/null)
if [ "$count" = "true" ]; then
assert "curl -s http://$host:4040/api/report | jq -r '.$topology.nodes | length > 0'" true
return
@@ -27,10 +31,10 @@ topology_is_not_empty() {
assert "curl -s http://$host:4040/api/report | jq -r '.$topology.nodes | length > 0'" true
}
topology_is_not_empty $HOST1 Endpoint
topology_is_not_empty $HOST1 Process
topology_is_not_empty $HOST1 Container
topology_is_not_empty $HOST1 ContainerImage
topology_is_not_empty $HOST1 Host
topology_is_not_empty "$HOST1" Endpoint
topology_is_not_empty "$HOST1" Process
topology_is_not_empty "$HOST1" Container
topology_is_not_empty "$HOST1" ContainerImage
topology_is_not_empty "$HOST1" Host
scope_end_suite

View File

@@ -1,29 +1,30 @@
#! /bin/bash
# shellcheck disable=SC1091
. ./config.sh
start_suite "Launch 2 scopes and check they cluster automatically"
weave_on $HOST1 launch $HOST1 $HOST2
weave_on $HOST2 launch $HOST1 $HOST2
weave_on "$HOST1" launch "$HOST1" "$HOST2"
weave_on "$HOST2" launch "$HOST1" "$HOST2"
scope_on $HOST1 launch
scope_on $HOST2 launch
scope_on "$HOST1" launch
scope_on "$HOST2" launch
docker_on $HOST1 run -dit --name db1 peterbourgon/tns-db
docker_on $HOST2 run -dit --name db2 peterbourgon/tns-db
docker_on "$HOST1" run -dit --name db1 peterbourgon/tns-db
docker_on "$HOST2" run -dit --name db2 peterbourgon/tns-db
sleep 30 # need to allow the scopes to poll dns, resolve the other app ids, and send them reports
check() {
has_container $1 weave 2
has_container $1 weaveproxy 2
has_container $1 weavescope 2
has_container $1 db1
has_container $1 db2
has_container "$1" weave 2
has_container "$1" weaveproxy 2
has_container "$1" weavescope 2
has_container "$1" db1
has_container "$1" db2
}
check $HOST1
check $HOST2
check "$HOST1"
check "$HOST2"
scope_end_suite

View File

@@ -1,26 +1,27 @@
#! /bin/bash
# shellcheck disable=SC1091
. ./config.sh
start_suite "Launch 2 scopes and check they cluster (without weave)"
scope_on $HOST1 launch $HOST2
scope_on $HOST2 launch $HOST1
scope_on "$HOST1" launch "$HOST2"
scope_on "$HOST2" launch "$HOST1"
docker_on $HOST1 run -dit --name db1 peterbourgon/tns-db
docker_on $HOST2 run -dit --name db2 peterbourgon/tns-db
docker_on "$HOST1" run -dit --name db1 peterbourgon/tns-db
docker_on "$HOST2" run -dit --name db2 peterbourgon/tns-db
sleep 30 # need to allow the scopes to poll dns, resolve the other app ids, and send them reports.
check() {
has_container $1 weave 0
has_container $1 weaveproxy 0
has_container $1 weavescope 2
has_container $1 db1
has_container $1 db2
has_container "$1" weave 0
has_container "$1" weaveproxy 0
has_container "$1" weavescope 2
has_container "$1" db1
has_container "$1" db2
}
check $HOST1
check $HOST2
check "$HOST1"
check "$HOST2"
scope_end_suite

View File

@@ -1,29 +1,30 @@
#! /bin/bash
# shellcheck disable=SC1091
. ./config.sh
start_suite "Launch 2 scopes and check they cluster automatically, with custom weave domain"
weave_on $HOST1 launch --dns-domain foo.local $HOST1 $HOST2
weave_on $HOST2 launch --dns-domain foo.local $HOST1 $HOST2
weave_on "$HOST1" launch --dns-domain foo.local "$HOST1" "$HOST2"
weave_on "$HOST2" launch --dns-domain foo.local "$HOST1" "$HOST2"
scope_on $HOST1 launch --weave.hostname=bar.foo.local
scope_on $HOST2 launch --weave.hostname bar.foo.local
scope_on "$HOST1" launch --weave.hostname=bar.foo.local
scope_on "$HOST2" launch --weave.hostname bar.foo.local
docker_on $HOST1 run -dit --name db1 peterbourgon/tns-db
docker_on $HOST2 run -dit --name db2 peterbourgon/tns-db
docker_on "$HOST1" run -dit --name db1 peterbourgon/tns-db
docker_on "$HOST2" run -dit --name db2 peterbourgon/tns-db
sleep 30 # need to allow the scopes to poll dns, resolve the other app ids, and send them reports
check() {
has_container $1 weave 2
has_container $1 weaveproxy 2
has_container $1 weavescope 2
has_container $1 db1
has_container $1 db2
has_container "$1" weave 2
has_container "$1" weaveproxy 2
has_container "$1" weavescope 2
has_container "$1" db1
has_container "$1" db2
}
check $HOST1
check $HOST2
check "$HOST1"
check "$HOST2"
scope_end_suite

View File

@@ -1,17 +1,18 @@
#! /bin/bash
# shellcheck disable=SC1091
. ./config.sh
start_suite "Launch 2 scopes and check they cluster (without weave)"
scope_on $HOST1 launch --no-app $HOST2
scope_on $HOST2 launch --no-probe
scope_on "$HOST1" launch --no-app "$HOST2"
scope_on "$HOST2" launch --no-probe
docker_on $HOST1 run -dit --name db1 peterbourgon/tns-db
docker_on "$HOST1" run -dit --name db1 peterbourgon/tns-db
sleep 30 # need to allow the scopes to poll dns, resolve the other app ids, and send them reports.
has_container $HOST2 weavescope
has_container $HOST2 db1
has_container "$HOST2" weavescope
has_container "$HOST2" db1
scope_end_suite

View File

@@ -1,5 +1,6 @@
#! /bin/bash
# shellcheck disable=SC1091
. ./config.sh
start_suite "Test short lived connections from the Internet"
@@ -10,21 +11,21 @@ if ! echo "$HOST1" | grep "us-central1-a"; then
exit
fi
weave_on $HOST1 launch
scope_on $HOST1 launch
docker_on $HOST1 run -d -p 80:80 --name nginx nginx
weave_on "$HOST1" launch
scope_on "$HOST1" launch
docker_on "$HOST1" run -d -p 80:80 --name nginx nginx
do_connections() {
while true; do
curl -s http://$HOST1:80/ >/dev/null || true
curl -s "http://$HOST1:80/" >/dev/null || true
sleep 1
done
}
do_connections&
wait_for_containers $HOST1 60 nginx "The Internet"
wait_for_containers "$HOST1" 60 nginx "The Internet"
has_connection_by_id containers $HOST1 "in-theinternet" $(node_id containers $HOST1 nginx)
has_connection_by_id containers "$HOST1" "in-theinternet" "$(node_id containers "$HOST1" nginx)"
kill %do_connections

View File

@@ -1,21 +1,22 @@
#! /bin/bash
# shellcheck disable=SC1091
. ./config.sh
start_suite "Test short lived connections between containers"
weave_on $HOST1 launch
scope_on $HOST1 launch
weave_on $HOST1 run -d --name nginx nginx
weave_on $HOST1 run -d --name client alpine /bin/sh -c "while true; do \
weave_on "$HOST1" launch
scope_on "$HOST1" launch
weave_on "$HOST1" run -d --name nginx nginx
weave_on "$HOST1" run -d --name client alpine /bin/sh -c "while true; do \
wget http://nginx.weave.local:80/ -O - >/dev/null || true; \
sleep 1; \
done"
wait_for_containers $HOST1 60 nginx client
wait_for_containers "$HOST1" 60 nginx client
has_container $HOST1 nginx
has_container $HOST1 client
has_connection containers $HOST1 client nginx
has_container "$HOST1" nginx
has_container "$HOST1" client
has_connection containers "$HOST1" client nginx
scope_end_suite

View File

@@ -1,17 +1,18 @@
#! /bin/bash
# shellcheck disable=SC1091
. ./config.sh
start_suite "Test short lived connections between containers on different hosts"
weave_on $HOST1 launch $HOST1 $HOST2
weave_on $HOST2 launch $HOST1 $HOST2
weave_on "$HOST1" launch "$HOST1" "$HOST2"
weave_on "$HOST2" launch "$HOST1" "$HOST2"
scope_on $HOST1 launch
scope_on $HOST2 launch
scope_on "$HOST1" launch
scope_on "$HOST2" launch
weave_on $HOST1 run -d --name nginx nginx
weave_on $HOST2 run -d --name client alpine /bin/sh -c "while true; do \
weave_on "$HOST1" run -d --name nginx nginx
weave_on "$HOST2" run -d --name client alpine /bin/sh -c "while true; do \
wget http://nginx.weave.local:80/ -O - >/dev/null || true; \
sleep 1; \
done"
@@ -19,12 +20,12 @@ done"
sleep 30 # need to allow the scopes to poll dns, resolve the other app ids, and send them reports
check() {
has_container $1 nginx
has_container $1 client
has_connection containers $1 client nginx
has_container "$1" nginx
has_container "$1" client
has_connection containers "$1" client nginx
}
check $HOST1
check $HOST2
check "$HOST1"
check "$HOST2"
scope_end_suite

View File

@@ -1,21 +1,22 @@
#! /bin/bash
# shellcheck disable=SC1091
. ./config.sh
start_suite "Test long connections (procspy) between processes"
weave_on $HOST1 launch
scope_on $HOST1 launch --probe.conntrack=false
weave_on $HOST1 run -d --name nginx nginx
weave_on $HOST1 run -dti --name client alpine /bin/sh -c "while true; do \
weave_on "$HOST1" launch
scope_on "$HOST1" launch --probe.conntrack=false
weave_on "$HOST1" run -d --name nginx nginx
weave_on "$HOST1" run -dti --name client alpine /bin/sh -c "while true; do \
nc nginx.weave.local 80 || true; \
sleep 1; \
done"
wait_for processes $HOST1 60 "nginx: worker process" nc
wait_for processes "$HOST1" 60 "nginx: worker process" nc
has processes $HOST1 "nginx: worker process"
has processes $HOST1 nc
has_connection processes $HOST1 nc "nginx: worker process"
has processes "$HOST1" "nginx: worker process"
has processes "$HOST1" nc
has_connection processes "$HOST1" nc "nginx: worker process"
scope_end_suite

View File

@@ -1,17 +1,18 @@
#! /bin/bash
# shellcheck disable=SC1091
. ./config.sh
start_suite "Test long connections (procspy) between processes on different hosts"
weave_on $HOST1 launch $HOST1 $HOST2
weave_on $HOST2 launch $HOST1 $HOST2
weave_on "$HOST1" launch "$HOST1" "$HOST2"
weave_on "$HOST2" launch "$HOST1" "$HOST2"
scope_on $HOST1 launch --probe.conntrack=false
scope_on $HOST2 launch --probe.conntrack=false
scope_on "$HOST1" launch --probe.conntrack=false
scope_on "$HOST2" launch --probe.conntrack=false
weave_on $HOST1 run -d --name nginx nginx
weave_on $HOST2 run -dti --name client alpine /bin/sh -c "while true; do \
weave_on "$HOST1" run -d --name nginx nginx
weave_on "$HOST2" run -dti --name client alpine /bin/sh -c "while true; do \
nc nginx.weave.local 80 || true; \
sleep 1; \
done"
@@ -19,12 +20,12 @@ done"
sleep 30 # need to allow the scopes to poll dns, resolve the other app ids, and send them reports
check() {
has processes $1 "nginx: worker process"
has processes $1 nc
has_connection processes $1 nc "nginx: worker process"
has processes "$1" "nginx: worker process"
has processes "$1" nc
has_connection processes "$1" nc "nginx: worker process"
}
check $HOST1
check $HOST2
check "$HOST1"
check "$HOST2"
scope_end_suite

View File

@@ -1,18 +1,19 @@
#! /bin/bash
# shellcheck disable=SC1091
. ./config.sh
start_suite "Test container controls"
weave_on $HOST1 launch
scope_on $HOST1 launch
weave_on "$HOST1" launch
scope_on "$HOST1" launch
CID=$(weave_on $HOST1 run -dti --name alpine alpine /bin/sh)
CID=$(weave_on "$HOST1" run -dti --name alpine alpine /bin/sh)
wait_for_containers $HOST1 60 alpine
wait_for_containers "$HOST1" 60 alpine
assert "docker_on $HOST1 inspect --format='{{.State.Running}}' alpine" "true"
PROBEID=$(docker_on $HOST1 logs weavescope 2>&1 | grep "probe starting" | sed -n 's/^.*ID \([0-9a-f]*\)$/\1/p')
PROBEID=$(docker_on "$HOST1" logs weavescope 2>&1 | grep "probe starting" | sed -n 's/^.*ID \([0-9a-f]*\)$/\1/p')
# Execute 'echo foo' in a container tty and check its output
PIPEID=$(curl -s -f -X POST "http://$HOST1:4040/api/control/$PROBEID/$CID;<container>/docker_exec_container" | jq -r '.pipe' )

View File

@@ -1,16 +1,17 @@
#! /bin/bash
# shellcheck disable=SC1091
. ./config.sh
start_suite "Test host controls"
weave_on $HOST1 launch
scope_on $HOST1 launch
weave_on "$HOST1" launch
scope_on "$HOST1" launch
sleep 10
PROBEID=$(docker_on $HOST1 logs weavescope 2>&1 | grep "probe starting" | sed -n 's/^.*ID \([0-9a-f]*\)$/\1/p')
HOSTID=$($SSH $HOST1 hostname)
PROBEID=$(docker_on "$HOST1" logs weavescope 2>&1 | grep "probe starting" | sed -n 's/^.*ID \([0-9a-f]*\)$/\1/p')
HOSTID=$($SSH "$HOST1" hostname)
# Execute 'echo foo' in the host tty and check its output
PIPEID=$(curl -s -f -X POST "http://$HOST1:4040/api/control/$PROBEID/$HOSTID;<host>/host_exec" | jq -r '.pipe' )

View File

@@ -1,3 +1,4 @@
#!/bin/bash
# NB only to be sourced
set -e
@@ -7,6 +8,7 @@ set -e
export SSH_DIR="$PWD"
export HOSTS
# shellcheck disable=SC1091
. "../tools/integration/config.sh"
WEAVE="./weave"
@@ -15,21 +17,21 @@ SCOPE="../scope"
scope_on() {
local host=$1
shift 1
[ -z "$DEBUG" ] || greyly echo "Scope on $host: $@" >&2
DOCKER_HOST=tcp://$host:$DOCKER_PORT CHECKPOINT_DISABLE=true $SCOPE "$@"
[ -z "$DEBUG" ] || greyly echo "Scope on $host: $*" >&2
DOCKER_HOST=tcp://$host:$DOCKER_PORT CHECKPOINT_DISABLE=true "$SCOPE" "$@"
}
weave_on() {
local host=$1
shift 1
[ -z "$DEBUG" ] || greyly echo "Weave on $host: $@" >&2
DOCKER_HOST=tcp://$host:$DOCKER_PORT CHECKPOINT_DISABLE=true $WEAVE "$@"
[ -z "$DEBUG" ] || greyly echo "Weave on $host: $*" >&2
DOCKER_HOST=tcp://$host:$DOCKER_PORT CHECKPOINT_DISABLE=true "$WEAVE" "$@"
}
scope_end_suite() {
end_suite
for host in $HOSTS; do
docker_on $host rm -f $(docker_on $host ps -a -q) 2>/dev/null 1>&2 || true
docker_on "$host" rm -f "$(docker_on "$host" ps -a -q)" 2>/dev/null 1>&2 || true
done
}
@@ -39,7 +41,7 @@ has() {
local host=$2
local name=$3
local count=${4:-1}
assert "curl -s http://${host}:4040/api/topology/${view}?system=show | jq -r '[.nodes[] | select(.label == \"${name}\")] | length'" $count
assert "curl -s http://${host}:4040/api/topology/${view}?system=show | jq -r '[.nodes[] | select(.label == \"${name}\")] | length'" "$count"
}
# this checks we have a named container
@@ -51,7 +53,7 @@ node_id() {
local view="$1"
local host="$2"
local name="$3"
echo $(curl -s http://${host}:4040/api/topology/${view}?system=show | jq -r ".nodes[] | select(.label == \"${name}\") | .id")
curl -s "http://${host}:4040/api/topology/${view}?system=show" | jq -r ".nodes[] | select(.label == \"${name}\") | .id"
}
container_id() {
@@ -66,9 +68,11 @@ has_connection_by_id() {
local to_id="$4"
local timeout="${5:-60}"
for i in $(seq $timeout); do
local nodes="$(curl -s http://$host:4040/api/topology/${view}?system=show)"
local edge=$(echo "$nodes" | jq -r ".nodes[\"$from_id\"].adjacency | contains([\"$to_id\"])" 2>/dev/null)
for i in $(seq "$timeout"); do
local nodes
local edge
edge=$(echo "$nodes" | jq -r ".nodes[\"$from_id\"].adjacency | contains([\"$to_id\"])" 2>/dev/null)
nodes="$(curl -s "http://$host:4040/api/topology/${view}?system=show")"
if [ "$edge" = "true" ]; then
echo "Found edge $from -> $to after $i secs"
assert "curl -s http://$host:4040/api/topology/${view}?system=show | jq -r '.nodes[\"$from_id\"].adjacency | contains([\"$to_id\"])'" true
@@ -87,10 +91,13 @@ has_connection() {
local from="$3"
local to="$4"
local timeout="${5:-60}"
local from_id="$(node_id "${view}" "${host}" "${from}")"
local to_id="$(node_id "${view}" "${host}" "${to}")"
local from_id
local to_id
has_connection_by_id "${view}" "${host}" "${from_id}" "${to_id}" "${timeout}"
from_id="$(node_id "${view}" "${host}" "${from}")"
to_id="$(node_id "${view}" "${host}" "${to}")"
has_connection_by_id "${view}" "${host}" "${from_id}" "${to_id}" "${timeout}"
}
wait_for() {
@@ -99,11 +106,13 @@ wait_for() {
local timeout="$3"
shift 3
for i in $(seq ${timeout}); do
local nodes="$(curl -s http://$host:4040/api/topology/${view}?system=show)"
for i in $(seq "${timeout}"); do
local nodes
local found=0
nodes="$(curl -s "http://$host:4040/api/topology/${view}?system=show")"
for name in "$@"; do
local count=$(echo "${nodes}" | jq -r "[.nodes[] | select(.label == \"${name}\")] | length")
local count
count=$(echo "${nodes}" | jq -r "[.nodes[] | select(.label == \"${name}\")] | length")
if [ -n "${count}" ] && [ "${count}" -ge 1 ]; then
found=$(( found + 1 ))
fi
@@ -117,7 +126,7 @@ wait_for() {
sleep 1
done
echo "Failed to find nodes $@ after $i secs"
echo "Failed to find nodes $* after $i secs"
}

View File

@@ -2,9 +2,11 @@
set -e
# shellcheck disable=SC1091
. ./config.sh
export PROJECT=scope-integration-tests
export TEMPLATE_NAME="test-template-5"
export NUM_HOSTS=5
# shellcheck disable=SC1091
. "../tools/integration/gce.sh" "$@"

View File

@@ -2,6 +2,7 @@
set -e
# shellcheck disable=SC1091
. ./config.sh
../tools/integration/run_all.sh "$@"

View File

@@ -2,33 +2,35 @@
set -e # NB don't set -u, as weave's config.sh doesn't like that.
# shellcheck disable=SC1091
. ./config.sh
echo Copying scope images and scripts to hosts
# shellcheck disable=SC2153
for HOST in $HOSTS; do
SIZE=$(stat --printf="%s" ../scope.tar)
cat ../scope.tar | pv -N "scope.tar" -s $SIZE | $SSH -C $HOST sudo docker load
pv -N "scope.tar" -s "$SIZE" ../scope.tar | $SSH -C "$HOST" sudo docker load
done
setup_host() {
local HOST=$1
echo Installing weave on $HOST
echo Installing weave on "$HOST"
# Download the latest released weave script locally,
# for use by weave_on
curl -sL git.io/weave -o ./weave
chmod a+x ./weave
run_on $HOST "sudo curl -sL git.io/weave -o /usr/local/bin/weave"
run_on $HOST "sudo chmod a+x /usr/local/bin/weave"
weave_on $HOST setup
run_on "$HOST" "sudo curl -sL git.io/weave -o /usr/local/bin/weave"
run_on "$HOST" "sudo chmod a+x /usr/local/bin/weave"
weave_on "$HOST" setup
echo Prefetching Images on $HOST
docker_on $HOST pull peterbourgon/tns-db
docker_on $HOST pull alpine
docker_on $HOST pull nginx
echo Prefetching Images on "$HOST"
docker_on "$HOST" pull peterbourgon/tns-db
docker_on "$HOST" pull alpine
docker_on "$HOST" pull nginx
}
for HOST in $HOSTS; do
setup_host $HOST &
setup_host "$HOST" &
done
wait