-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unify command-line options and configuration
This makes it possible to add command-line options to the configuration file. The config file is loaded then the command-line options are merged in. The first one option set takes precedence. So if an option, say output_type, is in the configuration file then passing output-type on the command-line will not override it. The workaround is to pass --config= to ipa-healthcheck in order to not load the configuration file. This will allow for greater flexibility when running this automatically without having to manually change test timer scripting directly. https://bugzilla.redhat.com/show_bug.cgi?id=1872467 Signed-off-by: Rob Crittenden <[email protected]>
- Loading branch information
Showing
8 changed files
with
81 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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,45 @@ | ||
# | ||
# Copyright (C) 2022 FreeIPA Contributors see COPYING for license | ||
# | ||
|
||
import argparse | ||
import os | ||
import tempfile | ||
from unittest.mock import patch | ||
|
||
from ipahealthcheck.core.core import RunChecks | ||
from ipahealthcheck.core.plugin import Results | ||
|
||
options = argparse.Namespace(check=None, source=None, debug=False, | ||
indent=2, list_sources=False, | ||
output_type='json', output_file=None, | ||
verbose=False, version=False, config=None) | ||
|
||
|
||
@patch('ipahealthcheck.core.core.run_service_plugins') | ||
@patch('ipahealthcheck.core.core.run_plugins') | ||
@patch('ipahealthcheck.core.core.parse_options') | ||
def test_options_merge(mock_parse, mock_run, mock_service): | ||
""" | ||
Test merging file-based and CLI options | ||
""" | ||
mock_service.return_value = (Results(), []) | ||
mock_run.return_value = Results() | ||
mock_parse.return_value = options | ||
fd, config_path = tempfile.mkstemp() | ||
os.close(fd) | ||
with open(config_path, "w") as fd: | ||
fd.write('[default]\n') | ||
fd.write('output_type=human\n') | ||
fd.write('indent=5\n') | ||
|
||
try: | ||
run = RunChecks(['ipahealthcheck.registry'], config_path) | ||
|
||
run.run_healthcheck() | ||
|
||
# verify two valus that have defaults with our overriden values | ||
assert run.options.output_type == 'human' | ||
assert run.options.indent == '5' | ||
finally: | ||
os.remove(config_path) |