Skip to content

Commit

Permalink
repo: make messaging an instance property so it can use instance vars
Browse files Browse the repository at this point in the history
  • Loading branch information
blackboxsw committed Apr 20, 2020
1 parent 714417c commit 215aaa7
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 24 deletions.
27 changes: 16 additions & 11 deletions uaclient/entitlements/cc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,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
)
],
}
28 changes: 19 additions & 9 deletions uaclient/entitlements/fips.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -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."
]
}
6 changes: 5 additions & 1 deletion uaclient/entitlements/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]":
Expand Down
12 changes: 9 additions & 3 deletions uaclient/entitlements/tests/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,11 @@ def test_enable_can_exit_on_pre_enable_messaging_hooks(
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()
Expand Down Expand Up @@ -411,8 +415,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()
Expand Down

0 comments on commit 215aaa7

Please sign in to comment.