Skip to content

Commit 67cecd4

Browse files
authored
Merge pull request #289 from splunk/test/splunk-apps-location
Adding test for splunk.apps_location in default.yml
2 parents b62b947 + 20ceb29 commit 67cecd4

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

tests/test_docker_splunk.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,64 @@ def test_adhoc_1so_postplaybook_with_sudo(self):
958958
if cid:
959959
self.client.remove_container(cid, v=True, force=True)
960960

961+
def test_adhoc_1so_apps_location_in_default_yml(self):
962+
with tarfile.open(EXAMPLE_APP_TGZ, "w:gz") as tar:
963+
tar.add(EXAMPLE_APP, arcname=os.path.basename(EXAMPLE_APP))
964+
# Generate default.yml
965+
cid = self.client.create_container(self.SPLUNK_IMAGE_NAME, tty=True, command="create-defaults")
966+
self.client.start(cid.get("Id"))
967+
output = self.get_container_logs(cid.get("Id"))
968+
self.client.remove_container(cid.get("Id"), v=True, force=True)
969+
# Get the password
970+
password = re.search(" password: (.*)", output).group(1).strip()
971+
assert password
972+
# Change repl factor & search factor
973+
output = re.sub(r' user: splunk', r' user: splunk\n apps_location: /tmp/defaults/splunk_app_example.tgz', output)
974+
# Write the default.yml to a file
975+
with open(os.path.join(FIXTURES_DIR, "default.yml"), "w") as f:
976+
f.write(output)
977+
# Create the container and mount the default.yml
978+
cid = None
979+
try:
980+
# Spin up this container, but also bind-mount the app in the fixtures directory
981+
splunk_container_name = generate_random_string()
982+
cid = self.client.create_container(self.SPLUNK_IMAGE_NAME, tty=True, command="start-service", ports=[8089],
983+
volumes=["/tmp/defaults/"], name=splunk_container_name,
984+
environment={"DEBUG": "true", "SPLUNK_START_ARGS": "--accept-license"},
985+
host_config=self.client.create_host_config(binds=[FIXTURES_DIR + ":/tmp/defaults/"],
986+
port_bindings={8089: ("0.0.0.0",)})
987+
)
988+
cid = cid.get("Id")
989+
self.client.start(cid)
990+
# Poll for the container to be ready
991+
assert self.wait_for_containers(1, name=splunk_container_name)
992+
# Check splunkd
993+
splunkd_port = self.client.port(cid, 8089)[0]["HostPort"]
994+
url = "https://localhost:{}/services/server/info".format(splunkd_port)
995+
kwargs = {"auth": ("admin", password), "verify": False}
996+
status, content = self.handle_request_retry("GET", url, kwargs)
997+
assert status == 200
998+
# Check the app endpoint
999+
splunkd_port = self.client.port(cid, 8089)[0]["HostPort"]
1000+
url = "https://localhost:{}/servicesNS/nobody/splunk_app_example/configs/conf-app/launcher?output_mode=json".format(splunkd_port)
1001+
kwargs = {"auth": ("admin", password), "verify": False}
1002+
status, content = self.handle_request_retry("GET", url, kwargs)
1003+
assert status == 200
1004+
# Let's go further and check app version
1005+
output = json.loads(content)
1006+
assert output["entry"][0]["content"]["version"] == "0.0.1"
1007+
except Exception as e:
1008+
self.logger.error(e)
1009+
raise e
1010+
finally:
1011+
if cid:
1012+
self.client.remove_container(cid, v=True, force=True)
1013+
try:
1014+
os.remove(EXAMPLE_APP_TGZ)
1015+
os.remove(os.path.join(FIXTURES_DIR, "default.yml"))
1016+
except OSError:
1017+
pass
1018+
9611019
def test_adhoc_1so_bind_mount_apps(self):
9621020
# Generate default.yml
9631021
cid = self.client.create_container(self.SPLUNK_IMAGE_NAME, tty=True, command="create-defaults")

0 commit comments

Comments
 (0)