Skip to content

Commit

Permalink
Remove python 3.6 incompatible pattern matching
Browse files Browse the repository at this point in the history
  • Loading branch information
m-czernek committed Feb 18, 2025
1 parent 1eb2278 commit 650cfee
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,18 @@ def parse_shared_buffers_to_mem_ratio(self, memory: int):
return

shared_buffers = int(shared_buffers)
match buffer_unit.lower():
case "kb":
... # conversion done
case "mb":
shared_buffers *= 1024
case "gb":
shared_buffers *= 1024 * 1024
case _:
print(f"Error when parsing shared buffer unit: {buffer_unit}")
return

buffer_unit = buffer_unit.lower()
if buffer_unit == "kb":
... # conversion done
elif buffer_unit == "mb":
shared_buffers *= 1024
elif buffer_unit == "gb":
shared_buffers *= 1024 * 1024
else:
print(f"Error when parsing shared buffer unit: {buffer_unit}")
return

self.shared_buffers_to_mem_ratio = round(shared_buffers / memory, 2)

def parse_prefork_c_params(self):
Expand Down Expand Up @@ -229,19 +231,19 @@ def _check_vol_params(self, mount: str, min_size_gb: int, fs: Dict) -> Dict:
else:
size, unit = float(size[:-1]), size[-1:]

match unit.lower():
case "k":
size /= 1024 * 1024
case "m":
size /= 1024
case "g":
... # already in GB
case "t":
size *= 1024
case "n/a":
... # no unit
case _:
print(f"Error when parsing shared buffer unit: {unit}")
unit = unit.lower()
if unit == "k":
size /= 1024 * 1024
elif unit == "m":
size /= 1024
elif unit == "g":
... # already in GB
elif unit == "t":
size *= 1024
elif unit == "n/a":
... # no unit
else:
print(f"Error when parsing shared buffer unit: {unit}")

res["too_small"] = 1 if min_size_gb > size else 0
return res
Expand Down
13 changes: 6 additions & 7 deletions python/health-check/src/health_check/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,12 @@ def _handle_text_from_process(verbose: bool, *objs: str):


def _check_retcode(retcode: int):
match retcode:
case 0:
... # success
case 127:
raise OSError("Command not found; podman is required")
case _:
raise HealthException("An error happened while running Podman")
if retcode == 0:
... # success
elif retcode == 127:
raise OSError("Command not found; podman is required")
else:
raise HealthException("An error happened while running Podman")


class HealthException(Exception):
Expand Down

0 comments on commit 650cfee

Please sign in to comment.