From 5cb5c7d42ed81a80b32192ec1290cc8235ffb12a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iago=20L=C3=B3pez=20Galeiras?= Date: Thu, 12 Jan 2017 16:06:47 +0100 Subject: [PATCH] Fix shfmt issues --- bin/release | 24 +-- bin/setup-circleci-secrets | 5 +- docker/entrypoint.sh | 8 +- docker/run-app | 2 +- extras/dialer/dialer | 22 +-- extras/dialer/listener | 4 +- extras/dialer/time-scope-probe | 26 +-- extras/example/run.sh | 1 - extras/example/run_tracer.sh | 13 +- extras/generate_latest_map | 8 +- extras/in_parallel.sh | 2 +- integration/100_launch_test.sh | 2 +- integration/110_shutdown_test.sh | 2 +- integration/115_topologies_test.sh | 38 ++-- integration/200_clustering_2_test.sh | 10 +- .../205_clustering_sans_weave_2_test.sh | 10 +- .../210_clustering_custom_hostname_2_test.sh | 10 +- integration/300_internet_edge_test.sh | 16 +- .../320_container_edge_cross_host_2_test.sh | 6 +- integration/410_container_control_test.sh | 2 +- integration/420_host_control_test.sh | 2 +- integration/config.sh | 163 +++++++++--------- scope | 74 ++++---- 23 files changed, 223 insertions(+), 227 deletions(-) diff --git a/bin/release b/bin/release index b94937053f..4bb1c2b0e8 100755 --- a/bin/release +++ b/bin/release @@ -11,9 +11,9 @@ RELEASE_DESCRIPTION=${RELEASE_DESCRIPTION:-"Container Visibility"} PWD=$(pwd) infer_release_type() { - if echo "$1" | grep -qE '^v[0-9]+\.[0-9]+\.0+$' ; then + if echo "$1" | grep -qE '^v[0-9]+\.[0-9]+\.0+$'; then echo MAINLINE - elif echo "$1" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$' ; then + elif echo "$1" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$'; then echo BRANCH else echo PRERELEASE @@ -28,7 +28,7 @@ setup() { TAG_COUNT=$(echo "$(echo "$HEAD_TAGS" | wc -w)") # mac hack case $TAG_COUNT in 1) - if [ "$HEAD_TAGS" != "latest_release" ] ; then + if [ "$HEAD_TAGS" != "latest_release" ]; then LATEST_TAG=$HEAD_TAGS else echo "Cannot determine version - latest_release points at HEAD" >&2 @@ -41,7 +41,7 @@ setup() { ;; *) echo "Cannot determine version - multiple tags point at HEAD:" >&2 - for TAG in $HEAD_TAGS ; do + for TAG in $HEAD_TAGS; do echo -e "\t$TAG" >&2 done exit 1 @@ -55,7 +55,7 @@ setup() { 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 + if [ "$RELEASE_TYPE" != 'PRERELEASE' ]; then VERSION=${LATEST_TAG#v} else VERSION=${LATEST_TAG} @@ -80,8 +80,8 @@ build() { 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) || \ - ! [ "$latest_changelog" = "$VERSION" ]; then + if ! latest_changelog=$(perl -nle'print $& if m{(?<=^## Release ).*}' ./CHANGELOG.md | head -1) \ + || ! [ "$latest_changelog" = "$VERSION" ]; then echo -e "\u2757 Latest changelog entry \"$latest_changelog\" does not match the release version $VERSION" >&2 exit 1 fi @@ -141,7 +141,7 @@ draft() { echo '** Sanity checks OK for publishing tag' "$LATEST_TAG" as "$DOCKERHUB_USER/scope:$VERSION" RELEASE_ARGS="--draft" - if [ "$RELEASE_TYPE" = 'PRERELEASE' ] ; then + if [ "$RELEASE_TYPE" = 'PRERELEASE' ]; then RELEASE_ARGS="$RELEASE_ARGS --pre-release" fi @@ -168,10 +168,10 @@ publish() { setup cd "$PWD"/"$RELEASE_DIR" - if [ "$RELEASE_TYPE" = 'PRERELEASE' ] ; then + 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 push "$DOCKERHUB_USER/scope:$VERSION" echo "** Docker images tagged and pushed" echo "== Publishing pre-release on GitHub" @@ -185,7 +185,7 @@ publish() { echo -e "\thttps://github.com/$GITHUB_USER/scope/releases/$LATEST_TAG" else echo "== Sanity checks" - if ! [ "$LATEST_TAG_COMMIT_SHA" == "$LATEST_RELEASE_COMMIT_SHA" ] ; then + if ! [ "$LATEST_TAG_COMMIT_SHA" == "$LATEST_RELEASE_COMMIT_SHA" ]; then echo -e "\u2757 The tag latest_release does not point to the same commit as $LATEST_TAG" >&2 echo "You may need to" >&2 echo -e "\tgit tag -af latest_release $LATEST_TAG" >&2 @@ -204,7 +204,7 @@ publish() { 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 push "$DOCKERHUB_USER"/scope:$"VERSION" echo "** Docker images tagged and pushed" echo "== Publishing release on GitHub" diff --git a/bin/setup-circleci-secrets b/bin/setup-circleci-secrets index d39df87646..e6b83318a1 100755 --- a/bin/setup-circleci-secrets +++ b/bin/setup-circleci-secrets @@ -5,10 +5,9 @@ set -eu # openssl enc -in do-setup-circleci-secrets.orig -out setup-circleci-secrets.orig -e -aes256 -pass stdin # openssl base64 < setup-circleci-secrets.orig -openssl base64 -d << EOF \ - | openssl enc \ +openssl base64 -d </var/run/weave/scope-app.args +declare -p ARGS >/var/run/weave/scope-app.args # shellcheck disable=SC2034 -typeset -p ARGS >/var/run/weave/scope-probe.args +declare -p ARGS >/var/run/weave/scope-probe.args exec /home/weave/runsvinit diff --git a/docker/run-app b/docker/run-app index 4d6c9d1948..fd049876be 100755 --- a/docker/run-app +++ b/docker/run-app @@ -2,5 +2,5 @@ # shellcheck disable=SC1091 source /var/run/weave/scope-app.args - + exec -a scope-app /home/weave/scope --mode app "${ARGS[@]}" diff --git a/extras/dialer/dialer b/extras/dialer/dialer index 46426b5676..c984c9615a 100755 --- a/extras/dialer/dialer +++ b/extras/dialer/dialer @@ -1,8 +1,8 @@ #!/bin/bash set -eu if [ $# -lt 1 ]; then - echo "Usage: $0 []" >&2 - exit 1 + echo "Usage: $0 []" >&2 + exit 1 fi readonly addr=$1 @@ -13,15 +13,15 @@ dialer=() trap 'echo -n "stopping ... "; for c in "${dialer[@]}"; do docker rm -f "$c" >/dev/null; done; echo "done"' EXIT while true; do - rand=$(( ( RANDOM % max_dialer ) + 1 )) - dialer+=("$(docker run -d dialer /go/bin/dialer connect "$addr" "$rand")") + rand=$(((RANDOM % max_dialer) + 1)) + dialer+=("$(docker run -d dialer /go/bin/dialer connect "$addr" "$rand")") - if [ ${#dialer[@]} -gt "$max_dialer" ]; then - container=${dialer[$rand]} - docker rm -f "$container" >/dev/null & - unset dialer[$rand] - dialer=("${dialer[@]}") - fi + if [ ${#dialer[@]} -gt "$max_dialer" ]; then + container=${dialer[$rand]} + docker rm -f "$container" >/dev/null & + unset dialer[$rand] + dialer=("${dialer[@]}") + fi - sleep $(( rand % 3 )) + sleep $((rand % 3)) done diff --git a/extras/dialer/listener b/extras/dialer/listener index 7e6112a67d..4d9c975920 100755 --- a/extras/dialer/listener +++ b/extras/dialer/listener @@ -2,7 +2,7 @@ set -eu readonly port=${1:-8082} ( -sleep 5 # wait for dialerserver to start -echo "IP addr + port: $(docker inspect -f '{{ .NetworkSettings.IPAddress }}' dialerserver):$port" + sleep 5 # wait for dialerserver to start + echo "IP addr + port: $(docker inspect -f '{{ .NetworkSettings.IPAddress }}' dialerserver):$port" ) & docker run --rm --name dialerserver dialer /go/bin/dialer listen "$port" diff --git a/extras/dialer/time-scope-probe b/extras/dialer/time-scope-probe index bc28644fd6..6963aea45f 100755 --- a/extras/dialer/time-scope-probe +++ b/extras/dialer/time-scope-probe @@ -1,8 +1,8 @@ #!/bin/bash set -eu if [ $EUID -ne 0 ]; then - echo "You must be root!" >&2 - exit 1 + echo "You must be root!" >&2 + exit 1 fi readonly interval_num=${1:-60} @@ -16,18 +16,18 @@ TIME_K2=0 TIME_T2=0 if [ "$(pidof scope-probe)" == "" ]; then - echo "No scope-probe process running - aborting" >&2 - exit 1 + echo "No scope-probe process running - aborting" >&2 + exit 1 fi -for ((i=0; i<"$interval_num"; i++)); do - sleep "$interval_sleep" - TIME_U1=$TIME_U2 - TIME_K1=$TIME_K2 - TIME_T1=$TIME_T2 +for ((i = 0; i < "$interval_num"; i++)); do + sleep "$interval_sleep" + TIME_U1=$TIME_U2 + TIME_K1=$TIME_K2 + TIME_T1=$TIME_T2 - TIME_U2=$(gawk '{print $14"*10"}'<"/proc/$(pidof scope-probe)/stat" | bc) - TIME_K2=$(gawk '{print $15"*10"}'<"/proc/$(pidof scope-probe)/stat" | bc) - TIME_T2=$(( TIME_U2 + TIME_K2 )) - echo "utime $(( TIME_U2 - TIME_U1)) + stime $(( TIME_K2 - TIME_K1 )) = $(( TIME_T2 - TIME_T1 ))" + TIME_U2=$(gawk '{print $14"*10"}' <"/proc/$(pidof scope-probe)/stat" | bc) + TIME_K2=$(gawk '{print $15"*10"}' <"/proc/$(pidof scope-probe)/stat" | bc) + TIME_T2=$((TIME_U2 + TIME_K2)) + echo "utime $((TIME_U2 - TIME_U1)) + stime $((TIME_K2 - TIME_K1)) = $((TIME_T2 - TIME_T1))" done diff --git a/extras/example/run.sh b/extras/example/run.sh index 633883d3d2..92b47c2ac4 100755 --- a/extras/example/run.sh +++ b/extras/example/run.sh @@ -35,4 +35,3 @@ start_container 1 tomwilkie/echo echo start_container 2 tomwilkie/app app start_container 2 tomwilkie/frontend frontend --add-host=dns.weave.local:"$(weave docker-bridge-ip)" start_container 1 tomwilkie/client client - diff --git a/extras/example/run_tracer.sh b/extras/example/run_tracer.sh index d9da6e9bb2..e22172b9d4 100755 --- a/extras/example/run_tracer.sh +++ b/extras/example/run_tracer.sh @@ -21,13 +21,13 @@ start_container() { while [ "$#" -gt 0 ]; do case "$1" in --) - shift - break - ;; + shift + break + ;; *) - docker_args="${docker_args} $1" - shift - ;; + docker_args="${docker_args} $1" + shift + ;; esac done local container_args="$*" @@ -46,4 +46,3 @@ start_container 1 tomwilkie/echo echo start_container 1 tomwilkie/trace_app app start_container 1 tomwilkie/client client -- -target app.weave.local \ -concurrency 1 -persist False - diff --git a/extras/generate_latest_map b/extras/generate_latest_map index 58b2d858c8..04e886a1cc 100755 --- a/extras/generate_latest_map +++ b/extras/generate_latest_map @@ -8,11 +8,11 @@ # Depends on: # - gofmt -function generate_header { +function generate_header() { local out_file="${1}" local cmd="${2}" - cat << EOF >"${out_file}" + cat <"${out_file}" // Generated file, do not edit. // To regenerate, run ${cmd} @@ -26,7 +26,7 @@ function generate_header { EOF } -function generate_latest_map { +function generate_latest_map() { local out_file="$1" local data_type="$2" local uppercase_data_type="${data_type^}" @@ -43,7 +43,7 @@ function generate_latest_map { # shellcheck disable=SC2016 local json_value='`json:"value"`' - cat << EOF >>"${out_file}" + cat <>"${out_file}" type ${wire_entry_type} struct { Timestamp time.Time ${json_timestamp} Value ${data_type} ${json_value} diff --git a/extras/in_parallel.sh b/extras/in_parallel.sh index e8c5e1f166..11a399b99c 100755 --- a/extras/in_parallel.sh +++ b/extras/in_parallel.sh @@ -26,7 +26,7 @@ echo Doing "$INPUTS" for INPUT in $INPUTS; do START=$(date +%s) "$COMMAND" "$INPUT" - RUNTIME=$(( $(date +%s) - START )) + RUNTIME=$(($(date +%s) - START)) "../tools/sched" time "$INPUT" "$RUNTIME" done diff --git a/integration/100_launch_test.sh b/integration/100_launch_test.sh index b3509e12b3..8c80c6c23d 100755 --- a/integration/100_launch_test.sh +++ b/integration/100_launch_test.sh @@ -1,7 +1,7 @@ #! /bin/bash # shellcheck disable=SC1091 - ./config.sh +./config.sh start_suite "Launch scope and check it boots" diff --git a/integration/110_shutdown_test.sh b/integration/110_shutdown_test.sh index a69ac994e7..855001b454 100755 --- a/integration/110_shutdown_test.sh +++ b/integration/110_shutdown_test.sh @@ -12,7 +12,7 @@ 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" diff --git a/integration/115_topologies_test.sh b/integration/115_topologies_test.sh index 81ed72eeb9..ca502a2a92 100755 --- a/integration/115_topologies_test.sh +++ b/integration/115_topologies_test.sh @@ -10,25 +10,25 @@ scope_on "$HOST1" launch wait_for_containers "$HOST1" 60 weavescope topology_is_not_empty() { - local host="$1" - local topology="$2" - local timeout="${5:-60}" - - 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 - 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 + local host="$1" + local topology="$2" + local timeout="${5:-60}" + + 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 + 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 } topology_is_not_empty "$HOST1" Endpoint diff --git a/integration/200_clustering_2_test.sh b/integration/200_clustering_2_test.sh index 7cba456574..07c6a6cf8e 100755 --- a/integration/200_clustering_2_test.sh +++ b/integration/200_clustering_2_test.sh @@ -17,11 +17,11 @@ 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" diff --git a/integration/205_clustering_sans_weave_2_test.sh b/integration/205_clustering_sans_weave_2_test.sh index b2cff6f71f..ad6a95c91f 100755 --- a/integration/205_clustering_sans_weave_2_test.sh +++ b/integration/205_clustering_sans_weave_2_test.sh @@ -14,11 +14,11 @@ 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" diff --git a/integration/210_clustering_custom_hostname_2_test.sh b/integration/210_clustering_custom_hostname_2_test.sh index 43897b4f85..043487659b 100755 --- a/integration/210_clustering_custom_hostname_2_test.sh +++ b/integration/210_clustering_custom_hostname_2_test.sh @@ -17,11 +17,11 @@ 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" diff --git a/integration/300_internet_edge_test.sh b/integration/300_internet_edge_test.sh index 6c844d75b0..a2770f2bda 100755 --- a/integration/300_internet_edge_test.sh +++ b/integration/300_internet_edge_test.sh @@ -6,9 +6,9 @@ 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 @@ -16,12 +16,12 @@ 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" diff --git a/integration/320_container_edge_cross_host_2_test.sh b/integration/320_container_edge_cross_host_2_test.sh index d2a879649c..5a0d3b19c2 100755 --- a/integration/320_container_edge_cross_host_2_test.sh +++ b/integration/320_container_edge_cross_host_2_test.sh @@ -20,9 +20,9 @@ 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" diff --git a/integration/410_container_control_test.sh b/integration/410_container_control_test.sh index 7aa354fb42..02f731f149 100755 --- a/integration/410_container_control_test.sh +++ b/integration/410_container_control_test.sh @@ -16,7 +16,7 @@ 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') # Execute 'echo foo' in a container tty and check its output -PIPEID=$(curl -s -f -X POST "http://$HOST1:4040/api/control/$PROBEID/$CID;/docker_exec_container" | jq -r '.pipe' ) +PIPEID=$(curl -s -f -X POST "http://$HOST1:4040/api/control/$PROBEID/$CID;/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;/docker_stop_container'" diff --git a/integration/420_host_control_test.sh b/integration/420_host_control_test.sh index 6e146b0d58..fe461b091f 100755 --- a/integration/420_host_control_test.sh +++ b/integration/420_host_control_test.sh @@ -14,7 +14,7 @@ PROBEID=$(docker_on "$HOST1" logs weavescope 2>&1 | grep "probe starting" | sed 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_exec" | jq -r '.pipe' ) +PIPEID=$(curl -s -f -X POST "http://$HOST1:4040/api/control/$PROBEID/$HOSTID;/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 diff --git a/integration/config.sh b/integration/config.sh index c7761886ea..05586e0115 100644 --- a/integration/config.sh +++ b/integration/config.sh @@ -15,45 +15,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" rm -f "$(docker_on "$host" ps -a -q)" 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" - 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() { @@ -62,74 +62,73 @@ 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}" - - 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 - 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 + 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 + 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 + 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 } has_connection() { - local view="$1" - local host="$2" - local from="$3" - local to="$4" - local timeout="${5:-60}" - local from_id - local to_id - - 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}" + local view="$1" + local host="$2" + local from="$3" + local to="$4" + local timeout="${5:-60}" + local from_id + local to_id + + 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() { - local view="$1" - local host="$2" - local timeout="$3" - shift 3 - - 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 - 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 - - sleep 1 - done - - echo "Failed to find nodes $* after $i secs" + local view="$1" + local host="$2" + local timeout="$3" + shift 3 + + 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 + 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 + + sleep 1 + done + + echo "Failed to find nodes $* after $i secs" } - wait_for_containers() { - wait_for containers "$@" + wait_for containers "$@" } diff --git a/scope b/scope index 8058b8eb40..5597b50da0 100755 --- a/scope +++ b/scope @@ -4,7 +4,7 @@ set -eu ARGS="$*" SCRIPT_VERSION="(unreleased version)" -if [ "$SCRIPT_VERSION" = "(unreleased version)" ] ; then +if [ "$SCRIPT_VERSION" = "(unreleased version)" ]; then IMAGE_VERSION=latest else IMAGE_VERSION="$SCRIPT_VERSION" @@ -79,8 +79,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 @@ -98,22 +98,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 @@ -145,34 +145,34 @@ 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() { # shellcheck disable=SC2086 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() { # shellcheck disable=SC2086 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() { @@ -213,7 +213,7 @@ case "$COMMAND" in $WEAVESCOPE_DOCKER_ARGS "$SCOPE_IMAGE" --mode=version ;; - -h|help|-help|--help) + -h | help | -help | --help) usage ;; @@ -223,9 +223,9 @@ case "$COMMAND" in # shellcheck disable=SC2086 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 @@ -248,7 +248,7 @@ case "$COMMAND" in 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 @@ -257,12 +257,12 @@ case "$COMMAND" in stop) [ $# -eq 0 ] || usage_and_die - 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 ;;