Repository navigation
Expand file tree
/
Copy pathexceptions.py
More file actions
290 lines (178 loc) · 7.31 KB
/
Copy pathexceptions.py
File metadata and controls
290 lines (178 loc) · 7.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
"""All custom exceptions used by Trigger. Where possible built-in exceptions are
used, but sometimes we need more descriptive errors.
""" # noqa: D205
# Imports
from simpleparse.error import ParserSyntaxError # noqa: F401
# Exceptions
class TriggerError(Exception):
"""A base exception for all Trigger-related errors."""
class ImproperlyConfigured(TriggerError):
"""Raised when something is improperly... configured..."""
################
# ACL Exceptions
################
class ACLError(TriggerError):
"""Base exception for all ACL-related errors."""
class ParseError(ACLError):
"""Raised when there is an error parsing/normalizing an ACL that tries to tell
you where it failed.
""" # noqa: D205
def __init__(self, reason, line=None, column=None): # noqa: D107
self.reason = reason
self.line = line
self.column = column
def __str__(self): # noqa: D105
s = self.reason
if self.line is not None and self.line > 1:
s += " at line %d" % self.line # noqa: UP031
return s
# ACL validation/formating errors
class BadTermName(ACLError):
"""Raised when an invalid name is assigned to a `~trigger.acl.parser.Term`
object.
""" # noqa: D205
class MissingTermName(ACLError):
"""Raised when a an un-named Term is output to a format that requires Terms to
be named (e.g. Juniper).
""" # noqa: D205
class VendorSupportLacking(ACLError):
"""Raised when a feature is not supported by a given vendor."""
# ACL naming errors
class ACLNameError(ACLError):
"""A base exception for all ACL naming errors."""
class MissingACLName(ACLNameError):
"""Raised when an ACL object is missing a name."""
class BadACLName(ACLNameError):
"""Raised when an ACL object is assigned an invalid name."""
# Misc. action errors
class ActionError(ACLError):
"""A base exception for all `~trigger.acl.parser.Term` action errors."""
class UnknownActionName(ActionError):
"""Raised when an action assigned to a ~trigger.acl.parser.Term` object is
unknown.
""" # noqa: D205
class BadRoutingInstanceName(ActionError):
"""Raised when a routing-instance name specified in an action is invalid."""
class BadRejectCode(ActionError):
"""Raised when an invalid rejection code is specified."""
class BadCounterName(ActionError):
"""Raised when a counter name is invalid."""
class BadForwardingClassName(ActionError):
"""Raised when a forwarding-class name is invalid."""
class BadIPSecSAName(ActionError):
"""Raised when an IPSec SA name is invalid."""
class BadPolicerName(ActionError):
"""Raised when a policer name is invalid."""
# Argument matching errors
class MatchError(ACLError):
"""A base exception for all errors related to Term
`~trigger.acl.parser.Matches` objects.
""" # noqa: D205
class BadMatchArgRange(MatchError):
"""Raised when a match condition argument does not fall within a specified
range.
""" # noqa: D205
class UnknownMatchType(MatchError):
"""Raised when an unknown match condition is specified."""
class UnknownMatchArg(MatchError):
"""Raised when an unknown match argument is specified."""
# ACLs database errors
class ACLSetError(ACLError):
"""A base exception for all ACL Set errors."""
class InvalidACLSet(ACLSetError):
"""Raised when an invalid ACL set is specified."""
# ACL/task queue errors
class ACLQueueError(TriggerError):
"""Raised when we encounter errors communicating with the Queue."""
# ACL workflow errors
class ACLStagingFailed(ACLError):
"""Raised when we encounter errors staging a file for loading."""
######################
# NetScreen Exceptions
######################
class NetScreenError(TriggerError):
"""A general exception for NetScreen devices."""
class NetScreenParseError(NetScreenError):
"""Raised when a NetScreen policy cannot be parsed."""
#####################
# Commando Exceptions
#####################
class CommandoError(TriggerError):
"""A base exception for all Commando-related errors."""
class UnsupportedVendor(CommandoError):
"""Raised when a vendor is not supported by Trigger."""
class UnsupportedDeviceType(CommandoError):
"""Raised when a device type is not supported by Trigger."""
class MissingPlatform(CommandoError):
"""Raised when a specific device platform is not supported."""
####################
# Twister Exceptions
####################
class TwisterError(TriggerError):
"""A base exception for all errors related to Twister."""
class LoginFailure(TwisterError):
"""Raised when authentication to a remote system fails."""
class EnablePasswordFailure(LoginFailure):
"""Raised when enable password was required but not found."""
class LoginTimeout(LoginFailure):
"""Raised when login to a remote systems times out."""
class ConnectionFailure(TwisterError):
"""Raised when a connection attempt totally fails."""
class SSHConnectionLost(TwisterError):
"""Raised when an SSH connection is lost for any reason."""
def __init__(self, code, desc): # noqa: D107
self.code = code
TwisterError.__init__(self, desc)
class CommandTimeout(TwisterError):
"""Raised when a command times out while executing."""
class CommandFailure(TwisterError):
"""Raised when a command fails to execute, such as when it results in an
error.
""" # noqa: D205
class IoslikeCommandFailure(CommandFailure):
"""Raised when a command fails on an IOS-like device."""
class NetscalerCommandFailure(CommandFailure):
"""Raised when a command fails on a NetScaler device."""
class JunoscriptCommandFailure(CommandFailure):
"""Raised when a Junoscript command fails on a Juniper device."""
def __init__(self, tag): # noqa: D107
self.tag = tag
def __str__(self): # noqa: D105
s = "JunOS XML command failure:\n"
ns = "{http://xml.juniper.net/xnm/1.1/xnm}"
for e in self.tag.findall(f".//{ns}error"):
for e2 in e:
s += " {}: {}\n".format(e2.tag.replace(ns, ""), e2.text)
return s
#######################
# NetDevices Exceptions
#######################
class NetDeviceError(TriggerError):
"""A base exception for all NetDevices related errors."""
class BadVendorName(NetDeviceError):
"""Raised when a Vendor object has a problem with the name."""
class LoaderFailed(NetDeviceError):
"""Raised when a metadata loader failed to load from data source."""
#########################
# Notification Exceptions
#########################
class NotificationFailure(TriggerError):
"""Raised when a notification fails and has not been silenced."""
##############################
# Bounce/Changemgmt Exceptions
##############################
class InvalidBounceWindow(TriggerError):
"""Raised when a BounceWindow object is kind of not good."""
#####################
# TACACSrc Exceptions
#####################
class TacacsrcError(Exception):
"""Base exception for TACACSrc errors."""
class CouldNotParse(TacacsrcError):
"""Raised when a ``.tacacsrc`` file failed to parse."""
class MissingPassword(TacacsrcError):
"""Raised when a credential is missing a password."""
class MissingRealmName(TacacsrcError):
"""Raised when a credential is missing a realm."""
class VersionMismatch(TacacsrcError):
"""Raised when the TACACSrc version does not match."""