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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow manually defining user & hostname in callback plugin #496

Merged
merged 1 commit into from Sep 3, 2023

Conversation

phemmer
Copy link
Contributor

@phemmer phemmer commented Jun 29, 2023

In some environments (e.g. containers), the user and hostname detected from the OS might not be relevant or useful. This change allows the user to pass in customized values for these attributes which override the automatic detection.

Note: I didn't see any tests for things like the the the controller name or user name, or any other playbook level attributes, so I didn't add any here.

Closes #493

In some environments (e.g. containers), the user and hostname detected from the OS might not be relevant or useful. This change allows the user to pass in customized values for these attributes which override the automatic detection.
@softwarefactory-project-zuul
Copy link

Build succeeded.
https://ansible.softwarefactory-project.io/zuul/buildset/d60769922b404a358b089733e5be8842

✔️ ara-tox-py3 SUCCESS in 4m 30s
✔️ ara-tox-linters SUCCESS in 5m 07s
✔️ ara-basic-ansible-core-devel SUCCESS in 5m 34s (non-voting)
✔️ ara-basic-ansible-8 SUCCESS in 6m 49s
✔️ ara-basic-ansible-core-2.15 SUCCESS in 5m 34s
✔️ ara-basic-ansible-core-2.14 SUCCESS in 6m 25s
✔️ ara-basic-ansible-2.9 SUCCESS in 5m 52s
✔️ ara-container-images SUCCESS in 12m 22s

@dmsimard
Copy link
Contributor

Thanks for the PR!

In some environments (e.g. containers), the user and hostname detected from the OS might not be relevant or useful. This change allows the user to pass in customized values for these attributes which override the automatic detection.

Looks good to me, though I had a question in-line.

Note: I didn't see any tests for things like the the the controller name or user name, or any other playbook level attributes, so I didn't add any here.

There's unit tests for playbook properties but it's more about the API than the callback plugin since a lot of it is mocked: https://github.com/ansible-community/ara/blob/master/ara/api/tests/tests_playbook.py

For testing playbook properties as recorded by the callback we have integration tests written as Ansible playbooks like here:

- name: Retrieve the current playbook so we can get the ID
ara_playbook:
register: playbook_query
- name: Save the playbook id so we can re-use it easily
set_fact:
playbook_id: "{{ playbook_query.playbook.id | string }}"
- name: Recover data from ARA
set_fact:
playbook: "{{ lookup('ara_api', '/api/v1/playbooks/' + playbook_id) }}"
tasks: "{{ lookup('ara_api', '/api/v1/tasks?playbook=' + playbook_id) }}"
results: "{{ lookup('ara_api', '/api/v1/results?playbook=' + playbook_id) }}"
hosts: "{{ lookup('ara_api', '/api/v1/hosts?playbook=' + playbook_id) }}"
- name: Print versions we're testing with
debug:
msg: >-
Integration test playbook running under ansible-core {{ ansible_version.full }},
ara {{ playbook.client_version }} (client) and {{ playbook.server_version }} (server)
- name: Assert playbook properties
assert:
that:
- playbook.name == 'ARA self tests'
- "playbook.labels | selectattr('name', 'search', 'lookup-tests') | list | length == 1"
- playbook.ansible_version == ansible_version.full
- playbook_dir in playbook.path
- "'tests/integration/lookups.yaml' in playbook.path"

That particular playbook is one of the test playbooks launched when running tox -e ansible-integration.

Adding coverage is always nice but not a hard requirement since we can take care of it in a follow up PR before release.

@dmsimard dmsimard added this to the 1.7.0 milestone Aug 29, 2023
@dmsimard
Copy link
Contributor

dmsimard commented Sep 3, 2023

Hi @phemmer and sorry it's taken so long.

There is nothing wrong with the code and I've tested it locally successfully:
Screenshot from 2023-09-03 15-15-21

I will merge this as-is and follow up with a patch for integration testing it.

@dmsimard dmsimard merged commit 3a180df into ansible-community:master Sep 3, 2023
1 check passed
@dmsimard
Copy link
Contributor

dmsimard commented Sep 3, 2023

This will be released as part of ara 1.7.0 sometime in the near future.

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.

Allow specifying username to record
2 participants