|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +import pytest |
| 4 | + |
| 5 | +import enum |
| 6 | +import functools |
3 | 7 | import logging |
| 8 | +import shlex |
4 | 9 | import time |
5 | 10 |
|
6 | 11 | import lib.commands as commands |
|
26 | 31 | from lib.host import Host |
27 | 32 | from lib.pool import Pool |
28 | 33 |
|
| 34 | +QUICKTEST_BIN = "/opt/xensource/debug/quicktest" |
| 35 | + |
| 36 | +QUICKTEST_SR_SUITES = ( |
| 37 | + "cbt,copy,SR tests,Quicktest_vdi,Quicktest_async_calls," |
| 38 | + "Quicktest_vm_import_export,Quicktest_vm_lifecycle,Quicktest_vm_snapshot," |
| 39 | + "Quicktest_vdi_ops_data_integrity,Quicktest_max_vdi_size,Quicktest_static_vdis" |
| 40 | +) |
| 41 | + |
| 42 | +QUICKTEST_COMMON_SUITES = ( |
| 43 | + "Quicktest_example,Quicktest_message,xenstore,event,import_raw_vdi," |
| 44 | + "Quicktest_date,Quicktest_crypt_r,http,unixext,Timer" |
| 45 | +) |
| 46 | + |
| 47 | +class QuicktestScoping(enum.Enum): |
| 48 | + NO_PARAM = enum.auto() |
| 49 | + RUN_ONLY_PARAM = enum.auto() |
| 50 | + SR_ONLY_PARAM = enum.auto() |
| 51 | + |
| 52 | +@functools.lru_cache(maxsize=None) |
| 53 | +def _quicktest_scoping(hostname_or_ip: str) -> QuicktestScoping: |
| 54 | + help_output = commands.ssh(hostname_or_ip, f"{QUICKTEST_BIN} --help", check=False) |
| 55 | + if "-sr-only" in help_output: |
| 56 | + return QuicktestScoping.SR_ONLY_PARAM |
| 57 | + if "-run-only" in help_output: |
| 58 | + return QuicktestScoping.RUN_ONLY_PARAM |
| 59 | + return QuicktestScoping.NO_PARAM |
| 60 | + |
29 | 61 | class SR: |
30 | 62 | xe_prefix = 'sr' |
31 | 63 |
|
@@ -230,14 +262,29 @@ def create_vdi( |
230 | 262 | vdi_uuid = self.pool.master.xe('vdi-create', args) |
231 | 263 | return VDI(vdi_uuid, sr=self) |
232 | 264 |
|
233 | | - def run_quicktest(self) -> None: |
234 | | - logging.info(f"Run quicktest on SR {self.uuid}") |
| 265 | + def run_quicktest(self, sr_specific: bool = True) -> None: |
| 266 | + scoping = _quicktest_scoping(self.pool.master.hostname_or_ip) |
| 267 | + cmd = f"{QUICKTEST_BIN} -sr {self.uuid}" |
| 268 | + |
| 269 | + if scoping is QuicktestScoping.SR_ONLY_PARAM: |
| 270 | + cmd += " -sr-only" if sr_specific else " -common-only" |
| 271 | + elif scoping is QuicktestScoping.RUN_ONLY_PARAM: |
| 272 | + suites = QUICKTEST_SR_SUITES if sr_specific else QUICKTEST_COMMON_SUITES |
| 273 | + cmd += f" -run-only {shlex.quote(suites)}" |
| 274 | + elif not sr_specific: |
| 275 | + # QuicktestScoping.NO_PARAM: no way to select just the common suites, and every |
| 276 | + # per-SR pass on this host is already unfiltered, so this run adds nothing. |
| 277 | + pytest.skip("quicktest has no scoping support on this host; " |
| 278 | + "common suites are already covered by the per-SR runs.") |
| 279 | + |
| 280 | + logging.info(f"Run quicktest on SR {self.uuid}: {cmd}") |
| 281 | + |
235 | 282 | # Always display the output of quicktest, failed or not. |
236 | 283 | # This will duplicate the output in some cases, but it ensures we always have it for failure analysis, |
237 | 284 | # even when quicktest leaves SRs in a state which makes teardown fail (in this case, pytest often doesn't |
238 | 285 | # manage to display the details of the failed command, for a reason unknown - no usable reproducer found) |
239 | 286 | try: |
240 | | - output = self.pool.master.ssh(f'/opt/xensource/debug/quicktest -sr {self.uuid}') |
| 287 | + output = self.pool.master.ssh(cmd) |
241 | 288 | logging.info(f"Quicktest output: {output}") |
242 | 289 | except commands.SSHCommandFailed as e: |
243 | 290 | logging.error(f"Quicktest output: {e.stdout}") |
|
0 commit comments