-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cli: refactor system to the new approach
Signed-off-by: Renan Rodrigo <[email protected]>
- Loading branch information
1 parent
fec8fec
commit 2ce58cb
Showing
4 changed files
with
84 additions
and
87 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from uaclient import event_logger, messages | ||
from uaclient.api.u.pro.security.status.reboot_required.v1 import ( | ||
_reboot_required, | ||
) | ||
from uaclient.cli.commands import ProCommand | ||
|
||
event = event_logger.get_event_logger() | ||
|
||
|
||
def action_reboot_required(args, *, cfg, **kwargs): | ||
result = _reboot_required(cfg) | ||
event.info(result.reboot_required) | ||
return 0 | ||
|
||
|
||
def action_system(args, *, cfg, **kwargs): | ||
# Avoiding a circular import | ||
from uaclient.cli import get_parser | ||
|
||
get_parser(cfg).parse_args(["system", "--help"]) | ||
|
||
|
||
reboot_required_subcommand = ProCommand( | ||
"reboot-required", | ||
help=messages.CLI_SYSTEM_REBOOT_REQUIRED, | ||
description=messages.CLI_SYSTEM_REBOOT_REQUIRED_DESC, | ||
action=action_reboot_required, | ||
preserve_description=True, | ||
) | ||
|
||
system_command = ProCommand( | ||
"system", | ||
help=messages.CLI_ROOT_SYSTEM, | ||
description=messages.CLI_SYSTEM_DESC, | ||
action=action_system, | ||
subcommands=[reboot_required_subcommand], | ||
) |
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 |
---|---|---|
@@ -1,38 +1,18 @@ | ||
import mock | ||
import pytest | ||
|
||
from uaclient.cli import main | ||
from uaclient.cli.system import reboot_required_subcommand | ||
|
||
HELP_OUTPUT = """\ | ||
usage: pro system reboot-required [flags] | ||
Report the current reboot-required status for the machine. | ||
This command will output one of the three following states | ||
for the machine regarding reboot: | ||
* no: The machine doesn't require a reboot | ||
* yes: The machine requires a reboot | ||
* yes-kernel-livepatches-applied: There are only kernel related | ||
packages that require a reboot, but Livepatch has already provided | ||
patches for the current running kernel. The machine still needs a | ||
reboot, but you can assess if the reboot can be performed in the | ||
nearest maintenance window. | ||
""" | ||
M_PATH = "uaclient.cli.system." | ||
|
||
|
||
class TestActionRebootRequired: | ||
@mock.patch("uaclient.log.setup_cli_logging") | ||
def test_enable_help(self, _m_setup_logging, capsys, FakeConfig): | ||
with pytest.raises(SystemExit): | ||
with mock.patch( | ||
"sys.argv", | ||
["/usr/bin/ua", "system", "reboot-required", "--help"], | ||
): | ||
with mock.patch( | ||
"uaclient.config.UAConfig", | ||
return_value=FakeConfig(), | ||
): | ||
main() | ||
out, _err = capsys.readouterr() | ||
assert HELP_OUTPUT in out | ||
@mock.patch(M_PATH + "_reboot_required") | ||
def test_returns_the_api_response(self, m_api_reboot_required, event): | ||
m_cfg = mock.MagicMock() | ||
with mock.patch.object(event, "info") as m_event_info: | ||
reboot_required_subcommand.action(mock.MagicMock(), cfg=m_cfg) | ||
|
||
assert [mock.call(m_cfg)] == m_api_reboot_required.call_args_list | ||
assert [ | ||
mock.call(m_api_reboot_required.return_value.reboot_required) | ||
] == m_event_info.call_args_list |