Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration test for procspy edges. #781

Merged
merged 2 commits into from
Jan 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions experimental/example/run.sh
Original file line number Diff line number Diff line change
@@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion integration/300_internet_edge_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions integration/310_container_to_container_edge_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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
6 changes: 3 additions & 3 deletions integration/320_container_edge_cross_host_2_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
21 changes: 21 additions & 0 deletions integration/330_application_edge_test.sh
Original file line number Diff line number Diff line change
@@ -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"

This comment was marked as abuse.

This comment was marked as abuse.


wait_for application $HOST1 60 nginx client

has applications $HOST1 nginx
has applications $HOST1 nc
has_connection applications $HOST1 nc nginx

This comment was marked as abuse.


scope_end_suite
30 changes: 30 additions & 0 deletions integration/340_application_edge_across_host_2_test.sh
Original file line number Diff line number Diff line change
@@ -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
80 changes: 49 additions & 31 deletions integration/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,73 +29,91 @@ 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
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_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 "$@"
}