diff --git a/experimental/example/run.sh b/experimental/example/run.sh index 8be48875ea..d003932ac7 100755 --- a/experimental/example/run.sh +++ b/experimental/example/run.sh @@ -1,21 +1,25 @@ #!/bin/bash -set -eux +set -ex + +readonly ARG="$1" eval $(weave env) start_container() { - IMAGE=$2 - BASENAME=$3 - REPLICAS=$1 + local IMAGE=$2 + local BASENAME=$3 + local REPLICAS=$1 shift 3 - HOSTNAME=$BASENAME.weave.local + local HOSTNAME=$BASENAME.weave.local for i in $(seq $REPLICAS); do if docker inspect $BASENAME$i >/dev/null 2>&1; then docker rm -f $BASENAME$i fi - docker run -d --name=$BASENAME$i --hostname=$HOSTNAME $@ $IMAGE + if [ "$ARG" != "-rm" ]; then + docker run -d --name=$BASENAME$i --hostname=$HOSTNAME $@ $IMAGE + fi done } diff --git a/integration/300_internet_edge_test.sh b/integration/300_internet_edge_test.sh index 3e5b07a1b9..eff59e43cb 100755 --- a/integration/300_internet_edge_test.sh +++ b/integration/300_internet_edge_test.sh @@ -26,7 +26,7 @@ wait_for_containers $HOST1 60 nginx "The Internet" has_container $HOST1 nginx has_container $HOST1 "The Internet" -has_connection $HOST1 "The Internet" nginx +has_connection containers $HOST1 "The Internet" nginx kill %do_connections diff --git a/integration/310_container_to_container_edge_test.sh b/integration/310_container_to_container_edge_test.sh index 1ff072a744..3922c7309c 100755 --- a/integration/310_container_to_container_edge_test.sh +++ b/integration/310_container_to_container_edge_test.sh @@ -4,7 +4,7 @@ start_suite "Test short lived connections between containers" -WEAVE_NO_FASTDP=true WEAVE_DOCKER_ARGS=$ADD_HOST_ARGS weave_on $HOST1 launch +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 \ @@ -16,6 +16,6 @@ wait_for_containers $HOST1 60 nginx client has_container $HOST1 nginx has_container $HOST1 client -has_connection $HOST1 client nginx +has_connection containers $HOST1 client nginx scope_end_suite diff --git a/integration/320_container_edge_cross_host_2_test.sh b/integration/320_container_edge_cross_host_2_test.sh index b424d21e59..26d6a3c02d 100755 --- a/integration/320_container_edge_cross_host_2_test.sh +++ b/integration/320_container_edge_cross_host_2_test.sh @@ -4,8 +4,8 @@ start_suite "Test short lived connections between containers on different hosts" -WEAVE_NO_FASTDP=true WEAVE_DOCKER_ARGS=$ADD_HOST_ARGS weave_on $HOST1 launch $HOST1 $HOST2 -WEAVE_NO_FASTDP=true WEAVE_DOCKER_ARGS=$ADD_HOST_ARGS 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 @@ -21,7 +21,7 @@ sleep 30 # need to allow the scopes to poll dns, resolve the other app ids, and check() { has_container $1 nginx has_container $1 client - has_connection $1 client nginx + has_connection containers $1 client nginx } check $HOST1 diff --git a/integration/330_application_edge_test.sh b/integration/330_application_edge_test.sh new file mode 100755 index 0000000000..56363b041d --- /dev/null +++ b/integration/330_application_edge_test.sh @@ -0,0 +1,21 @@ +#! /bin/bash + +. ./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 \ + nc nginx.weave.local 80 || true; \ + sleep 1; \ +done" + +wait_for application $HOST1 60 nginx client + +has applications $HOST1 nginx +has applications $HOST1 nc +has_connection applications $HOST1 nc nginx + +scope_end_suite diff --git a/integration/340_application_edge_across_host_2_test.sh b/integration/340_application_edge_across_host_2_test.sh new file mode 100755 index 0000000000..e3b43e07bf --- /dev/null +++ b/integration/340_application_edge_across_host_2_test.sh @@ -0,0 +1,30 @@ +#! /bin/bash + +. ./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 + +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 \ + nc nginx.weave.local 80 || true; \ + sleep 1; \ +done" + +sleep 30 # need to allow the scopes to poll dns, resolve the other app ids, and send them reports + +check() { + has applications $1 nginx + has applications $1 nc + has_connection applications $1 nc nginx +} + +check $HOST1 +check $HOST2 + +scope_end_suite diff --git a/integration/config.sh b/integration/config.sh index ed083c5d75..9d8b4dd459 100644 --- a/integration/config.sh +++ b/integration/config.sh @@ -29,14 +29,6 @@ weave_on() { DOCKER_HOST=tcp://$host:$DOCKER_PORT $WEAVE "$@" } -# this checks we have a named container -has_container() { - local host=$1 - local name=$2 - local count=${3:-1} - assert "curl -s http://$host:4040/api/topology/containers?system=show | jq -r '[.nodes[] | select(.label_major == \"$name\")] | length'" $count -} - scope_end_suite() { end_suite for host in $HOSTS; do @@ -44,58 +36,84 @@ scope_end_suite() { 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_major == \"${name}\")] | length'" $count +} + +# this checks we have a named container +has_container() { + 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_major == \"${name}\") | .id") +} + container_id() { - local host="$1" - local name="$2" - echo $(curl -s http://$host:4040/api/topology/containers?system=show | jq -r ".nodes[] | select(.label_major == \"$name\") | .id") + node_id containers "$@" } # this checks we have an edge from container 1 to container 2 has_connection() { - local host="$1" - local from="$2" - local to="$3" - local timeout="${4:-60}" - local from_id=$(container_id "$host" "$from") - local to_id=$(container_id "$host" "$to") + 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}") for i in $(seq $timeout); do - local containers="$(curl -s http://$host:4040/api/topology/containers?system=show)" - local edge=$(echo "$containers" | jq -r ".nodes[\"$from_id\"].adjacency | contains([\"$to_id\"])" 2>/dev/null) + 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/containers?system=show | jq -r '.nodes[\"$from_id\"].adjacency | contains([\"$to_id\"])'" true + 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/containers?system=show | jq -r '.nodes[\"$from_id\"].adjacency | contains([\"$to_id\"])'" true + assert "curl -s http://$host:4040/api/topology/${view}?system=show | jq -r '.nodes[\"$from_id\"].adjacency | contains([\"$to_id\"])'" true } -wait_for_containers() { - local host="$1" - local timeout="$2" +wait_for() { + local view="$1" + local host="$2" + local timeout="$3" shift 2 - for i in $(seq $timeout); do - local containers="$(curl -s http://$host:4040/api/topology/containers?system=show)" + 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 "$containers" | jq -r "[.nodes[] | select(.label_major == \"$name\")] | length") - if [ -n "$count" ] && [ "$count" -ge 1 ]; then + local count=$(echo "${nodes}" | jq -r "[.nodes[] | select(.label_major == \"${name}\")] | length") + if [ -n "${count}" ] && [ "${count}" -ge 1 ]; then found=$(( found + 1 )) fi done - if [ "$found" -eq $# ]; then - echo "Found $found containers after $i secs" + if [ "${found}" -eq $# ]; then + echo "Found ${found} nodes after $i secs" return fi sleep 1 done - echo "Failed to find containers $@ after $i secs" + echo "Failed to find nodes $@ after $i secs" +} + + +wait_for_containers() { + wait_for containers "$@" }