WIP -- fixing some shellcheck issues in scope

This commit is contained in:
Paul Bellamy
2016-10-26 17:20:14 +01:00
parent 9cc011a8f9
commit 7ddc893ec4
26 changed files with 313 additions and 302 deletions

View File

@@ -8,10 +8,10 @@ DOCKERHUB_USER=${DOCKERHUB_USER:-weaveworks}
RELEASE_NAME=${RELEASE_NAME:-"Weave Scope"}
RELEASE_DESCRIPTION=${RELEASE_DESCRIPTION:-"Container Visibility"}
PWD=`pwd`
PWD=$(pwd)
WC="wc"
# Use GNU wc on Darwin
case $OSTYPE in darwin*) WC="gwc" ;; esac
case "$OSTYPE" in darwin*) WC="gwc" ;; esac
infer_release_type() {
if echo $1 | grep -qE '^v[0-9]+\.[0-9]+\.0+$' ; then
@@ -26,7 +26,7 @@ infer_release_type() {
setup() {
# Ensure we have exactly one annotated tag pointing at HEAD
HEAD_TAGS=$(git tag --points-at HEAD)
TAG_COUNT=$(echo $(echo $HEAD_TAGS | wc -w)) # mac hack
TAG_COUNT=$(echo $(echo $HEAD_TAGS | wc -w)) # mac hack
case $TAG_COUNT in
1)
if [ $HEAD_TAGS != "latest_release" ] ; then
@@ -49,11 +49,11 @@ setup() {
;;
esac
RELEASE_TYPE=$(infer_release_type $LATEST_TAG)
RELEASE_TYPE=$(infer_release_type "$LATEST_TAG")
echo "== Inferred release type $RELEASE_TYPE from tag $LATEST_TAG"
LATEST_TAG_SHA=$(git rev-parse $LATEST_TAG)
LATEST_TAG_COMMIT_SHA=$(git rev-list -1 $LATEST_TAG)
LATEST_TAG_SHA=$(git rev-parse "$LATEST_TAG")
LATEST_TAG_COMMIT_SHA=$(git rev-list -1 "$LATEST_TAG")
LATEST_RELEASE_SHA=$(git rev-parse latest_release)
LATEST_RELEASE_COMMIT_SHA=$(git rev-list -1 latest_release)
if [ "$RELEASE_TYPE" != 'PRERELEASE' ] ; then
@@ -69,7 +69,7 @@ build() {
setup
echo "== Clone repo at $LATEST_TAG for version $VERSION"
if [ -d $RELEASE_DIR ]; then
if [ -d "$RELEASE_DIR" ]; then
echo -e "\u2757 Release directory $RELEASE_DIR already exists, you may want to" >&2
echo -e "\trm -rf $RELEASE_DIR" >&2
exit 1
@@ -77,12 +77,12 @@ build() {
## Clone the repo at the tag and go there
mkdir -p releases
git clone -q -b $LATEST_TAG . $RELEASE_DIR 2>/dev/null
cd $RELEASE_DIR
git clone -q -b "$LATEST_TAG" . "$RELEASE_DIR" 2>/dev/null
cd "$RELEASE_DIR"
## Check that the top changelog entry is this version
if ! latest_changelog=$(perl -nle'print $& if m{(?<=^## Release ).*}' ./CHANGELOG.md | head -1) || \
! [ `echo "$latest_changelog" = "$VERSION"` ]; then
! [ $(echo "$latest_changelog" = "$VERSION") ]; then
echo -e "\u2757 Latest changelog entry \"$latest_changelog\" does not match the release version $VERSION" >&2
exit 1
fi
@@ -93,9 +93,9 @@ build() {
## Inject the version numbers and build the distributables
## (library versions?)
sed -i.tmp "s/SCRIPT_VERSION=\"[^\"]*\"/SCRIPT_VERSION=\"$VERSION\"/" ./scope
make SUDO=$SUDO SCOPE_VERSION=$VERSION DOCKERHUB_USER=$DOCKERHUB_USER
make "SUDO=$SUDO" "SCOPE_VERSION=$VERSION" "DOCKERHUB_USER=$DOCKERHUB_USER"
if make tests SUDO=$SUDO; then
if make tests "SUDO=$SUDO"; then
echo -e '\u2713 Tests pass'
else
echo -e "\u2757 Tests failed, probably best not publish this one" >&2
@@ -110,13 +110,13 @@ build() {
#fi
echo -e '\u2713 Build OK'
echo '** Release artefacts in' $RELEASE_DIR
echo '** Release artefacts in' "$RELEASE_DIR"
}
draft() {
setup
cd $PWD/$RELEASE_DIR
cd "$PWD/$RELEASE_DIR"
echo "== Sanity checks"
@@ -133,13 +133,13 @@ draft() {
## Check that the version does not already exist by looking at github
## releases
if github-release info --user $GITHUB_USER --repo scope --tag $LATEST_TAG >/dev/null 2>&1; then
if github-release info --user "$GITHUB_USER" --repo scope --tag "$LATEST_TAG" >/dev/null 2>&1; then
echo -e "\u2757 Release $LATEST_TAG already exists on GitHub" >&2
echo -e "\thttps://github.com/$GITHUB_USER/scope/releases/$LATEST_TAG" >&2
exit 1
fi
echo '** Sanity checks OK for publishing tag' $LATEST_TAG as $DOCKERHUB_USER/scope:$VERSION
echo '** Sanity checks OK for publishing tag' "$LATEST_TAG" as "$DOCKERHUB_USER/scope:$VERSION"
RELEASE_ARGS="--draft"
if [ "$RELEASE_TYPE" = 'PRERELEASE' ] ; then
@@ -147,17 +147,17 @@ draft() {
fi
echo "== Creating GitHub release $RELEASE_ARGS $RELEASE_NAME $VERSION"
github-release release $RELEASE_ARGS \
--user $GITHUB_USER \
github-release release "$RELEASE_ARGS" \
--user "$GITHUB_USER" \
--repo scope \
--tag $LATEST_TAG \
--tag "$LATEST_TAG" \
--name "$RELEASE_NAME $VERSION" \
--description "$RELEASE_DESCRIPTION"
github-release upload \
--user $GITHUB_USER \
--user "$GITHUB_USER" \
--repo scope \
--tag $LATEST_TAG \
--tag "$LATEST_TAG" \
--name "scope" \
--file "./scope"
@@ -167,7 +167,7 @@ draft() {
publish() {
setup
cd $PWD/$RELEASE_DIR
cd "$PWD/$RELEASE_DIR"
UPDATE_LATEST=false
if [ "$RELEASE_TYPE" = 'MAINLINE' ] ; then
@@ -176,16 +176,16 @@ publish() {
if [ "$RELEASE_TYPE" = 'PRERELEASE' ] ; then
echo "== Tagging and pushing images on docker hub as user $DOCKERHUB_USER"
$SUDO docker tag -f $DOCKERHUB_USER/scope $DOCKERHUB_USER/scope:$VERSION
$SUDO docker push $DOCKERHUB_USER/scope:$VERSION
$SUDO docker tag -f "$DOCKERHUB_USER/scope" "$DOCKERHUB_USER/scope:$VERSION"
$SUDO docker push "$DOCKERHUB_USER/scope:$VERSION"
echo "** Docker images tagged and pushed"
echo "== Publishing pre-release on GitHub"
github-release publish \
--user $GITHUB_USER \
--user "$GITHUB_USER" \
--repo scope \
--tag $LATEST_TAG
--tag "$LATEST_TAG"
echo "** Pre-release $RELEASE_NAME $VERSION published at"
echo -e "\thttps://github.com/$GITHUB_USER/scope/releases/$LATEST_TAG"
@@ -199,44 +199,44 @@ publish() {
fi
## Check that the 'latest_release' tag exists by looking at github
if ! curl -sSf https://api.github.com/repos/$GITHUB_USER/scope/git/tags/$LATEST_RELEASE_SHA >/dev/null 2>&1; then
if ! curl -sSf "https://api.github.com/repos/$GITHUB_USER/scope/git/tags/$LATEST_RELEASE_SHA" >/dev/null 2>&1; then
echo -e "\u2757 Tag latest_release is not on GitHub, or is not the same as the local tag" >&2
echo -e "\thttps://github.com/$GITHUB_USER/scope/tags" >&2
echo "You may need to" >&2
echo -e "\tgit push -f git@github.com:$GITHUB_USER/scope latest_release" >&2
exit 1
fi
echo '** Sanity checks OK for publishing tag' $LATEST_TAG as $DOCKERHUB_USER/scope:$VERSION
echo '** Sanity checks OK for publishing tag' "$LATEST_TAG" as "$DOCKERHUB_USER/scope:$VERSION"
echo "== Tagging and pushing images on docker hub as user $DOCKERHUB_USER"
$SUDO docker tag -f $DOCKERHUB_USER/scope $DOCKERHUB_USER/scope:$VERSION
$SUDO docker push $DOCKERHUB_USER/scope:$VERSION
$SUDO docker tag -f "$DOCKERHUB_USER/scope $DOCKERHUB_USER/scope:$VERSION"
$SUDO docker push "$DOCKERHUB_USER/scope:$VERSION"
echo "** Docker images tagged and pushed"
echo "== Publishing release on GitHub"
github-release publish \
--user $GITHUB_USER \
--user "$GITHUB_USER" \
--repo scope \
--tag $LATEST_TAG
--tag "$LATEST_TAG"
if github-release info --user $GITHUB_USER --repo scope \
if github-release info --user "$GITHUB_USER" --repo scope \
--tag latest_release >/dev/null 2>&1; then
github-release delete \
--user $GITHUB_USER \
--user "$GITHUB_USER" \
--repo scope \
--tag latest_release
fi
github-release release \
--user $GITHUB_USER \
--user "$GITHUB_USER" \
--repo scope \
--tag latest_release \
--name "$RELEASE_NAME latest ($VERSION)" \
--description "[Release Notes](https://github.com/$GITHUB_USER/scope/releases/$LATEST_TAG)"
github-release upload \
--user $GITHUB_USER \
--user "$GITHUB_USER" \
--repo scope \
--tag latest_release \
--name "scope" \

View File

@@ -2,7 +2,7 @@
mkdir -p /var/run/weave
for arg in $@; do
for arg in "$@"; do
case "$arg" in
--no-app|--probe-only|--service-token*|--probe.token*)
touch /etc/service/app/down
@@ -13,6 +13,7 @@ for arg in $@; do
esac
done
# shellcheck disable=SC2034
ARGS=("$@")
typeset -p ARGS >/var/run/weave/scope-app.args

View File

@@ -1,5 +1,5 @@
#!/bin/bash
source /var/run/weave/scope-app.args
exec -a scope-app /home/weave/scope --mode app "${ARGS[@]}"

View File

@@ -2,4 +2,5 @@
set -e
./in_parallel.sh "make RM=" $(find . -maxdepth 2 -name *.go -printf "%h\n" | sort -u | sed -n 's/\.\/\(.*\)/\1\/\1/p')
# shellcheck disable=SC2046
./in_parallel.sh "make RM=" $(find . -maxdepth 2 -name "./*.go" -printf "%h\n" | sort -u | sed -n 's/\.\/\(.*\)/\1\/\1/p')

View File

@@ -19,14 +19,14 @@ shift 1
INPUTS="$*"
SCHED_NAME=parallel-$CIRCLE_PROJECT_USERNAME-$CIRCLE_PROJECT_REPONAME-$CIRCLE_BUILD_NUM
INPUTS=$(echo $INPUTS | "../tools/sched" sched $SCHED_NAME $CIRCLE_NODE_TOTAL $CIRCLE_NODE_INDEX)
INPUTS=$(echo "$INPUTS" | "../tools/sched" sched "$SCHED_NAME" "$CIRCLE_NODE_TOTAL" "$CIRCLE_NODE_INDEX")
echo Doing $INPUTS
echo Doing "$INPUTS"
for INPUT in $INPUTS; do
START=$(date +%s)
$COMMAND $INPUT
RUNTIME=$(( $(date +%s) - $START ))
"$COMMAND" "$INPUT"
RUNTIME=$(( $(date +%s) - START ))
"../tools/sched" time $INPUT $RUNTIME
"../tools/sched" time "$INPUT" "$RUNTIME"
done

View File

@@ -4,13 +4,13 @@
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

@@ -4,12 +4,12 @@
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

@@ -4,10 +4,10 @@
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

@@ -4,14 +4,14 @@
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
# Save stdout for debugging output
exec 3>&1
exec 3>&1
assert_raises "docker_on $HOST1 logs weavescope 2>&1 | grep 'app exiting' || (docker_on $HOST1 logs weavescope 2>&3 ; false)"
assert_raises "docker_on $HOST1 logs weavescope 2>&1 | grep 'probe exiting' || (docker_on $HOST1 logs weavescope 2>&3 ; false)"
assert_raises "docker_on $HOST1 inspect --format='{{.State.Running}}' weavescope" "false"

View File

@@ -4,33 +4,33 @@
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}"
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)
if [ "$count" = "true" ]; then
assert "curl -s http://$host:4040/api/report | jq -r '.$topology.nodes | length > 0'" true
return
fi
sleep 1
done
for _ 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)
if [ "$count" = "true" ]; then
assert "curl -s http://$host:4040/api/report | jq -r '.$topology.nodes | length > 0'" true
return
fi
sleep 1
done
echo "Failed to find any nodes in the $topology topology after $timeout secs"
assert "curl -s http://$host:4040/api/report | jq -r '.$topology.nodes | length > 0'" true
echo "Failed to find any nodes in the $topology topology after $timeout secs"
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

@@ -4,26 +4,26 @@
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

@@ -4,23 +4,23 @@
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

@@ -4,26 +4,26 @@
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

@@ -4,14 +4,14 @@
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

@@ -5,26 +5,26 @@
start_suite "Test short lived connections from the Internet"
if ! echo "$HOST1" | grep "us-central1-a"; then
echo "Skipping; test needs to be run against VMs on GCE."
scope_end_suite
exit
echo "Skipping; test needs to be run against VMs on GCE."
scope_end_suite
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
sleep 1
done
while true; do
curl -s "http://$HOST1:80/" >/dev/null || true
sleep 1
done
}
do_connections&
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

@@ -4,18 +4,18 @@
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

@@ -4,14 +4,14 @@
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 +19,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

@@ -4,18 +4,18 @@
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

@@ -4,14 +4,14 @@
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 +19,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

@@ -4,18 +4,18 @@
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' )
PIPEID=$(curl -s -f -X POST "http://$HOST1:4040/api/control/$PROBEID/$CID;<container>/docker_exec_container" | jq -r '.pipe')
assert "(sleep 1 && echo 'echo foo' && sleep 1) | wscat -b 'ws://$HOST1:4040/api/pipe/$PIPEID' | col -pb" "alpine:/# 6necho foo\nfoo\nalpine:/# 6n"
assert_raises "curl -f -X POST 'http://$HOST1:4040/api/control/$PROBEID/$CID;<container>/docker_stop_container'"

View File

@@ -4,16 +4,16 @@
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=$(sshcmd "$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' )
PIPEID=$(curl -s -f -X POST "http://$HOST1:4040/api/control/$PROBEID/$HOSTID;<host>/host_exec" | jq -r '.pipe')
assert "(sleep 1 && echo \"PS1=''; echo foo\" && sleep 1) | wscat -b 'ws://$HOST1:4040/api/pipe/$PIPEID' | col -pb | tail -n 1" "foo\n"
scope_end_suite

View File

@@ -13,45 +13,45 @@ WEAVE="./weave"
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 "$@"
local host=$1
shift 1
[ -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 "$@"
local host=$1
shift 1
[ -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
done
end_suite
for host in $HOSTS; do
(docker_on "$host" ps -a -q | xargs docker_on "$host" rm -f) 2>/dev/null 1>&2 || true
done
}
# this checks we have a named node in the given view
has() {
local view=$1
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
local view=$1
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"
}
# this checks we have a named container
has_container() {
has containers "$@"
has containers "$@"
}
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")
local host="$2"
local name="$3"
curl -s "http://${host}:4040/api/topology/${view}?system=show" | jq -r ".nodes[] | select(.label == \"${name}\") | .id"
}
container_id() {
@@ -60,33 +60,33 @@ container_id() {
# this checks we have an edge from container 1 to container 2
has_connection_by_id() {
local view="$1"
local host="$2"
local from_id="$3"
local to_id="$4"
local timeout="${5:-60}"
local view="$1"
local host="$2"
local from_id="$3"
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)
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
return
fi
sleep 1
done
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)
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
return
fi
sleep 1
done
echo "Failed to find edge $from -> $to after $timeout secs"
assert "curl -s http://$host:4040/api/topology/${view}?system=show | jq -r '.nodes[\"$from_id\"].adjacency | contains([\"$to_id\"])'" true
echo "Failed to find edge $from -> $to after $timeout secs"
assert "curl -s http://$host:4040/api/topology/${view}?system=show | jq -r '.nodes[\"$from_id\"].adjacency | contains([\"$to_id\"])'" true
}
has_connection() {
local view="$1"
local host="$2"
local from="$3"
local to="$4"
local timeout="${5:-60}"
local view="$1"
local host="$2"
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}")"
@@ -94,33 +94,32 @@ has_connection() {
}
wait_for() {
local view="$1"
local host="$2"
local timeout="$3"
shift 3
local view="$1"
local host="$2"
local timeout="$3"
shift 3
for i in $(seq ${timeout}); do
local nodes="$(curl -s http://$host:4040/api/topology/${view}?system=show)"
local found=0
for name in "$@"; do
local count=$(echo "${nodes}" | jq -r "[.nodes[] | select(.label == \"${name}\")] | length")
if [ -n "${count}" ] && [ "${count}" -ge 1 ]; then
found=$(( found + 1 ))
fi
done
for i in $(seq "${timeout}"); do
local nodes="$(curl -s "http://$host:4040/api/topology/${view}?system=show")"
local found=0
for name in "$@"; do
local count=$(echo "${nodes}" | jq -r "[.nodes[] | select(.label == \"${name}\")] | length")
if [ -n "${count}" ] && [ "${count}" -ge 1 ]; then
found=$((found + 1))
fi
done
if [ "${found}" -eq $# ]; then
echo "Found ${found} nodes after $i secs"
return
fi
if [ "${found}" -eq $# ]; then
echo "Found $found nodes after $i secs"
return
fi
sleep 1
done
sleep 1
done
echo "Failed to find nodes $@ after $i secs"
echo "Failed to find nodes $* after $i secs"
}
wait_for_containers() {
wait_for containers "$@"
wait_for containers "$@"
}

View File

@@ -7,28 +7,28 @@ set -e # NB don't set -u, as weave's config.sh doesn't like that.
echo Copying scope images and scripts to hosts
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 <../scope.tar -N "scope.tar" -s "$SIZE" | sshcmd -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

74
scope
View File

@@ -15,7 +15,7 @@ usage() {
}
SCRIPT_VERSION="(unreleased version)"
if [ "$SCRIPT_VERSION" = "(unreleased version)" ] ; then
if [ "$SCRIPT_VERSION" = "(unreleased version)" ]; then
IMAGE_VERSION=latest
else
IMAGE_VERSION=$SCRIPT_VERSION
@@ -60,8 +60,8 @@ check_docker_access() {
MIN_DOCKER_VERSION=1.6.0
check_docker_version() {
if ! DOCKER_VERSION=$(docker -v | sed -n 's%^Docker version \([0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}\).*$%\1%p') ||
[ -z "$DOCKER_VERSION" ] ; then
if ! DOCKER_VERSION=$(docker -v | sed -n 's%^Docker version \([0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}\).*$%\1%p') \
|| [ -z "$DOCKER_VERSION" ]; then
echo "ERROR: Unable to parse docker version" >&2
exit 1
fi
@@ -78,22 +78,22 @@ check_docker_version() {
\( "$DOCKER_VERSION_MAJOR" -eq "$MIN_DOCKER_VERSION_MAJOR" -a \
\( "$DOCKER_VERSION_MINOR" -lt "$MIN_DOCKER_VERSION_MINOR" -o \
\( "$DOCKER_VERSION_MINOR" -eq "$MIN_DOCKER_VERSION_MINOR" -a \
\( "$DOCKER_VERSION_PATCH" -lt "$MIN_DOCKER_VERSION_PATCH" \) \) \) \) ] ; then
\( "$DOCKER_VERSION_PATCH" -lt "$MIN_DOCKER_VERSION_PATCH" \) \) \) \) ]; then
echo "ERROR: scope requires Docker version $MIN_DOCKER_VERSION or later; you are running $DOCKER_VERSION" >&2
exit 1
fi
}
check_probe_only() {
echo "${ARGS}" | grep -q -E "\-\-no\-app|\-\-service\-token|\-\-probe\-only"
echo "${ARGS}" | grep -q -E "\-\-no\-app|\-\-service\-token|\-\-probe\-only"
}
check_docker_for_mac() {
[ "$(uname)" = "Darwin" ] \
&& [ -S /var/run/docker.sock ] \
&& [ ! "${DOCKER_HOST+x}" = x ] \
&& [ "${HOME+x}" = x ] \
&& [ -d "${HOME}/Library/Containers/com.docker.docker/Data/database" ]
[ "$(uname)" = "Darwin" ] \
&& [ -S /var/run/docker.sock ] \
&& [ ! "${DOCKER_HOST+x}" = x ] \
&& [ "${HOME+x}" = x ] \
&& [ -d "${HOME}/Library/Containers/com.docker.docker/Data/database" ]
}
# Check that a container named $1 with image $2 is not running
@@ -125,32 +125,32 @@ check_not_running() {
}
create_plugins_dir() {
# Docker for Mac (as of beta18) looks for this path on VM first, and when it doesn't
# find it there, it assumes the user referes to the path on Mac OS. Firstly, in most
# cases user won't have /var/run/scope/plugins on their Mac OS filesystem, and
# secondly Docker for Mac would have to be configured to share this path. The result
# of this "feature" is an error message: "The path /var/run/scope/plugins
# is not shared from OS X and does not belong to the system."
# In any case, creating /var/run/scope/plugins on Mac OS would not work, as domain
# sockets do not cross VM boundaries. We need this directory to exits on the VM.
docker run --rm --entrypoint=/bin/sh \
-v /var/run:/var/run \
$SCOPE_IMAGE -c "mkdir -p /var/run/scope/plugins"
# Docker for Mac (as of beta18) looks for this path on VM first, and when it doesn't
# find it there, it assumes the user referes to the path on Mac OS. Firstly, in most
# cases user won't have /var/run/scope/plugins on their Mac OS filesystem, and
# secondly Docker for Mac would have to be configured to share this path. The result
# of this "feature" is an error message: "The path /var/run/scope/plugins
# is not shared from OS X and does not belong to the system."
# In any case, creating /var/run/scope/plugins on Mac OS would not work, as domain
# sockets do not cross VM boundaries. We need this directory to exits on the VM.
docker run --rm --entrypoint=/bin/sh \
-v /var/run:/var/run \
$SCOPE_IMAGE -c "mkdir -p /var/run/scope/plugins"
}
launch_command() {
echo docker run --privileged -d --name=$SCOPE_CONTAINER_NAME --net=host --pid=host \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /var/run/scope/plugins:/var/run/scope/plugins \
-e CHECKPOINT_DISABLE \
$WEAVESCOPE_DOCKER_ARGS $SCOPE_IMAGE --probe.docker=true
-v /var/run/docker.sock:/var/run/docker.sock \
-v /var/run/scope/plugins:/var/run/scope/plugins \
-e CHECKPOINT_DISABLE \
$WEAVESCOPE_DOCKER_ARGS $SCOPE_IMAGE --probe.docker=true
}
launch_docker4mac_app_command() {
echo docker run -d --name=$SCOPE_APP_CONTAINER_NAME \
-e CHECKPOINT_DISABLE \
-p 0.0.0.0:4040:4040 \
$WEAVESCOPE_DOCKER_ARGS $SCOPE_IMAGE --no-probe
-e CHECKPOINT_DISABLE \
-p 0.0.0.0:4040:4040 \
$WEAVESCOPE_DOCKER_ARGS $SCOPE_IMAGE --no-probe
}
launch() {
@@ -172,7 +172,7 @@ check_docker_version
case "$COMMAND" in
command)
# TODO: properly escape/quote the output of "$@"
# TODO: properly escape/quote the output of "$@"
echo $(launch_command) "$@"
;;
@@ -207,9 +207,9 @@ EOF
docker run --rm -e CHECKPOINT_DISABLE --entrypoint=/home/weave/scope \
$WEAVESCOPE_DOCKER_ARGS $SCOPE_IMAGE --dry-run $@
if check_docker_for_mac ; then
if check_docker_for_mac; then
create_plugins_dir
if check_probe_only ; then
if check_probe_only; then
launch "$@"
exit
fi
@@ -231,7 +231,7 @@ EOF
fi
launch "$@"
if ! check_probe_only ; then
if ! check_probe_only; then
IP_ADDRS=$(docker run --rm --net=host --entrypoint /bin/sh $SCOPE_IMAGE -c "$IP_ADDR_CMD")
print_app_endpoints $IP_ADDRS
fi
@@ -240,12 +240,12 @@ EOF
stop)
[ $# -eq 0 ] || usage
if docker inspect $SCOPE_CONTAINER_NAME >/dev/null 2>&1 ; then
docker stop $SCOPE_CONTAINER_NAME >/dev/null
if docker inspect $SCOPE_CONTAINER_NAME >/dev/null 2>&1; then
docker stop $SCOPE_CONTAINER_NAME >/dev/null
fi
if check_docker_for_mac ; then
if docker inspect $SCOPE_APP_CONTAINER_NAME >/dev/null 2>&1 ; then
docker stop $SCOPE_APP_CONTAINER_NAME >/dev/null
if check_docker_for_mac; then
if docker inspect $SCOPE_APP_CONTAINER_NAME >/dev/null 2>&1; then
docker stop $SCOPE_APP_CONTAINER_NAME >/dev/null
fi
fi
;;

View File

@@ -36,8 +36,15 @@ HOST3=$(echo "$HOSTS" | cut -f 3 -d ' ')
. "$DIR/assert.sh"
SSH_DIR=${SSH_DIR:-$DIR}
SSH=${SSH:-ssh -l vagrant -i \"$SSH_DIR/insecure_private_key\" -o \"UserKnownHostsFile=$SSH_DIR/.ssh_known_hosts\" -o CheckHostIP=no -o StrictHostKeyChecking=no}
sshcmd() {
# shellcheck disable=SC2029
ssh -l vagrant \
-i "$SSH_DIR/insecure_private_key" \
-o "UserKnownHostsFile=$SSH_DIR/.ssh_known_hosts" \
-o CheckHostIP=no \
-o StrictHostKeyChecking=no \
"$@"
}
SMALL_IMAGE="alpine"
# shellcheck disable=SC2034
TEST_IMAGES="$SMALL_IMAGE"
@@ -81,7 +88,7 @@ run_on() {
host=$1
shift 1
[ -z "$DEBUG" ] || greyly echo "Running on $host:" "$@" >&2
remote "$host" "$SSH" "$host" "$@"
remote "$host" "ssh" "$host" "$@"
}
docker_on() {

View File

@@ -155,7 +155,10 @@ function hosts() {
hosts=($hostname "${hosts[@]}")
args=("--add-host=$hostname:$(internal_ip "$json" "$name")" "${args[@]}")
done
echo export SSH=\"ssh -l vagrant\"
function sshcmd() {
# shellcheck disable=SC2029
ssh -l vagrant "$@"
}
echo "export HOSTS=\"${hosts[*]}\""
echo "export ADD_HOST_ARGS=\"${args[*]}\""
rm "$json"