summaryrefslogtreecommitdiffstats
path: root/debian/tests/smoke-tests
blob: 2de85c492346d67bd62b99f4b61960de76ce35d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash

set -exo pipefail

# kea-ctrl-agent needs a password file, or else it won't start
# this also tests the debconf mechanism
debconf-set-selections << eof
kea-ctrl-agent kea-ctrl-agent/make_a_choice select configured_random_password
eof

dpkg-reconfigure kea-ctrl-agent
kea_password_file="/etc/kea/kea-api-password"
[ -s "${kea_password_file}" ] || {
    echo "ERROR, debconf-set-selections failed to set a password for kea-ctrl-agent"
    exit 1
}

# Arbitrary wait to allow for the services to start.
# This is needed to avoid having racy/flaky tests.
sleep 5

# Check that the PID files are in the right location
for f in kea-dhcp4.kea-dhcp4.pid kea-dhcp6.kea-dhcp6.pid kea-ctrl-agent.kea-ctrl-agent.pid kea-dhcp-ddns.kea-dhcp-ddns.pid; do
    test -f "/run/kea/$f"
done

# Check that the sockets are in the right location
for socket in kea-ddns-ctrl-socket kea4-ctrl-socket kea6-ctrl-socket; do
    test -S "/run/kea/$socket"
done

# Check that lock files are in the right location
test -f /run/lock/kea/logger_lockfile

check_kea_version() {
  CHECKED_VERSION=$1
  if [[ ! ${CHECKED_VERSION} =~ [0-9]+(\.[0-9]+){2} ]]; then
    echo "Version [ ${CHECKED_VERSION} ] does not match X.Y.Z format"
    exit 1
  fi
}

# Check dhcp4 server configuration file
kea-dhcp4 -t /etc/kea/kea-dhcp4.conf > /dev/null

# Check dhcp6 server configuration file
kea-dhcp6 -t /etc/kea/kea-dhcp6.conf > /dev/null

# Check if we need to provide authentication
auth_params=""
basic_auth_params=""
if [ -s /etc/kea/kea-api-password ]; then
    auth_params="--auth-user kea-api --auth-password $(cat /etc/kea/kea-api-password)"
    basic_auth_params="-u kea-api:$(cat /etc/kea/kea-api-password)"
fi

# Check control agent API
TEST_KEA_VERSION=$(curl ${basic_auth_params} -s -X POST -H "Content-Type: application/json" -d '{ "command": "version-get", "service": [ "dhcp4" ] }' 127.0.0.1:8000 | jq -r '.[0].text')
check_kea_version "${TEST_KEA_VERSION}"

# Check control agent API through kea-shell
TEST_KEA_VERSION=$(echo | kea-shell --service dhcp4 --host 127.0.0.1 --port 8000 ${auth_params} version-get | jq -r '.[0].text')
check_kea_version "${TEST_KEA_VERSION}"