diff --git a/uaclient/entitlements/cc.py b/uaclient/entitlements/cc.py index 961f3a2718..de7a30a59c 100644 --- a/uaclient/entitlements/cc.py +++ b/uaclient/entitlements/cc.py @@ -1,5 +1,11 @@ from uaclient.entitlements import repo +try: + from typing import Callable, Dict, List, Tuple, Union # noqa +except ImportError: + # typing isn't available on trusty, so ignore its absence + pass + CC_README = "/usr/share/doc/ubuntu-commoncriteria/README" @@ -11,14 +17,19 @@ class CommonCriteriaEntitlement(repo.RepoEntitlement): description = "Common Criteria EAL2 Provisioning Packages" repo_key_file = "ubuntu-cc-keyring.gpg" packages = ["ubuntu-commoncriteria"] - messaging = { - "pre_install": [ - "(This will download more than 500MB of packages, so may take some" - " time.)" - ], - "post_enable": [ - "Please follow instructions in {} to configure EAL2".format( - CC_README - ) - ], - } + + @property + def messaging( + self + ) -> "Dict[str, List[Union[str, Tuple[Callable, Dict]]]]": + return { + "pre_install": [ + "(This will download more than 500MB of packages, so may take" + " some time.)" + ], + "post_enable": [ + "Please follow instructions in {} to configure EAL2".format( + CC_README + ) + ], + } diff --git a/uaclient/entitlements/fips.py b/uaclient/entitlements/fips.py index 5e51f03295..f3ed3bab48 100644 --- a/uaclient/entitlements/fips.py +++ b/uaclient/entitlements/fips.py @@ -2,7 +2,7 @@ from uaclient import apt, status, util try: - from typing import Dict, List, Set, Tuple # noqa + from typing import Callable, Dict, List, Set, Tuple, Union # noqa except ImportError: # typing isn't available on trusty, so ignore its absence pass @@ -60,25 +60,24 @@ class FIPSEntitlement(FIPSCommonEntitlement): name = "fips" title = "FIPS" description = "NIST-certified FIPS modules" - messaging = { - "post_enable": ["A reboot is required to complete the install"] - } origin = "UbuntuFIPS" static_affordances = ( ("Cannot install FIPS on a container", util.is_container, False), ) + @property + def messaging( + self + ) -> "Dict[str, List[Union[str, Tuple[Callable, Dict]]]]": + return { + "post_enable": ["A reboot is required to complete the install"] + } + class FIPSUpdatesEntitlement(FIPSCommonEntitlement): name = "fips-updates" title = "FIPS Updates" - messaging = { - "post_enable": [ - "FIPS Updates configured and pending, please reboot to make" - " active." - ] - } origin = "UbuntuFIPSUpdates" description = "Uncertified security updates to FIPS modules" static_affordances = ( @@ -88,3 +87,14 @@ class FIPSUpdatesEntitlement(FIPSCommonEntitlement): False, ), ) + + @property + def messaging( + self + ) -> "Dict[str, List[Union[str, Tuple[Callable, Dict]]]]": + return { + "post_enable": [ + "FIPS Updates configured and pending, please reboot to make" + " active." + ] + } diff --git a/uaclient/entitlements/repo.py b/uaclient/entitlements/repo.py index 94334efa85..6cdca1a420 100644 --- a/uaclient/entitlements/repo.py +++ b/uaclient/entitlements/repo.py @@ -49,7 +49,11 @@ def disable_apt_auth_only(self) -> bool: # Any custom messages to emit to the console or callables which are # handled at pre_enable, pre_disable, pre_install or post_enable stages - messaging = {} # type: Dict[str, List[Union[str, Tuple[Callable, Dict]]]] + @property + def messaging( + self + ) -> "Dict[str, List[Union[str, Tuple[Callable, Dict]]]]": + return {} @property def packages(self) -> "List[str]": diff --git a/uaclient/entitlements/tests/test_repo.py b/uaclient/entitlements/tests/test_repo.py index 623ec1fb95..a84ef3cb60 100644 --- a/uaclient/entitlements/tests/test_repo.py +++ b/uaclient/entitlements/tests/test_repo.py @@ -344,8 +344,11 @@ def test_enable_can_exit_on_pre_enable_messaging_hooks( entitlement, capsys, ): - messaging = {"pre_enable": pre_enable_msg} - with mock.patch.object(type(entitlement), "messaging", messaging): + with mock.patch( + M_PATH + "RepoEntitlement.messaging", + new_callable=mock.PropertyMock, + ) as m_messaging: + m_messaging.return_value = {"pre_enable": pre_enable_msg} with mock.patch.object(type(entitlement), "packages", []): entitlement.enable() stdout, _ = capsys.readouterr() @@ -411,8 +414,10 @@ def test_enable_calls_adds_apt_repo_and_calls_apt_update( pre_install_msgs = ["Some pre-install information", "Some more info"] if with_pre_install_msg: - messaging_patch = mock.patch.object( - entitlement, "messaging", {"pre_install": pre_install_msgs} + messaging_patch = mock.patch( + M_PATH + "RepoEntitlement.messaging", + new_callable=mock.PropertyMock, + return_value={"pre_install": pre_install_msgs}, ) else: messaging_patch = mock.MagicMock()