Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UDS test #678

Draft
wants to merge 8 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions base/redhat-8/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ LABEL name="splunk" \
ARG BUSYBOX_URL

ENV BUSYBOX_URL=${BUSYBOX_URL} \
PYTHON_VERSION=3.7.16 \
PYTHON_GPG_KEY_ID=0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D
PYTHON_VERSION=3.9.19 \
PYTHON_GPG_KEY_ID=E3FF2839C048B25C084DEBE9B26995E310250568

COPY install.sh /install.sh

Expand Down
8 changes: 6 additions & 2 deletions base/redhat-8/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ set -e

# Generate UTF-8 char map and locale
# Reinstalling local English def for now, removed in minimal image: https://bugzilla.redhat.com/show_bug.cgi?id=1665251
microdnf -y --nodocs install glibc-langpack-en
# Comment below install until glibc update is available in minimal image: https://access.redhat.com/errata/RHSA-2024:2722
#microdnf -y --nodocs install glibc-langpack-en

# Currently there is no access to the UTF-8 char map. The following command is commented out until
# the base container can generate the locale.
Expand Down Expand Up @@ -74,9 +75,12 @@ ln -sf /usr/bin/pip${PY_SHORT} /usr/bin/pip

# Install splunk-ansible dependencies
cd /
/usr/bin/python3.7 -m pip install --upgrade pip
/usr/bin/python3.9 -m pip install --upgrade pip
pip -q --no-cache-dir install --upgrade "requests_unixsocket<2.29" "requests<2.29" six wheel Mako "urllib3<2.0.0" certifi jmespath future avro cryptography lxml protobuf setuptools ansible

# Avoid vulnerability on old pip version
/usr/libexec/platform-python -m pip install --upgrade pip

# Remove tests packaged in python libs
find /usr/lib/ -depth \( -type d -a -not -wholename '*/ansible/plugins/test' -a \( -name test -o -name tests -o -name idle_test \) \) -exec rm -rf '{}' \;
find /usr/lib/ -depth \( -type f -a -name '*.pyc' -o -name '*.pyo' -o -name '*.a' \) -exec rm -rf '{}' \;
Expand Down
14 changes: 8 additions & 6 deletions py23-image/redhat-8/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ FROM ${SPLUNK_PRODUCT}-redhat-8:latest
USER root

RUN microdnf -y --nodocs update \
&& microdnf -y --nodocs install python2-pip python2-devel \
&& microdnf -y --nodocs install python2 \
&& pip2 install --upgrade pip \
&& pip2 --no-cache-dir install requests pyyaml jmespath \
&& ln -sf /usr/bin/python3.7 /usr/bin/python3 \
&& ln -sf /usr/bin/pip3.7 /usr/bin/pip3 \
&& ln -sf /usr/bin/python3.7 /usr/bin/python \
&& ln -sf /usr/bin/pip3.7 /usr/bin/pip \
&& pip3 install --upgrade ansible==3.4.0 requests==2.25.1 pyyaml==5.4.1 jmespath==0.10.0
&& ln -sf /usr/bin/python3.9 /usr/bin/python3 \
&& ln -sf /usr/bin/pip3.9 /usr/bin/pip3 \
&& ln -sf /usr/bin/python3.9 /usr/bin/python \
&& ln -sf /usr/bin/pip3.9 /usr/bin/pip \
&& pip3 install --upgrade requests==2.25.1 pyyaml==5.4.1 jmespath==0.10.0 \
&& sed -i '/^\[defaults\]/a\interpreter_python = /usr/bin/python3' /opt/ansible/ansible.cfg
18 changes: 15 additions & 3 deletions tests/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ def get_container_logs(self, container_id):
stream = self.client.logs(container_id, stream=True)
output = ""
for char in stream:
if "Ansible playbook complete" in char:
break
if type(char) is bytes:
char = char.decode("utf-8")
output += char
if "Ansible playbook complete" in output:
break
return output

def cleanup_files(self, files):
Expand Down Expand Up @@ -148,6 +150,8 @@ def wait_for_containers(self, count, label=None, name=None, timeout=500):
# The healthcheck on our Splunk image is not reliable - resorting to checking logs
if container.get("Labels", {}).get("maintainer") == "[email protected]":
output = self.client.logs(container["Id"], tail=5)
if type(output) is bytes:
output = output.decode("utf-8")
if "unable to" in output or "denied" in output or "splunkd.pid file is unreadable" in output:
self.logger.error("Container {} did not start properly, last log line: {}".format(container["Names"][0], output))
elif "Ansible playbook complete" in output:
Expand Down Expand Up @@ -231,7 +235,9 @@ def extract_json(self, container_name):
retries = 15
for i in range(retries):
exec_command = self.client.exec_create(container_name, "cat /opt/container_artifact/ansible_inventory.json")
json_data = self.client.exec_start(exec_command)
json_data = self.client.exec_start(exec_command["Id"])
if type(json_data) is bytes:
json_data = json_data.decode("utf-8")
if "No such file or directory" in json_data:
time.sleep(5)
else:
Expand Down Expand Up @@ -380,3 +386,9 @@ def check_dmc_groups(self, splunkd_port, num_idx, num_sh, num_cm, num_lm):
assert status == 200
output = json.loads(content)
assert len(output["entry"][0]["content"]["member"]) == num_sh

def check_uds_socket_file(self, container_name):
# Check for cli.socket file
exec_command = self.client.exec_create(container_name, "ls /opt/splunkforwarder/var/run/splunk", user="splunk")
file_output = self.client.exec_start(exec_command)
return "cli.socket" in file_output.decode("utf-8")
2 changes: 1 addition & 1 deletion tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pytest==4.4.0
pyrsistent==0.16.1
requests
requests==2.31.0
docker
PyYAML
docker-compose
Expand Down
30 changes: 30 additions & 0 deletions tests/test_single_splunk_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -2778,3 +2778,33 @@ def test_compose_1hf_splunk_add(self):
assert self.check_splunkd("admin", self.password)
# Check Splunkd using the new users
assert self.check_splunkd("jerry", "seinfeld")

def test_compose_1uf_uds(self):
container_name = self.generate_random_string()
self.DIR = os.path.join(self.FIXTURES_DIR, container_name)
cid = None
try:
cid = self.client.create_container(self.UF_IMAGE_NAME, tty=True, command="start",
volumes=["/tmp/defaults/"], name=container_name,
environment={"DEBUG": "true", "SPLUNK_START_ARGS": "--accept-license",
"SPLUNK_PASSWORD": "Changeme", "ENABLE_TCP_MODE": "false"},
host_config=self.client.create_host_config(binds=[
os.path.join(self.FIXTURES_DIR, container_name) + ":/tmp/defaults/"])
)
cid = cid.get("Id")
self.client.start(cid)
assert self.wait_for_containers(1, name=container_name)
output = self.get_container_logs(cid)
assert "Allows UDS" in output
assert self.check_uds_socket_file(container_name)
except Exception as e:
self.logger.error(e)
raise e
finally:
if cid:
self.client.remove_container(cid, v=True, force=True)
try:
os.remove(os.path.join(self.DIR, "default.yml"))
os.rmdir(self.DIR)
except OSError:
pass