Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(integration tests): Utilities for testing ansible-trace #15

Merged

Conversation

louisquentinjoucla
Copy link
Contributor

@louisquentinjoucla louisquentinjoucla commented Jun 12, 2022

Hello everyone 馃憢 !

This is the first step for #10

This proposition allow creating tests using pytest framework where we can chose strategy, inventory for the same playbook file (see tests/integration/tests/basic.py)
I have also made some utilities functions that parse trace to ensure its integrity.
This include also related github action CI.yml (here a sample)

Waiting for your feedback,
Thanks!

feat(action): Change python version in action CI

feat(action): Rename file CI

fix(action): remove useless file
@@ -0,0 +1,11 @@
[all]
127.0.0.1 ansible_connection=local
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty clever, using multiple localhosts. Nice idea

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@@ -0,0 +1,3 @@
import pytest
from fixtures import ansible_play

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this file? Probably missing something but is it empty? Shouldn't there be, like, a test function or something in here? (I'm not very familiar with pytest)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is to import the fixture on every other pytest test file


# Set params for ansible runner
request.config.option.ansible_playbook_directory = "."
request.config.option.ansible_playbook_inventory = "inventory.ini"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we can't do = inventory ? Wouldn't that let us avoid the symlinking and renaming (and the resulting side-effects on the filesystem?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops my bad, forgot to unstash some of my work, will definitely fix that


return (hosts, duration_events, duration_stacks)

def add_duration_event(hosts: Dict[int, HostEvent], events: Dict[int, Any], curr_stacks: Dict[int, Deque], event_hash: Any) -> Tuple[Dict[int, Any], Dict[int, Deque]]:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind wrapping some of these very long lines? Whatever the other python files in the repo are wrapped at

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will

trace_hosts: Dict[int, HostEvent]
trace_events: Dict[int, Any]
trace_json: JSONTYPE = get_last_trace()
trace_hosts, trace_events = parse_trace(trace_json)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This last line feels a little funny; we're assigning variables we aren't using. I had to read the parse_trace to figure out that the bulk of the test is in there: that it's validating the trace as it's parsing. Could we name the function to make clear it's validating too? parse_and_validate_trace or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I will !

@mhansen
Copy link
Owner

mhansen commented Jun 16, 2022

This overall looks really good to me. Thanks so much for writing these tests. I really like how they're integration-level tests that actually run Ansible, and have semantic validations on the output (e.g. timestamps nest).

@louisquentinjoucla louisquentinjoucla marked this pull request as ready for review June 17, 2022 04:09
@louisquentinjoucla
Copy link
Contributor Author

Review taken in account ! Lint pep8, removed the symlinks stuff, and changed sub name.
Waiting for this one to be merge before rebasing other PRs!

Do not hesitate if something is still not good!

Copy link
Owner

@mhansen mhansen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks, and thanks for cleaning up my code too

@mhansen mhansen merged commit b9d7992 into mhansen:main Jun 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants