-
Notifications
You must be signed in to change notification settings - Fork 10
Add basic tracing functionality to tests #525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -116,6 +116,12 @@ def pytest_addoption(parser: pytest.Parser) -> None: | |
| default="2GiB", | ||
| help="Maximum amount of data written to a volume" | ||
| ) | ||
| parser.addoption( | ||
| "--tracing-endpoint", | ||
| action="store", | ||
| default=None, | ||
| help="Specify distributed tracing endpoint." | ||
| ) | ||
|
|
||
| def pytest_configure(config: pytest.Config) -> None: | ||
| global_config.ignore_ssh_banner = config.getoption('--ignore-ssh-banner') | ||
|
|
@@ -192,6 +198,19 @@ def pytest_runtest_makereport( | |
|
|
||
| # END make test results visible from fixtures | ||
|
|
||
| def setup_tracing(host: Host, endpoint: str): | ||
| logging.info(f'Enabling tracing on {host}, endpoint = {endpoint}') | ||
| host.ssh('printf "observer-endpoint-http-enabled=true\nobserver-experimental-components=\\"\\"\n" > /etc/xapi.conf.d/observer.conf') | ||
| host.restart_toolstack(verify=True) | ||
| observer_uuid = host.xe('observer-create', {'name-label': 'xcpng-test', 'endpoints': endpoint, 'enabled': 'true'}) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we don't provide the host's uuid in |
||
| host.restart_toolstack(verify=True) | ||
| return observer_uuid | ||
|
|
||
| def teardown_tracing(host, observer): | ||
| logging.info(f'Disabling tracing on {host}') | ||
| host.xe('observer-destroy', {'uuid': observer}) | ||
| host.ssh('rm -f /etc/xapi.conf.d/observer.conf') | ||
| host.restart_toolstack(verify=True) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think these could be added as methods of the Host object. |
||
|
|
||
| # fixtures | ||
|
|
||
|
|
@@ -259,8 +278,20 @@ def cleanup_hosts() -> None: | |
|
|
||
| if not host_list: | ||
| pytest.fail("This test requires at least one --hosts parameter") | ||
|
|
||
| tracing_endpoint = pytestconfig.getoption("--tracing-endpoint") | ||
| has_tracing = tracing_endpoint is not None | ||
| observers = [] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's just one observer per host, right? So rather than maintaining a list of observers, I think each host should have its optional observer as an attribute, and maybe the setup and teardown parts should be handled directly in setup_host and cleanup_hosts.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can have several observers per host with different endpoint for example.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can, but that's not what's in the current implementation, and I suppose that if/when we need more than one observer per host we can have a list or dict of observers attached to the host. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From my understanding of the relationship between observers and hosts, it's the other way around: observers contain an optional list of hosts uuids. If this list is empty then the observer is pool-wide, we provide hosts uuids if we need to filter which hosts in the pool are affected by this observer (most importantly it dictates which ones are not). |
||
| if has_tracing: | ||
| for h in host_list: | ||
| observers.append(setup_tracing(h, tracing_endpoint)) | ||
|
|
||
| yield host_list | ||
|
|
||
| if has_tracing: | ||
| for h, o in zip(host_list, observers): | ||
| teardown_tracing(h, o) | ||
|
|
||
| cleanup_hosts() | ||
|
|
||
| @pytest.fixture(scope='session') | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add examples of endpoints here for users?