diff --git a/docker-compose-ci.yml b/docker-compose-ci.yml index a699498..7566f3d 100644 --- a/docker-compose-ci.yml +++ b/docker-compose-ci.yml @@ -6,10 +6,16 @@ # #You should have received a copy of the CC0 legalcode along with this #work. If not, see . -version: "3.2" +version: "3.7" services: test: build: ./tests + entrypoint: + - /entrypoint.sh + - --workers + - auto + - --tests-per-worker + - auto links: - splunk - sc4s diff --git a/tests/Dockerfile b/tests/Dockerfile index 0bf3d12..285d52c 100644 --- a/tests/Dockerfile +++ b/tests/Dockerfile @@ -9,13 +9,14 @@ FROM python:3.7 COPY requirements.txt / - RUN pip3 install -r /requirements.txt 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 ./data /work/tests/data #WORKDIR /work -CMD /entrypoint.sh \ No newline at end of file +CMD /entrypoint.sh + diff --git a/tests/entrypoint.sh b/tests/entrypoint.sh index 646dd56..6128096 100755 --- a/tests/entrypoint.sh +++ b/tests/entrypoint.sh @@ -20,4 +20,4 @@ echo check for splunk hec wait-for splunk:8088 -t 0 -- echo splunkhec is up -cd /work;python -m pytest --junitxml=/work/test-results/functional/functional.xml +cd /work;python -m pytest --junitxml=/work/test-results/functional/functional.xml $@ diff --git a/tests/pytest.ini b/tests/pytest.ini new file mode 100644 index 0000000..00b64d9 --- /dev/null +++ b/tests/pytest.ini @@ -0,0 +1,5 @@ +[pytest] +addopts = + --force-flaky --max-runs=3 --min-passes=1 +filterwarnings = + ignore::DeprecationWarning diff --git a/tests/requirements.txt b/tests/requirements.txt index 6d908dd..b530d97 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -11,4 +11,7 @@ jinja2 jinja2-time splunk-sdk flake8 -pytz \ No newline at end of file +pytz +flaky +#pytest-randomly +pytest-parallel \ No newline at end of file diff --git a/tests/test_ubiquiti_unifi.py b/tests/test_ubiquiti_unifi.py index 4eed2b2..0a69280 100644 --- a/tests/test_ubiquiti_unifi.py +++ b/tests/test_ubiquiti_unifi.py @@ -17,12 +17,12 @@ def test_ubiquiti_unifi_us8p60(record_property, setup_wordlist, setup_splunk): host = "{}-{}".format(random.choice(setup_wordlist), random.choice(setup_wordlist)) mt = env.from_string( - "{{mark}}{% now 'utc', '%b %d %H:%M:%S' %} US8P60,18e8294876c3,v4.0.66.10832 switch: DOT1S: dot1sBpduReceive(): Discarding the BPDU on port 0/7, since it is an invalid BPDU type") - message = mt.render(mark="<27>", host=host) + "{{mark}}{% now 'utc', '%b %d %H:%M:%S' %} US8P60,18e8294876c3,v4.0.66.10832 switch: DOT1S: dot1sBpduReceive(): Discarding the BPDU on port 0/7, since it is an invalid BPDU type {{key}}") + message = mt.render(mark="<27>", key=host) sendsingle(message) - st = env.from_string("search index=netops sourcetype=ubnt:switch earliest=-2m | head 2") - search = st.render(host=host) + st = env.from_string("search index=netops sourcetype=ubnt:switch \"{{key}}\" earliest=-2m | head 2") + search = st.render(key=host) resultCount, eventCount = splunk_single(setup_splunk, search) @@ -37,12 +37,12 @@ def test_ubiquiti_unifi_switch_us24p250(record_property, setup_wordlist, setup_s host = "{}-{}".format(random.choice(setup_wordlist), random.choice(setup_wordlist)) mt = env.from_string( - "{{mark}}{% now 'utc', '%b %d %H:%M:%S' %} US24P250,f09fc26f4419,v4.0.54.10625 switch: TRAPMGR: Cold Start: Unit: 0") - message = mt.render(mark="<27>", host=host) + "{{mark}}{% now 'utc', '%b %d %H:%M:%S' %} US24P250,f09fc26f4419,v4.0.54.10625 switch: TRAPMGR: Cold Start: Unit: {{key}}") + message = mt.render(mark="<27>", key=host) sendsingle(message) - st = env.from_string("search index=netops sourcetype=ubnt:switch earliest=-2m | head 2") - search = st.render(host=host) + st = env.from_string("search index=netops sourcetype=ubnt:switch \"{{key}}\" earliest=-2m | head 2") + search = st.render(key=host) resultCount, eventCount = splunk_single(setup_splunk, search)