better test-bed scripts

This commit is contained in:
nom3ad 2024-01-02 09:46:22 +05:30 committed by Brian May
parent d4d0fa945d
commit db9ec36fac
8 changed files with 48 additions and 23 deletions

11
hack/README.md Normal file
View File

@ -0,0 +1,11 @@
# Container based test bed for sshuttle
```bash
test-bed up -d # start containers
exec-sshuttle node-1 # start sshuttle to connect to node-1
exec-tool curl node-1 # curl to nginx instance running on node1 via IP that is only reachable via sshuttle
exec-tool iperf3 node-1 # measure throughput to node-1
```

View File

@ -5,8 +5,6 @@ services:
image: ghcr.io/sshuttle/sshuttle-testbed
container_name: sshuttle-testbed-node-1
hostname: node-1
ports:
- 22001:2222
cap_add:
- "NET_ADMIN"
environment:
@ -15,8 +13,6 @@ services:
image: ghcr.io/sshuttle/sshuttle-testbed
container_name: sshuttle-testbed-node-2
hostname: node-2
ports:
- 22002:2222
cap_add:
- "NET_ADMIN"
environment:

View File

@ -9,9 +9,9 @@ if [[ ! $node =~ [1-9]+ ]]; then
fi
shift
port="2200$node"
port="2222"
subnet_args="-N"
host=localhost
host=$("$(dirname "$0")/test-bed" get-ip "$node")
user="test:test"
if ! command -v sshpass >/dev/null; then

View File

@ -2,10 +2,11 @@
set -e
tool=${1?:"tool argument missing. should be one of iperf3,ping,curl,ab"}
node=${2?:"node argument missing. should be '1' , '2' etc"}
node=${2?:"node argument missing. should be 'node-1' , 'node-2' etc"}
shift 2
ip="10.55.$node.77"
index=${node#node-}
ip="10.55.$index.77"
connect_timeout_sec=3
function with_set_x() {
@ -34,4 +35,8 @@ ab)
port=8080
with_set_x exec ab -n 100 -c 20 -s $connect_timeout_sec "$@" "http://$ip:$port/"
;;
*)
echo "Unknown tool: $tool" >&2
exit 2
;;
esac

View File

@ -5,14 +5,15 @@ cd "$(dirname "$0")"
function with_set_x() {
set -x
"$@"
{ ec=$?; set +x;return $ec; } 2>/dev/null
{
ec=$?
set +x
return $ec
} 2>/dev/null
}
./test-bed up -d
benchmark() {
local sshuttle_bin="${1?:}"
echo -e "\n======== Benchmarking sshuttle: $sshuttle_bin ========"
@ -29,12 +30,9 @@ benchmark() {
wait $sshuttle_pid || true
}
if [[ "$1" ]]; then
benchmark "$1"
else
benchmark "${SSHUTTLE_BIN:-/bin/sshuttle}"
benchmark dev
fi

View File

@ -6,4 +6,4 @@ export PYTHONPATH=.
set -x
python -m pytest .
python -m flake8 .
python -m flake8 .

View File

@ -8,10 +8,13 @@ echo -e ">>> Setting up $(hostname) | id: $(id) | $(python --version) \nip: $(ip
function with_set_x() {
set -x
"$@"
{ ec=$?; set +x;return $ec; } 2>/dev/null
{
ec=$?
set +x
return $ec
} 2>/dev/null
}
iface="$(ip route | awk '/default/ { print $5 }')"
default_gw="$(ip route | awk '/default/ { print $3 }')"
for addr in ${IP_ADDRESSES//,/ }; do

View File

@ -2,7 +2,6 @@
set -e
cd "$(dirname "$0")"
if [[ -z $1 || $1 = -* ]]; then
set -- up "$@"
fi
@ -10,7 +9,11 @@ fi
function with_set_x() {
set -x
"$@"
{ ec=$?; set +x;return $ec; } 2>/dev/null
{
ec=$?
set +x
return $ec
} 2>/dev/null
}
function build() {
@ -23,8 +26,17 @@ function compose() {
with_set_x docker compose "$@"
}
function get-ip() {
local container_name=sshuttle-testbed-"$1"
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$container_name"
}
if [[ $* = *--build* ]]; then
build
if [[ $1 == get-ip ]]; then
shift
get-ip "$@"
else
if [[ $* = *--build* ]]; then
build
fi
compose "$@"
fi
compose "$@"