|
4 | 4 | import json
|
5 | 5 | import logging
|
6 | 6 | import os
|
| 7 | +import sys |
7 | 8 | import time
|
8 | 9 |
|
9 | 10 | from pathlib import Path
|
|
26 | 27 | from .utils import playbook
|
27 | 28 |
|
28 | 29 |
|
| 30 | +logger = logging.getLogger(__name__) |
| 31 | + |
29 | 32 | # Configure logging
|
30 | 33 | logging.basicConfig(
|
31 | 34 | level=logging.DEBUG,
|
32 | 35 | format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", # cspell:ignore levelname
|
33 |
| - handlers=[logging.FileHandler("pytest-network.log"), logging.StreamHandler()], |
| 36 | + handlers=[logging.FileHandler("pytest-network.log"), logging.StreamHandler(sys.stdout)], |
34 | 37 | )
|
35 | 38 |
|
36 |
| -logger = logging.getLogger(__name__) |
37 |
| - |
38 | 39 |
|
39 | 40 | @pytest.fixture(scope="function")
|
40 | 41 | def network_test_vars(request: pytest.FixtureRequest) -> Dict[str, Any]:
|
@@ -104,6 +105,7 @@ def pytest_addoption(parser: pytest.Parser) -> None:
|
104 | 105 | action="store",
|
105 | 106 | help="The comma delimited negative search substring to filter the roles",
|
106 | 107 | )
|
| 108 | + parser.addoption("--wait-extra", action="store", help="Add extra wait time in seconds.") |
107 | 109 |
|
108 | 110 |
|
109 | 111 | OPTIONS = None
|
@@ -357,8 +359,20 @@ def _appliance_dhcp_address(env_vars: Dict[str, str]) -> Generator[str, None, No
|
357 | 359 | port=int(env_vars["cml_ssh_port"]),
|
358 | 360 | )
|
359 | 361 |
|
| 362 | + # Handle the wait_extra_time |
| 363 | + wait_extra_time = OPTIONS.wait_extra |
| 364 | + if wait_extra_time: |
| 365 | + try: |
| 366 | + wait_seconds = int(wait_extra_time) |
| 367 | + except ValueError: |
| 368 | + logger.warning( |
| 369 | + "Invalid wait_extra value: '%s'. Expected an integer. Skipping extra wait.", |
| 370 | + wait_extra_time, |
| 371 | + ) |
| 372 | + wait_seconds = 0 |
| 373 | + |
360 | 374 | try:
|
361 |
| - ip_address = virsh.get_dhcp_lease(lab_id) |
| 375 | + ip_address = virsh.get_dhcp_lease(lab_id, wait_seconds) |
362 | 376 | except PytestNetworkError as exc:
|
363 | 377 | logger.error("Failed to get DHCP lease for the appliance")
|
364 | 378 | virsh.close()
|
|
0 commit comments