2022-02-10 01:19:39 -05:00
|
|
|
#!/bin/sh
|
|
|
|
set -euxo pipefail
|
|
|
|
|
2022-05-21 02:41:30 -04:00
|
|
|
ipv4='192.5'
|
2022-02-10 01:19:39 -05:00
|
|
|
|
|
|
|
# change to this directory
|
|
|
|
cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")"
|
|
|
|
|
2022-05-21 02:41:30 -04:00
|
|
|
usage() { echo "Usage: $0 [-i 192.5] [-d] [-r] [-b] [-n]" 1>&2; exit 1; }
|
2022-02-10 01:19:39 -05:00
|
|
|
|
|
|
|
build=0
|
|
|
|
build_args=''
|
|
|
|
img='xmpp-proxy-test'
|
|
|
|
xmpp_proxy_bind=''
|
|
|
|
run_blocked=0
|
2022-04-25 00:57:26 -04:00
|
|
|
rebuild_image=0
|
2022-02-10 01:19:39 -05:00
|
|
|
ecdsa=0
|
2022-05-23 00:34:32 -04:00
|
|
|
# if we have access to nproc, divide that by 2, otherwise use 1 thread by default
|
|
|
|
threads=$(($(nproc || echo 2) / 2))
|
2022-05-21 02:41:30 -04:00
|
|
|
while getopts ":it:drbeno" o; do
|
2022-02-10 01:19:39 -05:00
|
|
|
case "${o}" in
|
|
|
|
i)
|
|
|
|
ipv4=${OPTARG}
|
2022-05-21 02:41:30 -04:00
|
|
|
;;
|
|
|
|
t)
|
|
|
|
threads=${OPTARG}
|
2022-02-10 01:19:39 -05:00
|
|
|
;;
|
|
|
|
d)
|
|
|
|
build=1
|
2022-05-21 02:41:30 -04:00
|
|
|
xmpp_proxy_bind="-v $PWD/../target/debug/xmpp-proxy:/usr/bin/xmpp-proxy:ro"
|
2022-02-10 01:19:39 -05:00
|
|
|
;;
|
|
|
|
r)
|
|
|
|
build=1
|
|
|
|
build_args='--release'
|
2022-05-21 02:41:30 -04:00
|
|
|
xmpp_proxy_bind="-v $PWD/../target/release/xmpp-proxy:/usr/bin/xmpp-proxy:ro"
|
2022-02-10 01:19:39 -05:00
|
|
|
;;
|
|
|
|
e)
|
|
|
|
ecdsa=1
|
|
|
|
;;
|
|
|
|
b)
|
|
|
|
run_blocked=1
|
|
|
|
;;
|
2022-02-13 14:45:13 -05:00
|
|
|
n)
|
|
|
|
podman image rm -f "$img" "$img-dev" "$img-dev-ecdsa"
|
|
|
|
exit $?
|
|
|
|
;;
|
2022-04-25 00:57:26 -04:00
|
|
|
o)
|
|
|
|
rebuild_image=1
|
|
|
|
;;
|
2022-02-10 01:19:39 -05:00
|
|
|
*)
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $((OPTIND-1))
|
|
|
|
|
|
|
|
[ $build -eq 1 ] && img="$img-dev"
|
|
|
|
[ $ecdsa -eq 1 ] && img="$img-ecdsa"
|
|
|
|
|
|
|
|
rm -rf /tmp/xp-logs/
|
|
|
|
mkdir -p /tmp/xp-logs/
|
|
|
|
|
2022-05-21 02:41:30 -04:00
|
|
|
success=/tmp/xp-logs/success.txt
|
|
|
|
error=/tmp/xp-logs/error.txt
|
|
|
|
skipped=/tmp/xp-logs/skipped.txt
|
|
|
|
|
2022-02-10 01:19:39 -05:00
|
|
|
run_container() {
|
|
|
|
set +x
|
2022-05-21 02:41:30 -04:00
|
|
|
network_name="$1"
|
|
|
|
shift
|
|
|
|
num="$1"
|
|
|
|
shift
|
2022-02-10 01:19:39 -05:00
|
|
|
args=()
|
|
|
|
if [ "$1" == "-d" ]
|
|
|
|
then
|
|
|
|
args+=("-d")
|
|
|
|
shift
|
|
|
|
fi
|
2022-02-17 00:14:40 -05:00
|
|
|
while [ "$1" == "-v" -o "$1" == "-w" ]
|
2022-02-10 01:19:39 -05:00
|
|
|
do
|
2022-02-17 00:14:40 -05:00
|
|
|
args+=("$1")
|
2022-02-10 01:19:39 -05:00
|
|
|
shift
|
|
|
|
args+=("$1")
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
ip="$1"
|
|
|
|
shift
|
|
|
|
name="$1"
|
|
|
|
shift
|
|
|
|
|
|
|
|
set -x
|
2022-05-21 02:41:30 -04:00
|
|
|
podman run "${args[@]}" --rm --log-driver=k8s-file "--log-opt=path=/tmp/xp-logs/$dir-$name.log" --network "$network_name" --dns-search example.org --dns "$ipv4.$num.10" --hostname "$name" --name "$num-$name" --ip "$ipv4.$num.$ip" "$img" "$@"
|
2022-02-10 01:19:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
cleanup() {
|
2022-05-21 02:41:30 -04:00
|
|
|
network_name="$1"
|
2022-02-10 01:19:39 -05:00
|
|
|
set +e
|
|
|
|
# this shuts down all containers first too, handy!
|
2022-05-21 02:41:30 -04:00
|
|
|
podman network rm -f -t 0 "$network_name"
|
2022-02-10 01:19:39 -05:00
|
|
|
set -e
|
|
|
|
}
|
|
|
|
|
|
|
|
run_test() {
|
2022-05-21 02:41:30 -04:00
|
|
|
dir="$1"
|
|
|
|
shift
|
|
|
|
network_name="$1"
|
2022-02-10 01:19:39 -05:00
|
|
|
(
|
2022-05-21 02:41:30 -04:00
|
|
|
set +exo pipefail
|
|
|
|
num="$(echo "$dir" | grep -o '^[0-9]*' | sed 's/^0//')"
|
|
|
|
|
2022-02-10 01:19:39 -05:00
|
|
|
# create the network
|
2022-05-21 02:41:30 -04:00
|
|
|
podman network create --disable-dns --internal --subnet $ipv4.$num.0/24 "$network_name"
|
2022-02-10 01:19:39 -05:00
|
|
|
#podman network create --disable-dns --internal --ipv6 --subnet 2001:db8::/64 xmpp-proxy-net6
|
|
|
|
|
2022-05-21 02:41:30 -04:00
|
|
|
cp -a ./ "/tmp/xp-logs/$dir/"
|
|
|
|
cd "/tmp/xp-logs/$dir/"
|
|
|
|
sed -i "s/192\.5\.0\./$ipv4.$num./g" *
|
|
|
|
|
2022-02-10 01:19:39 -05:00
|
|
|
# start the dns server
|
2022-05-21 02:41:30 -04:00
|
|
|
run_container "$network_name" $num -d -v ./example.org.zone:/var/named/example.org.zone:ro 10 dns named -g -u named -d 99
|
2022-02-10 01:19:39 -05:00
|
|
|
|
|
|
|
# start the prosody servers if required
|
2022-05-21 02:41:30 -04:00
|
|
|
[ -f ./prosody1.cfg.lua ] && run_container "$network_name" $num -d -v ./prosody1.cfg.lua:/etc/prosody/prosody.cfg.lua:ro 20 server1 prosody && podman exec $num-server1 prosodyctl register romeo one.example.org pass && podman exec $num-server1 prosodyctl register juliet two.example.org pass
|
|
|
|
[ -f ./prosody2.cfg.lua ] && run_container "$network_name" $num -d -v ./prosody2.cfg.lua:/etc/prosody/prosody.cfg.lua:ro 30 server2 prosody && podman exec $num-server2 prosodyctl register juliet two.example.org pass
|
2022-05-22 23:30:10 -04:00
|
|
|
# or the ejabberd servers
|
|
|
|
[ -f ./ejabberd1.yml ] && run_container "$network_name" $num -d -v ./ejabberd1.yml:/etc/ejabberd/ejabberd.yml:ro 20 server1 /usr/bin/ejabberdctl foreground
|
|
|
|
[ -f ./ejabberd2.yml ] && run_container "$network_name" $num -d -v ./ejabberd2.yml:/etc/ejabberd/ejabberd.yml:ro 30 server2 /usr/bin/ejabberdctl foreground
|
2022-05-21 02:41:30 -04:00
|
|
|
|
|
|
|
[ -f ./xmpp-proxy1.toml ] && run_container "$network_name" $num -d $xmpp_proxy_bind -v ./xmpp-proxy1.toml:/etc/xmpp-proxy/xmpp-proxy.toml:ro 40 xp1 xmpp-proxy
|
|
|
|
[ -f ./xmpp-proxy2.toml ] && run_container "$network_name" $num -d $xmpp_proxy_bind -v ./xmpp-proxy2.toml:/etc/xmpp-proxy/xmpp-proxy.toml:ro 50 xp2 xmpp-proxy
|
|
|
|
[ -f ./xmpp-proxy3.toml ] && run_container "$network_name" $num -d $xmpp_proxy_bind -v ./xmpp-proxy3.toml:/etc/xmpp-proxy/xmpp-proxy.toml:ro 60 xp3 xmpp-proxy
|
|
|
|
[ -f ./nginx1.conf ] && run_container "$network_name" $num -d -v ./nginx1.conf:/etc/nginx/nginx.conf:ro 70 web1 nginx
|
|
|
|
[ -f ./nginx2.conf ] && run_container "$network_name" $num -d -v ./nginx2.conf:/etc/nginx/nginx.conf:ro 80 web2 nginx
|
2022-02-10 01:19:39 -05:00
|
|
|
|
2022-05-22 23:30:10 -04:00
|
|
|
# can't register ejabberd user until it finishes starting up, hopefully that's done by now
|
|
|
|
[ -f ./ejabberd1.yml ] && podman exec $num-server1 ejabberdctl started && podman exec $num-server1 ejabberdctl register romeo one.example.org pass && podman exec $num-server1 ejabberdctl register juliet two.example.org pass
|
|
|
|
[ -f ./ejabberd2.yml ] && podman exec $num-server2 ejabberdctl started && podman exec $num-server2 ejabberdctl register juliet two.example.org pass
|
|
|
|
|
2022-02-10 01:19:39 -05:00
|
|
|
# run the actual tests
|
2022-02-17 00:14:40 -05:00
|
|
|
tests="$(cat tests || echo "-d .")"
|
2022-05-21 02:41:30 -04:00
|
|
|
run_container "$network_name" $num -w /scansion/ 89 scansion scansion $tests
|
2022-02-10 01:19:39 -05:00
|
|
|
# juliet_messages_romeo.scs juliet_presence.scs romeo_messages_juliet.scs romeo_presence.scs
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-05-21 02:41:30 -04:00
|
|
|
try_run() {
|
|
|
|
export dir="$(echo "$1" | tr -d '/')"
|
|
|
|
|
|
|
|
set +exo pipefail
|
|
|
|
echo "$dir" | grep -E "$dir_pattern" &>/dev/null
|
|
|
|
[ $? -ne 0 ] && echo "$dir" >> "$skipped" && return
|
|
|
|
set -e
|
|
|
|
|
|
|
|
cd "$dir"
|
|
|
|
|
|
|
|
[ $run_blocked -eq 0 ] && [ -e blocked ] && echo "$dir" >> "$skipped" && cd .. && return
|
|
|
|
|
|
|
|
set +e
|
|
|
|
network_name="xmpp-proxy-$dir"
|
|
|
|
run_test "$dir" "$network_name"
|
|
|
|
if [ $? -eq 0 ]
|
|
|
|
then
|
|
|
|
echo "$dir" >> "$success"
|
|
|
|
else
|
|
|
|
echo "$dir" >> "$error"
|
|
|
|
fi
|
|
|
|
# this usually takes a few seconds, but we don't care, background it and ignore output
|
|
|
|
cleanup "$network_name" >/dev/null &
|
|
|
|
set -e
|
|
|
|
|
|
|
|
cd ..
|
|
|
|
}
|
|
|
|
|
2022-02-10 01:19:39 -05:00
|
|
|
(
|
|
|
|
set -euxo pipefail
|
|
|
|
|
2022-05-21 02:41:30 -04:00
|
|
|
export -f cleanup
|
|
|
|
podman network ls | grep -o 'xmpp-proxy-[^ ]*' | xargs -n1 --no-run-if-empty cleanup || true
|
2022-02-10 01:19:39 -05:00
|
|
|
|
2022-04-25 00:57:26 -04:00
|
|
|
podman image exists "$img" || rebuild_image=1
|
|
|
|
[ $rebuild_image -eq 0 ] || podman build -f Dockerfile --build-arg="ECDSA=$ecdsa" --build-arg="BUILD=$build" -t "$img" ..
|
2022-02-10 01:19:39 -05:00
|
|
|
#podman run --rm "$img" openssl pkey -in /etc/prosody/certs/one.example.org.key -text
|
|
|
|
|
|
|
|
if [ $build -eq 1 ]
|
|
|
|
then
|
|
|
|
cd ..
|
|
|
|
cargo build $build_args
|
|
|
|
cd integration
|
|
|
|
fi
|
|
|
|
|
|
|
|
dir_pattern="$(echo "$@" | tr -d '/' | sed -r 's/ +/|/g')"
|
|
|
|
[ -z "$dir_pattern" ] && dir_pattern='.'
|
|
|
|
|
2022-05-21 02:41:30 -04:00
|
|
|
echo -n | tee "$success" "$error" "$skipped"
|
2022-02-10 01:19:39 -05:00
|
|
|
|
2022-05-21 02:41:30 -04:00
|
|
|
# all variables the functions use
|
|
|
|
export dir_pattern ipv4 build build_args img xmpp_proxy_bind run_blocked rebuild_image ecdsa success error skipped
|
|
|
|
# all the functions
|
|
|
|
export -f try_run run_test run_container
|
2022-02-10 01:19:39 -05:00
|
|
|
|
2022-05-21 02:41:30 -04:00
|
|
|
set +e
|
|
|
|
printf '%s\0' */ | xargs -0 --max-procs=$threads -n1 bash -c 'try_run "$@"' _
|
2022-02-10 01:19:39 -05:00
|
|
|
|
|
|
|
set +x
|
|
|
|
cat <<EOF
|
|
|
|
|
2022-05-21 02:41:30 -04:00
|
|
|
skipped: $(sort "$skipped" | tr '\n' ' ')
|
2022-02-10 01:19:39 -05:00
|
|
|
|
2022-05-21 02:41:30 -04:00
|
|
|
successful: $(sort "$success" | tr '\n' ' ')
|
2022-02-10 01:19:39 -05:00
|
|
|
|
2022-05-21 02:41:30 -04:00
|
|
|
failed: $(sort "$error" | tr '\n' ' ')
|
2022-02-10 01:19:39 -05:00
|
|
|
EOF
|
|
|
|
|
2022-05-21 02:41:30 -04:00
|
|
|
exit $(tr ' ' '\n' < "$error" | wc -l)
|
2022-02-10 01:19:39 -05:00
|
|
|
)
|
|
|
|
|