Skip to content

Commit b5cb29f

Browse files
authored
Add more e2e test cases for influxdb 2.0. (#447)
1 parent 4d733ea commit b5cb29f

8 files changed

+744
-0
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/usr/bin/env bash
2+
set -eo pipefail
3+
4+
declare -r SCRIPT_DIR=$(cd $(dirname $0) >/dev/null 2>&1 && pwd)
5+
source ${SCRIPT_DIR}/common.sh
6+
7+
declare -r tag=$1 container_name=$2 data=$3 config=$4 logs=$5
8+
9+
# Extract the default config from the container.
10+
log_msg Getting default config
11+
if ! docker run --rm influxdb:${tag} influxd print-config > ${config}/default-config.yml; then
12+
log_msg Error: Failed to extract default config
13+
exit 1
14+
fi
15+
16+
# Rewrite data paths.
17+
sed -e 's#/var/lib/influxdb2#/home/influxdb/influxdb2#g' -e 's#:8086#:9000#g' ${config}/default-config.yml > ${config}/config.yml
18+
19+
declare -ra docker_run_influxd=(
20+
docker run -i -d
21+
--name=${container_name}
22+
-u $(id -u):influxdb
23+
-p 8086:9000
24+
-v ${data}:/home/influxdb/influxdb2
25+
-v ${config}:/etc/influxdb2
26+
-e INFLUXDB_INIT_MODE=setup
27+
-e INFLUXDB_INIT_USERNAME=${TEST_USER}
28+
-e INFLUXDB_INIT_PASSWORD=${TEST_PASSWORD}
29+
-e INFLUXDB_INIT_ORG=${TEST_ORG}
30+
-e INFLUXDB_INIT_BUCKET=${TEST_BUCKET}
31+
-e INFLUXDB_INIT_RETENTION=${TEST_RETENTION_SECONDS}s
32+
influxdb:${tag} influxd
33+
)
34+
35+
log_msg Booting 2.x container in setup mode
36+
if ! ${docker_run_influxd[@]} > /dev/null; then
37+
log_msg Error: Failed to launch container
38+
exit 1
39+
fi
40+
wait_container_ready
41+
42+
# Check that the DB reports it's been set up.
43+
log_msg Checking onboarding API post-start
44+
declare onboarding_allowed=$(curl -s localhost:8086/api/v2/setup | jq .allowed)
45+
if [[ ${onboarding_allowed} != 'false' ]]; then
46+
log_msg Error: Onboarding allowed post-start
47+
exit 1
48+
fi
49+
50+
# Get the auth token generated by setup.
51+
declare -r auth_token=$(extract_token ${container_name})
52+
53+
# Make sure we can use the generated auth token to find the resources we expect.
54+
log_msg Checking org list post-setup
55+
declare orgs=$(curl -s -H "Authorization: Token ${auth_token}" localhost:8086/api/v2/orgs | jq -r .orgs[].name)
56+
if [[ ${orgs} != ${TEST_ORG} ]]; then
57+
log_msg Error: Bad org list post-setup
58+
echo ${orgs}
59+
exit 1
60+
fi
61+
62+
log_msg Checking bucket list post-setup
63+
declare buckets=$(curl -s -H "Authorization: Token ${auth_token}" "localhost:8086/api/v2/buckets?name=${TEST_BUCKET}" | jq -r .buckets[].name)
64+
if [[ ${buckets} != ${TEST_BUCKET} ]]; then
65+
log_msg Error: Bad bucket list post-setup
66+
echo ${buckets}
67+
exit 1
68+
fi
69+
70+
log_msg Checking bucket RP
71+
declare rp=$(curl -s -H "Authorization: Token ${auth_token}" "localhost:8086/api/v2/buckets?name=${TEST_BUCKET}" | jq -r .buckets[].retentionRules[].everySeconds)
72+
73+
if [[ ${rp} != ${TEST_RETENTION_SECONDS} ]]; then
74+
log_msg Error: Bad bucket RP post-setup
75+
echo ${rp}
76+
exit 1
77+
fi
78+
79+
log_msg Tearing down 2.x container
80+
docker stop ${container_name} > /dev/null
81+
docker logs ${container_name} > ${logs}/init-docker-stdout.log 2> ${logs}/init-docker-stderr.log
82+
docker rm ${container_name} > /dev/null
83+
84+
# Check that files were persisted to the host.
85+
if [ ! -f ${data}/influxd.bolt ]; then
86+
log_msg Error: BoltDB not persisted to host directory
87+
exit 1
88+
fi
89+
90+
# Create a new container using the same mount-points.
91+
log_msg Booting another 2.x container
92+
if ! ${docker_run_influxd[@]} > /dev/null; then
93+
log_msg Error: failed to launch container
94+
exit 1
95+
fi
96+
wait_container_ready
97+
98+
# Make sure the DB still reports that it's been set up.
99+
log_msg Checking onboarding API after recreating container
100+
onboarding_allowed=$(curl -s localhost:8086/api/v2/setup | jq .allowed)
101+
102+
if [[ ${onboarding_allowed} != 'false' ]]; then
103+
log_msg Error: Onboarding allowed after recreating container
104+
exit 1
105+
fi
106+
107+
log_msg Checking org list after recreating container
108+
declare orgs=$(curl -s -H "Authorization: Token ${auth_token}" localhost:8086/api/v2/orgs | jq -r .orgs[].name)
109+
if [[ ${orgs} != ${TEST_ORG} ]]; then
110+
log_msg Error: Bad org list post-setup
111+
echo ${orgs}
112+
exit 1
113+
fi
114+
115+
log_msg Checking bucket list after recreating container
116+
declare buckets=$(curl -s -H "Authorization: Token ${auth_token}" "localhost:8086/api/v2/buckets?name=${TEST_BUCKET}" | jq -r .buckets[].name)
117+
if [[ ${buckets} != ${TEST_BUCKET} ]]; then
118+
log_msg Error: Bad bucket list post-setup
119+
echo ${buckets}
120+
exit 1
121+
fi
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
set -eo pipefail
3+
4+
declare -r SCRIPT_DIR=$(cd $(dirname $0) >/dev/null 2>&1 && pwd)
5+
source ${SCRIPT_DIR}/common.sh
6+
7+
declare -r tag=$1 container_name=$2 data=$3 config=$4 logs=$5 scripts=$6
8+
9+
echo "$TEST_CREATE_DBRP_SCRIPT" > ${scripts}/1-create-dbrp.sh
10+
echo "$TEST_CREATE_V1_AUTH_SCRIPT" > ${scripts}/2-create-v1-auth.sh
11+
chmod +x ${scripts}/1-create-dbrp.sh
12+
chmod +x ${scripts}/2-create-v1-auth.sh
13+
14+
declare -ra docker_run_influxd=(
15+
docker run -i -d
16+
--name=${container_name}
17+
-u $(id -u):influxdb
18+
-p 8086:8086
19+
-v ${data}:/var/lib/influxdb2
20+
-v ${config}:/etc/influxdb2
21+
-v ${scripts}:/docker-entrypoint-initdb.d
22+
-e INFLUXDB_INIT_MODE=setup
23+
-e INFLUXDB_INIT_USERNAME=${TEST_USER}
24+
-e INFLUXDB_INIT_PASSWORD=${TEST_PASSWORD}
25+
-e INFLUXDB_INIT_ORG=${TEST_ORG}
26+
-e INFLUXDB_INIT_BUCKET=${TEST_BUCKET}
27+
influxdb:${tag}
28+
)
29+
30+
log_msg Booting 2.x container in setup mode
31+
if ! ${docker_run_influxd[@]} > /dev/null; then
32+
log_msg Error: Failed to launch container
33+
exit 1
34+
fi
35+
wait_container_ready
36+
37+
log_msg Checking we can read from V1 API
38+
declare -ra curl_v1=(
39+
curl -s
40+
-u ${TEST_V1_USER}:${TEST_V1_PASSWORD}
41+
--data-urlencode db=${TEST_V1_DB}
42+
--data-urlencode rp=${TEST_V1_RP}
43+
--data-urlencode q='SHOW MEASUREMENTS'
44+
localhost:8086/query
45+
)
46+
declare -r measurements=$("${curl_v1[@]}" | jq -r .results[].statement_id)
47+
if [[ "${measurements}" != 0 ]]; then
48+
log_msg Got unexpected response from V1 API
49+
echo ${measurements}
50+
exit 1
51+
fi
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/usr/bin/env bash
2+
set -eo pipefail
3+
4+
declare -r SCRIPT_DIR=$(cd $(dirname $0) >/dev/null 2>&1 && pwd)
5+
source ${SCRIPT_DIR}/common.sh
6+
7+
declare -r tag=$1 container_name=$2 data=$3 config=$4 logs=$5
8+
9+
declare -ra docker_run_influxd=(
10+
docker run -i -d
11+
--name=${container_name}
12+
-u $(id -u):influxdb
13+
-p 8086:8086
14+
-v ${data}:/var/lib/influxdb2
15+
-v ${config}:/etc/influxdb2
16+
-e INFLUXDB_INIT_MODE=setup
17+
-e INFLUXDB_INIT_USERNAME=${TEST_USER}
18+
-e INFLUXDB_INIT_PASSWORD=${TEST_PASSWORD}
19+
-e INFLUXDB_INIT_ORG=${TEST_ORG}
20+
-e INFLUXDB_INIT_BUCKET=${TEST_BUCKET}
21+
-e INFLUXDB_INIT_RETENTION=${TEST_RETENTION_SECONDS}s
22+
-e INFLUXDB_INIT_ADMIN_TOKEN=${TEST_ADMIN_TOKEN}
23+
influxdb:${tag} influxd run
24+
)
25+
26+
log_msg Booting 2.x container in setup mode
27+
if ! ${docker_run_influxd[@]} > /dev/null; then
28+
log_msg Error: Failed to launch container
29+
exit 1
30+
fi
31+
wait_container_ready
32+
33+
# Check that the DB reports it's been set up.
34+
log_msg Checking onboarding API post-start
35+
declare onboarding_allowed=$(curl -s localhost:8086/api/v2/setup | jq .allowed)
36+
if [[ ${onboarding_allowed} != 'false' ]]; then
37+
log_msg Error: Onboarding allowed post-start
38+
exit 1
39+
fi
40+
41+
42+
# Make sure we can use the auth token we passed in to find the resources we expect.
43+
log_msg Checking org list post-setup
44+
declare orgs=$(curl -s -H "Authorization: Token ${TEST_ADMIN_TOKEN}" localhost:8086/api/v2/orgs | jq -r .orgs[].name)
45+
if [[ ${orgs} != ${TEST_ORG} ]]; then
46+
log_msg Error: Bad org list post-setup
47+
echo ${orgs}
48+
exit 1
49+
fi
50+
51+
log_msg Checking bucket list post-setup
52+
declare buckets=$(curl -s -H "Authorization: Token ${TEST_ADMIN_TOKEN}" localhost:8086/api/v2/buckets?name=${TEST_BUCKET} | jq -r .buckets[].name)
53+
if [[ ${buckets} != ${TEST_BUCKET} ]]; then
54+
log_msg Error: Bad bucket list post-setup
55+
echo ${buckets}
56+
exit 1
57+
fi
58+
59+
# Destroy the container
60+
log_msg Tearing down 2.x container
61+
docker stop ${container_name} > /dev/null
62+
docker logs ${container_name} > ${logs}/init-docker-stdout.log 2> ${logs}/init-docker-stderr.log
63+
docker rm ${container_name} > /dev/null
64+
65+
# Check that files were persisted to the host.
66+
if [ ! -f ${data}/influxd.bolt ]; then
67+
log_msg Error: BoltDB not persisted to host directory
68+
exit 1
69+
fi
70+
if [ ! -f ${config}/influx-configs ]; then
71+
log_msg Error: CLI configs not persisted to host directory
72+
exit 1
73+
fi
74+
75+
# Create a new container using the same mount-points and env.
76+
# The INIT_MODE should be ignored since the bolt file is present.
77+
log_msg Booting another 2.x container
78+
if ! ${docker_run_influxd[@]} > /dev/null; then
79+
log_msg Error: failed to launch container
80+
exit 1
81+
fi
82+
wait_container_ready
83+
84+
# Make sure the DB still reports that it's been set up.
85+
log_msg Checking onboarding API after recreating container
86+
onboarding_allowed=$(curl -s localhost:8086/api/v2/setup | jq .allowed)
87+
88+
if [[ ${onboarding_allowed} != 'false' ]]; then
89+
log_msg Error: Onboarding allowed after recreating container
90+
exit 1
91+
fi
92+
93+
# Make sure we can still use the generated auth token to find the resources we expect.
94+
log_msg Checking org list after recreating container
95+
declare orgs=$(curl -s -H "Authorization: Token ${TEST_ADMIN_TOKEN}" localhost:8086/api/v2/orgs | jq -r .orgs[].name)
96+
if [[ ${orgs} != ${TEST_ORG} ]]; then
97+
log_msg Error: Bad org list post-setup
98+
echo ${orgs}
99+
exit 1
100+
fi
101+
102+
log_msg Checking bucket list after recreating container
103+
declare buckets=$(curl -s -H "Authorization: Token ${TEST_ADMIN_TOKEN}" localhost:8086/api/v2/buckets?name=${TEST_BUCKET} | jq -r .buckets[].name)
104+
if [[ ${buckets} != ${TEST_BUCKET} ]]; then
105+
log_msg Error: Bad bucket list post-setup
106+
echo ${buckets}
107+
exit 1
108+
fi
109+
110+
log_msg Checking bucket RP
111+
declare rp=$(curl -s -H "Authorization: Token ${TEST_ADMIN_TOKEN}" localhost:8086/api/v2/buckets?name=${TEST_BUCKET} | jq -r .buckets[].retentionRules[].everySeconds)
112+
113+
if [[ ${rp} != ${TEST_RETENTION_SECONDS} ]]; then
114+
log_msg Error: Bad bucket RP post-setup
115+
echo ${rp}
116+
exit 1
117+
fi
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
set -eo pipefail
3+
4+
declare -r SCRIPT_DIR=$(cd $(dirname $0) >/dev/null 2>&1 && pwd)
5+
source ${SCRIPT_DIR}/common.sh
6+
7+
declare -r tag=$1 container_name=$2 data=$3 config=$4 logs=$5
8+
9+
declare -ra docker_run_influxd=(
10+
docker run -i -d
11+
--name=${container_name}
12+
-u $(id -u):influxdb
13+
-p 8086:8086
14+
-v ${data}:/var/lib/influxdb2
15+
-v ${config}:/etc/influxdb2
16+
-e INFLUXDB_INIT_MODE=setup
17+
-e INFLUXDB_INIT_USERNAME=${TEST_USER}
18+
-e INFLUXDB_INIT_PASSWORD=${TEST_PASSWORD}
19+
-e INFLUXDB_INIT_ORG=${TEST_ORG}
20+
-e INFLUXDB_INIT_BUCKET=${TEST_BUCKET}
21+
-e INFLUXDB_INIT_RETENTION=${TEST_RETENTION_SECONDS}s
22+
influxdb:${tag} influxd run
23+
)
24+
25+
# Boot the container
26+
log_msg Booting 2.x container in setup mode
27+
if ! ${docker_run_influxd[@]} > /dev/null; then
28+
log_msg Error: Failed to launch container
29+
exit 1
30+
fi
31+
wait_container_ready
32+
33+
# Get the auth token generated by setup.
34+
declare -r auth_token=$(extract_token ${container_name})
35+
36+
log_msg Checking bucket RP
37+
declare rp=$(curl -s -H "Authorization: Token ${auth_token}" "localhost:8086/api/v2/buckets?name=${TEST_BUCKET}" | jq -r .buckets[].retentionRules[].everySeconds)
38+
39+
if [[ ${rp} != ${TEST_RETENTION_SECONDS} ]]; then
40+
log_msg Error: Bad bucket RP post-setup
41+
echo ${rp}
42+
exit 1
43+
fi

0 commit comments

Comments
 (0)