@@ -71,10 +71,10 @@ def __init__(self, result, timeout): # type: (exec_result.ExecResult, typing.Un
7171 :param timeout: timeout for command
7272 :type timeout: typing.Union[int, float]
7373 """
74- self .result = result
75- self .timeout = timeout
7674 message = _log_templates .CMD_WAIT_ERROR .format (result = result , timeout = timeout )
7775 super (ExecHelperTimeoutError , self ).__init__ (message )
76+ self .result = result
77+ self .timeout = timeout
7878
7979 @property
8080 def cmd (self ): # type: () -> str
@@ -100,14 +100,14 @@ class CalledProcessError(ExecCalledProcessError):
100100 def __init__ (
101101 self ,
102102 result , # type: exec_result.ExecResult
103- expected = None , # type: typing.Optional[typing.List [typing.Union[int, proc_enums.ExitCodes]]]
103+ expected = None , # type: typing.Optional[typing.Iterable [typing.Union[int, proc_enums.ExitCodes]]]
104104 ): # type: (...) -> None
105105 """Exception for error on process calls.
106106
107107 :param result: execution result
108108 :type result: exec_result.ExecResult
109109 :param expected: expected return codes
110- :type expected: typing.Optional[typing.List [typing.Union[int, proc_enums.ExitCodes]]]
110+ :type expected: typing.Optional[typing.Iterable [typing.Union[int, proc_enums.ExitCodes]]]
111111
112112 .. versionchanged:: 1.1.1 - provide full result
113113 """
@@ -144,91 +144,97 @@ def stderr(self): # type: () -> typing.Text
144144 return self .result .stderr_str
145145
146146
147- class ParallelCallExceptions (ExecCalledProcessError ):
148- """Exception raised during parallel call as result of exceptions ."""
147+ class ParallelCallProcessError (ExecCalledProcessError ):
148+ """Exception during parallel execution ."""
149149
150- __slots__ = ("cmd" , "exceptions" , " errors" , "results" , "expected" )
150+ __slots__ = ("cmd" , "errors" , "results" , "expected" )
151151
152152 def __init__ (
153153 self ,
154154 command , # type: str
155- exceptions , # type: typing.Dict[typing.Tuple[str, int], Exception]
156155 errors , # type: typing.Dict[typing.Tuple[str, int], exec_result.ExecResult]
157156 results , # type: typing.Dict[typing.Tuple[str, int], exec_result.ExecResult]
158157 expected = None , # type: typing.Optional[typing.List[typing.Union[int, proc_enums.ExitCodes]]]
158+ ** kwargs # type: typing.Any
159159 ): # type: (...) -> None
160160 """Exception raised during parallel call as result of exceptions.
161161
162162 :param command: command
163163 :type command: str
164- :param exceptions: Exceptions on connections
165- :type exceptions: typing.Dict[typing.Tuple[str, int], Exception]
166164 :param errors: results with errors
167165 :type errors: typing.Dict[typing.Tuple[str, int], ExecResult]
168166 :param results: all results
169167 :type results: typing.Dict[typing.Tuple[str, int], ExecResult]
170168 :param expected: expected return codes
171169 :type expected: typing.Optional[typing.List[typing.Union[int, proc_enums.ExitCodes]]]
170+ :keyword _message: error message override
172171 """
173172 expected = expected or [proc_enums .ExitCodes .EX_OK ]
174- self .expected = proc_enums .exit_codes_to_enums (expected )
175- self .cmd = command
176- self .exceptions = exceptions
177- self .errors = errors
178- self .results = results
179- message = (
180- "Command {self.cmd!r} "
181- "during execution raised exceptions: \n "
182- "\t {exceptions}" .format (
183- self = self ,
184- exceptions = "\n \t " .join (
185- "{host}:{port} - {exc} " .format (host = host , port = port , exc = exc )
186- for (host , port ), exc in exceptions .items ()
173+ prep_expected = proc_enums .exit_codes_to_enums (expected )
174+ message = kwargs .get ("_message" , None ) or (
175+ "Command {cmd!r} "
176+ "returned unexpected exit codes on several hosts\n "
177+ "Expected: {expected}\n "
178+ "Got:\n "
179+ "\t {errors}" .format (
180+ cmd = command ,
181+ expected = prep_expected ,
182+ errors = "\n \t " .join (
183+ "{host}:{port} - {code} " .format (host = host , port = port , code = result .exit_code )
184+ for (host , port ), result in errors .items ()
187185 ),
188186 )
189187 )
190- super (ParallelCallExceptions , self ).__init__ (message )
188+ super (ParallelCallProcessError , self ).__init__ (message )
189+ self .cmd = command
190+ self .errors = errors
191+ self .results = results
192+ self .expected = prep_expected
191193
192194
193- class ParallelCallProcessError ( ExecCalledProcessError ):
194- """Exception during parallel execution ."""
195+ class ParallelCallExceptions ( ParallelCallProcessError ):
196+ """Exception raised during parallel call as result of exceptions ."""
195197
196- __slots__ = ("cmd" , "errors" , "results" , "expected " )
198+ __slots__ = ("cmd" , "exceptions " )
197199
198200 def __init__ (
199201 self ,
200202 command , # type: str
203+ exceptions , # type: typing.Dict[typing.Tuple[str, int], Exception]
201204 errors , # type: typing.Dict[typing.Tuple[str, int], exec_result.ExecResult]
202205 results , # type: typing.Dict[typing.Tuple[str, int], exec_result.ExecResult]
203206 expected = None , # type: typing.Optional[typing.List[typing.Union[int, proc_enums.ExitCodes]]]
207+ ** kwargs # type: typing.Any
204208 ): # type: (...) -> None
205209 """Exception during parallel execution.
206210
207211 :param command: command
208212 :type command: str
213+ :param exceptions: Exceptions on connections
214+ :type exceptions: typing.Dict[typing.Tuple[str, int], Exception]
209215 :param errors: results with errors
210216 :type errors: typing.Dict[typing.Tuple[str, int], ExecResult]
211217 :param results: all results
212218 :type results: typing.Dict[typing.Tuple[str, int], ExecResult]
213219 :param expected: expected return codes
214220 :type expected: typing.Optional[typing.List[typing.Union[int, proc_enums.ExitCodes]]]
221+ :keyword _message: error message override
215222 """
216223 expected = expected or [proc_enums .ExitCodes .EX_OK ]
217- self .expected = proc_enums .exit_codes_to_enums (expected )
218- self .cmd = command
219- self .errors = errors
220- self .results = results
221- message = (
222- "Command {self.cmd!r} "
223- "returned unexpected exit codes on several hosts\n "
224- "Expected: {self.expected}\n "
225- "Got:\n "
226- "\t {errors}" .format (
227- self = self ,
228- errors = "\n \t " .join (
229- "{host}:{port} - {code} " .format (host = host , port = port , code = result .exit_code )
230- for (host , port ), result in errors .items ()
224+ prep_expected = proc_enums .exit_codes_to_enums (expected )
225+ message = kwargs .get ("_message" , None ) or (
226+ "Command {cmd!r} "
227+ "during execution raised exceptions: \n "
228+ "\t {exceptions}" .format (
229+ cmd = command ,
230+ exceptions = "\n \t " .join (
231+ "{host}:{port} - {exc} " .format (host = host , port = port , exc = exc )
232+ for (host , port ), exc in exceptions .items ()
231233 ),
232234 )
233235 )
234- super (ParallelCallProcessError , self ).__init__ (message )
236+ super (ParallelCallExceptions , self ).__init__ (
237+ command = command , errors = errors , results = results , expected = prep_expected , _message = message
238+ )
239+ self .cmd = command
240+ self .exceptions = exceptions
0 commit comments