Skip to content

Commit

Permalink
integration: add tests for eBPF
Browse files Browse the repository at this point in the history
  • Loading branch information
iaguis authored and alban committed Mar 8, 2017
1 parent 0e05198 commit 6d55a34
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
28 changes: 28 additions & 0 deletions integration/301_internet_edge_with_ebpf_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#! /bin/bash

# shellcheck disable=SC1091
. ./config.sh

start_suite "Test short lived connections from the Internet"

weave_on "$HOST1" launch
scope_on "$HOST1" launch --probe.ebpf.connections=true
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
}
do_connections &

wait_for_containers "$HOST1" 60 nginx "The Internet"

has_connection_by_id containers "$HOST1" "in-theinternet" "$(node_id containers "$HOST1" nginx)"

endpoints_have_ebpf "$HOST1"

kill %do_connections

scope_end_suite
24 changes: 24 additions & 0 deletions integration/311_container_to_container_edge_with_ebpf_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#! /bin/bash

# shellcheck disable=SC1091
. ./config.sh

start_suite "Test short lived connections between containers, with ebpf connection tracking enabled"

weave_on "$HOST1" launch
scope_on "$HOST1" launch --probe.ebpf.connections=true
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

has_container "$HOST1" nginx
has_container "$HOST1" client
has_connection containers "$HOST1" client nginx

endpoints_have_ebpf "$HOST1"

scope_end_suite
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#! /bin/bash

# shellcheck disable=SC1091
. ./config.sh

start_suite "Test short lived connection between containers in same network namespace, with ebpf connection tracking enabled"

scope_on "$HOST1" launch --probe.ebpf.connections=true
docker_on "$HOST1" run -d --name nginx nginx
docker_on "$HOST1" run -d --net=container:nginx --name client albanc/dialer /go/bin/dialer connectshortlived localhost:80

wait_for_containers "$HOST1" 60 nginx client

has_container "$HOST1" nginx
has_container "$HOST1" client
has_connection containers "$HOST1" client nginx

endpoints_have_ebpf "$HOST1"

scope_end_suite
24 changes: 24 additions & 0 deletions integration/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,30 @@ has_connection_by_id() {
assert "curl -s http://$host:4040/api/topology/${view}?system=show | jq -r '.nodes[\"$from_id\"].adjacency | contains([\"$to_id\"])'" true
}

# this checks if ebpf is true on all endpoints on a given host
endpoints_have_ebpf() {
local host="$1"
local timeout="${2:-60}"
local number_of_endpoints=-1
local have_ebpf=-1
local report

for i in $(seq "$timeout"); do
report=$(curl -s "http://${host}:4040/api/report")
number_of_endpoints=$(echo "${report}" | jq -r '.Endpoint.nodes | length')
have_ebpf=$(echo "${report}" | jq -r '.Endpoint.nodes[].latest.eBPF | select(.value != null) | contains({"value": "true"})' | wc -l)
if [[ "$number_of_endpoints" -gt 0 && "$have_ebpf" -gt 0 && "$number_of_endpoints" -eq "$have_ebpf" ]]; then
echo "Found ${number_of_endpoints} endpoints with ebpf enabled"
assert "echo '$have_ebpf'" "$number_of_endpoints"
return
fi
sleep 1
done

echo "Only ${have_ebpf} endpoints of ${number_of_endpoints} have ebpf enabled, should be equal"
assert "echo '$have_ebpf" "$number_of_endpoints"
}

has_connection() {
local view="$1"
local host="$2"
Expand Down

0 comments on commit 6d55a34

Please sign in to comment.