Skip to content

Commit

Permalink
Fix up treatment of possibly inconsistent values
Browse files Browse the repository at this point in the history
Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed May 3, 2022
1 parent 2999cf8 commit 7fdf76f
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions src/stratis_cli/_actions/_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,31 +469,41 @@ def list_stopped_pools(namespace):

stopped_pools = _fetch_stopped_pools_property(proxy)

def na_string(value):
def maybe_inconsistent(value):
"""
Get a cell value or N/A if None.
Take a value that represents possibly inconsistency via option type.
:param value: some value
:type value: str or NoneType
:param value: a tuple, second item is the value
:type value: bool * object
:rtype: str
"""
return "N/A" if value is None else value
(real, value) = value
return str(value) if real else "inconsistent"

def interp_clevis(value):
""" """
(real, value) = value
return "present" if real else "inconsistent"

def clevis_string(clevis_info):
def na_string(value, interp_option):
"""
Get a cell value for the Clevis info.
Get a cell value or N/A if None.
:param clevis_info: clevis info
:type clevis_info: str(JSON) or NoneType
:param value: some value
:type value: str or NoneType
:param interp_option: function to interpret optional value
:type interp_option: object -> str
:rtype: str
"""
return "No" if clevis_info is None else "Yes"
return "N/A" if value is None else interp_option(value)

if namespace.uuid is None:
tables = [
(
pool_uuid,
str(len(info["devs"])),
na_string(info.get("key_description")),
clevis_string(info.get("clevis_info")),
na_string(info.get("key_description"), maybe_inconsistent),
na_string(info.get("clevis_info"), interp_clevis),
)
for (pool_uuid, info) in stopped_pools.items()
]
Expand All @@ -518,11 +528,11 @@ def clevis_string(clevis_info):
print("UUID: %s", this_uuid)
print(
"Kernel Key Description: %s",
na_string(stopped_pool.get("key_description")),
na_string(stopped_pool.get("key_description"), maybe_inconsistent),
)
print(
"Clevis Configuration: %",
na_string(stopped_pool.get("clevis_info")),
na_string(stopped_pool.get("clevis_info"), maybe_inconsistent),
)

print("Devices:")
Expand Down

0 comments on commit 7fdf76f

Please sign in to comment.