Skip to content

Commit 691caee

Browse files
committed
Add tracing setup and teardown
Signed-off-by: Colin James <contificate@gmail.com>
1 parent c7a0a1c commit 691caee

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

conftest.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ def pytest_addoption(parser: pytest.Parser) -> None:
103103
help="Format of VDI to execute tests on."
104104
"Example: vhd,qcow2"
105105
)
106+
parser.addoption(
107+
"--tracing-endpoint",
108+
action="store",
109+
default=None,
110+
help="Specify distributed tracing endpoint."
111+
)
106112

107113
def pytest_configure(config: pytest.Config) -> None:
108114
global_config.ignore_ssh_banner = config.getoption('--ignore-ssh-banner')
@@ -173,6 +179,19 @@ def pytest_runtest_makereport(
173179

174180
# END make test results visible from fixtures
175181

182+
def setup_tracing(host: Host, endpoint: str):
183+
logging.info(f'Enabling tracing on {host}, endpoint = {endpoint}')
184+
host.ssh('printf "observer-endpoint-http-enabled=true\nobserver-experimental-components=\\"\\"\n" > /etc/xapi.conf.d/observer.conf')
185+
host.restart_toolstack(verify=True)
186+
observer_uuid = host.xe('observer-create', {'name-label': 'xcpng-test', 'endpoints': endpoint, 'enabled': 'true'})
187+
host.restart_toolstack(verify=True)
188+
return observer_uuid
189+
190+
def teardown_tracing(host, observer):
191+
logging.info(f'Disabling tracing on {host}')
192+
host.xe('observer-destroy', {'uuid': observer})
193+
host.ssh('rm -f /etc/xapi.conf.d/observer.conf')
194+
host.restart_toolstack(verify=True)
176195

177196
# fixtures
178197

@@ -240,8 +259,20 @@ def cleanup_hosts() -> None:
240259

241260
if not host_list:
242261
pytest.fail("This test requires at least one --hosts parameter")
262+
263+
tracing_endpoint = pytestconfig.getoption("--tracing-endpoint")
264+
has_tracing = tracing_endpoint is not None
265+
observers = []
266+
if has_tracing:
267+
for h in host_list:
268+
observers.append(setup_tracing(h, tracing_endpoint))
269+
243270
yield host_list
244271

272+
if has_tracing:
273+
for h, o in zip(host_list, observers):
274+
teardown_tracing(h, o)
275+
245276
cleanup_hosts()
246277

247278
@pytest.fixture(scope='session')

0 commit comments

Comments
 (0)