From 0a114ca7d146bc7e84b5ab318c1f3936863ff4dc Mon Sep 17 00:00:00 2001 From: mmetc <92726601+mmetc@users.noreply.github.com> Date: Thu, 9 Mar 2023 12:00:29 +0100 Subject: [PATCH] Fix docker tests by increasing timeout (again) and move compose test to plugin (#2112) * Fix docker tests by increasing timeout (again) and move compose test to plugin * Bump workflow timeout to 30 min * Test only alpine-slim and debian-full flavors --- .github/workflows/docker-tests.yml | 27 ++++++++++--------- docker/test/tests/compose/test_compose.py | 21 --------------- .../compose/test_compose/docker-compose.yml | 8 ------ docker/test/tests/test_agent_only.py | 7 +++-- docker/test/tests/test_simple.py | 4 +-- 5 files changed, 21 insertions(+), 46 deletions(-) delete mode 100644 docker/test/tests/compose/test_compose.py delete mode 100644 docker/test/tests/compose/test_compose/docker-compose.yml diff --git a/.github/workflows/docker-tests.yml b/.github/workflows/docker-tests.yml index 1af2529e4..2887166c4 100644 --- a/.github/workflows/docker-tests.yml +++ b/.github/workflows/docker-tests.yml @@ -17,6 +17,7 @@ on: jobs: test_docker_image: runs-on: ubuntu-latest + timeout-minutes: 30 steps: - name: Check out the repo @@ -29,17 +30,17 @@ jobs: with: config: .github/buildkit.toml - - name: "Build flavor: full" - uses: docker/build-push-action@v4 - with: - context: . - file: ./Dockerfile - tags: crowdsecurity/crowdsec:test - target: full - platforms: linux/amd64 - load: true - cache-from: type=gha - cache-to: type=gha,mode=min + # - name: "Build flavor: full" + # uses: docker/build-push-action@v4 + # with: + # context: . + # file: ./Dockerfile + # tags: crowdsecurity/crowdsec:test + # target: full + # platforms: linux/amd64 + # load: true + # cache-from: type=gha + # cache-to: type=gha,mode=min - name: "Build flavor: slim" uses: docker/build-push-action@v4 @@ -94,9 +95,9 @@ jobs: - name: "Run tests" env: CROWDSEC_TEST_VERSION: test - CROWDSEC_TEST_FLAVORS: full,slim,debian + CROWDSEC_TEST_FLAVORS: slim,debian CROWDSEC_TEST_NETWORK: net-test - CROWDSEC_TEST_TIMEOUT: 60 + CROWDSEC_TEST_TIMEOUT: 90 run: | cd docker/test pipenv run pytest -n 2 --durations=0 --color=yes diff --git a/docker/test/tests/compose/test_compose.py b/docker/test/tests/compose/test_compose.py deleted file mode 100644 index 4c712054b..000000000 --- a/docker/test/tests/compose/test_compose.py +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env python - -import time - -import pytest -import requests - -pytestmark = pytest.mark.compose - - -def test_compose_simple(compose, datadir): - with compose(datadir / 'docker-compose.yml') as project: - j = project.ps() - assert len(j) == 1 - assert j[0]['Name'] == 'test_compose-server-1' - assert j[0]['State'] == 'running' - assert j[0]['Publishers'][0]['TargetPort'] == 8000 - port = j[0]['Publishers'][0]['PublishedPort'] - # XXX: should retry with a timeout - time.sleep(.5) - assert requests.get(f'http://localhost:{port}').status_code == 200 diff --git a/docker/test/tests/compose/test_compose/docker-compose.yml b/docker/test/tests/compose/test_compose/docker-compose.yml deleted file mode 100644 index 4853883ba..000000000 --- a/docker/test/tests/compose/test_compose/docker-compose.yml +++ /dev/null @@ -1,8 +0,0 @@ -version: "3" - -services: - server: - image: python:alpine - command: python -m http.server 8000 - ports: - - 8000 diff --git a/docker/test/tests/test_agent_only.py b/docker/test/tests/test_agent_only.py index 9b9aacf69..be66f04e9 100644 --- a/docker/test/tests/test_agent_only.py +++ b/docker/test/tests/test_agent_only.py @@ -8,7 +8,7 @@ import pytest pytestmark = pytest.mark.docker -def test_split_lapi_agent(crowdsec): +def test_split_lapi_agent(crowdsec, flavor): rand = str(random.randint(0, 10000)) lapiname = f'lapi-{rand}' agentname = f'agent-{rand}' @@ -25,7 +25,10 @@ def test_split_lapi_agent(crowdsec): 'LOCAL_API_URL': f'http://{lapiname}:8080', } - with crowdsec(name=lapiname, environment=lapi_env) as lapi, crowdsec(name=agentname, environment=agent_env) as agent: + cs_lapi = crowdsec(name=lapiname, environment=lapi_env, flavor=flavor) + cs_agent = crowdsec(name=agentname, environment=agent_env, flavor=flavor) + + with cs_lapi as lapi, cs_agent as agent: lapi.wait_for_log("*CrowdSec Local API listening on 0.0.0.0:8080*") agent.wait_for_log("*Starting processing data*") lapi.wait_for_http(8080, '/health', want_status=HTTPStatus.OK) diff --git a/docker/test/tests/test_simple.py b/docker/test/tests/test_simple.py index 682e7f182..951d8be4b 100644 --- a/docker/test/tests/test_simple.py +++ b/docker/test/tests/test_simple.py @@ -6,8 +6,8 @@ pytestmark = pytest.mark.docker # XXX this is redundant, already tested in pytest_cs -def test_crowdsec(crowdsec): - with crowdsec() as cs: +def test_crowdsec(crowdsec, flavor): + with crowdsec(flavor=flavor) as cs: for waiter in cs.log_waiters(): with waiter as matcher: matcher.fnmatch_lines(["*Starting processing data*"])