Compare commits

...

4 Commits

Author SHA1 Message Date
Brian Picciano
a77617ae96 Add test for network creation 2023-09-01 17:20:03 +02:00
Brian Picciano
ae70278a9f Add --keep-tmp flag to test script 2023-09-01 17:19:48 +02:00
Brian Picciano
0b486d5d27 Allow setting tun name in daemon config 2023-09-01 16:45:21 +02:00
Brian Picciano
d2d25d3621 Set XDG variables on a per-test basis 2023-09-01 16:18:23 +02:00
6 changed files with 93 additions and 18 deletions

View File

@ -52,6 +52,10 @@ vpn:
# That's it.
tun:
# Name of the tun network device which will route VPN traffic.
device: isle-tun
storage:
# Allocations defined here are used to store data in the distributed storage

View File

@ -165,8 +165,17 @@ in rec {
};
tests = pkgs.writeShellScript "isle-tests" ''
export PATH=$PATH:${appImage}/bin
export PATH=${appImage}/bin:$PATH
test_dir=${./tests}
exec $SHELL $test_dir/entrypoint.sh "$@"
this_user="$(${pkgs.coreutils}/bin/whoami)"
echo "Requesting sudo in order to set thread capabilities, will drop back down to user '$this_user' immediately"
sudo ${pkgs.libcap}/bin/capsh \
--caps="cap_net_admin+eip cap_setpcap,cap_setuid,cap_setgid+ep" \
--keep=1 \
--user="$this_user" \
--addamb=cap_net_admin \
-- $test_dir/entrypoint.sh "$@"
'';
}

View File

@ -68,7 +68,7 @@ func nebulaPmuxProcConfig(
"respond": true,
},
"tun": map[string]interface{}{
"dev": "isle-tun",
"dev": daemonConfig.VPN.Tun.Device,
},
"firewall": daemonConfig.VPN.Firewall,
}

View File

@ -2,6 +2,10 @@ package daemon
import "strconv"
type ConfigTun struct {
Device string `yaml:"device"`
}
type ConfigFirewall struct {
Conntrack ConfigConntrack `yaml:"conntrack"`
Outbound []ConfigFirewallRule `yaml:"outbound"`
@ -50,6 +54,7 @@ type Config struct {
VPN struct {
PublicAddr string `yaml:"public_addr"`
Firewall ConfigFirewall `yaml:"firewall"`
Tun ConfigTun `yaml:"tun"`
} `yaml:"vpn"`
Storage struct {
Allocations []ConfigStorageAllocation

View File

@ -0,0 +1,31 @@
mkdir a
mkdir b
mkdir c
cat >daemon.yml <<EOF
vpn:
tun:
device: isle-test
storage:
allocations:
- data_path: a/data
meta_path: a/meta
capacity: 100
- data_path: b/data
meta_path: b/meta
capacity: 100
- data_path: c/data
meta_path: c/meta
capacity: 100
EOF
isle admin create-network \
--config-path daemon.yml \
--domain test.isle.com \
--hostname primus \
--ip-net "10.6.9.1/24" \
--name "testing"
[ "$(cat a/meta/isle/rpc_port)" = "3900" ]
[ "$(cat b/meta/isle/rpc_port)" = "3910" ]
[ "$(cat c/meta/isle/rpc_port)" = "3920" ]

View File

@ -1,14 +1,30 @@
set -e
REGEXS=()
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
cat <<EOF
USAGE: [flags] [test regexs...]
FLAGS
--keep-tmp
--verbose (-v)
--help (-h)
EOF
exit 1
;;
-v|--verbose)
VERBOSE=1
shift;
shift
;;
--keep-tmp)
KEEP_TMP=1
shift
;;
*)
echo "USAGE: [-v|--verbose]"
exit 1
REGEXS+=("$1")
shift
;;
esac
done
@ -18,7 +34,7 @@ cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null
root=$(pwd)
TMPDIR="$(mktemp --tmpdir -d isle-tests.XXXXXX)"
trap 'rm -rf $TMPDIR' EXIT
if [ -z "$KEEP_TMP" ]; then trap 'rm -rf $TMPDIR' EXIT; fi
export TMPDIR
echo "tmp dir is $TMPDIR"
@ -30,25 +46,35 @@ test_files=$(
| sort -n\
)
for r in "${REGEXS[@]}"; do
test_files="$(echo "$test_files" | grep -P "$r")"
done
echo -e "number of tests: $(echo "$test_files" | wc -l)\n"
for file in $test_files; do
echo "$file"
[ -z "$VERBOSE" ] && output="$TMPDIR/$file.log" || output=/dev/stdout
tmp="$TMPDIR/$file.tmp"
mkdir -p "$tmp"
(
export TMPDIR="$TMPDIR/$file.tmp"
export XDG_RUNTIME_DIR="$TMPDIR/.run"
export XDG_DATA_HOME="$TMPDIR/.data"
if ! (cd "$tmp" && TMPDIR="$tmp" $SHELL -e -x "$root/$file" >"$output" 2>&1); then
echo "$file FAILED"
if [ -z "$VERBOSE" ]; then
echo "output of test is as follows"
echo "------------------------------"
cat "$TMPDIR/$file.log"
echo "------------------------------"
mkdir -p "$TMPDIR" "$XDG_RUNTIME_DIR" "$XDG_DATA_HOME"
cd "$TMPDIR"
if ! $SHELL -e -x "$root/$file" >"$output" 2>&1; then
echo "$file FAILED"
if [ -z "$VERBOSE" ]; then
echo "output of test is as follows"
echo "------------------------------"
cat "$output"
echo "------------------------------"
fi
exit 1
fi
exit 1
fi
)
done
echo -e '\nall tests succeeded!'