Skip to content

Commit 94bc882

Browse files
authored
Bugfix/sha512sum (#451)
* Convert md5sum to sha512sum * Fixing tests * Correct function return values
1 parent a24e84c commit 94bc882

File tree

3 files changed

+27
-62
lines changed

3 files changed

+27
-62
lines changed

splunk/common-files/Dockerfile

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,19 @@ ARG SPLUNK_BASE_IMAGE=base-debian-10
2020
FROM ${SPLUNK_BASE_IMAGE}:latest as package
2121
ARG SPLUNK_BUILD_URL
2222
COPY splunk/common-files/make-minimal-exclude.py /tmp
23-
RUN python /tmp/make-minimal-exclude.py ${SPLUNK_BUILD_URL} > /tmp/splunk-minimal-exclude.list
24-
RUN wget -qO /tmp/splunk.tgz ${SPLUNK_BUILD_URL}
25-
RUN wget -qO /tmp/splunk.tgz.md5 ${SPLUNK_BUILD_URL}.md5
26-
RUN test $(md5sum /tmp/splunk.tgz | sed 's,\([a-z0-9]*\).*,\1,') = $(cat /tmp/splunk.tgz.md5 | sed 's,MD5.*=.\([a-z0-9]*\).*,\1,')
27-
RUN mkdir -p /minimal/splunk/var /extras/splunk/var
28-
RUN tar -C /minimal/splunk --strip 1 --exclude-from=/tmp/splunk-minimal-exclude.list -zxf /tmp/splunk.tgz
29-
RUN tar -C /extras/splunk --strip 1 --wildcards --files-from=/tmp/splunk-minimal-exclude.list -zxf /tmp/splunk.tgz
30-
RUN mv /minimal/splunk/etc /minimal/splunk-etc
31-
RUN mv /extras/splunk/etc /extras/splunk-etc
32-
RUN mkdir -p /minimal/splunk/etc /minimal/splunk/share/splunk/search_mrsparkle/modules.new
23+
RUN python /tmp/make-minimal-exclude.py ${SPLUNK_BUILD_URL} > /tmp/splunk-minimal-exclude.list \
24+
&& echo "Downloading Splunk and validating the checksum at: ${SPLUNK_BUILD_URL}" \
25+
&& wget -qO /tmp/`basename ${SPLUNK_BUILD_URL}` ${SPLUNK_BUILD_URL} \
26+
&& wget -qO /tmp/splunk.tgz.sha512 ${SPLUNK_BUILD_URL}.sha512 \
27+
&& cd /tmp \
28+
&& echo "$(cat /tmp/splunk.tgz.sha512)" | sha512sum --check --status \
29+
&& rm /tmp/splunk.tgz.sha512 \
30+
&& mkdir -p /minimal/splunk/var /extras/splunk/var \
31+
&& tar -C /minimal/splunk --strip 1 --exclude-from=/tmp/splunk-minimal-exclude.list -zxf /tmp/`basename ${SPLUNK_BUILD_URL}` \
32+
&& tar -C /extras/splunk --strip 1 --wildcards --files-from=/tmp/splunk-minimal-exclude.list -zxf /tmp/`basename ${SPLUNK_BUILD_URL}` \
33+
&& mv /minimal/splunk/etc /minimal/splunk-etc \
34+
&& mv /extras/splunk/etc /extras/splunk-etc \
35+
&& mkdir -p /minimal/splunk/etc /minimal/splunk/share/splunk/search_mrsparkle/modules.new
3336
COPY splunk/common-files/apps /extras/splunk-etc/apps/
3437

3538

tests/executor.py

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -83,37 +83,13 @@ def teardown_class(cls):
8383
def generate_random_string():
8484
return ''.join(choice(ascii_lowercase) for b in range(10))
8585

86-
@classmethod
87-
def _run_cmd(cls, cmd, cwd=REPO_DIR):
88-
if isinstance(cmd, list):
89-
sh = command
90-
elif isinstance(command, str):
91-
sh = shlex.split(command)
92-
cls.logger.info("CALL: {}".format(sh))
93-
proc = subprocess.Popen(sh, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd)
94-
lines = []
95-
err_lines = []
96-
for line in iter(proc.stdout.readline, ''):
97-
lines.append(line)
98-
for line in iter(proc.stderr.readline, ''):
99-
err_lines.append(line)
100-
proc.stdout.close()
101-
proc.stderr.close()
102-
proc.wait()
103-
out = "".join(lines)
104-
self.logger.info("STDOUT: {}".format(out))
105-
err = "".join(err_lines)
106-
self.logger.info("STDERR: {}".format(err))
107-
self.logger.info("RC: {}".format(proc.returncode))
108-
return out, err, proc.returncode
109-
11086
def handle_request_retry(self, method, url, kwargs):
11187
for n in range(Executor.RETRY_COUNT):
11288
try:
11389
self.logger.info("Attempt #{}: running {} against {} with kwargs {}".format(n+1, method, url, kwargs))
11490
resp = requests.request(method, url, **kwargs)
11591
resp.raise_for_status()
116-
return resp
92+
return resp.status_code, resp.content
11793
except Exception as e:
11894
self.logger.error("Attempt #{} error: {}".format(n+1, str(e)))
11995
if n < Executor.RETRY_COUNT-1:
@@ -187,22 +163,6 @@ def wait_for_containers(self, count, label=None, name=None, timeout=500):
187163
end = time.time()
188164
return True
189165

190-
def handle_request_retry(self, method, url, kwargs):
191-
RETRIES = 10
192-
IMPLICIT_WAIT = 6
193-
for n in range(RETRIES):
194-
try:
195-
self.logger.info("Attempt #{}: running {} against {} with kwargs {}".format(n+1, method, url, kwargs))
196-
resp = requests.request(method, url, **kwargs)
197-
resp.raise_for_status()
198-
return (resp.status_code, resp.content)
199-
except Exception as e:
200-
self.logger.error("Attempt #{} error: {}".format(n+1, str(e)))
201-
if n < RETRIES-1:
202-
time.sleep(IMPLICIT_WAIT)
203-
continue
204-
raise e
205-
206166
def check_splunkd(self, username, password, name=None, scheme="https"):
207167
'''
208168
NOTE: This helper method can only be used for `compose up` scenarios where self.project_name is defined
@@ -330,8 +290,8 @@ def _run_command(self, command, defaults_url=None, apps_url=None):
330290
def check_common_keys(self, log_output, role):
331291
try:
332292
assert log_output["all"]["vars"]["ansible_ssh_user"] == "splunk"
333-
assert log_output["all"]["vars"]["ansible_pre_tasks"] == None
334-
assert log_output["all"]["vars"]["ansible_post_tasks"] == None
293+
assert log_output["all"]["vars"]["ansible_pre_tasks"] == []
294+
assert log_output["all"]["vars"]["ansible_post_tasks"] == []
335295
assert log_output["all"]["vars"]["retry_num"] == 60
336296
assert log_output["all"]["vars"]["retry_delay"] == 6
337297
assert log_output["all"]["vars"]["wait_for_splunk_retry_num"] == 60
@@ -419,4 +379,4 @@ def check_dmc_groups(self, splunkd_port, num_idx, num_sh, num_cm, num_lm):
419379
{"auth": ("admin", self.password), "verify": False})
420380
assert status == 200
421381
output = json.loads(content)
422-
assert len(output["entry"][0]["content"]["member"]) == num_sh
382+
assert len(output["entry"][0]["content"]["member"]) == num_sh

uf/common-files/Dockerfile

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2018 Splunk
1+
# Copyright 2018-2021 Splunk
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -20,13 +20,15 @@ ARG SPLUNK_BASE_IMAGE=base-debian-10
2020
FROM ${SPLUNK_BASE_IMAGE}:latest as package
2121
ARG SPLUNK_BUILD_URL
2222
ENV SPLUNK_HOME=/opt/splunkforwarder
23-
RUN echo "Downloading Splunk and validating the checksum at: ${SPLUNK_BUILD_URL}"
24-
RUN wget -qO /tmp/splunk.tgz ${SPLUNK_BUILD_URL}
25-
RUN wget -qO /tmp/splunk.tgz.md5 ${SPLUNK_BUILD_URL}.md5
26-
RUN test $(md5sum /tmp/splunk.tgz | sed 's,\([a-z0-9]*\).*,\1,') = $(cat /tmp/splunk.tgz.md5 | sed 's,MD5.*=.\([a-z0-9]*\).*,\1,')
27-
RUN tar -C /opt -zxf /tmp/splunk.tgz
28-
RUN mv ${SPLUNK_HOME}/etc ${SPLUNK_HOME}-etc
29-
RUN mkdir -p ${SPLUNK_HOME}/etc ${SPLUNK_HOME}/var
23+
RUN echo "Downloading Splunk and validating the checksum at: ${SPLUNK_BUILD_URL}" \
24+
&& wget -qO /tmp/`basename ${SPLUNK_BUILD_URL}` ${SPLUNK_BUILD_URL} \
25+
&& wget -qO /tmp/splunk.tgz.sha512 ${SPLUNK_BUILD_URL}.sha512 \
26+
&& cd /tmp \
27+
&& echo "$(cat /tmp/splunk.tgz.sha512)" | sha512sum --check --status \
28+
&& rm /tmp/splunk.tgz.sha512 \
29+
&& tar -C /opt -zxf /tmp/`basename ${SPLUNK_BUILD_URL}` \
30+
&& mv ${SPLUNK_HOME}/etc ${SPLUNK_HOME}-etc \
31+
&& mkdir -p ${SPLUNK_HOME}/etc ${SPLUNK_HOME}/var
3032
COPY uf/common-files/apps ${SPLUNK_HOME}-etc/apps/
3133

3234

0 commit comments

Comments
 (0)