fuel-qa/fuelweb_test/helpers/exceptions.py
Alexey Stepanov b661d47b32 Pylint: fix trivial issues 2
Change-Id: Id29cb8831714fd96960f85c29d866084a5565f5c
fix: invalid import order, double import, relative import, no super call, instance defined outside of init, incorrect __all__ variable
Related-bug: #1556791
2016-03-16 10:30:31 +03:00

42 lines
1.7 KiB
Python

# Copyright 2016 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
class UnexpectedExitCode(Exception):
def __init__(self, command, ec, expected_ec, stdout=None, stderr=None):
"""Exception for unexpected exit code after executing shell/ssh command
:param command: str - executed command
:param ec: int - actual exit code
:param expected_ec: list of integers - expected exit codes
:param stdout: str
:param stderr: str
"""
self.ec = ec
self.expected_ec = expected_ec
self.cmd = command
self.stdout = stdout
self.stderr = stderr
super(UnexpectedExitCode, self).__init__()
def __str__(self):
message = "Command '{cmd:s}' returned unexpected exit code {code:d}," \
" while waiting for {exp}".format(cmd=self.cmd,
code=self.ec,
exp=self.expected_ec)
if self.stdout:
message += "stdout: {}\n".format(self.stdout)
if self.stderr:
message += "stderr: {}\n".format(self.stderr)
return message