-
Notifications
You must be signed in to change notification settings - Fork 25
List enabled and available features #404
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
47d047c
List enabled and available features
74c001d
Use custom stdout callback to display features
a5468c3
Make callback obsah independent and add fallback logic
a8d918d
Add custom tag to skip the default callback
c4f9d5d
List enabled features only when passed --list-enabled
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| from ansible.plugins.callback.default import CallbackModule as DefaultCallbackModule | ||
|
|
||
| DOCUMENTATION = """ | ||
| name: foremanctl | ||
| type: stdout | ||
| short_description: foremanctl stdout callback | ||
| description: | ||
| - Suppresses default Ansible output for plays tagged with | ||
| foremanctl_suppress_default_output, displaying only task msg rather than ansible default output. | ||
| extends_documentation_fragment: | ||
| - default_callback | ||
| - result_format_callback | ||
| requirements: | ||
| - set as stdout in configuration | ||
| """ | ||
|
|
||
| class CallbackModule(DefaultCallbackModule): | ||
| """Foremanctl callback.""" | ||
|
|
||
| CALLBACK_VERSION = 2.0 | ||
| CALLBACK_TYPE = 'stdout' | ||
| CALLBACK_NAME = 'foremanctl' | ||
|
|
||
| FALLBACK_TO_DEFAULT = True | ||
|
|
||
| def v2_playbook_on_start(self, playbook): | ||
| plays = playbook.get_plays() | ||
| tags = plays[0].tags | ||
| if 'foremanctl_suppress_default_output' in tags: | ||
| self.FALLBACK_TO_DEFAULT = False | ||
| if self.FALLBACK_TO_DEFAULT: | ||
| super().v2_playbook_on_start(playbook) | ||
|
|
||
| def v2_playbook_on_play_start(self, play): | ||
| if self.FALLBACK_TO_DEFAULT: | ||
| super().v2_playbook_on_play_start(play) | ||
|
|
||
| def v2_playbook_on_task_start(self, task, is_conditional): | ||
| if self.FALLBACK_TO_DEFAULT: | ||
| super().v2_playbook_on_task_start(task, is_conditional) | ||
|
|
||
| def v2_runner_on_ok(self, result): | ||
| if self.FALLBACK_TO_DEFAULT: | ||
| super().v2_runner_on_ok(result) | ||
| else: | ||
| if msg := result._result.get('msg'): | ||
| self._display.display(msg) | ||
|
|
||
| def v2_playbook_on_stats(self, stats): | ||
| if self.FALLBACK_TO_DEFAULT: | ||
| super().v2_playbook_on_stats(stats) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| --- | ||
| - name: List features | ||
| hosts: quadlet | ||
|
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. In theory this shouldn't need to be locked to quadlet, but we can leave it for now as that's a bigger question we need to answer across multiple playbooks. |
||
| gather_facts: false | ||
| tags: | ||
| - foremanctl_suppress_default_output | ||
| vars: | ||
| list_enabled: false | ||
| vars_files: | ||
| - "../../vars/defaults.yml" | ||
| - "../../vars/flavors/{{ flavor }}.yml" | ||
| - "../../vars/base.yaml" | ||
| tasks: | ||
| - name: Print features | ||
| ansible.builtin.debug: | ||
| msg: "{{ enabled_features | list_all_features(list_enabled) }}" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| help: List all enabled and available features | ||
|
|
||
| variables: | ||
| list_enabled: | ||
| parameter: --list-enabled | ||
| help: List only enabled features | ||
| action: store_true | ||
| persist: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import subprocess | ||
|
|
||
| def test_foremanctl_features(): | ||
| command = ['./foremanctl', 'features'] | ||
| result = subprocess.run(command, capture_output=True, text=True) | ||
|
|
||
| assert result.returncode == 0 | ||
|
|
||
| for noise in ['PLAY [', 'TASK [', 'ok:', 'changed:', 'PLAY RECAP']: | ||
| assert noise not in result.stdout, f"Ansible output not suppressed: found '{noise}'" | ||
|
|
||
| for feature in ['foreman', 'foreman-proxy', 'azure-rm']: | ||
| assert feature in result.stdout, f"Expected feature '{feature}' in output" | ||
|
|
||
| def test_foremanctl_features_list_enabled(): | ||
| command = ['./foremanctl', 'features', '--list-enabled'] | ||
| result = subprocess.run(command, capture_output=True, text=True) | ||
|
|
||
| assert result.returncode == 0 | ||
|
|
||
| assert 'enabled' in result.stdout | ||
| assert 'available' not in result.stdout |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.