Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fractal version does not fail with server down #724

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}" f"\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
13 changes: 13 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ def test_version(invoke):
assert iface.retcode == 0


def test_version_connect_error(invoke, monkeypatch):
monkeypatch.setattr(
"fractal_client.cmd.__init__.settings.FRACTAL_SERVER",
"http://localhost:9999",
)

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