|
16 | 16 | from termcolor import colored
|
17 | 17 |
|
18 | 18 | import testcases
|
| 19 | +from docker import DockerRunner |
19 | 20 | from result import TestResult
|
20 | 21 | from testcases import Perspective
|
21 | 22 |
|
@@ -122,46 +123,48 @@ def _check_impl_is_compliant(self, name: str) -> bool:
|
122 | 123 |
|
123 | 124 | # check that the client is capable of returning UNSUPPORTED
|
124 | 125 | logging.debug("Checking compliance of %s client", name)
|
125 |
| - cmd = ( |
126 |
| - "CERTS=./certs" + " " |
127 |
| - "TESTCASE_CLIENT=" + random_string(6) + " " |
128 |
| - "SERVER_LOGS=/dev/null " |
129 |
| - "CLIENT_LOGS=" + client_log_dir.name + " " |
130 |
| - "WWW=" + www_dir.name + " " |
131 |
| - "DOWNLOADS=" + downloads_dir.name + " " |
132 |
| - 'SCENARIO="simple-p2p --delay=15ms --bandwidth=10Mbps --queue=25" ' |
133 |
| - "CLIENT=" + self._implementations[name]["image"] + " " |
134 |
| - "docker-compose up --timeout 0 --abort-on-container-exit -V sim client" |
135 |
| - ) |
136 |
| - output = subprocess.run( |
137 |
| - cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT |
138 |
| - ) |
139 |
| - if not self._is_unsupported(output.stdout.splitlines()): |
| 126 | + env_sim = {"SCENARIO": "simple-p2p --delay=15ms --bandwidth=10Mbps --queue=25"} |
| 127 | + env_client = { |
| 128 | + "CERTS": "./certs", |
| 129 | + "TESTCASE_CLIENT": random_string(6), |
| 130 | + "DOWNLOADS": downloads_dir.name, |
| 131 | + "CLIENT_LOGS": client_log_dir.name, |
| 132 | + "CLIENT": self._implementations[name]["image"], |
| 133 | + } |
| 134 | + env = {} |
| 135 | + env.update(env_sim) |
| 136 | + env.update(env_client) |
| 137 | + r = DockerRunner(15) |
| 138 | + r.add_container("client", env) |
| 139 | + r.add_container("sim", env) |
| 140 | + output, expired = r.run() |
| 141 | + if expired or not self._is_unsupported(output.splitlines()): |
140 | 142 | logging.error("%s client not compliant.", name)
|
141 |
| - logging.debug("%s", output.stdout.decode("utf-8")) |
| 143 | + logging.debug("%s", output) |
142 | 144 | self.compliant[name] = False
|
143 | 145 | return False
|
144 | 146 | logging.debug("%s client compliant.", name)
|
145 | 147 |
|
146 | 148 | # check that the server is capable of returning UNSUPPORTED
|
147 | 149 | logging.debug("Checking compliance of %s server", name)
|
148 | 150 | server_log_dir = tempfile.TemporaryDirectory(dir="/tmp", prefix="logs_server_")
|
149 |
| - cmd = ( |
150 |
| - "CERTS=./certs" + " " |
151 |
| - "TESTCASE_SERVER=" + random_string(6) + " " |
152 |
| - "SERVER_LOGS=" + server_log_dir.name + " " |
153 |
| - "CLIENT_LOGS=/dev/null " |
154 |
| - "WWW=" + www_dir.name + " " |
155 |
| - "DOWNLOADS=" + downloads_dir.name + " " |
156 |
| - "SERVER=" + self._implementations[name]["image"] + " " |
157 |
| - "docker-compose up -V server" |
158 |
| - ) |
159 |
| - output = subprocess.run( |
160 |
| - cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT |
161 |
| - ) |
162 |
| - if not self._is_unsupported(output.stdout.splitlines()): |
| 151 | + env_server = { |
| 152 | + "CERTS": "./certs", |
| 153 | + "TESTCASE_SERVER": random_string(6), |
| 154 | + "SERVER_LOGS": server_log_dir.name, |
| 155 | + "WWW": www_dir.name, |
| 156 | + "SERVER": self._implementations[name]["image"], |
| 157 | + } |
| 158 | + env = {} |
| 159 | + env.update(env_sim) |
| 160 | + env.update(env_server) |
| 161 | + r = DockerRunner(15) |
| 162 | + r.add_container("server", env) |
| 163 | + r.add_container("sim", env) |
| 164 | + output, expired = r.run() |
| 165 | + if expired or not self._is_unsupported(output.splitlines()): |
163 | 166 | logging.error("%s server not compliant.", name)
|
164 |
| - logging.debug("%s", output.stdout.decode("utf-8")) |
| 167 | + logging.debug("%s", output) |
165 | 168 | self.compliant[name] = False
|
166 | 169 | return False
|
167 | 170 | logging.debug("%s server compliant.", name)
|
@@ -330,73 +333,51 @@ def _run_test(
|
330 | 333 | server_keylog_file=server_log_dir.name + "/keys.log",
|
331 | 334 | )
|
332 | 335 | print(
|
333 |
| - "Server: " |
334 |
| - + server |
335 |
| - + ". Client: " |
336 |
| - + client |
337 |
| - + ". Running test case: " |
338 |
| - + str(testcase) |
| 336 | + "Server: {}. Client: {}. Running test: {}".format( |
| 337 | + server, client, str(testcase) |
| 338 | + ) |
339 | 339 | )
|
340 | 340 |
|
341 | 341 | reqs = " ".join(["https://server:443/" + p for p in testcase.get_paths()])
|
342 | 342 | logging.debug("Requests: %s", reqs)
|
343 |
| - params = ( |
344 |
| - "CERTS=./certs" + " " |
345 |
| - "TESTCASE_SERVER=" + testcase.testname(Perspective.SERVER) + " " |
346 |
| - "TESTCASE_CLIENT=" + testcase.testname(Perspective.CLIENT) + " " |
347 |
| - "WWW=" + testcase.www_dir() + " " |
348 |
| - "DOWNLOADS=" + testcase.download_dir() + " " |
349 |
| - "SERVER_LOGS=" + server_log_dir.name + " " |
350 |
| - "CLIENT_LOGS=" + client_log_dir.name + " " |
351 |
| - 'SCENARIO="{}" ' |
352 |
| - "CLIENT=" + self._implementations[client]["image"] + " " |
353 |
| - "SERVER=" + self._implementations[server]["image"] + " " |
354 |
| - 'REQUESTS="' + reqs + '" ' |
355 |
| - ).format(testcase.scenario()) |
356 |
| - params += " ".join(testcase.additional_envs()) |
357 |
| - containers = "sim client server " + " ".join(testcase.additional_containers()) |
358 |
| - cmd = ( |
359 |
| - params |
360 |
| - + " docker-compose up --abort-on-container-exit --timeout 1 " |
361 |
| - + containers |
362 |
| - ) |
363 |
| - logging.debug("Command: %s", cmd) |
| 343 | + r = DockerRunner(timeout=testcase.timeout()) |
| 344 | + env_server = { |
| 345 | + "CERTS": "./certs", |
| 346 | + "TESTCASE_SERVER": testcase.testname(Perspective.SERVER), |
| 347 | + "WWW": testcase.www_dir(), |
| 348 | + "SERVER_LOGS": server_log_dir.name, |
| 349 | + "SERVER": self._implementations[server]["image"], |
| 350 | + } |
| 351 | + env_client = { |
| 352 | + "CERTS": "./certs", |
| 353 | + "TESTCASE_CLIENT": testcase.testname(Perspective.CLIENT), |
| 354 | + "DOWNLOADS": testcase.download_dir(), |
| 355 | + "CLIENT_LOGS": client_log_dir.name, |
| 356 | + "CLIENT": self._implementations[client]["image"], |
| 357 | + "REQUESTS": reqs, |
| 358 | + } |
| 359 | + env_sim = {"SCENARIO": testcase.scenario()} |
| 360 | + env = {} |
| 361 | + env.update(env_server) |
| 362 | + env.update(env_client) |
| 363 | + env.update(env_sim) |
| 364 | + r.add_container(name="server", env=env) |
| 365 | + r.add_container(name="client", env=env) |
| 366 | + r.add_container(name="sim", env=env) |
| 367 | + for c in testcase.additional_containers(): |
| 368 | + r.add_container(name=c, env=testcase.additional_envs()) |
| 369 | + output, expired = r.run() |
364 | 370 |
|
365 | 371 | status = TestResult.FAILED
|
366 |
| - output = "" |
367 |
| - expired = False |
368 |
| - try: |
369 |
| - r = subprocess.run( |
370 |
| - cmd, |
371 |
| - shell=True, |
372 |
| - stdout=subprocess.PIPE, |
373 |
| - stderr=subprocess.STDOUT, |
374 |
| - timeout=testcase.timeout(), |
375 |
| - ) |
376 |
| - output = r.stdout |
377 |
| - except subprocess.TimeoutExpired as ex: |
378 |
| - output = ex.stdout |
379 |
| - expired = True |
380 |
| - |
381 |
| - logging.debug("%s", output.decode("utf-8")) |
382 |
| - |
383 |
| - if expired: |
384 |
| - logging.debug("Test failed: took longer than %ds.", testcase.timeout()) |
385 |
| - r = subprocess.run( |
386 |
| - "docker-compose stop " + containers, |
387 |
| - shell=True, |
388 |
| - stdout=subprocess.PIPE, |
389 |
| - stderr=subprocess.STDOUT, |
390 |
| - timeout=60, |
391 |
| - ) |
392 |
| - logging.debug("%s", r.stdout.decode("utf-8")) |
393 | 372 |
|
394 | 373 | # copy the pcaps from the simulator
|
395 | 374 | self._copy_logs("sim", sim_log_dir)
|
396 | 375 | self._copy_logs("client", client_log_dir)
|
397 | 376 | self._copy_logs("server", server_log_dir)
|
398 | 377 |
|
399 |
| - if not expired: |
| 378 | + if expired: |
| 379 | + logging.debug("Test failed: took longer than %ds.", testcase.timeout()) |
| 380 | + else: |
400 | 381 | lines = output.splitlines()
|
401 | 382 | if self._is_unsupported(lines):
|
402 | 383 | status = TestResult.UNSUPPORTED
|
|
0 commit comments