Skip to content

Commit

Permalink
Merge pull request #724 from fractal-analytics-platform/723-command-v…
Browse files Browse the repository at this point in the history
…ersion-should-not-fail-if-fractal-server-is-not-alive

`fractal version` does not fail with server down
  • Loading branch information
ychiucco authored Oct 29, 2024
2 parents 261a7e3 + 9829060 commit 5946515
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* Add `--new-ssh-settings-json` option to `fractal user edit` (\#715).
* Add `--private` option to task-creating commands (\#717).
* Drop `task delete` command (\#717).
* Handle missing server in `fractal version` (\#724).
* Testing:
* Run all tests against a single `fractal-server` instance (\#717).
* Run tests in random module order, based on `pytest-randomly` (\#717).
Expand Down
15 changes: 10 additions & 5 deletions fractal_client/cmd/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from httpx import Client
from httpx import ConnectError

from ..authclient import AuthClient
from ..config import settings
Expand Down Expand Up @@ -298,16 +299,20 @@ def job(


def version(client: Client, **kwargs) -> Interface:
res = client.get(f"{settings.FRACTAL_SERVER}/api/alive/")
data = res.json()
try:
res = client.get(f"{settings.FRACTAL_SERVER}/api/alive/")
data = res.json()
server_str = (
f"\turl: {settings.FRACTAL_SERVER}\tversion: {data['version']}"
)
except ConnectError:
server_str = f"\tConnection to '{settings.FRACTAL_SERVER}' refused"

return Interface(
retcode=0,
data=(
f"Fractal client\n\tversion: {__VERSION__}\n"
"Fractal server:\n"
f"\turl: {settings.FRACTAL_SERVER}"
f"\tversion: {data['version']}"
f"Fractal server:\n{server_str}"
),
)

Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures_testserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def testserver(tester, tmpdir_factory, request):
while True:
try:
res = handle(shlex.split("fractal version"))
if res.retcode == 0:
if "refused" not in res.data:
break
else:
raise ConnectError("fractal-server not ready")
Expand Down
14 changes: 14 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from fractal_client import __VERSION__
from fractal_client.client import handle
from fractal_client.config import Settings


def test_debug(invoke):
Expand All @@ -21,6 +22,19 @@ def test_version(invoke):
assert iface.retcode == 0


def test_version_connect_error(invoke, monkeypatch):

mock_settings = Settings()
mock_settings.FRACTAL_SERVER = "http://localhost:9999"
monkeypatch.setattr("fractal_client.cmd.settings", mock_settings)

iface = invoke("version")
debug(iface.data)
assert f"version: {__VERSION__}" in iface.data
assert "refused" in iface.data
assert iface.retcode == 0


def test_server():
"""
GIVEN a testserver
Expand Down

0 comments on commit 5946515

Please sign in to comment.