Skip to content

Commit 74e92d2

Browse files
test: drop the testutils fork, use mender-server's
This repo carried a fork of mender-server's testutils, 12 of 36 files diverged. Roughly a third of that was genuine fixes that upstream never got; the rest was this repo's own compose setups sitting in a directory that shadowed upstream's. The fixes are now upstream in mender-server#2146, so the fork is deleted and testutils comes from the submodule. conftest puts it on sys.path and sets GATEWAY_HOSTNAME, which upstream defaults to "traefik" and this suite needs as "docker.mender.io". What stays is tests/container_manager/: the compose setups encode which files this suite runs, tests/compose/*.yml rather than mender-server's, and the class set differs from upstream's in both directions. requests_get moves to MenderAPI/requests_helpers.py, the one common.py helper upstream does not have. Do not merge before mender-server#2146. The submodule is pinned to that PR's head; it needs re-pinning to main once that lands. Ticket: QA-1702 Signed-off-by: Rewan Rashid <rewan.rashid@northern.tech>
1 parent 7812640 commit 74e92d2

46 files changed

Lines changed: 54 additions & 2789 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

tests/MenderAPI/requests_helpers.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,14 @@ def requests_retry(status_forcelist=[500, 502, 503, 504], host=GATEWAY_HOSTNAME)
4141
if host:
4242
s.headers.update({"Host": host})
4343
return s
44+
45+
46+
def requests_get(url):
47+
"""Plain GET that raises on a non-2xx.
48+
49+
Moved here when this repo stopped forking mender-server's testutils; it was
50+
the one helper in that fork's common.py which upstream does not have.
51+
"""
52+
req = requests.get(url, timeout=30)
53+
req.raise_for_status()
54+
return req

tests/common_setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from testutils.common import User, new_tenant_client
2424
from testutils.infra.cli import CliTenantadm
2525
from testutils.infra.device import MenderDevice, MenderDeviceGroup
26-
from testutils.infra.container_manager import factory
26+
from .container_manager import factory
2727

2828
container_factory = factory.get_factory()
2929

tests/conftest.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,28 @@
1717
import re
1818
import subprocess
1919
import shutil
20+
import sys
2021
import tempfile
2122
import packaging.version
2223

2324
import multiprocessing
2425

26+
# testutils comes from the mender-server submodule -- this repo no longer keeps a
27+
# fork of it. Both of these have to happen before the first testutils import
28+
# below: the path so it resolves at all, and the hostname because
29+
# testutils.api.client reads it into a module-level constant at import time.
30+
#
31+
# Traefik's routers match on Host as well as path, and the tests address the
32+
# ingress by container IP, so every request has to carry this. Upstream defaults
33+
# it to "traefik", which is the name its own deployments answer to.
34+
sys.path.insert(
35+
0,
36+
os.path.join(
37+
os.path.dirname(os.path.abspath(__file__)), "mender_server", "backend", "tests"
38+
),
39+
)
40+
os.environ.setdefault("GATEWAY_HOSTNAME", "docker.mender.io")
41+
2542
import filelock
2643
import pytest
2744
from filelock import FileLock
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2021 Northern.tech AS
1+
# Copyright 2026 Northern.tech AS
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.
@@ -11,12 +11,10 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
"""Compose setups specific to this repository.
1415
15-
HOST = "mender-devicemonitor:8080"
16-
17-
URL_DEVICES = "/api/devices/v1/devicemonitor"
18-
URL_INTERNAL = "/api/internal/v1/devicemonitor"
19-
URL_MGMT = "/api/management/v1/devicemonitor"
20-
21-
URL_ALERT = "/alert"
22-
URL_DEVICE_ALERTS = lambda device_id: f"/devices/{id}/alerts".format(id=device_id)
16+
These used to live under a fork of mender-server's testutils. They stayed behind
17+
when that fork was dropped because they encode which compose files this suite
18+
runs -- tests/compose/*.yml -- rather than mender-server's own, and the class set
19+
differs from upstream's in both directions.
20+
"""

testutils/infra/container_manager/docker_compose_base_manager.py renamed to tests/container_manager/docker_compose_base_manager.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
import requests
2525
from urllib3.exceptions import InsecureRequestWarning
2626

27-
from .docker_manager import DockerNamespace
28-
from ...api.client import GATEWAY_HOSTNAME as _GATEWAY_HOSTNAME
27+
from testutils.infra.container_manager.docker_manager import DockerNamespace
28+
from testutils.api.client import GATEWAY_HOSTNAME as _GATEWAY_HOSTNAME
2929

3030
logger = logging.getLogger("root")
3131

@@ -34,11 +34,17 @@
3434

3535

3636
class DockerComposeBaseNamespace(DockerNamespace):
37+
# Repo root: this module lives at tests/container_manager/, so two levels up.
3738
COMPOSE_FILES_PATH = os.path.realpath(
38-
os.path.join(os.path.dirname(__file__), "..", "..", "..")
39+
os.path.join(os.path.dirname(__file__), "..", "..")
3940
)
4041
BASE_FILES = []
4142

43+
# How long 'up --wait' is given for every container to report healthy. Used
44+
# to live on testutils' BaseContainerManagerNamespace, which this repo no
45+
# longer forks.
46+
wait_healthy_timeout = 300
47+
4248
# Traefik routes on the Host header and we address it by container IP, so
4349
# every request has to carry this explicitly. Single source of truth lives in
4450
# testutils.api.client; exposed here so callers holding a container manager
@@ -217,8 +223,8 @@ def restart_service(self, service):
217223
# stack, which is already running.
218224
self._docker_compose_up(f"--scale {service}=1 {service}", wait_ready=False)
219225

220-
def get_file(self, container_name, path):
221-
container_id = super().getid([container_name])
226+
def get_file(self, service, path):
227+
container_id = super().getid(service)
222228
return super().execute(container_id, ["cat", path])
223229

224230
def _debug_log_containers_logs(self):

testutils/infra/container_manager/docker_compose_manager.py renamed to tests/container_manager/docker_compose_manager.py

File renamed without changes.
File renamed without changes.

tests/mender_server

Submodule mender_server updated 176 files

tests/tests/test_docker_compose.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from .common_update import common_update_procedure
2727
from ..MenderAPI import DeviceAuthV2, Deployments, logger
2828
from .mendertesting import MenderTesting
29-
from testutils.common import requests_get
29+
from ..MenderAPI.requests_helpers import requests_get
3030

3131

3232
@pytest.fixture(scope="session")

tests/tests/test_filetransfer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
from .common_connect import prepare_env_for_connect, wait_for_connect
5050
from .common import md5sum
5151
from .mendertesting import MenderTesting
52-
from testutils.infra.container_manager import factory
52+
from ..container_manager import factory
5353
from testutils.infra.device import MenderDevice
5454

5555
container_factory = factory.get_factory()

0 commit comments

Comments
 (0)