Skip to content

Commit

Permalink
entitlements: enable USG instead of CIS on Focal
Browse files Browse the repository at this point in the history
As Focal is the only series to ever have both of the services in a valid
state at different times, there is a particular path to enable USG
instead of CIS when users call `pro enable cis`. A specific message is
shown on the CLI to tell users that it changed.

Signed-off-by: Renan Rodrigo <renanrodrigo@canonical.com>
  • Loading branch information
renanrodrigo authored and orndorffgrant committed Oct 23, 2024
1 parent b4caa31 commit 7a187f1
Show file tree
Hide file tree
Showing 9 changed files with 296 additions and 17 deletions.
36 changes: 35 additions & 1 deletion uaclient/api/tests/test_api_u_pro_services_disable_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,83 +15,112 @@
class TestDisable:
@pytest.mark.parametrize(
[
"series",
"options",
"we_are_currently_root",
"is_attached",
"enabled_services_names_before",
"enabled_services_names_after",
"disable_result",
"expected_service",
"expected_raises",
"expected_result",
],
[
# not root
(
"any_series",
DisableOptions(service="s1"),
False,
False,
None,
None,
None,
None,
pytest.raises(exceptions.NonRootUserError),
None,
),
# not attached
(
"any_series",
DisableOptions(service="s1"),
True,
False,
None,
None,
None,
None,
pytest.raises(exceptions.UnattachedError),
None,
),
# generic disable failure
(
"any_series",
DisableOptions(service="s1"),
True,
True,
["s1"],
None,
(False, None),
"s1",
pytest.raises(exceptions.EntitlementNotDisabledError),
None,
),
# success
(
"any_series",
DisableOptions(service="s1"),
True,
True,
["s1"],
[],
(True, None),
"s1",
does_not_raise(),
DisableResult(
disabled=["s1"],
),
),
# cis on focal
(
"focal",
DisableOptions(service="cis"),
True,
True,
["usg"],
[],
(True, None),
"usg",
does_not_raise(),
DisableResult(
disabled=["usg"],
),
),
# success already disabled
(
"any_series",
DisableOptions(service="s1"),
True,
True,
[],
None,
None,
"s1",
does_not_raise(),
DisableResult(
disabled=[],
),
),
# success with additional disablements
(
"any_series",
DisableOptions(service="s1"),
True,
True,
["s1", "s2", "s3"],
["s2"],
(True, None),
"s1",
does_not_raise(),
DisableResult(
disabled=["s1", "s3"],
Expand All @@ -106,25 +135,30 @@ class TestDisable:
@mock.patch(M_PATH + "_enabled_services_names")
@mock.patch(M_PATH + "_is_attached")
@mock.patch(M_PATH + "util.we_are_currently_root")
@mock.patch(M_PATH + "system.get_release_info")
def test_disable(
self,
m_get_release_info,
m_we_are_currently_root,
m_is_attached,
m_enabled_services_names,
m_entitlement_factory,
m_spin_lock,
m_clear_lock_file_if_present,
m_status,
series,
options,
we_are_currently_root,
is_attached,
enabled_services_names_before,
enabled_services_names_after,
disable_result,
expected_service,
expected_raises,
expected_result,
FakeConfig,
):
m_get_release_info.return_value.series = series
m_we_are_currently_root.return_value = we_are_currently_root
m_is_attached.return_value = mock.MagicMock(is_attached=is_attached)
m_enabled_services_names.side_effect = [
Expand All @@ -149,7 +183,7 @@ def test_disable(
assert m_entitlement_factory.call_args_list == [
mock.call(
cfg=cfg,
name=options.service,
name=expected_service,
purge=options.purge,
)
]
Expand Down
Loading

0 comments on commit 7a187f1

Please sign in to comment.