Skip to content

Commit

Permalink
Use custom exception for Ursula having a version that is too old.
Browse files Browse the repository at this point in the history
  • Loading branch information
derekpierre committed Aug 8, 2024
1 parent 1c22001 commit bd537c6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
19 changes: 10 additions & 9 deletions porter/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ class DecryptOutcome(NamedTuple):
]
errors: Dict[ChecksumAddress, str]

class UrsulaVersionTooOld(Exception):
def __init__(self, ursula_address: str, version: str, min_version: str):
super().__init__(
f"Ursula ({ursula_address}) version is too old ({version} < {min_version})"
)

def __init__(
self,
eth_endpoint: str,
Expand Down Expand Up @@ -197,14 +203,12 @@ def get_ursula_info(ursula_address) -> Porter.UrsulaInfo:
ursula_address = to_checksum_address(ursula_address)
ursula = self.known_nodes[ursula_address]
try:
# ensure node is up and reachable and check version
# ensure node is up and reachable and possibly check version
version = self._get_ursula_version(ursula)
if parse_min_version and not self._is_version_greater_or_equal(
parse_min_version, version
):
raise ValueError(
f"Ursula ({ursula_address}) has too old version ({version})"
)
raise self.UrsulaVersionTooOld(ursula_address, version, min_version)

return Porter.UrsulaInfo(
checksum_address=ursula_address,
Expand Down Expand Up @@ -447,15 +451,12 @@ def make_sure_ursula_is_online(ursula_address) -> ChecksumAddress:
ursula_address = to_checksum_address(ursula_address)
ursula = self.known_nodes[ursula_address]
try:
# ensure node is up and reachable
# self.network_middleware.ping(ursula)
# ensure node is up and reachable and possibly check version
version = self._get_ursula_version(ursula)
if parse_min_version and not self._is_version_greater_or_equal(
parse_min_version, version
):
raise ValueError(
f"Ursula ({ursula_address}) has too old version ({version})"
)
raise self.UrsulaVersionTooOld(ursula_address, version, min_version)

return ursula_address
except Exception as e:
Expand Down
10 changes: 8 additions & 2 deletions tests/test_bucket_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,10 @@ def test_bucket_sampling_web_interface(
response = porter_web_controller.get(
"/bucket_sampling", data=json.dumps(failed_ursula_params)
)
assert "has too old version (1.1.1)" in response.text
assert (
f"version is too old (1.1.1 < {failed_ursula_params['min_version']})"
in response.text
)

porter.network_middleware.set_ursulas_versions({sampled_ursulas[0]: "3.0.0"})
response = porter_web_controller.get(
Expand All @@ -373,5 +376,8 @@ def test_bucket_sampling_web_interface(
response = porter_web_controller.get(
"/bucket_sampling", data=json.dumps(failed_ursula_params)
)
assert "has too old version (1.1.1)" in response.text
assert (
f"version is too old (1.1.1 < {failed_ursula_params['min_version']})"
in response.text
)
porter.network_middleware.clean_ursulas_versions()
10 changes: 8 additions & 2 deletions tests/test_get_ursulas.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,10 @@ def test_get_ursulas_web_interface(
response = porter_web_controller.get(
"/get_ursulas", data=json.dumps(failed_ursula_params)
)
assert "has too old version (1.1.1)" in response.text
assert (
f"version is too old (1.1.1 < {failed_ursula_params['min_version']})"
in response.text
)

porter.network_middleware.set_ursulas_versions({include_ursulas[0]: "3.0.0"})
response = porter_web_controller.get(
Expand All @@ -455,5 +458,8 @@ def test_get_ursulas_web_interface(
response = porter_web_controller.get(
"/get_ursulas", data=json.dumps(failed_ursula_params)
)
assert "has too old version (1.1.1)" in response.text
assert (
f"version is too old (1.1.1 < {failed_ursula_params['min_version']})"
in response.text
)
porter.network_middleware.clean_ursulas_versions()

0 comments on commit bd537c6

Please sign in to comment.