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

Add launcher cli arg to check_config (New) #757

Merged
merged 4 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions checkbox-ng/checkbox_ng/launcher/check_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class CheckConfig:
"""Implementation of the `check-config` sub-command."""

@staticmethod
def invoked(_):
def invoked(context):
"""Function that's run with `check-config` invocation."""
config = load_configs()
config = load_configs(context.args.launcher)
print("Configuration files:")
for source in config.sources:
print(" - {}".format(source))
Expand All @@ -50,4 +50,6 @@ def invoked(_):
return 1

def register_arguments(self, parser):
"""Register extra args for this subcmd. No extra args ATM."""
parser.add_argument(
"launcher", nargs="?", help="launcher definition file to use"
)
16 changes: 14 additions & 2 deletions checkbox-ng/checkbox_ng/launcher/test_check_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# along with Checkbox. If not, see <http://www.gnu.org/licenses/>.

from unittest import TestCase, mock
from unittest.mock import MagicMock

from checkbox_ng.launcher.check_config import CheckConfig
from plainbox.impl.config import Configuration
Expand All @@ -26,10 +27,12 @@ class CheckConfigTests(TestCase):
@mock.patch("builtins.print")
@mock.patch("checkbox_ng.launcher.check_config.load_configs")
def test_invoked_ok(self, mock_load_configs, mock_print):
args_mock = MagicMock()
args_mock.args.launcher = None
# this is the default configuration
mock_load_configs.return_value = Configuration()

ret_val = CheckConfig.invoked(...)
ret_val = CheckConfig.invoked(args_mock)

mock_print.assert_any_call("Configuration files:")
mock_print.assert_any_call("No problems with config(s) found!")
Expand All @@ -38,14 +41,23 @@ def test_invoked_ok(self, mock_load_configs, mock_print):
@mock.patch("builtins.print")
@mock.patch("checkbox_ng.launcher.check_config.load_configs")
def test_invoked_has_problems(self, mock_load_configs, mock_print):
args_mock = MagicMock()
args_mock.args.launcher = None
# this is the default configuration
conf = Configuration()
conf.notice_problem("Test problem")
mock_load_configs.return_value = conf

ret_val = CheckConfig.invoked(...)
ret_val = CheckConfig.invoked(args_mock)

mock_print.assert_any_call("Configuration files:")
mock_print.assert_any_call("Problems:")
mock_print.assert_any_call("- ", "Test problem")
self.assertEqual(ret_val, 1)

def test_register_arguments(self):
self_mock = MagicMock()
parser_mock = MagicMock()
CheckConfig.register_arguments(self_mock, parser_mock)

self.assertTrue(parser_mock.add_argument.called)
41 changes: 39 additions & 2 deletions docs/tutorial/using-checkbox/launcher.rst
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ and where it comes from. Run the following command:

.. code-block:: none

$ checkbox.checkbox-cli check-config
Configuration files:
$ checkbox.checkbox-cli check-config
Configuration files:
- /var/snap/checkbox/2799/checkbox.conf
- /home/user/.config/checkbox.conf
[config]
Expand Down Expand Up @@ -286,6 +286,43 @@ environment variable is set to ``120`` because it is specified in
a Checkbox configuration that comes with the snap version I'm using
(``/var/snap/checkbox/2799/checkbox.conf``).

If you want to debug a Checkbox run that involves a ``launcher``, fear not.
The ``check-config`` command works with launchers as well. Try the previous
command with the ``launcher`` we created before:

.. code-block:: none
:emphasize-lines: 8,14,17-18,21,28

$ checkbox.checkbox-cli check-config mylauncher
Configuration files:
- /var/snap/checkbox/2799/checkbox.conf
- /home/user/.config/checkbox.conf
[config]
config_filename=checkbox.conf (Default)
[launcher]
app_id=com.canonical.certification:tutorial From config file: /home/user/mylauncher
app_version= (Default)
launcher_version=1 From config file: /home/user/.config/checkbox.conf
local_submission=True (Default)
session_desc= (Default)
session_title=session title (Default)
stock_reports=text, submission_files From config file: /home/user/mylauncher
[test plan]
filter=* (Default)
forced=True From config file: /home/user/mylauncher
unit=com.canonical.certification::tutorial-base From config file: /home/user/mylauncher
[test selection]
exclude= (Default)
forced=True From config file: /home/user/mylauncher
(...)
[environment]
STRESS_S3_WAIT_DELAY=120 From config file: /var/snap/checkbox/2799/checkbox.conf
(...)
TUTO=tutorial From config file: /home/user/.config/checkbox.conf
(...)
TUTORIAL=Value from my launcher! From config file: /home/user/mylauncher
No problems with config(s) found!

Create an executable launcher
=============================

Expand Down
Loading