etcd: Connection options (socket file, ipv6)

- Allow unix domain socket to be used as client url
- Using ::1 as clienturl should not create default local ipv4 listener
- Add shell tests
This commit is contained in:
Johan Bloemberg
2019-02-06 16:51:13 +01:00
parent 4c8086977a
commit f7a06c1da9
11 changed files with 163 additions and 8 deletions

40
test/shell/clustersize.sh Executable file
View File

@@ -0,0 +1,40 @@
#!/bin/bash
set -o errexit
set -o pipefail
if ! command -v etcdctl >/dev/null; then
echo "Missing etcdctl, skipping"
exit 0
fi
. "$(dirname "$0")/../util.sh"
mkdir /tmp/mgmt/{A..E}
# kill servers on error/exit
trap 'pkill -9 mgmt' EXIT
"$MGMT" run --hostname h1 --tmp-prefix --no-pgp empty &
"$MGMT" run --hostname h2 --tmp-prefix --no-pgp --seeds http://127.0.0.1:2379 --client-urls http://127.0.0.1:2381 --server-urls http://127.0.0.1:2382 empty &
"$MGMT" run --hostname h3 --tmp-prefix --no-pgp --seeds http://127.0.0.1:2379 --client-urls http://127.0.0.1:2383 --server-urls http://127.0.0.1:2384 empty &
# wait for everything to converge
sleep 10
ETCDCTL_API=3 etcdctl --endpoints 127.0.0.1:2379 put /_mgmt/idealClusterSize 3
"$MGMT" run --hostname h4 --tmp-prefix --no-pgp --seeds http://127.0.0.1:2379 --client-urls http://127.0.0.1:2385 --server-urls http://127.0.0.1:2386 empty &
"$MGMT" run --hostname h5 --tmp-prefix --no-pgp --seeds http://127.0.0.1:2379 --client-urls http://127.0.0.1:2387 --server-urls http://127.0.0.1:2388 empty &
# wait for everything to converge
sleep 10
test "$(ETCDCTL_API=3 etcdctl --endpoints 127.0.0.1:2379 member list | wc -l)" -eq 3
ETCDCTL_API=3 etcdctl --endpoints 127.0.0.1:2381 put /_mgmt/idealClusterSize 5
# wait for everything to converge
sleep 5
test "$(ETCDCTL_API=3 etcdctl --endpoints 127.0.0.1:2381 member list | wc -l)" -eq 5

22
test/shell/exchange.sh Executable file
View File

@@ -0,0 +1,22 @@
#!/bin/bash
set -o errexit
set -o pipefail
. "$(dirname "$0")/../util.sh"
"$MGMT" run --hostname h1 --ideal-cluster-size 1 --tmp-prefix --no-pgp lang --lang exchange0.mcl &
"$MGMT" run --hostname h2 --seeds http://127.0.0.1:2379 --client-urls http://127.0.0.1:2381 --server-urls http://127.0.0.1:2382 --tmp-prefix --no-pgp lang --lang exchange0.mcl &
"$MGMT" run --hostname h3 --seeds http://127.0.0.1:2379 --client-urls http://127.0.0.1:2383 --server-urls http://127.0.0.1:2384 --tmp-prefix --no-pgp lang --lang exchange0.mcl &
"$MGMT" run --hostname h4 --seeds http://127.0.0.1:2379 --client-urls http://127.0.0.1:2385 --server-urls http://127.0.0.1:2386 --tmp-prefix --no-pgp lang --lang exchange0.mcl &
# kill servers on error/exit
trap 'pkill -9 mgmt' EXIT
# wait for everything to converge
sleep 10
test "$(cat /tmp/mgmt/exchange-* | grep -c h1)" -eq 4
test "$(cat /tmp/mgmt/exchange-* | grep -c h2)" -eq 4
test "$(cat /tmp/mgmt/exchange-* | grep -c h3)" -eq 4
test "$(cat /tmp/mgmt/exchange-* | grep -c h4)" -eq 4

16
test/shell/exchange0.mcl Normal file
View File

@@ -0,0 +1,16 @@
# run this example with these commands
# watch -n 0.1 'tail *' # run this in /tmp/mgmt/
# time ./mgmt run --hostname h1 --ideal-cluster-size 1 --tmp-prefix --no-pgp lang --lang examples/lang/exchange0.mcl
# time ./mgmt run --hostname h2 --seeds http://127.0.0.1:2379 --client-urls http://127.0.0.1:2381 --server-urls http://127.0.0.1:2382 --tmp-prefix --no-pgp lang --lang examples/lang/exchange0.mcl
# time ./mgmt run --hostname h3 --seeds http://127.0.0.1:2379 --client-urls http://127.0.0.1:2383 --server-urls http://127.0.0.1:2384 --tmp-prefix --no-pgp lang --lang examples/lang/exchange0.mcl
# time ./mgmt run --hostname h4 --seeds http://127.0.0.1:2379 --client-urls http://127.0.0.1:2385 --server-urls http://127.0.0.1:2386 --tmp-prefix --no-pgp lang --lang examples/lang/exchange0.mcl
import "sys"
import "world"
$rand = random1(8)
$exchanged = world.exchange("keyns", $rand)
file "/tmp/mgmt/exchange-${sys.hostname()}" {
content => template("Found: {{ . }}\n", $exchanged),
}

29
test/shell/ipv6-localhost.sh Executable file
View File

@@ -0,0 +1,29 @@
#!/bin/bash
set -o errexit
set -o pipefail
if ! ifconfig lo | grep 'inet6 ::1' >/dev/null; then
echo "No IPv6, skipping test"
exit 0
fi
. "$(dirname "$0")/../util.sh"
tmpdir="$($mktemp --tmpdir -d tmp.XXX)"
# run empty graph listing only to IPv6 addresses
"$MGMT" run --client-urls "http://[::1]:2379" --server-urls "http://[::1]:2380" --tmp-prefix empty &
pid=$!
# kill server on error/exit
trap 'pkill -9 mgmt' EXIT
# give mgmt a little time to startup
sleep 10
# mgmt configured for ipv6 only should not listen on any IPv4 ports
lsof -Pn -p "$pid" -a -i | grep '127.0.0.1' && false
# instead it should listen on IPv6
lsof -Pn -p "$pid" -a -i | grep '::1' || false

26
test/shell/no-network.sh Executable file
View File

@@ -0,0 +1,26 @@
#!/bin/bash
# Tests the behaviour of the --no-network
set -o errexit
set -o pipefail
. "$(dirname "$0")/../util.sh"
tmpdir="$($mktemp --tmpdir -d tmp.XXX)"
# run empty graph, with standalone enabled
"$MGMT" run --no-network --prefix "$tmpdir" empty &
pid=$!
# kill server on error/exit
trap 'kill -SIGINT "$pid"' EXIT
# give mgmt a little time to startup
sleep 10
# standalone mgmt should not listen on any tcp ports
lsof -i | grep "$pid" | grep TCP && false
# instead unix domain sockets should have been created
test -S "servers.sock:0"
test -S "clients.sock:0"

View File

@@ -21,7 +21,7 @@ fi
# As per https://github.com/travis-ci/docs-travis-ci-com/blob/master/user/docker.md
# Docker is not supported on Travis macOS test instances.
if [[ "$TRAVIS_OS_NAME" == "osx" ]];then
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
XTAGS+=('nodocker')
fi