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

Add error handling for "no host found in environment" #414

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions examples/errorsnohost/.batou.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"migration": {
"version": 2400
}
}
1 change: 1 addition & 0 deletions examples/errorsnohost/appenv
1 change: 1 addition & 0 deletions examples/errorsnohost/batou
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[environment]
connect_method = local
17 changes: 17 additions & 0 deletions examples/errorsnohost/requirements.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# appenv-requirements-hash: a12a4aceadd6cbfbc0c654d8540fe14587d0fee8084431a7fe37a5ca9cea5260
-e ../../
ConfigUpdater==3.1.1
Jinja2==3.0.1
MarkupSafe==2.0.1
PyYAML==6.0.1
certifi==2022.6.15
charset-normalizer==2.0.12
execnet==1.9.0
idna==3.3
importlib-metadata==4.8.3
py==1.11.0
remote-pdb==2.1.0
requests==2.27.1
typing_extensions==4.1.1
urllib3==1.26.11
zipp==3.6.0
2 changes: 2 additions & 0 deletions examples/errorsnohost/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# appenv-python-preference: 3.6,3.7,3.8,3.9
-e ../../
13 changes: 10 additions & 3 deletions src/batou/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
import traceback
from concurrent.futures import ThreadPoolExecutor

from batou import ReportingException, SilentConfigurationError
from batou import (
ConfigurationError,
ReportingException,
SilentConfigurationError,
)
from batou._output import TerminalBackend, output

from .environment import Environment
Expand Down Expand Up @@ -98,7 +102,6 @@ def __str__(self):


class Deployment(object):

_upstream = None

def __init__(
Expand All @@ -111,7 +114,6 @@ def __init__(
predict_only=False,
provision_rebuild=False,
):

self.environment = Environment(
environment, timeout, platform, provision_rebuild=provision_rebuild
)
Expand Down Expand Up @@ -205,6 +207,11 @@ def connect(self):
all_reporting_hostnames.add(reporting_hostname)
all_errors.extend([(reporting_hostname, e) for e in errors])
# collects all errors into (reporting_hostname, error) tuples
# if there are no connections, then we append a ConfigurationError
if not self.connections:
raise ConfigurationError.from_context(
"No host found in environment."
)
# if there are no errors, we're done
if not all_errors:
return
Expand Down
36 changes: 36 additions & 0 deletions src/batou/tests/test_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,39 @@ def test_main_with_errors(capsys):
======================= DEPLOYMENT FAILED (during load) ========================
"""
) # noqa: E501 line too long


def test_main_fails_if_no_host_in_environment(capsys):
os.chdir("examples/errorsnohost")

from batou.deploy import main

with pytest.raises(SystemExit) as r:
main(
environment="errorsnohost",
platform=None,
timeout=None,
dirty=False,
consistency_only=False,
predict_only=False,
jobs=None,
provision_rebuild=False,
)

assert r.value.code == 1

out, err = capsys.readouterr()
assert err == ""
assert out == Ellipsis(
"""\
batou/2... (cpython 3...)
================================== Preparing ===================================
main: Loading environment `errorsnohost`...
main: Verifying repository ...
main: Loading secrets ...
================== Connecting hosts and configuring model ... ==================

ERROR: No host found in environment.
====================== DEPLOYMENT FAILED (during connect) ======================
"""
) # noqa: E501 line too long
Loading