From 0ee7ebbce6b1d5421fc38ade6f00c1b0ecfd48dd Mon Sep 17 00:00:00 2001 From: rfaircloth-splunk Date: Fri, 7 Feb 2020 10:20:36 -0500 Subject: [PATCH] updates --- demo-with-compose.sh | 10 ++---- pytest.ini | 8 ++--- test-with-compose.sh | 5 ++- tests/Dockerfile | 3 +- tests/conftest.py | 19 +++++++++- tests/docker-compose-ci.yml | 69 +++++++++++++++++++++++++++++++++++++ tests/docker-compose.yml | 22 ++---------- tests/pytest-ci.ini | 11 ++++++ tests/pytest.ini | 5 --- 9 files changed, 112 insertions(+), 40 deletions(-) create mode 100644 tests/docker-compose-ci.yml create mode 100644 tests/pytest-ci.ini delete mode 100644 tests/pytest.ini diff --git a/demo-with-compose.sh b/demo-with-compose.sh index cba338c..15eb88a 100755 --- a/demo-with-compose.sh +++ b/demo-with-compose.sh @@ -4,13 +4,7 @@ #Use of this source code is governed by a BSD-2-clause-style #license that can be found in the LICENSE-BSD2 file or at #https://opensource.org/licenses/BSD-2-Clause -export SPLUNK=8.0 -export SYSLOG=3.25.1 - -docker-compose build -docker-compose up -d splunk -docker-compose up -d sc4s -sleep 60 -docker-compose up +docker-compose -f tests/docker-compose-ci.yml build +docker-compose -f tests/docker-compose-ci.yml up EXIT=$0 diff --git a/pytest.ini b/pytest.ini index 36a1996..01ff4c6 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,8 +1,8 @@ [pytest] testpaths = tests -#addopts = --tb=long -# --force-flaky --max-runs=3 --min-passes=1 +addopts = + -v --tb=long + --splunk_type=docker filterwarnings = ignore::DeprecationWarning -#[pytest] -#junit_family = xunit2 +junit_family = xunit1 diff --git a/test-with-compose.sh b/test-with-compose.sh index 27a367e..50e25b9 100755 --- a/test-with-compose.sh +++ b/test-with-compose.sh @@ -4,4 +4,7 @@ #Use of this source code is governed by a BSD-2-clause-style #license that can be found in the LICENSE-BSD2 file or at #https://opensource.org/licenses/BSD-2-Clause -SPLUNK=8.0;SYSLOG=3.25.1 pytest --splunk_password=Changed@11 +docker-compose -f tests/docker-compose-ci.yml up --abort-on-container-exit + +EXIT=$0 + diff --git a/tests/Dockerfile b/tests/Dockerfile index 285d52c..56537b2 100644 --- a/tests/Dockerfile +++ b/tests/Dockerfile @@ -10,12 +10,13 @@ FROM python:3.7 COPY requirements.txt / RUN pip3 install -r /requirements.txt +RUN pip3 install pytest-xdist RUN mkdir -p /work/tests RUN mkdir -p /work/test-results/functional COPY entrypoint.sh / COPY wait-for /bin/ COPY ./* /work/tests/ -COPY pytest.ini /work +COPY pytest-ci.ini /work/pytest.ini COPY ./data /work/tests/data #WORKDIR /work CMD /entrypoint.sh diff --git a/tests/conftest.py b/tests/conftest.py index dfec407..a2fc51e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -6,6 +6,7 @@ import os import random import socket +import uuid from time import sleep import pytest @@ -82,9 +83,16 @@ def pytest_addoption(parser): '--splunk_password', action='store', dest='splunk_password', - default='changeme', + default='Changed@11', help='Splunk password' ) + group.addoption( + '--splunk_hec_token', + action='store', + dest='splunk_hec_token', + default=str(uuid.uuid1()), + help='Splunk HEC token' + ) group.addoption( '--splunk_version', action='store', @@ -112,12 +120,21 @@ def is_responsive_splunk(splunk): return False +@pytest.fixture(scope="session") +def docker_compose_file(pytestconfig): + """Get an absolute path to the `docker-compose.yml` file. Override this + fixture in your tests if you need a custom location.""" + + return os.path.join(str(pytestconfig.invocation_dir), "tests", "docker-compose.yml") + @pytest.fixture(scope="session") def splunk(request): if request.config.getoption('splunk_type') == 'external': request.fixturenames.append('splunk_external') splunk = request.getfixturevalue("splunk_external") elif request.config.getoption('splunk_type') == 'docker': + os.environ['SPLUNK_PASSWORD'] = request.config.getoption('splunk_password') + os.environ['SPLUNK_HEC_TOKEN'] = request.config.getoption('splunk_hec_token') request.fixturenames.append('splunk_docker') splunk = request.getfixturevalue("splunk_docker") else: diff --git a/tests/docker-compose-ci.yml b/tests/docker-compose-ci.yml new file mode 100644 index 0000000..b3ffd08 --- /dev/null +++ b/tests/docker-compose-ci.yml @@ -0,0 +1,69 @@ +#Splunk Connect for Syslog (SC4S) by Splunk, Inc. +# +#To the extent possible under law, the person who associated CC0 with +#Splunk Connect for Syslog (SC4S) has waived all copyright and related or neighboring rights +#to Splunk Connect for Syslog (SC4S). +# +#You should have received a copy of the CC0 legalcode along with this +#work. If not, see . +version: "3.7" + + +services: + test: + build: . + image: docker.pkg.github.com/splunk/splunk-connect-for-syslog/stg-splunk-connect-for-syslog:tests-${CIRCLE_SHA1} + links: + - splunk + - sc4s + volumes: + - results:/work/test-results + + sc4s: + build: + context: ../package + image: docker.pkg.github.com/splunk/splunk-connect-for-syslog/stg-splunk-connect-for-syslog:sc4s-${SYSLOG}-${CIRCLE_SHA1} + hostname: sc4s + #When this is enabled test_common will fail + # command: -det + ports: + - "514" + - "601" + - "514/udp" + - "5000-5050" + - "5000-5050/udp" + - "6514" + stdin_open: true + tty: true + links: + - splunk + environment: + - SPLUNK_HEC_URL=https://splunk:8088 + - SPLUNK_HEC_TOKEN=70b6ae71-76b3-4c38-9597-0c5b37ad9630 + - SC4S_SOURCE_TLS_ENABLE=no + - SC4S_DEST_SPLUNK_HEC_TLS_VERIFY=no + - SC4S_LISTEN_JUNIPER_NETSCREEN_TCP_PORT=5000 + - SC4S_LISTEN_CISCO_ASA_TCP_PORT=5001 + - SC4S_LISTEN_CISCO_IOS_TCP_PORT=5002 + - SC4S_LISTEN_CISCO_MERAKI_TCP_PORT=5003 + - SC4S_LISTEN_JUNIPER_IDP_TCP_PORT=5004 + - SC4S_LISTEN_PALOALTO_PANOS_TCP_PORT=5005 + - SC4S_LISTEN_PFSENSE_TCP_PORT=5006 + - SC4S_ARCHIVE_GLOBAL=no + splunk: + build: + context: ../splunk + image: docker.pkg.github.com/splunk/splunk-connect-for-syslog/stg-splunk-connect-for-syslog:splunk-${SPLUNK}-${CIRCLE_SHA1} + hostname: splunk + ports: + - "8000" + - "8088" + - "8089" + environment: + - SPLUNK_HEC_TOKEN=70b6ae71-76b3-4c38-9597-0c5b37ad9630 + - SPLUNK_PASSWORD=Changed@11 + - SPLUNK_START_ARGS=--accept-license + +volumes: + results: + external: false \ No newline at end of file diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index 63f10dc..e6ec6c7 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose.yml @@ -10,24 +10,9 @@ version: "3.7" services: - test: - build: . - image: docker.pkg.github.com/splunk/splunk-connect-for-syslog/stg-splunk-connect-for-syslog:tests-${CIRCLE_SHA1} - links: - - splunk - - sc4s - environment: - - SPLUNK_USER=admin - - SPLUNK_PASSWORD=${SPLUNK_PASSWORD} - - SPLUNK_HOST=splunk - - docke=sc4s - volumes: - - results:/work/test-results - sc4s: build: context: ../package - image: docker.pkg.github.com/splunk/splunk-connect-for-syslog/stg-splunk-connect-for-syslog:sc4s-${SYSLOG}-${CIRCLE_SHA1} hostname: sc4s #When this is enabled test_common will fail # command: -det @@ -36,7 +21,7 @@ services: - "601" - "514/udp" - "5000-5050" - - "5000-5200/udp" + - "5000-5050/udp" - "6514" stdin_open: true tty: true @@ -55,15 +40,12 @@ services: - SC4S_LISTEN_PALOALTO_PANOS_TCP_PORT=5005 - SC4S_LISTEN_PFSENSE_TCP_PORT=5006 - SC4S_ARCHIVE_GLOBAL=no - volumes: - - ./tls:/opt/syslog-ng/tls splunk: build: context: ../splunk - image: docker.pkg.github.com/splunk/splunk-connect-for-syslog/stg-splunk-connect-for-syslog:splunk-${SPLUNK}-${CIRCLE_SHA1} hostname: splunk ports: - - "8000:8000" + - "8000" - "8088" - "8089" environment: diff --git a/tests/pytest-ci.ini b/tests/pytest-ci.ini new file mode 100644 index 0000000..def1d4a --- /dev/null +++ b/tests/pytest-ci.ini @@ -0,0 +1,11 @@ +[pytest] +addopts = -v + --splunk_type=external + --splunk_password=Changed@11 + --splunk_hec_token=70b6ae71-76b3-4c38-9597-0c5b37ad9630 + --splunk_host=splunk + --sc4s_host=sc4s + --maxfail=5 + -n 4 +filterwarnings = + ignore::DeprecationWarning diff --git a/tests/pytest.ini b/tests/pytest.ini deleted file mode 100644 index ce9083e..0000000 --- a/tests/pytest.ini +++ /dev/null @@ -1,5 +0,0 @@ -[pytest] -addopts = -# --force-flaky --max-runs=3 --min-passes=1 -filterwarnings = - ignore::DeprecationWarning