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 a5fadb4
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 26 deletions.
33 changes: 22 additions & 11 deletions uaclient/entitlements/cc.py
Original file line number Diff line number Diff line change
@@ -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"


Expand All @@ -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
)
],
}
30 changes: 20 additions & 10 deletions uaclient/entitlements/fips.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down 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
13 changes: 9 additions & 4 deletions uaclient/entitlements/tests/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit a5fadb4

Please sign in to comment.