Skip to content

Commit

Permalink
Turn old-style format strings into f-strings
Browse files Browse the repository at this point in the history
Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed Jun 1, 2022
1 parent d3534ec commit aa88741
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 57 deletions.
88 changes: 42 additions & 46 deletions src/stratis_cli/_actions/_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,7 @@ def stop_pool(namespace):

if not stopped: # pragma: no cover
raise StratisCliIncoherenceError(
"Expected to stop pool with name %s but it was already stopped."
% pool_name
f"Expected to stop pool with name {pool_name} but it was already stopped."
)

@staticmethod
Expand Down Expand Up @@ -516,50 +515,49 @@ def alert_string(mopool):

encrypted = mopool.Encrypted()

print("UUID: %s" % format_uuid(this_uuid))
print("Name: %s" % mopool.Name())
print(f"UUID: {format_uuid(this_uuid)}")
print(f"Name: {mopool.Name()}")
print(
"Actions Allowed: %s"
% PoolActionAvailability.from_str(mopool.AvailableActions())
f"Actions Allowed: "
f"{PoolActionAvailability.from_str(mopool.AvailableActions())}"
)
print("Cache: %s" % ("Yes" if mopool.HasCache() else "No"))
print("Filesystem Limit: %s" % mopool.FsLimit())
print(f"Cache: {'Yes' if mopool.HasCache() else 'No'}")
print(f"Filesystem Limit: {mopool.FsLimit()}")
print(
"Allows Overprovisioning: %s"
% ("Yes" if mopool.Overprovisioning() else "No")
f"Allows Overprovisioning: "
f"{'Yes' if mopool.Overprovisioning() else 'No'}"
)
print(
"Key Description: %s"
% (
_interp_inconsistent_option(mopool.KeyDescription())
if encrypted
else "unencrypted"
)

key_description_str = (
_interp_inconsistent_option(mopool.KeyDescription())
if encrypted
else "unencrypted"
)
print(
"Clevis Configuration: %s"
% (
_interp_inconsistent_option(mopool.ClevisInfo())
if encrypted
else "unencrypted"
)
print(f"Key Description: {key_description_str}")

clevis_info_str = (
_interp_inconsistent_option(mopool.ClevisInfo())
if encrypted
else "unencrypted"
)
print(f"Clevis Configuration: {clevis_info_str}")

total_physical_used = get_property(mopool.TotalPhysicalUsed(), Range, None)

print("Space Usage:")
print("Fully Allocated: %s" % ("Yes" if mopool.NoAllocSpace() else "No"))
print(" Size: %s" % Range(mopool.TotalPhysicalSize()))
print(" Allocated: %s" % Range(mopool.AllocatedSize()))
print(
" Used: %s"
% (
TABLE_FAILURE_STRING
if total_physical_used is None
else total_physical_used
)
print(f"Fully Allocated: {'Yes' if mopool.NoAllocSpace() else 'No'}")
print(f" Size: {Range(mopool.TotalPhysicalSize())}")
print(f" Allocated: {Range(mopool.AllocatedSize())}")

total_physical_used = get_property(mopool.TotalPhysicalUsed(), Range, None)
total_physical_used_str = (
TABLE_FAILURE_STRING
if total_physical_used is None
else total_physical_used
)

print(f" Used: {total_physical_used_str}")

@staticmethod
def _list_stopped_pools(namespace, *, pool_uuid=None):
"""
Expand Down Expand Up @@ -627,23 +625,21 @@ def unencrypted_string(value, interp):
if stopped_pool is None:
raise StratisCliResourceNotFoundError("list", this_uuid)

print("UUID: %s" % format_uuid(this_uuid))
print(
"Key Description: %s"
% unencrypted_string(
stopped_pool.get("key_description"), _interp_inconsistent_option
),
print(f"UUID: {format_uuid(this_uuid)}")

key_description_str = unencrypted_string(
stopped_pool.get("key_description"), _interp_inconsistent_option
)
print(
"Clevis Configuration: %s"
% unencrypted_string(
stopped_pool.get("clevis_info"), _interp_inconsistent_option
),
print(f"Key Description: {key_description_str}")

clevis_info_str = unencrypted_string(
stopped_pool.get("clevis_info"), _interp_inconsistent_option
)
print(f"Clevis Configuration: {clevis_info_str}")

print("Devices:")
for dev in stopped_pool["devs"]:
print("%s %s" % (format_uuid(dev["uuid"]), dev["devnode"]))
print(f"{format_uuid(dev['uuid'])} {dev['devnode']}")

@staticmethod
def destroy_pool(namespace):
Expand Down
10 changes: 3 additions & 7 deletions tests/whitebox/_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@ def setUpClass(cls):
try:
if psutil.Process(pid).name() == "stratisd":
raise RuntimeError(
"Evidently a stratisd process with process id %u is running"
% pid
f"Evidently a stratisd process with process id {pid} is running"
)
except psutil.NoSuchProcess:
pass
Expand Down Expand Up @@ -325,14 +324,11 @@ def stop_pool(pool_name):
)

if not return_code == _OK:
raise RuntimeError(
"Pool with name %s was not stopped: %s" % (pool_name, message)
)
raise RuntimeError(f"Pool with name {pool_name} was not stopped: {message}")

if not stopped:
raise RuntimeError(
"Pool with name %s was supposed to have been started but was not"
% pool_name
f"Pool with name {pool_name} was supposed to have been started but was not"
)

return UUID(pool_uuid)
8 changes: 4 additions & 4 deletions tests/whitebox/integration/pool/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def test_list_bogus_uuid(self):
"""
Test listing a bogus stopped pool.
"""
command_line = self._MENU + ["--uuid=%s" % uuid4()]
command_line = self._MENU + [f"--uuid={uuid4()}"]
self.check_error(DbusClientUniqueResultError, command_line, _ERROR)

def test_list_with_uuid(self):
Expand All @@ -131,7 +131,7 @@ def test_list_with_uuid(self):
proxy = get_object(TOP_OBJECT)

mopool = MOPool(get_pool(proxy, self._POOLNAME)[1])
command_line = self._MENU + ["--uuid=%s" % mopool.Uuid()]
command_line = self._MENU + [f"--uuid={mopool.Uuid()}"]
TEST_RUNNER(command_line)


Expand Down Expand Up @@ -172,14 +172,14 @@ def test_list_specific(self):

pool_uuid = stop_pool(self._POOLNAME)

command_line = self._MENU + ["--uuid=%s" % pool_uuid]
command_line = self._MENU + [f"--uuid={pool_uuid}"]
TEST_RUNNER(command_line)

def test_list_bogus(self):
"""
Test listing a bogus stopped pool.
"""
command_line = self._MENU + ["--uuid=%s" % uuid4()]
command_line = self._MENU + [f"--uuid={uuid4()}"]
self.check_error(StratisCliResourceNotFoundError, command_line, _ERROR)


Expand Down

0 comments on commit aa88741

Please sign in to comment.