batou 2.5.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- batou/__init__.py +985 -0
- batou/_output.py +47 -0
- batou/agent.py +0 -0
- batou/c.py +3 -0
- batou/component.py +1246 -0
- batou/conftest.py +33 -0
- batou/deploy.py +424 -0
- batou/environment.py +686 -0
- batou/fixtures.py +58 -0
- batou/host.py +374 -0
- batou/init-template/.hgignore +6 -0
- batou/init-template/components/example/component.py +7 -0
- batou/init-template/environments/dev.cfg +5 -0
- batou/insecure-private.key +7 -0
- batou/lib/__init__.py +1 -0
- batou/lib/appenv.py +126 -0
- batou/lib/archive.py +217 -0
- batou/lib/buildout.py +106 -0
- batou/lib/cmmi.py +88 -0
- batou/lib/cron.py +96 -0
- batou/lib/debian.py +52 -0
- batou/lib/download.py +83 -0
- batou/lib/file.py +759 -0
- batou/lib/git.py +200 -0
- batou/lib/goceptnet.py +25 -0
- batou/lib/logrotate.py +52 -0
- batou/lib/mercurial.py +145 -0
- batou/lib/mysql.py +148 -0
- batou/lib/nagios.py +104 -0
- batou/lib/package.py +25 -0
- batou/lib/python.py +252 -0
- batou/lib/resources/check_supervisor.py.in +77 -0
- batou/lib/resources/crontab +10 -0
- batou/lib/resources/init.sh +31 -0
- batou/lib/resources/logrotate.in +19 -0
- batou/lib/resources/nagios.cfg +30 -0
- batou/lib/resources/nrpe.cfg +4 -0
- batou/lib/resources/supervisor.buildout.cfg +24 -0
- batou/lib/resources/supervisor.conf +27 -0
- batou/lib/service.py +29 -0
- batou/lib/supervisor.py +329 -0
- batou/lib/svn.py +40 -0
- batou/lib/tests/__init__.py +0 -0
- batou/lib/tests/test_appenv.py +96 -0
- batou/lib/tests/test_archive.py +140 -0
- batou/lib/tests/test_buildout.py +93 -0
- batou/lib/tests/test_cmmi.py +131 -0
- batou/lib/tests/test_cron.py +62 -0
- batou/lib/tests/test_debian.py +29 -0
- batou/lib/tests/test_download.py +67 -0
- batou/lib/tests/test_file.py +1166 -0
- batou/lib/tests/test_git.py +348 -0
- batou/lib/tests/test_mercurial.py +207 -0
- batou/lib/tests/test_mysql.py +5 -0
- batou/lib/tests/test_nagios.py +39 -0
- batou/lib/tests/test_python.py +57 -0
- batou/lib/tests/test_service.py +56 -0
- batou/lib/tests/test_supervisor.py +104 -0
- batou/lib/tests/test_svn.py +24 -0
- batou/main.py +239 -0
- batou/migrate/__init__.py +121 -0
- batou/migrate/migrations/2300.py +15 -0
- batou/migrate/migrations/2301.py +60 -0
- batou/migrate/migrations/2302.py +30 -0
- batou/migrate/migrations/2303.py +29 -0
- batou/migrate/migrations/2400.py +40 -0
- batou/migrate/migrations/__init__.py +0 -0
- batou/migrate/tests/__init__.py +0 -0
- batou/migrate/tests/test_migrate.py +176 -0
- batou/provision.py +483 -0
- batou/remote_core.py +418 -0
- batou/repository.py +435 -0
- batou/resources.py +204 -0
- batou/secrets/__init__.py +645 -0
- batou/secrets/edit.py +141 -0
- batou/secrets/encryption.py +577 -0
- batou/secrets/manage.py +96 -0
- batou/secrets/tests/__init__.py +1 -0
- batou/secrets/tests/test_editor.py +188 -0
- batou/secrets/tests/test_manage.py +157 -0
- batou/secrets/tests/test_secrets.py +182 -0
- batou/template.py +82 -0
- batou/tests/__init__.py +0 -0
- batou/tests/conftest.py +23 -0
- batou/tests/ellipsis.py +104 -0
- batou/tests/fixture/basic_service/.batou.json +1 -0
- batou/tests/fixture/basic_service/components/zeo/component.py +8 -0
- batou/tests/fixture/basic_service/components/zope/component.py +5 -0
- batou/tests/fixture/basic_service/environments/dev/environment.cfg +6 -0
- batou/tests/fixture/basic_service/environments/production/environment.cfg +9 -0
- batou/tests/fixture/component/haproxy.cfg +2 -0
- batou/tests/fixture/sample_service/.batou.json +1 -0
- batou/tests/fixture/sample_service/components/hello/component.py +84 -0
- batou/tests/fixture/sample_service/environments/test-multiple-components/environment.cfg +10 -0
- batou/tests/fixture/sample_service/environments/test-multiple-hosts/environment.cfg +6 -0
- batou/tests/fixture/sample_service/environments/test-overlapping-components/environment.cfg +7 -0
- batou/tests/fixture/sample_service/environments/test-resolver/environment.cfg +7 -0
- batou/tests/fixture/sample_service/environments/test-resolver-invalid/environment.cfg +8 -0
- batou/tests/fixture/sample_service/environments/test-resources-host/environment.cfg +3 -0
- batou/tests/fixture/sample_service/environments/test-unused/environment.cfg +5 -0
- batou/tests/fixture/sample_service/environments/test-with-env-config/environment.cfg +12 -0
- batou/tests/fixture/sample_service/environments/test-with-overrides/environment.cfg +8 -0
- batou/tests/fixture/sample_service/environments/test-with-provide-require/environment.cfg +5 -0
- batou/tests/fixture/sample_service/environments/test-with-vfs-sandbox/environment.cfg +5 -0
- batou/tests/fixture/sample_service/environments/test-without-env-config/environment.cfg +2 -0
- batou/tests/fixture/service_early_resource/.batou.json +1 -0
- batou/tests/fixture/service_early_resource/components/zeo/component.py +10 -0
- batou/tests/fixture/service_early_resource/components/zope/component.py +6 -0
- batou/tests/fixture/service_early_resource/environments/dev/environment.cfg +5 -0
- batou/tests/fixture/template/haproxy.cfg +3 -0
- batou/tests/fixture/template/haproxy.cfg.jinja2 +4 -0
- batou/tests/test_bootstrap.py +0 -0
- batou/tests/test_component.py +727 -0
- batou/tests/test_config.py +150 -0
- batou/tests/test_dependencies.py +185 -0
- batou/tests/test_deploy.py +104 -0
- batou/tests/test_endtoend.py +374 -0
- batou/tests/test_environment.py +344 -0
- batou/tests/test_exceptions.py +83 -0
- batou/tests/test_host.py +21 -0
- batou/tests/test_main.py +47 -0
- batou/tests/test_remote.py +49 -0
- batou/tests/test_remote_core.py +323 -0
- batou/tests/test_repository.py +148 -0
- batou/tests/test_resources.py +40 -0
- batou/tests/test_template.py +91 -0
- batou/tests/test_utils.py +530 -0
- batou/tests/test_vfs.py +41 -0
- batou/utils.py +661 -0
- batou/version.txt +1 -0
- batou/vfs.py +34 -0
- batou-2.5.2.dist-info/LICENSE.txt +27 -0
- batou-2.5.2.dist-info/METADATA +131 -0
- batou-2.5.2.dist-info/RECORD +137 -0
- batou-2.5.2.dist-info/WHEEL +5 -0
- batou-2.5.2.dist-info/entry_points.txt +9 -0
- batou-2.5.2.dist-info/top_level.txt +1 -0
batou/__init__.py
ADDED
|
@@ -0,0 +1,985 @@
|
|
|
1
|
+
# This code must not cause non-stdlib imports to support self-bootstrapping.
|
|
2
|
+
import os
|
|
3
|
+
import os.path
|
|
4
|
+
import socket
|
|
5
|
+
import traceback
|
|
6
|
+
from typing import List, Optional
|
|
7
|
+
|
|
8
|
+
import jinja2
|
|
9
|
+
|
|
10
|
+
from ._output import output
|
|
11
|
+
|
|
12
|
+
with open(os.path.dirname(__file__) + "/version.txt") as f:
|
|
13
|
+
__version__ = f.read().strip()
|
|
14
|
+
|
|
15
|
+
# Configure `remote-pdb` to be used with `breakpoint()` in Python 3.7+:
|
|
16
|
+
os.environ["PYTHONBREAKPOINT"] = "remote_pdb.set_trace"
|
|
17
|
+
if not os.environ.get("REMOTE_PDB_HOST", None):
|
|
18
|
+
os.environ["REMOTE_PDB_HOST"] = "127.0.0.1"
|
|
19
|
+
if not os.environ.get("REMOTE_PDB_PORT", None):
|
|
20
|
+
os.environ["REMOTE_PDB_PORT"] = "4444"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def prepare_error(error):
|
|
24
|
+
return f"{error.__class__.__name__}: {error}"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def prepare_traceback(tb):
|
|
28
|
+
from batou import component, environment
|
|
29
|
+
|
|
30
|
+
stack = traceback.extract_tb(tb)
|
|
31
|
+
while stack:
|
|
32
|
+
# Delete remoting-internal stack frames.'
|
|
33
|
+
line = stack.pop(0)
|
|
34
|
+
if line[0] in [
|
|
35
|
+
"<string>",
|
|
36
|
+
"<remote exec>",
|
|
37
|
+
environment.__file__.rstrip("c"),
|
|
38
|
+
component.__file__.rstrip("c"),
|
|
39
|
+
]:
|
|
40
|
+
continue
|
|
41
|
+
stack.insert(0, line)
|
|
42
|
+
break
|
|
43
|
+
if not stack:
|
|
44
|
+
return "<no-non-remote-internal-traceback-lines-found>"
|
|
45
|
+
return "".join(traceback.format_list(stack))
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class ReportingException(Exception):
|
|
49
|
+
"""Exceptions that support user-readable reporting."""
|
|
50
|
+
|
|
51
|
+
affected_hostname: Optional[str]
|
|
52
|
+
|
|
53
|
+
def __str__(self):
|
|
54
|
+
raise NotImplementedError()
|
|
55
|
+
|
|
56
|
+
def report(self):
|
|
57
|
+
raise NotImplementedError()
|
|
58
|
+
|
|
59
|
+
def should_merge(self, other):
|
|
60
|
+
"""
|
|
61
|
+
checks, wether two exceptions have the same type as well as data
|
|
62
|
+
and as such, should be merged into one exception.
|
|
63
|
+
"""
|
|
64
|
+
# generic check:
|
|
65
|
+
# the other class should have: the same class as self, in both directions
|
|
66
|
+
if type(other) != type(self):
|
|
67
|
+
return False
|
|
68
|
+
# now both should have the same attributes
|
|
69
|
+
# compare by all attributes except: .affected_hostname
|
|
70
|
+
dict_self = self.__dict__.copy()
|
|
71
|
+
dict_self.pop("affected_hostname", None)
|
|
72
|
+
dict_other = other.__dict__.copy()
|
|
73
|
+
dict_other.pop("affected_hostname", None)
|
|
74
|
+
return dict_self == dict_other
|
|
75
|
+
|
|
76
|
+
@classmethod
|
|
77
|
+
def merge(cls, selfs):
|
|
78
|
+
"""Merge multiple instances of this exception."""
|
|
79
|
+
# remove and collect .affected_hostname from all exceptions
|
|
80
|
+
if hasattr(selfs[0], "affected_hostname"):
|
|
81
|
+
hostnames = set()
|
|
82
|
+
for self in selfs:
|
|
83
|
+
hostnames.add(self.affected_hostname)
|
|
84
|
+
else:
|
|
85
|
+
hostnames = None
|
|
86
|
+
# create a new exception with the merged attributes
|
|
87
|
+
first_self_dict = selfs[0].__dict__.copy()
|
|
88
|
+
first_self_dict.pop("affected_hostname", None)
|
|
89
|
+
new_exception = cls()
|
|
90
|
+
new_exception.__dict__.update(first_self_dict)
|
|
91
|
+
new_exception.affected_hostname = "<HOSTNAME>"
|
|
92
|
+
return (new_exception, hostnames)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
class FileLockedError(ReportingException):
|
|
96
|
+
"""A file is already locked and we do not want to block."""
|
|
97
|
+
|
|
98
|
+
filename: str
|
|
99
|
+
|
|
100
|
+
@classmethod
|
|
101
|
+
def from_context(cls, filename):
|
|
102
|
+
self = cls()
|
|
103
|
+
self.filename = filename
|
|
104
|
+
return self
|
|
105
|
+
|
|
106
|
+
def __str__(self):
|
|
107
|
+
return "File already locked: {}".format(self.filename)
|
|
108
|
+
|
|
109
|
+
def report(self):
|
|
110
|
+
output.error(str(self))
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
class GPGCallError(ReportingException):
|
|
114
|
+
"""There was an error calling GPG on encrypted file."""
|
|
115
|
+
|
|
116
|
+
command: str
|
|
117
|
+
exitcode: str
|
|
118
|
+
output: str
|
|
119
|
+
|
|
120
|
+
@classmethod
|
|
121
|
+
def from_context(cls, command, exitcode, output):
|
|
122
|
+
self = cls()
|
|
123
|
+
self.command = " ".join(command)
|
|
124
|
+
self.exitcode = str(exitcode)
|
|
125
|
+
self.output = output.decode("ascii", errors="replace")
|
|
126
|
+
return self
|
|
127
|
+
|
|
128
|
+
def __str__(self):
|
|
129
|
+
return (
|
|
130
|
+
f"Exitcode {self.exitcode} while calling: "
|
|
131
|
+
f"{self.command}\n{self.output}"
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
def report(self):
|
|
135
|
+
output.error("Error while calling GPG")
|
|
136
|
+
output.tabular("command", self.command, red=True)
|
|
137
|
+
output.tabular("exit code", self.exitcode)
|
|
138
|
+
output.tabular("message", self.output, separator=":\n")
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
class AgeCallError(ReportingException):
|
|
142
|
+
"""There was an error calling age on encrypted file."""
|
|
143
|
+
|
|
144
|
+
command: str
|
|
145
|
+
exitcode: str
|
|
146
|
+
output: str
|
|
147
|
+
|
|
148
|
+
@classmethod
|
|
149
|
+
def from_context(cls, command, exitcode, output):
|
|
150
|
+
self = cls()
|
|
151
|
+
self.command = " ".join(command)
|
|
152
|
+
self.exitcode = str(exitcode)
|
|
153
|
+
self.output = output.decode("ascii", errors="replace")
|
|
154
|
+
return self
|
|
155
|
+
|
|
156
|
+
def __str__(self):
|
|
157
|
+
return (
|
|
158
|
+
f"Exitcode {self.exitcode} while calling: "
|
|
159
|
+
f"{self.command}\n{self.output}"
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
def report(self):
|
|
163
|
+
output.error("Error while calling age")
|
|
164
|
+
output.tabular("command", self.command, red=True)
|
|
165
|
+
output.tabular("exit code", self.exitcode)
|
|
166
|
+
output.tabular("message", self.output, separator=":\n")
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
class GetAddressInfoError(ReportingException, socket.gaierror):
|
|
170
|
+
"""There was an error calling getaddrinfo."""
|
|
171
|
+
|
|
172
|
+
hostname: str
|
|
173
|
+
error: str
|
|
174
|
+
|
|
175
|
+
@classmethod
|
|
176
|
+
def from_context(cls, hostname, error):
|
|
177
|
+
self = cls()
|
|
178
|
+
self.hostname = hostname
|
|
179
|
+
self.error = error
|
|
180
|
+
return self
|
|
181
|
+
|
|
182
|
+
def __str__(self):
|
|
183
|
+
return f"Error while resolving {self.hostname}: {self.error}"
|
|
184
|
+
|
|
185
|
+
def report(self):
|
|
186
|
+
output.error("Error while resolving hostname")
|
|
187
|
+
output.tabular("hostname", self.hostname, red=True)
|
|
188
|
+
output.tabular("message", self.error, separator=":\n")
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
class UpdateNeeded(AssertionError):
|
|
192
|
+
"""A component requires an update."""
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
class ConfigurationError(ReportingException):
|
|
196
|
+
"""Indicates that an environment could not be configured successfully."""
|
|
197
|
+
|
|
198
|
+
message: str
|
|
199
|
+
has_component: bool
|
|
200
|
+
component_root_name: Optional[str]
|
|
201
|
+
|
|
202
|
+
@property
|
|
203
|
+
def sort_key(self):
|
|
204
|
+
return (0, self.message)
|
|
205
|
+
|
|
206
|
+
@classmethod
|
|
207
|
+
def from_context(cls, message, component=None):
|
|
208
|
+
self = cls()
|
|
209
|
+
self.message = message
|
|
210
|
+
self.has_component = component is not None
|
|
211
|
+
self.component_root_name = component.root.name if component else None
|
|
212
|
+
self.affected_hostname = component.root.host.name if component else None
|
|
213
|
+
return self
|
|
214
|
+
|
|
215
|
+
def __str__(self):
|
|
216
|
+
return str(self.message)
|
|
217
|
+
|
|
218
|
+
def report(self):
|
|
219
|
+
message = self.message
|
|
220
|
+
if self.has_component:
|
|
221
|
+
message = "{}: {}".format(
|
|
222
|
+
self.component_root_name,
|
|
223
|
+
message,
|
|
224
|
+
)
|
|
225
|
+
output.error(message)
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
class AttributeExpansionError(ConfigurationError):
|
|
229
|
+
"""An override attribute could not be expanded properly."""
|
|
230
|
+
|
|
231
|
+
component_breadcrumbs: str
|
|
232
|
+
value_repr: str
|
|
233
|
+
error_str: str
|
|
234
|
+
key: str
|
|
235
|
+
|
|
236
|
+
@property
|
|
237
|
+
def sort_key(self):
|
|
238
|
+
return (
|
|
239
|
+
1,
|
|
240
|
+
self.affected_hostname,
|
|
241
|
+
self.component_breadcrumbs,
|
|
242
|
+
self.key,
|
|
243
|
+
)
|
|
244
|
+
|
|
245
|
+
@classmethod
|
|
246
|
+
def from_context(cls, component, key, value, error):
|
|
247
|
+
self = cls()
|
|
248
|
+
self.affected_hostname = component.root.host.name
|
|
249
|
+
self.component_breadcrumbs = component._breadcrumbs
|
|
250
|
+
self.value_repr = repr(value)
|
|
251
|
+
self.error = prepare_error(error)
|
|
252
|
+
self.key = key
|
|
253
|
+
return self
|
|
254
|
+
|
|
255
|
+
def __str__(self):
|
|
256
|
+
return "Error while expanding attribute: " + self.error
|
|
257
|
+
|
|
258
|
+
def report(self):
|
|
259
|
+
output.error("Error while expanding attribute:")
|
|
260
|
+
output.tabular(
|
|
261
|
+
"Message",
|
|
262
|
+
self.error,
|
|
263
|
+
red=True,
|
|
264
|
+
)
|
|
265
|
+
output.tabular(
|
|
266
|
+
"Attribute",
|
|
267
|
+
"{}.{}".format(self.component_breadcrumbs, self.key),
|
|
268
|
+
red=True,
|
|
269
|
+
)
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
class ConversionError(ConfigurationError):
|
|
273
|
+
"""An override attribute could not be converted properly."""
|
|
274
|
+
|
|
275
|
+
component_breadcrumbs: str
|
|
276
|
+
conversion_name: str
|
|
277
|
+
value_repr: str
|
|
278
|
+
error_str: str
|
|
279
|
+
key: str
|
|
280
|
+
|
|
281
|
+
@property
|
|
282
|
+
def sort_key(self):
|
|
283
|
+
return (
|
|
284
|
+
1,
|
|
285
|
+
self.affected_hostname,
|
|
286
|
+
self.component_breadcrumbs,
|
|
287
|
+
self.key,
|
|
288
|
+
)
|
|
289
|
+
|
|
290
|
+
@classmethod
|
|
291
|
+
def from_context(cls, component, key, value, conversion, error):
|
|
292
|
+
self = cls()
|
|
293
|
+
self.affected_hostname = component.root.host.name
|
|
294
|
+
self.component_breadcrumbs = component._breadcrumbs
|
|
295
|
+
self.conversion_name = conversion.__name__
|
|
296
|
+
self.value_repr = repr(value)
|
|
297
|
+
self.error_str = str(error)
|
|
298
|
+
self.key = key
|
|
299
|
+
return self
|
|
300
|
+
|
|
301
|
+
def __str__(self):
|
|
302
|
+
return self.error_str
|
|
303
|
+
|
|
304
|
+
def report(self):
|
|
305
|
+
output.error(self.error_str)
|
|
306
|
+
output.tabular(
|
|
307
|
+
"Attribute",
|
|
308
|
+
"{}.{}".format(self.component_breadcrumbs, self.key),
|
|
309
|
+
red=True,
|
|
310
|
+
)
|
|
311
|
+
output.tabular(
|
|
312
|
+
"Conversion",
|
|
313
|
+
"{}({})".format(self.conversion_name, self.value_repr),
|
|
314
|
+
red=True,
|
|
315
|
+
)
|
|
316
|
+
# TODO provide traceback in debug output
|
|
317
|
+
# provide file, line number, excerpt of attribute definition
|
|
318
|
+
# see: https://github.com/flyingcircusio/batou/issues/316
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
class SilentConfigurationError(Exception):
|
|
322
|
+
"""These are exceptions that will be reported by other exceptions.
|
|
323
|
+
|
|
324
|
+
They basically only influence control flow during configuration and
|
|
325
|
+
are manually placed to avoid double reporting.
|
|
326
|
+
|
|
327
|
+
"""
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
class MissingOverrideAttributes(ConfigurationError):
|
|
331
|
+
component_breadcrumbs: str
|
|
332
|
+
attributes: List[str]
|
|
333
|
+
|
|
334
|
+
@property
|
|
335
|
+
def sort_key(self):
|
|
336
|
+
return (3, self.affected_hostname, self.component_breadcrumbs)
|
|
337
|
+
|
|
338
|
+
@classmethod
|
|
339
|
+
def from_context(cls, component, attributes):
|
|
340
|
+
self = cls()
|
|
341
|
+
self.affected_hostname = component.root.host.name
|
|
342
|
+
self.component_breadcrumbs = component._breadcrumbs
|
|
343
|
+
self.attributes = attributes
|
|
344
|
+
return self
|
|
345
|
+
|
|
346
|
+
def __str__(self):
|
|
347
|
+
return "Overrides for undefined attributes " + ",".join(self.attributes)
|
|
348
|
+
|
|
349
|
+
def report(self):
|
|
350
|
+
output.error("Overrides for undefined attributes")
|
|
351
|
+
output.tabular("Component", self.component_breadcrumbs, red=True)
|
|
352
|
+
output.tabular("Attributes", ", ".join(self.attributes), red=True)
|
|
353
|
+
|
|
354
|
+
# TODO point to specific line in secrets or environments
|
|
355
|
+
# cfg file and show context
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
class DuplicateComponent(ConfigurationError):
|
|
359
|
+
a_name: str
|
|
360
|
+
a_filename: str
|
|
361
|
+
b_filename: str
|
|
362
|
+
|
|
363
|
+
@property
|
|
364
|
+
def sort_key(self):
|
|
365
|
+
return (2, self.a_name)
|
|
366
|
+
|
|
367
|
+
@classmethod
|
|
368
|
+
def from_context(cls, a, b):
|
|
369
|
+
self = cls()
|
|
370
|
+
self.a_name = a.name
|
|
371
|
+
self.a_filename = a.filename
|
|
372
|
+
self.b_filename = b.filename
|
|
373
|
+
return self
|
|
374
|
+
|
|
375
|
+
def __str__(self):
|
|
376
|
+
return "Duplicate component: " + self.a_name
|
|
377
|
+
|
|
378
|
+
def report(self):
|
|
379
|
+
output.error('Duplicate component "{}"'.format(self.a_name))
|
|
380
|
+
output.tabular("Occurrence", self.a_filename)
|
|
381
|
+
output.tabular("Occurrence", self.b_filename)
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
class DuplicateHostMapping(ConfigurationError):
|
|
385
|
+
affected_hostname: str
|
|
386
|
+
a: str
|
|
387
|
+
b: str
|
|
388
|
+
|
|
389
|
+
@property
|
|
390
|
+
def sort_key(self):
|
|
391
|
+
return (3, self.affected_hostname, self.a, self.b)
|
|
392
|
+
|
|
393
|
+
@classmethod
|
|
394
|
+
def from_context(cls, hostname, a, b):
|
|
395
|
+
self = cls()
|
|
396
|
+
self.affected_hostname = hostname
|
|
397
|
+
self.a = a
|
|
398
|
+
self.b = b
|
|
399
|
+
return self
|
|
400
|
+
|
|
401
|
+
def __str__(self):
|
|
402
|
+
return "Duplicate host mapping: " + self.affected_hostname
|
|
403
|
+
|
|
404
|
+
def report(self):
|
|
405
|
+
output.error(
|
|
406
|
+
'Duplicate host mapping "{}"'.format(self.affected_hostname)
|
|
407
|
+
)
|
|
408
|
+
output.tabular("Mapping 1: ", self.a)
|
|
409
|
+
output.tabular("Mapping 2: ", self.b)
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
class UnknownComponentConfigurationError(ConfigurationError):
|
|
413
|
+
"""An unknown error occured while configuring a component."""
|
|
414
|
+
|
|
415
|
+
@property
|
|
416
|
+
def sort_key(self):
|
|
417
|
+
return (4, self.root_host_name, 2)
|
|
418
|
+
|
|
419
|
+
@classmethod
|
|
420
|
+
def from_context(cls, root, exception, tb):
|
|
421
|
+
self = cls()
|
|
422
|
+
self.root_name = root.name
|
|
423
|
+
self.root_host_name = root.host.name
|
|
424
|
+
self.exception_repr = prepare_error(exception)
|
|
425
|
+
stack = traceback.extract_tb(tb)
|
|
426
|
+
from batou import component, environment
|
|
427
|
+
|
|
428
|
+
self.traceback = prepare_traceback(tb)
|
|
429
|
+
return self
|
|
430
|
+
|
|
431
|
+
def __str__(self):
|
|
432
|
+
return self.exception_repr
|
|
433
|
+
|
|
434
|
+
def report(self):
|
|
435
|
+
output.error(self.exception_repr)
|
|
436
|
+
output.annotate(
|
|
437
|
+
"This /might/ be a batou bug. Please consider reporting it.\n",
|
|
438
|
+
red=True,
|
|
439
|
+
)
|
|
440
|
+
output.tabular("Host", self.root_host_name, red=True)
|
|
441
|
+
output.tabular("Component", self.root_name + "\n", red=True)
|
|
442
|
+
output.annotate(
|
|
443
|
+
"Traceback (simplified, most recent call last):", red=True
|
|
444
|
+
)
|
|
445
|
+
output.annotate(self.traceback, red=True)
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
class UnusedResources(ConfigurationError):
|
|
449
|
+
"""Some provided resources were never used."""
|
|
450
|
+
|
|
451
|
+
sort_key = (5, "unused")
|
|
452
|
+
|
|
453
|
+
@classmethod
|
|
454
|
+
def from_context(cls, resources):
|
|
455
|
+
self = cls()
|
|
456
|
+
self.unused_resources = []
|
|
457
|
+
for key in sorted(resources.keys()):
|
|
458
|
+
for component, value in resources[key].items():
|
|
459
|
+
self.unused_resources.append((key, component.name, str(value)))
|
|
460
|
+
return self
|
|
461
|
+
|
|
462
|
+
def __str__(self):
|
|
463
|
+
return "Unused provided resources"
|
|
464
|
+
|
|
465
|
+
def report(self):
|
|
466
|
+
output.error("Unused provided resources")
|
|
467
|
+
for key, component, value in self.unused_resources:
|
|
468
|
+
output.line(
|
|
469
|
+
' Resource "{}" provided by {} with value {}'.format(
|
|
470
|
+
key, component, value
|
|
471
|
+
),
|
|
472
|
+
red=True,
|
|
473
|
+
)
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
class UnusedComponentsInitialized(ConfigurationError):
|
|
477
|
+
"""Some components were initialized but never used."""
|
|
478
|
+
|
|
479
|
+
sort_key = (5, "unused")
|
|
480
|
+
|
|
481
|
+
@classmethod
|
|
482
|
+
def from_context(cls, components, root):
|
|
483
|
+
self = cls()
|
|
484
|
+
self.unused_components = []
|
|
485
|
+
self.breadcrumbs = []
|
|
486
|
+
self.init_file_paths = []
|
|
487
|
+
self.init_line_numbers = []
|
|
488
|
+
for component in components:
|
|
489
|
+
self.unused_components.append(repr(component.__class__.__name__))
|
|
490
|
+
self.breadcrumbs.append(component._init_breadcrumbs)
|
|
491
|
+
self.init_file_paths.append(component._init_file_path)
|
|
492
|
+
self.init_line_numbers.append(component._init_line_number)
|
|
493
|
+
self.root_name = root.name
|
|
494
|
+
return self
|
|
495
|
+
|
|
496
|
+
def __str__(self):
|
|
497
|
+
out_str = "Some components were initialized but never added to the environment:"
|
|
498
|
+
for i, component in enumerate(self.unused_components):
|
|
499
|
+
out_str += f"\n {component}: {' -> '.join(self.breadcrumbs[i])}"
|
|
500
|
+
out_str += f"\n initialized in {self.init_file_paths[i]}:{self.init_line_numbers[i]}"
|
|
501
|
+
out_str += f"\nRoot: {self.root_name}"
|
|
502
|
+
out_str += f"\nAdd the components to the environment using `self += component`."
|
|
503
|
+
return out_str
|
|
504
|
+
|
|
505
|
+
def report(self):
|
|
506
|
+
output.error(
|
|
507
|
+
f"Some components were initialized but never added to the environment:"
|
|
508
|
+
)
|
|
509
|
+
for i, component in enumerate(self.unused_components):
|
|
510
|
+
output.line(
|
|
511
|
+
f" {component}: {' -> '.join(self.breadcrumbs[i])}", red=True
|
|
512
|
+
)
|
|
513
|
+
output.line(
|
|
514
|
+
f" initialized in {self.init_file_paths[i]}:{self.init_line_numbers[i]}",
|
|
515
|
+
red=True,
|
|
516
|
+
)
|
|
517
|
+
output.line(
|
|
518
|
+
f"Add the components to the environment using `self += component`.",
|
|
519
|
+
red=True,
|
|
520
|
+
)
|
|
521
|
+
output.tabular("Root", self.root_name, red=True)
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
class ComponentWithUpdateWithoutVerify(ConfigurationError):
|
|
525
|
+
"""Some components have an update method but no verify method."""
|
|
526
|
+
|
|
527
|
+
sort_key = (5, "without_verify")
|
|
528
|
+
|
|
529
|
+
@classmethod
|
|
530
|
+
def from_context(cls, components, roots):
|
|
531
|
+
self = cls()
|
|
532
|
+
self.components = []
|
|
533
|
+
for component in components:
|
|
534
|
+
self.components.append(repr(component.__class__.__name__))
|
|
535
|
+
self.roots = []
|
|
536
|
+
for root in roots:
|
|
537
|
+
self.roots.append(root.name)
|
|
538
|
+
return self
|
|
539
|
+
|
|
540
|
+
def __str__(self):
|
|
541
|
+
out_str = "Some components have an update method but no verify method:"
|
|
542
|
+
for idx, component in enumerate(self.components):
|
|
543
|
+
out_str += f"\n {component}"
|
|
544
|
+
out_str += f"\nRoot: {self.roots[idx]}"
|
|
545
|
+
out_str += f"\nThe update() method may not be called by batou if the verify() method is missing."
|
|
546
|
+
return out_str
|
|
547
|
+
|
|
548
|
+
def report(self):
|
|
549
|
+
output.error(
|
|
550
|
+
f"Some components have an update method but no verify method:"
|
|
551
|
+
)
|
|
552
|
+
for component in self.components:
|
|
553
|
+
output.line(f" {component}", red=True)
|
|
554
|
+
output.tabular("Root", self.root_name, red=True)
|
|
555
|
+
output.line(
|
|
556
|
+
f"The update() method may not be called by batou if the verify() method is missing.",
|
|
557
|
+
red=True,
|
|
558
|
+
)
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
class UnsatisfiedResources(ConfigurationError):
|
|
562
|
+
"""Some required resources were never provided."""
|
|
563
|
+
|
|
564
|
+
sort_key = (6, "unsatisfied")
|
|
565
|
+
|
|
566
|
+
@classmethod
|
|
567
|
+
def from_context(cls, resources):
|
|
568
|
+
self = cls()
|
|
569
|
+
self.unsatisfied_resources = []
|
|
570
|
+
for (key, host), res_for_key in sorted(resources.items()):
|
|
571
|
+
self.unsatisfied_resources.append(
|
|
572
|
+
(key, host, [r.name for r in res_for_key])
|
|
573
|
+
)
|
|
574
|
+
return self
|
|
575
|
+
|
|
576
|
+
def __str__(self):
|
|
577
|
+
return "Unsatisfied resource requirements"
|
|
578
|
+
|
|
579
|
+
def report(self):
|
|
580
|
+
output.error("Unsatisfied resource requirements")
|
|
581
|
+
for key, host, resources in self.unsatisfied_resources:
|
|
582
|
+
if host is None:
|
|
583
|
+
msg = (
|
|
584
|
+
f' Resource "{key}" required by '
|
|
585
|
+
f'{",".join(resources)}'
|
|
586
|
+
)
|
|
587
|
+
|
|
588
|
+
else:
|
|
589
|
+
msg = (
|
|
590
|
+
f' Resource "{key}" on "{host}" required by '
|
|
591
|
+
f'{",".join(resources)}'
|
|
592
|
+
)
|
|
593
|
+
|
|
594
|
+
output.line(msg, red=True)
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
class MissingEnvironment(ConfigurationError):
|
|
598
|
+
"""The specified environment does not exist."""
|
|
599
|
+
|
|
600
|
+
sort_key = (0,)
|
|
601
|
+
|
|
602
|
+
@classmethod
|
|
603
|
+
def from_context(cls, environment):
|
|
604
|
+
self = cls()
|
|
605
|
+
self.environment_name = environment.name
|
|
606
|
+
return self
|
|
607
|
+
|
|
608
|
+
def __str__(self):
|
|
609
|
+
return "Missing environment `{}`".format(self.environment_name)
|
|
610
|
+
|
|
611
|
+
def report(self):
|
|
612
|
+
output.error("Missing environment")
|
|
613
|
+
output.tabular("Environment", self.environment_name, red=True)
|
|
614
|
+
|
|
615
|
+
|
|
616
|
+
class ComponentLoadingError(ConfigurationError):
|
|
617
|
+
"""The specified component file failed to load."""
|
|
618
|
+
|
|
619
|
+
sort_key = (0,)
|
|
620
|
+
|
|
621
|
+
@classmethod
|
|
622
|
+
def from_context(cls, filename, exception, tb):
|
|
623
|
+
self = cls()
|
|
624
|
+
self.filename = filename
|
|
625
|
+
self.exception_str = str(exception)
|
|
626
|
+
|
|
627
|
+
self.traceback = prepare_traceback(tb)
|
|
628
|
+
return self
|
|
629
|
+
|
|
630
|
+
def __str__(self):
|
|
631
|
+
return "Failed loading component file " + self.filename
|
|
632
|
+
|
|
633
|
+
def report(self):
|
|
634
|
+
output.error("Failed loading component file")
|
|
635
|
+
output.tabular("File", self.filename, red=True)
|
|
636
|
+
output.tabular("Exception", self.exception_str, red=True)
|
|
637
|
+
output.annotate(
|
|
638
|
+
"Traceback (simplified, most recent call last):", red=True
|
|
639
|
+
)
|
|
640
|
+
output.annotate(self.traceback, red=True)
|
|
641
|
+
|
|
642
|
+
# TODO provide traceback in debug output
|
|
643
|
+
# see: https://github.com/flyingcircusio/batou/issues/316
|
|
644
|
+
|
|
645
|
+
|
|
646
|
+
class MissingComponent(ConfigurationError):
|
|
647
|
+
"""The specified environment does not exist."""
|
|
648
|
+
|
|
649
|
+
sort_key = (0,)
|
|
650
|
+
|
|
651
|
+
@classmethod
|
|
652
|
+
def from_context(cls, component_name, hostname):
|
|
653
|
+
self = cls()
|
|
654
|
+
self.component_name = component_name
|
|
655
|
+
self.affected_hostname = hostname
|
|
656
|
+
return self
|
|
657
|
+
|
|
658
|
+
def __str__(self):
|
|
659
|
+
return "Missing component: " + self.component_name
|
|
660
|
+
|
|
661
|
+
def report(self):
|
|
662
|
+
output.error("Missing component")
|
|
663
|
+
output.tabular("Component", self.component_name, red=True)
|
|
664
|
+
|
|
665
|
+
|
|
666
|
+
class SuperfluousSection(ConfigurationError):
|
|
667
|
+
"""A superfluous section was found in the environment
|
|
668
|
+
configuration file."""
|
|
669
|
+
|
|
670
|
+
sort_key = (0,)
|
|
671
|
+
|
|
672
|
+
@classmethod
|
|
673
|
+
def from_context(cls, section):
|
|
674
|
+
self = cls()
|
|
675
|
+
self.section = section
|
|
676
|
+
return self
|
|
677
|
+
|
|
678
|
+
def __str__(self):
|
|
679
|
+
return "Superfluous section in environment: " + self.section
|
|
680
|
+
|
|
681
|
+
def report(self):
|
|
682
|
+
output.error("Superfluous section in environment configuration")
|
|
683
|
+
output.tabular("Section", self.section, red=True)
|
|
684
|
+
# TODO provide location and context in debug output
|
|
685
|
+
# see: https://github.com/flyingcircusio/batou/issues/316
|
|
686
|
+
|
|
687
|
+
|
|
688
|
+
class SuperfluousComponentSection(ConfigurationError):
|
|
689
|
+
"""A component section was found in the environment
|
|
690
|
+
but no associated component is known."""
|
|
691
|
+
|
|
692
|
+
sort_key = (0,)
|
|
693
|
+
|
|
694
|
+
@classmethod
|
|
695
|
+
def from_context(cls, component_name):
|
|
696
|
+
self = cls()
|
|
697
|
+
self.component_name = component_name
|
|
698
|
+
return self
|
|
699
|
+
|
|
700
|
+
def __str__(self):
|
|
701
|
+
return (
|
|
702
|
+
"Override section for unknown component found: "
|
|
703
|
+
+ self.component_name
|
|
704
|
+
)
|
|
705
|
+
|
|
706
|
+
def report(self):
|
|
707
|
+
output.error("Override section for unknown component found")
|
|
708
|
+
output.tabular("Component", self.component_name, red=True)
|
|
709
|
+
# TODO provide traceback in debug output
|
|
710
|
+
# see: https://github.com/flyingcircusio/batou/issues/316
|
|
711
|
+
|
|
712
|
+
|
|
713
|
+
class SuperfluousSecretsSection(ConfigurationError):
|
|
714
|
+
"""A component section was found in the secrets
|
|
715
|
+
but no associated component is known."""
|
|
716
|
+
|
|
717
|
+
sort_key = (0,)
|
|
718
|
+
|
|
719
|
+
@classmethod
|
|
720
|
+
def from_context(cls, component_name):
|
|
721
|
+
self = cls()
|
|
722
|
+
self.component_name = component_name
|
|
723
|
+
return self
|
|
724
|
+
|
|
725
|
+
def __str__(self):
|
|
726
|
+
return (
|
|
727
|
+
"Secrets section for unknown component found: "
|
|
728
|
+
+ self.component_name
|
|
729
|
+
)
|
|
730
|
+
|
|
731
|
+
def report(self):
|
|
732
|
+
output.error("Secrets section for unknown component found")
|
|
733
|
+
output.tabular("Component", self.component_name, red=True)
|
|
734
|
+
# TODO provide traceback in debug output
|
|
735
|
+
# see: https://github.com/flyingcircusio/batou/issues/316
|
|
736
|
+
|
|
737
|
+
|
|
738
|
+
class UnknownHostSecretsSection(ConfigurationError):
|
|
739
|
+
"""A host section was found in the secrets
|
|
740
|
+
but no associated host is known."""
|
|
741
|
+
|
|
742
|
+
sort_key = (0,)
|
|
743
|
+
|
|
744
|
+
@classmethod
|
|
745
|
+
def from_context(cls, hostname):
|
|
746
|
+
self = cls()
|
|
747
|
+
self.hostname = hostname
|
|
748
|
+
return self
|
|
749
|
+
|
|
750
|
+
def __str__(self):
|
|
751
|
+
return "Secrets section for unknown host found: " + self.hostname
|
|
752
|
+
|
|
753
|
+
def report(self):
|
|
754
|
+
output.error("Secrets section for unknown host found")
|
|
755
|
+
output.tabular("Host", self.hostname, red=True)
|
|
756
|
+
|
|
757
|
+
|
|
758
|
+
class DuplicateOverride(ConfigurationError):
|
|
759
|
+
"""An override for a component attribute was found both in the secrets and
|
|
760
|
+
in the environment configuration."""
|
|
761
|
+
|
|
762
|
+
sort_key = (0,)
|
|
763
|
+
|
|
764
|
+
@classmethod
|
|
765
|
+
def from_context(cls, component_name, attribute):
|
|
766
|
+
self = cls()
|
|
767
|
+
self.component_name = component_name
|
|
768
|
+
self.attribute = attribute
|
|
769
|
+
return self
|
|
770
|
+
|
|
771
|
+
def __str__(self):
|
|
772
|
+
return (
|
|
773
|
+
f"A value {self.component_name}.{self.attribute} is defined both in"
|
|
774
|
+
" environment and secrets."
|
|
775
|
+
)
|
|
776
|
+
|
|
777
|
+
def report(self):
|
|
778
|
+
output.error("Attribute override found both in environment and secrets")
|
|
779
|
+
output.tabular("Component", self.component_name, red=True)
|
|
780
|
+
output.tabular("Attribute", self.attribute, red=True)
|
|
781
|
+
# TODO provide traceback in debug output
|
|
782
|
+
# see: https://github.com/flyingcircusio/batou/issues/316
|
|
783
|
+
|
|
784
|
+
|
|
785
|
+
class DuplicateSecretsComponentAttribute(ConfigurationError):
|
|
786
|
+
"""A component attribute was specified multiple times in the secrets."""
|
|
787
|
+
|
|
788
|
+
sort_key = (0,)
|
|
789
|
+
|
|
790
|
+
@classmethod
|
|
791
|
+
def from_context(cls, component_name, attribute):
|
|
792
|
+
self = cls()
|
|
793
|
+
self.component_name = component_name
|
|
794
|
+
self.attribute = attribute
|
|
795
|
+
return self
|
|
796
|
+
|
|
797
|
+
def __str__(self):
|
|
798
|
+
return (
|
|
799
|
+
f"A value {self.component_name}.{self.attribute} is defined multiple"
|
|
800
|
+
" times in secrets."
|
|
801
|
+
)
|
|
802
|
+
|
|
803
|
+
def report(self):
|
|
804
|
+
output.error("Attribute defined multiple times in secrets")
|
|
805
|
+
output.tabular("Component", self.component_name, red=True)
|
|
806
|
+
output.tabular("Attribute", self.attribute, red=True)
|
|
807
|
+
# TODO provide traceback in debug output
|
|
808
|
+
# see: https://github.com/flyingcircusio/batou/issues/316
|
|
809
|
+
|
|
810
|
+
|
|
811
|
+
class CycleErrorDetected(ConfigurationError):
|
|
812
|
+
"""We think we found a cycle in the component dependencies."""
|
|
813
|
+
|
|
814
|
+
sort_key = (99,)
|
|
815
|
+
|
|
816
|
+
@classmethod
|
|
817
|
+
def from_context(cls, error):
|
|
818
|
+
self = cls()
|
|
819
|
+
self.error_str = str(error)
|
|
820
|
+
return self
|
|
821
|
+
|
|
822
|
+
def report(self):
|
|
823
|
+
output.error("Found dependency cycle")
|
|
824
|
+
output.annotate(self.error_str, red=True)
|
|
825
|
+
# TODO provide traceback in debug output
|
|
826
|
+
# see: https://github.com/flyingcircusio/batou/issues/316
|
|
827
|
+
|
|
828
|
+
def __str__(self):
|
|
829
|
+
return "Found dependency cycle: " + self.error_str
|
|
830
|
+
|
|
831
|
+
|
|
832
|
+
class NonConvergingWorkingSet(ConfigurationError):
|
|
833
|
+
"""A working set did not converge."""
|
|
834
|
+
|
|
835
|
+
sort_key = (100,)
|
|
836
|
+
|
|
837
|
+
@classmethod
|
|
838
|
+
def from_context(cls, roots):
|
|
839
|
+
self = cls()
|
|
840
|
+
self.roots_len = len(roots)
|
|
841
|
+
self.root_names = ", ".join(sorted([r.name for r in roots]))
|
|
842
|
+
return self
|
|
843
|
+
|
|
844
|
+
def __str__(self):
|
|
845
|
+
return "There are unconfigured components remaining."
|
|
846
|
+
|
|
847
|
+
def report(self):
|
|
848
|
+
# TODO show this last or first, but not in the middle
|
|
849
|
+
# of everything
|
|
850
|
+
output.error(
|
|
851
|
+
"{} remaining unconfigured component(s): {}".format(
|
|
852
|
+
self.roots_len, self.root_names
|
|
853
|
+
)
|
|
854
|
+
)
|
|
855
|
+
# TODO show all incl. their host name in -vv or so
|
|
856
|
+
|
|
857
|
+
|
|
858
|
+
class DeploymentError(ReportingException):
|
|
859
|
+
"""Indicates that a deployment failed.."""
|
|
860
|
+
|
|
861
|
+
sort_key = (100,)
|
|
862
|
+
|
|
863
|
+
def __str__(self):
|
|
864
|
+
return "The deployment encountered an error."
|
|
865
|
+
|
|
866
|
+
def report(self):
|
|
867
|
+
pass
|
|
868
|
+
|
|
869
|
+
|
|
870
|
+
class RepositoryDifferentError(DeploymentError):
|
|
871
|
+
"""The repository on the remote side is different."""
|
|
872
|
+
|
|
873
|
+
sort_key = (150,)
|
|
874
|
+
|
|
875
|
+
@classmethod
|
|
876
|
+
def from_context(cls, local, remote):
|
|
877
|
+
self = cls()
|
|
878
|
+
self.local = local
|
|
879
|
+
self.remote = remote
|
|
880
|
+
return self
|
|
881
|
+
|
|
882
|
+
def __str__(self):
|
|
883
|
+
return "Remote repository has diverged. Wrong branch?"
|
|
884
|
+
|
|
885
|
+
def report(self):
|
|
886
|
+
output.error(
|
|
887
|
+
"The remote working copy is based on a different revision. "
|
|
888
|
+
"Maybe you tried to deploy from the wrong branch."
|
|
889
|
+
)
|
|
890
|
+
output.tabular("Local", self.local, red=True)
|
|
891
|
+
output.tabular("Remote", self.remote, red=True)
|
|
892
|
+
|
|
893
|
+
|
|
894
|
+
class DuplicateHostError(ConfigurationError):
|
|
895
|
+
@property
|
|
896
|
+
def sort_key(self):
|
|
897
|
+
return (0,)
|
|
898
|
+
|
|
899
|
+
@classmethod
|
|
900
|
+
def from_context(cls, hostname):
|
|
901
|
+
self = cls()
|
|
902
|
+
self.affected_hostname = hostname
|
|
903
|
+
return self
|
|
904
|
+
|
|
905
|
+
def __str__(self):
|
|
906
|
+
return "Duplicate host: " + self.affected_hostname
|
|
907
|
+
|
|
908
|
+
def report(self):
|
|
909
|
+
output.error(
|
|
910
|
+
"Duplicate definition of host: {}".format(self.affected_hostname)
|
|
911
|
+
)
|
|
912
|
+
|
|
913
|
+
|
|
914
|
+
class InvalidIPAddressError(ConfigurationError):
|
|
915
|
+
sort_key = (0,)
|
|
916
|
+
|
|
917
|
+
@classmethod
|
|
918
|
+
def from_context(cls, address):
|
|
919
|
+
self = cls()
|
|
920
|
+
self.address = address
|
|
921
|
+
return self
|
|
922
|
+
|
|
923
|
+
def __str__(self):
|
|
924
|
+
return "Not a valid IP address: " + self.address
|
|
925
|
+
|
|
926
|
+
def report(self):
|
|
927
|
+
output.error("Not a valid IP address: {}".format(self.address))
|
|
928
|
+
|
|
929
|
+
|
|
930
|
+
class IPAddressConfigurationError(ConfigurationError):
|
|
931
|
+
"""An IP address family was accessed but not configured."""
|
|
932
|
+
|
|
933
|
+
sort_key = (0,)
|
|
934
|
+
|
|
935
|
+
@classmethod
|
|
936
|
+
def from_context(cls, address, kind):
|
|
937
|
+
self = cls()
|
|
938
|
+
self.address = address
|
|
939
|
+
self.kind = kind
|
|
940
|
+
return self
|
|
941
|
+
|
|
942
|
+
def __str__(self):
|
|
943
|
+
return (
|
|
944
|
+
f"Trying to access address family IPv{self.kind} which is not"
|
|
945
|
+
f" configured for {self.address}."
|
|
946
|
+
)
|
|
947
|
+
|
|
948
|
+
def report(self):
|
|
949
|
+
output.error(str(self))
|
|
950
|
+
|
|
951
|
+
output.tabular(
|
|
952
|
+
"Hint",
|
|
953
|
+
f"Use `require_v{self.kind}=True` when instantiating the Address"
|
|
954
|
+
" object.",
|
|
955
|
+
red=True,
|
|
956
|
+
)
|
|
957
|
+
|
|
958
|
+
# TODO provide traceback/line numbers/excerpt
|
|
959
|
+
# see: https://github.com/flyingcircusio/batou/issues/316
|
|
960
|
+
|
|
961
|
+
|
|
962
|
+
class TemplatingError(ReportingException):
|
|
963
|
+
"""An error occured while rendering a template."""
|
|
964
|
+
|
|
965
|
+
sort_key = (0,)
|
|
966
|
+
|
|
967
|
+
@classmethod
|
|
968
|
+
def from_context(cls, exception, template_identifier):
|
|
969
|
+
self = cls()
|
|
970
|
+
self.exception_str = prepare_error(exception)
|
|
971
|
+
self.template_identifier = template_identifier
|
|
972
|
+
# if exception is instance of jinja2.TemplateSyntaxError
|
|
973
|
+
# there is some magic in jinja2 that makes the __str__ method
|
|
974
|
+
# less capable, if exception.translated is set to True
|
|
975
|
+
if isinstance(exception, jinja2.TemplateSyntaxError):
|
|
976
|
+
exception.translated = False
|
|
977
|
+
self.exception_str = str(exception)
|
|
978
|
+
exception.translated = True
|
|
979
|
+
return self
|
|
980
|
+
|
|
981
|
+
def __str__(self):
|
|
982
|
+
return f"An error occured while rendering a template ({self.template_identifier}): {self.exception_str}"
|
|
983
|
+
|
|
984
|
+
def report(self):
|
|
985
|
+
output.error(str(self))
|