Skip to content

Commit 2d162ef

Browse files
authored
Updating teardown for graceful shutdown procedure (#490)
* Updating teardown for graceful shutdown procedure * Attempting to fix tests that involve restarts
1 parent cd13f18 commit 2d162ef

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

splunk/common-files/entrypoint.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ setup() {
2727

2828
teardown() {
2929
# Always run the stop command on termination
30-
${SPLUNK_HOME}/bin/splunk stop 2>/dev/null || true
30+
if [ `whoami` != "${SPLUNK_USER}" ]; then
31+
RUN_AS_SPLUNK="sudo -u ${SPLUNK_USER}"
32+
fi
33+
${RUN_AS_SPLUNK} ${SPLUNK_HOME}/bin/splunk stop || true
3134
}
3235

3336
trap teardown SIGINT SIGTERM
@@ -83,7 +86,6 @@ start_and_exit() {
8386
}
8487

8588
start() {
86-
trap teardown EXIT
8789
start_and_exit
8890
watch_for_failure
8991
}
@@ -94,7 +96,6 @@ configure_multisite() {
9496
}
9597

9698
restart(){
97-
trap teardown EXIT
9899
sh -c "echo 'restarting' > ${CONTAINER_ARTIFACT_DIR}/splunk-container.state"
99100
prep_ansible
100101
${SPLUNK_HOME}/bin/splunk stop 2>/dev/null || true

tests/executor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def wait_for_containers(self, count, label=None, name=None, timeout=500):
147147
for container in containers:
148148
# The healthcheck on our Splunk image is not reliable - resorting to checking logs
149149
if container.get("Labels", {}).get("maintainer") == "[email protected]":
150-
output = self.client.logs(container["Id"], tail=10)
150+
output = self.client.logs(container["Id"], tail=5)
151151
if "unable to" in output or "denied" in output or "splunkd.pid file is unreadable" in output:
152152
self.logger.error("Container {} did not start properly, last log line: {}".format(container["Names"][0], output))
153153
elif "Ansible playbook complete" in output:

tests/test_single_splunk_image.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,6 @@ def test_adhoc_1so_run_as_root(self):
852852
finally:
853853
if cid:
854854
self.client.remove_container(cid, v=True, force=True)
855-
856855

857856
def test_adhoc_1so_declarative_password(self):
858857
"""
@@ -1014,6 +1013,9 @@ def test_adhoc_1so_hec_idempotence(self):
10141013
self.client.exec_start(exec_command)
10151014
# Restart the container - it should pick up the new HEC settings in /tmp/defaults/default.yml
10161015
self.client.restart(splunk_container_name)
1016+
# After restart, a container's logs are preserved. So, sleep in order for the self.wait_for_containers()
1017+
# to avoid seeing the prior entrypoint's "Ansible playbook complete" string
1018+
time.sleep(15)
10171019
assert self.wait_for_containers(1, name=splunk_container_name)
10181020
assert self.check_splunkd("admin", self.password, name=splunk_container_name)
10191021
# Check the new HEC settings
@@ -1047,6 +1049,9 @@ def test_adhoc_1so_hec_idempotence(self):
10471049
self.client.exec_start(exec_command)
10481050
# Restart the container - it should pick up the new HEC settings in /tmp/defaults/default.yml
10491051
self.client.restart(splunk_container_name)
1052+
# After restart, a container's logs are preserved. So, sleep in order for the self.wait_for_containers()
1053+
# to avoid seeing the prior entrypoint's "Ansible playbook complete" string
1054+
time.sleep(15)
10501055
assert self.wait_for_containers(1, name=splunk_container_name)
10511056
assert self.check_splunkd("admin", self.password, name=splunk_container_name)
10521057
# Check the new HEC settings
@@ -1078,6 +1083,9 @@ def test_adhoc_1so_hec_idempotence(self):
10781083
self.client.exec_start(exec_command)
10791084
# Restart the container - it should pick up the new HEC settings in /tmp/defaults/default.yml
10801085
self.client.restart(splunk_container_name)
1086+
# After restart, a container's logs are preserved. So, sleep in order for the self.wait_for_containers()
1087+
# to avoid seeing the prior entrypoint's "Ansible playbook complete" string
1088+
time.sleep(15)
10811089
assert self.wait_for_containers(1, name=splunk_container_name)
10821090
assert self.check_splunkd("admin", self.password, name=splunk_container_name)
10831091
# Check the new HEC settings
@@ -1102,6 +1110,9 @@ def test_adhoc_1so_hec_idempotence(self):
11021110
self.client.exec_start(exec_command)
11031111
# Restart the container - it should pick up the new HEC settings in /tmp/defaults/default.yml
11041112
self.client.restart(splunk_container_name)
1113+
# After restart, a container's logs are preserved. So, sleep in order for the self.wait_for_containers()
1114+
# to avoid seeing the prior entrypoint's "Ansible playbook complete" string
1115+
time.sleep(15)
11051116
assert self.wait_for_containers(1, name=splunk_container_name)
11061117
assert self.check_splunkd("admin", self.password, name=splunk_container_name)
11071118
# Check the new HEC settings
@@ -1288,13 +1299,15 @@ def test_compose_1so_java_oracle(self):
12881299
assert "java version \"1.8.0" in std_out
12891300
# Restart the container and make sure java is still installed
12901301
self.client.restart("{}_so1_1".format(self.project_name))
1302+
# After restart, a container's logs are preserved. So, sleep in order for the self.wait_for_containers()
1303+
# to avoid seeing the prior entrypoint's "Ansible playbook complete" string
1304+
time.sleep(15)
12911305
assert self.wait_for_containers(container_count, label="com.docker.compose.project={}".format(self.project_name))
12921306
assert self.check_splunkd("admin", self.password)
12931307
exec_command = self.client.exec_create("{}_so1_1".format(self.project_name), "java -version")
12941308
std_out = self.client.exec_start(exec_command)
12951309
assert "java version \"1.8.0" in std_out
12961310

1297-
12981311
def test_compose_1so_java_openjdk8(self):
12991312
# Standup deployment
13001313
self.compose_file_name = "1so_java_openjdk8.yaml"
@@ -1322,6 +1335,9 @@ def test_compose_1so_java_openjdk8(self):
13221335
assert "openjdk version \"1.8.0" in std_out
13231336
# Restart the container and make sure java is still installed
13241337
self.client.restart("{}_so1_1".format(self.project_name))
1338+
# After restart, a container's logs are preserved. So, sleep in order for the self.wait_for_containers()
1339+
# to avoid seeing the prior entrypoint's "Ansible playbook complete" string
1340+
time.sleep(15)
13251341
assert self.wait_for_containers(container_count, label="com.docker.compose.project={}".format(self.project_name))
13261342
assert self.check_splunkd("admin", self.password)
13271343
exec_command = self.client.exec_create("{}_so1_1".format(self.project_name), "java -version")
@@ -1356,6 +1372,9 @@ def test_compose_1so_java_openjdk11(self):
13561372
assert "openjdk version \"11.0.2" in std_out
13571373
# Restart the container and make sure java is still installed
13581374
self.client.restart("{}_so1_1".format(self.project_name))
1375+
# After restart, a container's logs are preserved. So, sleep in order for the self.wait_for_containers()
1376+
# to avoid seeing the prior entrypoint's "Ansible playbook complete" string
1377+
time.sleep(15)
13591378
assert self.wait_for_containers(container_count, label="com.docker.compose.project={}".format(self.project_name))
13601379
assert self.check_splunkd("admin", self.password)
13611380
exec_command = self.client.exec_create("{}_so1_1".format(self.project_name), "java -version")

uf/common-files/entrypoint.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ setup() {
2828

2929
teardown() {
3030
# Always run the stop command on termination
31-
${SPLUNK_HOME}/bin/splunk stop 2>/dev/null || true
31+
if [ `whoami` != "${SPLUNK_USER}" ]; then
32+
RUN_AS_SPLUNK="sudo -u ${SPLUNK_USER}"
33+
fi
34+
${RUN_AS_SPLUNK} ${SPLUNK_HOME}/bin/splunk stop || true
3235
}
3336

3437
trap teardown SIGINT SIGTERM
@@ -83,13 +86,11 @@ start_and_exit() {
8386
}
8487

8588
start() {
86-
trap teardown EXIT
8789
start_and_exit
8890
watch_for_failure
8991
}
9092

9193
restart(){
92-
trap teardown EXIT
9394
sh -c "echo 'restarting' > ${CONTAINER_ARTIFACT_DIR}/splunk-container.state"
9495
prep_ansible
9596
${SPLUNK_HOME}/bin/splunk stop 2>/dev/null || true

0 commit comments

Comments
 (0)