mender-testkit 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mender_testkit-0.1.1/LICENSE +181 -0
- mender_testkit-0.1.1/PKG-INFO +215 -0
- mender_testkit-0.1.1/README.md +190 -0
- mender_testkit-0.1.1/pyproject.toml +64 -0
- mender_testkit-0.1.1/setup.cfg +4 -0
- mender_testkit-0.1.1/src/mender_testkit/__init__.py +31 -0
- mender_testkit-0.1.1/src/mender_testkit/_server_ref.py +27 -0
- mender_testkit-0.1.1/src/mender_testkit/compose.py +114 -0
- mender_testkit-0.1.1/src/mender_testkit/data/mender_server/.env +7 -0
- mender_testkit-0.1.1/src/mender_testkit/data/mender_server/compose/certs/mender.crt +12 -0
- mender_testkit-0.1.1/src/mender_testkit/data/mender_server/compose/certs/mender.key +5 -0
- mender_testkit-0.1.1/src/mender_testkit/data/mender_server/compose/config/mender.pem +28 -0
- mender_testkit-0.1.1/src/mender_testkit/data/mender_server/compose/config/traefik/middlewares.yaml +48 -0
- mender_testkit-0.1.1/src/mender_testkit/data/mender_server/compose/config/traefik/tls.yaml +9 -0
- mender_testkit-0.1.1/src/mender_testkit/data/mender_server/compose/docker-compose.enterprise.yml +181 -0
- mender_testkit-0.1.1/src/mender_testkit/data/mender_server/compose/docker-compose.seaweedfs.yml +102 -0
- mender_testkit-0.1.1/src/mender_testkit/data/mender_server/docker-compose.yml +436 -0
- mender_testkit-0.1.1/src/mender_testkit/data/overlays/no-ports.yml +15 -0
- mender_testkit-0.1.1/src/mender_testkit/devices.py +161 -0
- mender_testkit-0.1.1/src/mender_testkit/docker.py +60 -0
- mender_testkit-0.1.1/src/mender_testkit/plugin.py +183 -0
- mender_testkit-0.1.1/src/mender_testkit/projects.py +35 -0
- mender_testkit-0.1.1/src/mender_testkit/server.py +443 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/__init__.py +13 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/api/__init__.py +13 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/api/auditlogs.py +16 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/api/client.py +143 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/api/deployments.py +33 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/api/deployments_v2.py +23 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/api/deviceauth.py +57 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/api/deviceconfig.py +17 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/api/deviceconnect.py +19 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/api/devicemonitor.py +22 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/api/inventory.py +30 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/api/inventory_v2.py +27 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/api/iot_manager.py +21 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/api/proto_shell.py +82 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/api/protomsg.py +91 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/api/tenantadm.py +33 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/api/tenantadm_v2.py +24 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/api/useradm.py +36 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/api/workflows.py +18 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/common.py +641 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/infra/__init__.py +13 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/infra/cli.py +279 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/infra/container_manager/__init__.py +14 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/infra/container_manager/base.py +70 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/infra/container_manager/docker_compose_base_manager.py +200 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/infra/container_manager/docker_compose_manager.py +589 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/infra/container_manager/docker_manager.py +77 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/infra/container_manager/factory.py +250 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/infra/container_manager/kubernetes_manager.py +210 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/infra/device.py +459 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/infra/mongo.py +44 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/infra/smtpd_mock.py +176 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/integration/stripe.py +61 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/util/__init__.py +13 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/util/artifact.py +306 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/util/crypto.py +119 -0
- mender_testkit-0.1.1/src/mender_testkit/testutils/util/websockets.py +111 -0
- mender_testkit-0.1.1/src/mender_testkit.egg-info/PKG-INFO +215 -0
- mender_testkit-0.1.1/src/mender_testkit.egg-info/SOURCES.txt +64 -0
- mender_testkit-0.1.1/src/mender_testkit.egg-info/dependency_links.txt +1 -0
- mender_testkit-0.1.1/src/mender_testkit.egg-info/entry_points.txt +2 -0
- mender_testkit-0.1.1/src/mender_testkit.egg-info/requires.txt +15 -0
- mender_testkit-0.1.1/src/mender_testkit.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
Copyright 2026 Northern.tech AS
|
|
2
|
+
|
|
3
|
+
All content in this project is licensed under the Apache License v2, unless
|
|
4
|
+
indicated otherwise.
|
|
5
|
+
|
|
6
|
+
-------------------------------------------------------------------------------
|
|
7
|
+
|
|
8
|
+
Apache License
|
|
9
|
+
Version 2.0, January 2004
|
|
10
|
+
http://www.apache.org/licenses/
|
|
11
|
+
|
|
12
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
13
|
+
|
|
14
|
+
1. Definitions.
|
|
15
|
+
|
|
16
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
17
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
18
|
+
|
|
19
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
20
|
+
the copyright owner that is granting the License.
|
|
21
|
+
|
|
22
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
23
|
+
other entities that control, are controlled by, or are under common
|
|
24
|
+
control with that entity. For the purposes of this definition,
|
|
25
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
26
|
+
direction or management of such entity, whether by contract or
|
|
27
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
28
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
29
|
+
|
|
30
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
31
|
+
exercising permissions granted by this License.
|
|
32
|
+
|
|
33
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
34
|
+
including but not limited to software source code, documentation
|
|
35
|
+
source, and configuration files.
|
|
36
|
+
|
|
37
|
+
"Object" form shall mean any form resulting from mechanical
|
|
38
|
+
transformation or translation of a Source form, including but
|
|
39
|
+
not limited to compiled object code, generated documentation,
|
|
40
|
+
and conversions to other media types.
|
|
41
|
+
|
|
42
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
43
|
+
Object form, made available under the License, as indicated by a
|
|
44
|
+
copyright notice that is included in or attached to the work
|
|
45
|
+
(an example is provided in the Appendix below).
|
|
46
|
+
|
|
47
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
48
|
+
form, that is based on (or derived from) the Work and for which the
|
|
49
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
50
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
51
|
+
of this License, Derivative Works shall not include works that remain
|
|
52
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
53
|
+
the Work and Derivative Works thereof.
|
|
54
|
+
|
|
55
|
+
"Contribution" shall mean any work of authorship, including
|
|
56
|
+
the original version of the Work and any modifications or additions
|
|
57
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
58
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
59
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
60
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
61
|
+
means any form of electronic, verbal, or written communication sent
|
|
62
|
+
to the Licensor or its representatives, including but not limited to
|
|
63
|
+
communication on electronic mailing lists, source code control systems,
|
|
64
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
65
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
66
|
+
excluding communication that is conspicuously marked or otherwise
|
|
67
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
68
|
+
|
|
69
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
70
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
71
|
+
subsequently incorporated within the Work.
|
|
72
|
+
|
|
73
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
77
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
78
|
+
Work and such Derivative Works in Source or Object form.
|
|
79
|
+
|
|
80
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
81
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
82
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
83
|
+
(except as stated in this section) patent license to make, have made,
|
|
84
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
85
|
+
where such license applies only to those patent claims licensable
|
|
86
|
+
by such Contributor that are necessarily infringed by their
|
|
87
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
88
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
89
|
+
institute patent litigation against any entity (including a
|
|
90
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
91
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
92
|
+
or contributory patent infringement, then any patent licenses
|
|
93
|
+
granted to You under this License for that Work shall terminate
|
|
94
|
+
as of the date such litigation is filed.
|
|
95
|
+
|
|
96
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
97
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
98
|
+
modifications, and in Source or Object form, provided that You
|
|
99
|
+
meet the following conditions:
|
|
100
|
+
|
|
101
|
+
(a) You must give any other recipients of the Work or
|
|
102
|
+
Derivative Works a copy of this License; and
|
|
103
|
+
|
|
104
|
+
(b) You must cause any modified files to carry prominent notices
|
|
105
|
+
stating that You changed the files; and
|
|
106
|
+
|
|
107
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
108
|
+
that You distribute, all copyright, patent, trademark, and
|
|
109
|
+
attribution notices from the Source form of the Work,
|
|
110
|
+
excluding those notices that do not pertain to any part of
|
|
111
|
+
the Derivative Works; and
|
|
112
|
+
|
|
113
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
114
|
+
distribution, then any Derivative Works that You distribute must
|
|
115
|
+
include a readable copy of the attribution notices contained
|
|
116
|
+
within such NOTICE file, excluding those notices that do not
|
|
117
|
+
pertain to any part of the Derivative Works, in at least one
|
|
118
|
+
of the following places: within a NOTICE text file distributed
|
|
119
|
+
as part of the Derivative Works; within the Source form or
|
|
120
|
+
documentation, if provided along with the Derivative Works; or,
|
|
121
|
+
within a display generated by the Derivative Works, if and
|
|
122
|
+
wherever such third-party notices normally appear. The contents
|
|
123
|
+
of the NOTICE file are for informational purposes only and
|
|
124
|
+
do not modify the License. You may add Your own attribution
|
|
125
|
+
notices within Derivative Works that You distribute, alongside
|
|
126
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
127
|
+
that such additional attribution notices cannot be construed
|
|
128
|
+
as modifying the License.
|
|
129
|
+
|
|
130
|
+
You may add Your own copyright statement to Your modifications and
|
|
131
|
+
may provide additional or different license terms and conditions
|
|
132
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
133
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
134
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
135
|
+
the conditions stated in this License.
|
|
136
|
+
|
|
137
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
138
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
139
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
140
|
+
this License, without any additional terms or conditions.
|
|
141
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
142
|
+
the terms of any separate license agreement you may have executed
|
|
143
|
+
with Licensor regarding such Contributions.
|
|
144
|
+
|
|
145
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
146
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
147
|
+
except as required for reasonable and customary use in describing the
|
|
148
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
149
|
+
|
|
150
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
151
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
152
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
153
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
154
|
+
implied, including, without limitation, any warranties or conditions
|
|
155
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
156
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
157
|
+
appropriateness of using or redistributing the Work and assume any
|
|
158
|
+
risks associated with Your exercise of permissions under this License.
|
|
159
|
+
|
|
160
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
161
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
162
|
+
unless required by applicable law (such as deliberate and grossly
|
|
163
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
164
|
+
liable to You for damages, including any direct, indirect, special,
|
|
165
|
+
incidental, or consequential damages of any character arising as a
|
|
166
|
+
result of this License or out of the use or inability to use the
|
|
167
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
168
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
169
|
+
other commercial damages or losses), even if such Contributor
|
|
170
|
+
has been advised of the possibility of such damages.
|
|
171
|
+
|
|
172
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
173
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
174
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
175
|
+
or other liability obligations and/or rights consistent with this
|
|
176
|
+
License. However, in accepting such obligations, You may act only
|
|
177
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
178
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
179
|
+
defend, and hold each Contributor harmless for any liability
|
|
180
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
181
|
+
of your accepting any such warranty or additional liability.
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mender-testkit
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Shared test infrastructure for the Mender integration test suites
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
Project-URL: Repository, https://github.com/mendersoftware/mender-testkit
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: aiosmtpd>=1.4.6
|
|
11
|
+
Requires-Dist: cryptography>=47.0.0
|
|
12
|
+
Requires-Dist: docker>=7.1.0
|
|
13
|
+
Requires-Dist: filelock>=3.29.0
|
|
14
|
+
Requires-Dist: msgpack>=1.2.1
|
|
15
|
+
Requires-Dist: pymongo>=4.17.0
|
|
16
|
+
Requires-Dist: pytest>=9.0.3
|
|
17
|
+
Requires-Dist: redo>=3.0.0
|
|
18
|
+
Requires-Dist: requests>=2.34.2
|
|
19
|
+
Requires-Dist: stripe>=15.2.0
|
|
20
|
+
Requires-Dist: urllib3>=2.7.0
|
|
21
|
+
Requires-Dist: websockets>=16.0
|
|
22
|
+
Provides-Extra: kubernetes
|
|
23
|
+
Requires-Dist: kubernetes>=36.0.2; extra == "kubernetes"
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# mender-testkit
|
|
27
|
+
|
|
28
|
+
Shared test infrastructure for the Mender integration test suites.
|
|
29
|
+
|
|
30
|
+
The suites in `mender-binary-delta`, `mender-configure-module`, `mender-gateway`,
|
|
31
|
+
`mender-orchestrator` and `integration` all rely on the same things: a mender-server
|
|
32
|
+
backend brought up under docker compose, a client for its management API, and a
|
|
33
|
+
way to start QEMU devices against it. Each repo used to carry its own copy of all
|
|
34
|
+
of it, kept in step by hand, plus a `mender_server` submodule for the compose
|
|
35
|
+
files. This package is that copy.
|
|
36
|
+
|
|
37
|
+
## Install
|
|
38
|
+
```
|
|
39
|
+
pip install mender-testkit
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
That replaces both the `mender_server` submodule and the
|
|
43
|
+
`pip install -r mender_server/backend/tests/requirements-integration.txt` line
|
|
44
|
+
that every consuming repo used to have -- the dependency list is this package's
|
|
45
|
+
own.
|
|
46
|
+
|
|
47
|
+
`kubernetes` is an extra rather than a dependency. Nothing here imports it unless
|
|
48
|
+
`K8S` is set in the environment, so a suite running against docker compose does
|
|
49
|
+
not need it installed:
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
pip install mender-testkit[kubernetes] # only if you run against a cluster
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Using it
|
|
56
|
+
|
|
57
|
+
**The backend.** Request one of two pytest fixtures and it is up before your test
|
|
58
|
+
runs. They arrive through an entry point, so there is nothing to import or
|
|
59
|
+
register:
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
def test_something(os_backend_server):
|
|
63
|
+
server = Server() # plan="os"
|
|
64
|
+
|
|
65
|
+
def test_something_else(enterprise_backend_server):
|
|
66
|
+
server = Server(plan="enterprise") # provisions a tenant via tenantadm
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
One backend runs at a time. Two full stacks plus QEMU clients starve the Go
|
|
70
|
+
services of CPU and requests start coming back from Traefik as 504s, so asking
|
|
71
|
+
for the other flavour switches rather than adding. Under `pytest-xdist` the stack
|
|
72
|
+
is started once for the whole run and torn down when the last worker finishes.
|
|
73
|
+
|
|
74
|
+
**The API.** `Server` is a client, not a lifecycle manager -- it assumes the
|
|
75
|
+
backend is already up:
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
from mender_testkit.server import Server
|
|
79
|
+
|
|
80
|
+
server = Server(plan="enterprise")
|
|
81
|
+
device_ids = server.accept_devices(env.devices)
|
|
82
|
+
server.upload_image("artifact.mender")
|
|
83
|
+
deployment = server.create_deployment("artifact.mender", device_ids)
|
|
84
|
+
server.check_expected_status("finished", deployment)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Every request carries `Host: docker.mender.io`, because Traefik's routers match on
|
|
88
|
+
Host as well as path and the tests reach it by container IP. `GATEWAY_HOSTNAME`
|
|
89
|
+
is set when this package is first imported; override it in the environment if your
|
|
90
|
+
ingress answers to something else.
|
|
91
|
+
|
|
92
|
+
**Devices.**
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
from mender_testkit.devices import Env, clients_up, wait_for_devices
|
|
96
|
+
|
|
97
|
+
env = Env()
|
|
98
|
+
env.server = Server()
|
|
99
|
+
env.devices = clients_up(2, "docker-compose.client.yml", network=env.server.network)
|
|
100
|
+
wait_for_devices(env)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Client compose files stay in the consuming repo: the device under test is the
|
|
104
|
+
repo's product, not this package's business. What this package supplies is the
|
|
105
|
+
network it attaches to, via `MENDER_SERVER_NETWORK`, which `clients_up` exports.
|
|
106
|
+
Declare it in your client compose file as
|
|
107
|
+
|
|
108
|
+
```yaml
|
|
109
|
+
networks:
|
|
110
|
+
mender_server:
|
|
111
|
+
external: true
|
|
112
|
+
name: ${MENDER_SERVER_NETWORK:-mender_default}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**Compose files, directly.** If you drive compose yourself rather than through the
|
|
116
|
+
fixtures:
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
from mender_testkit.compose import compose_dir, compose_files
|
|
120
|
+
|
|
121
|
+
files = compose_files("enterprise") # absolute paths, in -f order
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
They are package data, so they are copied to a real directory on first use --
|
|
125
|
+
compose needs actual files, and it needs the whole tree, because
|
|
126
|
+
`docker-compose.yml` bind-mounts `./compose/certs` and `./compose/config` relative
|
|
127
|
+
to the project directory. Pass `compose_dir()` as `--project-directory`. It is a
|
|
128
|
+
temporary directory removed at process exit; pass `compose_dir(dest=...)` if you
|
|
129
|
+
need one that outlives the process.
|
|
130
|
+
|
|
131
|
+
By default the backend publishes no host ports. The tests reach Traefik by
|
|
132
|
+
container IP, so publishing buys nothing and costs exclusivity -- only one stack
|
|
133
|
+
can hold 443. Pass `publish_ports=True` if you want to reach the backend from the
|
|
134
|
+
host, which works for one backend at a time.
|
|
135
|
+
|
|
136
|
+
## The vendored trees
|
|
137
|
+
|
|
138
|
+
Two directories are **generated, not written**:
|
|
139
|
+
|
|
140
|
+
| path | from |
|
|
141
|
+
| --- | --- |
|
|
142
|
+
| `src/mender_testkit/testutils/` | mender-server's `backend/tests/testutils` |
|
|
143
|
+
| `src/mender_testkit/data/mender_server/` | mender-server's compose files |
|
|
144
|
+
|
|
145
|
+
Both are copies of the commit in `src/mender_testkit/_server_ref.py`, produced by
|
|
146
|
+
`scripts/vendor.py`. Do not edit either by hand: a fix belongs upstream in
|
|
147
|
+
mender-server, after which the ref moves and the copies are regenerated. Editing
|
|
148
|
+
them here creates a fork that looks identical to a stale one, which is the state
|
|
149
|
+
this package exists to end.
|
|
150
|
+
|
|
151
|
+
`testutils` is vendored rather than depended on because mender-server does not
|
|
152
|
+
publish it. Committing the copies rather than fetching at build time keeps the
|
|
153
|
+
wheel reproducible from a tag and lets `pip install` work without reaching
|
|
154
|
+
GitHub.
|
|
155
|
+
|
|
156
|
+
To refresh:
|
|
157
|
+
|
|
158
|
+
```
|
|
159
|
+
$EDITOR src/mender_testkit/_server_ref.py # or let Renovate do it
|
|
160
|
+
scripts/vendor.py
|
|
161
|
+
scripts/vendor.py --check # asserts the trees match the ref
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
`--check` is worth running in CI: it catches both a hand-edit and a ref bump whose
|
|
165
|
+
files were never regenerated.
|
|
166
|
+
|
|
167
|
+
### Why a commit and not a release tag
|
|
168
|
+
|
|
169
|
+
Because these suites test unreleased server code. `.env` pins the backend images
|
|
170
|
+
to `main`, and the clients they run against are `client-main` builds, so the
|
|
171
|
+
compose files and `testutils` have to come from the same place -- a release tag
|
|
172
|
+
would mean a released compose driving unreleased images.
|
|
173
|
+
|
|
174
|
+
The immediate reason is narrower: fixes these suites need land on `main` first and
|
|
175
|
+
reach a tag only at the next release, so a tag-based pin is always some way behind
|
|
176
|
+
what the tests require.
|
|
177
|
+
|
|
178
|
+
A tag is otherwise perfectly workable. Tracking released versions instead would
|
|
179
|
+
mean putting a tag in `_server_ref.py`, swapping this file's manager to the
|
|
180
|
+
`github-releases` datasource (matching `currentValue` rather than
|
|
181
|
+
`currentDigest`), and teaching `scripts/vendor.py` to fetch a tag rather than a
|
|
182
|
+
SHA. Note that release tags route on path alone; the `Host(...)` clause matching
|
|
183
|
+
`MENDER_HOSTNAME` is something `main` *added*, so the explicit `Host` header this
|
|
184
|
+
package sends is required by `main` and merely redundant against a tag.
|
|
185
|
+
|
|
186
|
+
### Judging a ref bump
|
|
187
|
+
|
|
188
|
+
mender-server moves at roughly 280 commits a month, so most bumps change nothing
|
|
189
|
+
here. What matters is whether the files these suites actually consume moved:
|
|
190
|
+
|
|
191
|
+
```
|
|
192
|
+
git diff <old>..<new> -- docker-compose.yml compose/docker-compose.enterprise.yml \
|
|
193
|
+
compose/config compose/certs
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Empty or cosmetic, and one suite is enough to gate it. If the service list moved,
|
|
197
|
+
run them all. A 1699-commit bump once turned out to be nine lines of image tags.
|
|
198
|
+
|
|
199
|
+
## Building
|
|
200
|
+
|
|
201
|
+
```
|
|
202
|
+
rm -rf build dist src/*.egg-info
|
|
203
|
+
python -m build --wheel
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
The `rm` is needed here because setuptools reuses `build/lib`, and after
|
|
207
|
+
`testutils` moved under `mender_testkit/`, a stale copy there produced a wheel
|
|
208
|
+
containing the tree *twice* -- once at top level, once namespaced -- with no
|
|
209
|
+
warning. Verify what you built:
|
|
210
|
+
|
|
211
|
+
```
|
|
212
|
+
python -c "import zipfile,glob; \
|
|
213
|
+
print([n for n in zipfile.ZipFile(sorted(glob.glob('dist/*.whl'))[-1]).namelist() \
|
|
214
|
+
if n.startswith('testutils/')])" # must be empty
|
|
215
|
+
```
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# mender-testkit
|
|
2
|
+
|
|
3
|
+
Shared test infrastructure for the Mender integration test suites.
|
|
4
|
+
|
|
5
|
+
The suites in `mender-binary-delta`, `mender-configure-module`, `mender-gateway`,
|
|
6
|
+
`mender-orchestrator` and `integration` all rely on the same things: a mender-server
|
|
7
|
+
backend brought up under docker compose, a client for its management API, and a
|
|
8
|
+
way to start QEMU devices against it. Each repo used to carry its own copy of all
|
|
9
|
+
of it, kept in step by hand, plus a `mender_server` submodule for the compose
|
|
10
|
+
files. This package is that copy.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
```
|
|
14
|
+
pip install mender-testkit
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
That replaces both the `mender_server` submodule and the
|
|
18
|
+
`pip install -r mender_server/backend/tests/requirements-integration.txt` line
|
|
19
|
+
that every consuming repo used to have -- the dependency list is this package's
|
|
20
|
+
own.
|
|
21
|
+
|
|
22
|
+
`kubernetes` is an extra rather than a dependency. Nothing here imports it unless
|
|
23
|
+
`K8S` is set in the environment, so a suite running against docker compose does
|
|
24
|
+
not need it installed:
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
pip install mender-testkit[kubernetes] # only if you run against a cluster
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Using it
|
|
31
|
+
|
|
32
|
+
**The backend.** Request one of two pytest fixtures and it is up before your test
|
|
33
|
+
runs. They arrive through an entry point, so there is nothing to import or
|
|
34
|
+
register:
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
def test_something(os_backend_server):
|
|
38
|
+
server = Server() # plan="os"
|
|
39
|
+
|
|
40
|
+
def test_something_else(enterprise_backend_server):
|
|
41
|
+
server = Server(plan="enterprise") # provisions a tenant via tenantadm
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
One backend runs at a time. Two full stacks plus QEMU clients starve the Go
|
|
45
|
+
services of CPU and requests start coming back from Traefik as 504s, so asking
|
|
46
|
+
for the other flavour switches rather than adding. Under `pytest-xdist` the stack
|
|
47
|
+
is started once for the whole run and torn down when the last worker finishes.
|
|
48
|
+
|
|
49
|
+
**The API.** `Server` is a client, not a lifecycle manager -- it assumes the
|
|
50
|
+
backend is already up:
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from mender_testkit.server import Server
|
|
54
|
+
|
|
55
|
+
server = Server(plan="enterprise")
|
|
56
|
+
device_ids = server.accept_devices(env.devices)
|
|
57
|
+
server.upload_image("artifact.mender")
|
|
58
|
+
deployment = server.create_deployment("artifact.mender", device_ids)
|
|
59
|
+
server.check_expected_status("finished", deployment)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Every request carries `Host: docker.mender.io`, because Traefik's routers match on
|
|
63
|
+
Host as well as path and the tests reach it by container IP. `GATEWAY_HOSTNAME`
|
|
64
|
+
is set when this package is first imported; override it in the environment if your
|
|
65
|
+
ingress answers to something else.
|
|
66
|
+
|
|
67
|
+
**Devices.**
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from mender_testkit.devices import Env, clients_up, wait_for_devices
|
|
71
|
+
|
|
72
|
+
env = Env()
|
|
73
|
+
env.server = Server()
|
|
74
|
+
env.devices = clients_up(2, "docker-compose.client.yml", network=env.server.network)
|
|
75
|
+
wait_for_devices(env)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Client compose files stay in the consuming repo: the device under test is the
|
|
79
|
+
repo's product, not this package's business. What this package supplies is the
|
|
80
|
+
network it attaches to, via `MENDER_SERVER_NETWORK`, which `clients_up` exports.
|
|
81
|
+
Declare it in your client compose file as
|
|
82
|
+
|
|
83
|
+
```yaml
|
|
84
|
+
networks:
|
|
85
|
+
mender_server:
|
|
86
|
+
external: true
|
|
87
|
+
name: ${MENDER_SERVER_NETWORK:-mender_default}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**Compose files, directly.** If you drive compose yourself rather than through the
|
|
91
|
+
fixtures:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from mender_testkit.compose import compose_dir, compose_files
|
|
95
|
+
|
|
96
|
+
files = compose_files("enterprise") # absolute paths, in -f order
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
They are package data, so they are copied to a real directory on first use --
|
|
100
|
+
compose needs actual files, and it needs the whole tree, because
|
|
101
|
+
`docker-compose.yml` bind-mounts `./compose/certs` and `./compose/config` relative
|
|
102
|
+
to the project directory. Pass `compose_dir()` as `--project-directory`. It is a
|
|
103
|
+
temporary directory removed at process exit; pass `compose_dir(dest=...)` if you
|
|
104
|
+
need one that outlives the process.
|
|
105
|
+
|
|
106
|
+
By default the backend publishes no host ports. The tests reach Traefik by
|
|
107
|
+
container IP, so publishing buys nothing and costs exclusivity -- only one stack
|
|
108
|
+
can hold 443. Pass `publish_ports=True` if you want to reach the backend from the
|
|
109
|
+
host, which works for one backend at a time.
|
|
110
|
+
|
|
111
|
+
## The vendored trees
|
|
112
|
+
|
|
113
|
+
Two directories are **generated, not written**:
|
|
114
|
+
|
|
115
|
+
| path | from |
|
|
116
|
+
| --- | --- |
|
|
117
|
+
| `src/mender_testkit/testutils/` | mender-server's `backend/tests/testutils` |
|
|
118
|
+
| `src/mender_testkit/data/mender_server/` | mender-server's compose files |
|
|
119
|
+
|
|
120
|
+
Both are copies of the commit in `src/mender_testkit/_server_ref.py`, produced by
|
|
121
|
+
`scripts/vendor.py`. Do not edit either by hand: a fix belongs upstream in
|
|
122
|
+
mender-server, after which the ref moves and the copies are regenerated. Editing
|
|
123
|
+
them here creates a fork that looks identical to a stale one, which is the state
|
|
124
|
+
this package exists to end.
|
|
125
|
+
|
|
126
|
+
`testutils` is vendored rather than depended on because mender-server does not
|
|
127
|
+
publish it. Committing the copies rather than fetching at build time keeps the
|
|
128
|
+
wheel reproducible from a tag and lets `pip install` work without reaching
|
|
129
|
+
GitHub.
|
|
130
|
+
|
|
131
|
+
To refresh:
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
$EDITOR src/mender_testkit/_server_ref.py # or let Renovate do it
|
|
135
|
+
scripts/vendor.py
|
|
136
|
+
scripts/vendor.py --check # asserts the trees match the ref
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
`--check` is worth running in CI: it catches both a hand-edit and a ref bump whose
|
|
140
|
+
files were never regenerated.
|
|
141
|
+
|
|
142
|
+
### Why a commit and not a release tag
|
|
143
|
+
|
|
144
|
+
Because these suites test unreleased server code. `.env` pins the backend images
|
|
145
|
+
to `main`, and the clients they run against are `client-main` builds, so the
|
|
146
|
+
compose files and `testutils` have to come from the same place -- a release tag
|
|
147
|
+
would mean a released compose driving unreleased images.
|
|
148
|
+
|
|
149
|
+
The immediate reason is narrower: fixes these suites need land on `main` first and
|
|
150
|
+
reach a tag only at the next release, so a tag-based pin is always some way behind
|
|
151
|
+
what the tests require.
|
|
152
|
+
|
|
153
|
+
A tag is otherwise perfectly workable. Tracking released versions instead would
|
|
154
|
+
mean putting a tag in `_server_ref.py`, swapping this file's manager to the
|
|
155
|
+
`github-releases` datasource (matching `currentValue` rather than
|
|
156
|
+
`currentDigest`), and teaching `scripts/vendor.py` to fetch a tag rather than a
|
|
157
|
+
SHA. Note that release tags route on path alone; the `Host(...)` clause matching
|
|
158
|
+
`MENDER_HOSTNAME` is something `main` *added*, so the explicit `Host` header this
|
|
159
|
+
package sends is required by `main` and merely redundant against a tag.
|
|
160
|
+
|
|
161
|
+
### Judging a ref bump
|
|
162
|
+
|
|
163
|
+
mender-server moves at roughly 280 commits a month, so most bumps change nothing
|
|
164
|
+
here. What matters is whether the files these suites actually consume moved:
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
git diff <old>..<new> -- docker-compose.yml compose/docker-compose.enterprise.yml \
|
|
168
|
+
compose/config compose/certs
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Empty or cosmetic, and one suite is enough to gate it. If the service list moved,
|
|
172
|
+
run them all. A 1699-commit bump once turned out to be nine lines of image tags.
|
|
173
|
+
|
|
174
|
+
## Building
|
|
175
|
+
|
|
176
|
+
```
|
|
177
|
+
rm -rf build dist src/*.egg-info
|
|
178
|
+
python -m build --wheel
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
The `rm` is needed here because setuptools reuses `build/lib`, and after
|
|
182
|
+
`testutils` moved under `mender_testkit/`, a stale copy there produced a wheel
|
|
183
|
+
containing the tree *twice* -- once at top level, once namespaced -- with no
|
|
184
|
+
warning. Verify what you built:
|
|
185
|
+
|
|
186
|
+
```
|
|
187
|
+
python -c "import zipfile,glob; \
|
|
188
|
+
print([n for n in zipfile.ZipFile(sorted(glob.glob('dist/*.whl'))[-1]).namelist() \
|
|
189
|
+
if n.startswith('testutils/')])" # must be empty
|
|
190
|
+
```
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "mender-testkit"
|
|
7
|
+
version = "0.1.1"
|
|
8
|
+
description = "Shared test infrastructure for the Mender integration test suites"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = { text = "Apache-2.0" }
|
|
12
|
+
|
|
13
|
+
# What this package's own code imports, at the floors mender-server's
|
|
14
|
+
# backend/tests/requirements-integration.txt was tested against.
|
|
15
|
+
#
|
|
16
|
+
# Not a copy of that file: it is a lockfile listing the whole resolved tree, so
|
|
17
|
+
# copying it here declared 25 transitive packages as direct dependencies and
|
|
18
|
+
# pinned all 37 exactly. Both are wrong for a library -- the exact pins made this
|
|
19
|
+
# uninstallable beside any consumer with its own opinion, and azure-iot-hub-api,
|
|
20
|
+
# which nothing imports, dragged in azure-cli and constrained cryptography for
|
|
21
|
+
# everyone. Consumers keep the exact set in their own lockfiles.
|
|
22
|
+
#
|
|
23
|
+
# 'kubernetes' is deliberately absent: testutils no longer imports it at module
|
|
24
|
+
# scope, so a consumer running against docker compose does not need it. Install
|
|
25
|
+
# the 'kubernetes' extra if you do run against a cluster.
|
|
26
|
+
dependencies = [
|
|
27
|
+
"aiosmtpd>=1.4.6",
|
|
28
|
+
"cryptography>=47.0.0",
|
|
29
|
+
"docker>=7.1.0",
|
|
30
|
+
"filelock>=3.29.0",
|
|
31
|
+
"msgpack>=1.2.1",
|
|
32
|
+
"pymongo>=4.17.0",
|
|
33
|
+
"pytest>=9.0.3",
|
|
34
|
+
"redo>=3.0.0",
|
|
35
|
+
"requests>=2.34.2",
|
|
36
|
+
"stripe>=15.2.0",
|
|
37
|
+
"urllib3>=2.7.0",
|
|
38
|
+
"websockets>=16.0",
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
# So the PyPI page links back to the source. Without it there is no way to get
|
|
42
|
+
# from a requirements entry to this repo.
|
|
43
|
+
[project.urls]
|
|
44
|
+
Repository = "https://github.com/mendersoftware/mender-testkit"
|
|
45
|
+
|
|
46
|
+
[project.optional-dependencies]
|
|
47
|
+
kubernetes = ["kubernetes>=36.0.2"]
|
|
48
|
+
|
|
49
|
+
[project.entry-points.pytest11]
|
|
50
|
+
mender_testkit = "mender_testkit.plugin"
|
|
51
|
+
|
|
52
|
+
[tool.setuptools.packages.find]
|
|
53
|
+
where = ["src"]
|
|
54
|
+
|
|
55
|
+
# The compose tree is data, not code, and its layout matters: docker-compose.yml
|
|
56
|
+
# binds ./compose/certs and ./compose/config relative to the project directory.
|
|
57
|
+
[tool.setuptools.package-data]
|
|
58
|
+
# The explicit .env entry is not redundant: glob patterns do not match dotfiles,
|
|
59
|
+
# so "data/**/*" silently skips it, and compose then falls back to
|
|
60
|
+
# MENDER_IMAGE_TAG=latest instead of the "main" that .env sets.
|
|
61
|
+
mender_testkit = ["data/**/*", "data/mender_server/.env"]
|
|
62
|
+
|
|
63
|
+
[tool.black]
|
|
64
|
+
extend-exclude = "^/src/mender_testkit/testutils/"
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Copyright 2026 Northern.tech AS
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
"""Shared test infrastructure for the Mender integration test suites."""
|
|
15
|
+
|
|
16
|
+
import os
|
|
17
|
+
|
|
18
|
+
# Traefik's routers match on Host as well as path, and the tests address the
|
|
19
|
+
# ingress by container IP, so every request has to carry this. testutils defaults
|
|
20
|
+
# it to "traefik", the name mender-server's own deployments answer to.
|
|
21
|
+
#
|
|
22
|
+
# Set here rather than in plugin.py because it has to happen before
|
|
23
|
+
# testutils.api.client is imported -- that module reads it into a module-level
|
|
24
|
+
# constant. Importing any submodule of this package runs this file first, whereas
|
|
25
|
+
# plugin.py's own module-level imports already pull testutils in before its body
|
|
26
|
+
# executes.
|
|
27
|
+
os.environ.setdefault("GATEWAY_HOSTNAME", "docker.mender.io")
|
|
28
|
+
|
|
29
|
+
from ._server_ref import MENDER_SERVER_REF # noqa: E402
|
|
30
|
+
|
|
31
|
+
__all__ = ["MENDER_SERVER_REF"]
|