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

Separate CIS and USG in the client #3344

Merged
merged 9 commits into from
Oct 23, 2024
2 changes: 1 addition & 1 deletion lib/convert_list_to_deb822.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
setup_cli_logging(logging.DEBUG, defaults.CONFIG_DEFAULTS["log_file"])
cfg = UAConfig()

for entitlement_class in entitlements.ENTITLEMENT_CLASSES:
for entitlement_class in entitlements.get_entitlement_classes():
if not issubclass(
entitlement_class, entitlements.repo.RepoEntitlement
):
Expand Down
2 changes: 1 addition & 1 deletion uaclient/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def _get_state_files(cfg: config.UAConfig):
CLOUD_BUILD_INFO,
*(
entitlement_cls(cfg).repo_file
for entitlement_cls in entitlements.ENTITLEMENT_CLASSES
for entitlement_cls in entitlements.get_entitlement_classes()
if issubclass(entitlement_cls, entitlements.repo.RepoEntitlement)
),
]
Expand Down
50 changes: 26 additions & 24 deletions uaclient/api/tests/test_api_u_pro_services_dependencies_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@


class TestServicesDependenciesV1:
def test_dependencies(self):
@mock.patch("uaclient.system.get_release_info")
def test_dependencies(self, m_release_info):
m_release_info.return_value.series = "noble"
assert _dependencies(cfg=mock.MagicMock()) == DependenciesResult(
services=[
ServiceWithDependencies(
Expand All @@ -20,9 +22,6 @@ def test_dependencies(self):
ServiceWithDependencies(
name="cc-eal", incompatible_with=[], depends_on=[]
),
ServiceWithDependencies(
name="cis", incompatible_with=[], depends_on=[]
),
ServiceWithDependencies(
name="esm-apps", incompatible_with=[], depends_on=[]
),
Expand Down Expand Up @@ -56,26 +55,6 @@ def test_dependencies(self):
],
depends_on=[],
),
ServiceWithDependencies(
name="fips-updates",
incompatible_with=[
ServiceWithReason(
name="fips",
reason=Reason(
code=messages.FIPS_INVALIDATES_FIPS_UPDATES.name, # noqa: E501
title=messages.FIPS_INVALIDATES_FIPS_UPDATES.msg, # noqa: E501
),
),
ServiceWithReason(
name="realtime-kernel",
reason=Reason(
code=messages.REALTIME_FIPS_UPDATES_INCOMPATIBLE.name, # noqa: E501
title=messages.REALTIME_FIPS_UPDATES_INCOMPATIBLE.msg, # noqa: E501
),
),
],
depends_on=[],
),
ServiceWithDependencies(
name="fips-preview",
incompatible_with=[
Expand Down Expand Up @@ -110,6 +89,26 @@ def test_dependencies(self):
],
depends_on=[],
),
ServiceWithDependencies(
name="fips-updates",
incompatible_with=[
ServiceWithReason(
name="fips",
reason=Reason(
code=messages.FIPS_INVALIDATES_FIPS_UPDATES.name, # noqa: E501
title=messages.FIPS_INVALIDATES_FIPS_UPDATES.msg, # noqa: E501
),
),
ServiceWithReason(
name="realtime-kernel",
reason=Reason(
code=messages.REALTIME_FIPS_UPDATES_INCOMPATIBLE.name, # noqa: E501
title=messages.REALTIME_FIPS_UPDATES_INCOMPATIBLE.msg, # noqa: E501
),
),
],
depends_on=[],
),
ServiceWithDependencies(
name="landscape", incompatible_with=[], depends_on=[]
),
Expand Down Expand Up @@ -207,5 +206,8 @@ def test_dependencies(self):
),
],
),
ServiceWithDependencies(
name="usg", incompatible_with=[], depends_on=[]
),
]
)
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