mirror of
https://github.com/sshuttle/sshuttle.git
synced 2024-11-25 01:13:37 +01:00
better test-bed scripts
This commit is contained in:
parent
d4d0fa945d
commit
db9ec36fac
11
hack/README.md
Normal file
11
hack/README.md
Normal 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
|
||||||
|
|
||||||
|
```
|
@ -5,8 +5,6 @@ services:
|
|||||||
image: ghcr.io/sshuttle/sshuttle-testbed
|
image: ghcr.io/sshuttle/sshuttle-testbed
|
||||||
container_name: sshuttle-testbed-node-1
|
container_name: sshuttle-testbed-node-1
|
||||||
hostname: node-1
|
hostname: node-1
|
||||||
ports:
|
|
||||||
- 22001:2222
|
|
||||||
cap_add:
|
cap_add:
|
||||||
- "NET_ADMIN"
|
- "NET_ADMIN"
|
||||||
environment:
|
environment:
|
||||||
@ -15,8 +13,6 @@ services:
|
|||||||
image: ghcr.io/sshuttle/sshuttle-testbed
|
image: ghcr.io/sshuttle/sshuttle-testbed
|
||||||
container_name: sshuttle-testbed-node-2
|
container_name: sshuttle-testbed-node-2
|
||||||
hostname: node-2
|
hostname: node-2
|
||||||
ports:
|
|
||||||
- 22002:2222
|
|
||||||
cap_add:
|
cap_add:
|
||||||
- "NET_ADMIN"
|
- "NET_ADMIN"
|
||||||
environment:
|
environment:
|
||||||
|
@ -9,9 +9,9 @@ if [[ ! $node =~ [1-9]+ ]]; then
|
|||||||
fi
|
fi
|
||||||
shift
|
shift
|
||||||
|
|
||||||
port="2200$node"
|
port="2222"
|
||||||
subnet_args="-N"
|
subnet_args="-N"
|
||||||
host=localhost
|
host=$("$(dirname "$0")/test-bed" get-ip "$node")
|
||||||
user="test:test"
|
user="test:test"
|
||||||
|
|
||||||
if ! command -v sshpass >/dev/null; then
|
if ! command -v sshpass >/dev/null; then
|
||||||
|
@ -2,10 +2,11 @@
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
tool=${1?:"tool argument missing. should be one of iperf3,ping,curl,ab"}
|
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
|
shift 2
|
||||||
|
|
||||||
ip="10.55.$node.77"
|
index=${node#node-}
|
||||||
|
ip="10.55.$index.77"
|
||||||
connect_timeout_sec=3
|
connect_timeout_sec=3
|
||||||
|
|
||||||
function with_set_x() {
|
function with_set_x() {
|
||||||
@ -34,4 +35,8 @@ ab)
|
|||||||
port=8080
|
port=8080
|
||||||
with_set_x exec ab -n 100 -c 20 -s $connect_timeout_sec "$@" "http://$ip:$port/"
|
with_set_x exec ab -n 100 -c 20 -s $connect_timeout_sec "$@" "http://$ip:$port/"
|
||||||
;;
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unknown tool: $tool" >&2
|
||||||
|
exit 2
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
@ -5,14 +5,15 @@ cd "$(dirname "$0")"
|
|||||||
function with_set_x() {
|
function with_set_x() {
|
||||||
set -x
|
set -x
|
||||||
"$@"
|
"$@"
|
||||||
{ ec=$?; set +x;return $ec; } 2>/dev/null
|
{
|
||||||
|
ec=$?
|
||||||
|
set +x
|
||||||
|
return $ec
|
||||||
|
} 2>/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
./test-bed up -d
|
./test-bed up -d
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
benchmark() {
|
benchmark() {
|
||||||
local sshuttle_bin="${1?:}"
|
local sshuttle_bin="${1?:}"
|
||||||
echo -e "\n======== Benchmarking sshuttle: $sshuttle_bin ========"
|
echo -e "\n======== Benchmarking sshuttle: $sshuttle_bin ========"
|
||||||
@ -29,12 +30,9 @@ benchmark() {
|
|||||||
wait $sshuttle_pid || true
|
wait $sshuttle_pid || true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if [[ "$1" ]]; then
|
if [[ "$1" ]]; then
|
||||||
benchmark "$1"
|
benchmark "$1"
|
||||||
else
|
else
|
||||||
benchmark "${SSHUTTLE_BIN:-/bin/sshuttle}"
|
benchmark "${SSHUTTLE_BIN:-/bin/sshuttle}"
|
||||||
benchmark dev
|
benchmark dev
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,10 +8,13 @@ echo -e ">>> Setting up $(hostname) | id: $(id) | $(python --version) \nip: $(ip
|
|||||||
function with_set_x() {
|
function with_set_x() {
|
||||||
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 }')"
|
iface="$(ip route | awk '/default/ { print $5 }')"
|
||||||
default_gw="$(ip route | awk '/default/ { print $3 }')"
|
default_gw="$(ip route | awk '/default/ { print $3 }')"
|
||||||
for addr in ${IP_ADDRESSES//,/ }; do
|
for addr in ${IP_ADDRESSES//,/ }; do
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
set -e
|
set -e
|
||||||
cd "$(dirname "$0")"
|
cd "$(dirname "$0")"
|
||||||
|
|
||||||
|
|
||||||
if [[ -z $1 || $1 = -* ]]; then
|
if [[ -z $1 || $1 = -* ]]; then
|
||||||
set -- up "$@"
|
set -- up "$@"
|
||||||
fi
|
fi
|
||||||
@ -10,7 +9,11 @@ fi
|
|||||||
function with_set_x() {
|
function with_set_x() {
|
||||||
set -x
|
set -x
|
||||||
"$@"
|
"$@"
|
||||||
{ ec=$?; set +x;return $ec; } 2>/dev/null
|
{
|
||||||
|
ec=$?
|
||||||
|
set +x
|
||||||
|
return $ec
|
||||||
|
} 2>/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
function build() {
|
function build() {
|
||||||
@ -23,8 +26,17 @@ function compose() {
|
|||||||
with_set_x docker 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
|
if [[ $1 == get-ip ]]; then
|
||||||
|
shift
|
||||||
|
get-ip "$@"
|
||||||
|
else
|
||||||
|
if [[ $* = *--build* ]]; then
|
||||||
build
|
build
|
||||||
|
fi
|
||||||
|
compose "$@"
|
||||||
fi
|
fi
|
||||||
compose "$@"
|
|
||||||
|
Loading…
Reference in New Issue
Block a user