Use user-defined exception in execute_on_remote

We need user-defined exception in execute_on_remote to
catch it in failover tests. Base Exception isn't suitable
as it mask all other exception types

Change-Id: Ic48d73c2fabcf32eed8b57db047d60307e8ce63a
Closes-Bug: #1552692
This commit is contained in:
Maksym Strukov 2016-03-03 21:39:26 +02:00
parent 4925947806
commit 0143a79467
4 changed files with 54 additions and 9 deletions

View File

@ -33,6 +33,11 @@ Eb tables
.. automodule:: fuelweb_test.helpers.eb_tables
:members:
Exceptions
----------
.. automodule:: fuelweb_test.helpers.exceptions
:members:
Fuel Actions
------------
.. automodule:: fuelweb_test.helpers.fuel_actions

View File

@ -0,0 +1,33 @@
# 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):
self.ec = ec
self.expected_ec = expected_ec
self.cmd = command
self.stdout = stdout
self.stderr = stderr
def __str__(self):
message = "Command '{cmd:s}' returned unexpected exit code {code:d}," \
" while waiting for {exp:d}".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

View File

@ -25,6 +25,7 @@ from devops.helpers.helpers import wait
from devops.models.node import SSHClient
from fuelweb_test import logger
from fuelweb_test.helpers.metaclasses import SingletonMeta
from fuelweb_test.helpers.exceptions import UnexpectedExitCode
class SSHManager(object):
@ -163,7 +164,14 @@ class SSHManager(object):
"""
if assert_ec_equal is None:
assert_ec_equal = [0]
result = self.execute(ip=ip, port=port, cmd=cmd)
result['stdout_str'] = ''.join(result['stdout']).strip()
result['stdout_len'] = len(result['stdout'])
result['stderr_str'] = ''.join(result['stderr']).strip()
result['stderr_len'] = len(result['stderr'])
if result['exit_code'] not in assert_ec_equal:
error_details = {
'command': cmd,
@ -180,12 +188,11 @@ class SSHManager(object):
"Details: {2}".format(error_msg, cmd, error_details))
logger.error(log_msg)
if raise_on_assert:
raise Exception(log_msg)
result['stdout_str'] = ''.join(result['stdout']).strip()
result['stdout_len'] = len(result['stdout'])
result['stderr_str'] = ''.join(result['stderr']).strip()
result['stderr_len'] = len(result['stderr'])
raise UnexpectedExitCode(cmd,
result['exit_code'],
assert_ec_equal,
stdout=result['stdout_str'],
stderr=result['stderr_str'])
if jsonify:
try:

View File

@ -15,7 +15,6 @@ import tempfile
import textwrap
from devops.helpers.helpers import wait
from devops import error
from proboscis.asserts import assert_equal
from proboscis.asserts import assert_not_equal
from proboscis.asserts import assert_raises
@ -28,6 +27,7 @@ from fuelweb_test.helpers import utils
from fuelweb_test.helpers.decorators import log_snapshot_after_test
from fuelweb_test import settings
from fuelweb_test.tests import base_test_case
from fuelweb_test.helpers.exceptions import UnexpectedExitCode
@test(groups=["ubuntu_bootstrap_builder", "bvt_ubuntu_bootstrap"])
@ -290,7 +290,7 @@ class UbuntuBootstrapBuild(base_test_case.TestBasic):
"Bootstrap {0} was not deleted and still available: {1}"
.format(uuid, bootstrap_uuids))
assert_raises(error.DevopsCalledProcessError,
assert_raises(UnexpectedExitCode,
self.env.fuel_bootstrap_actions.activate_bootstrap_image,
uuid)
@ -300,7 +300,7 @@ class UbuntuBootstrapBuild(base_test_case.TestBasic):
uuid = self.env.fuel_bootstrap_actions.get_active_bootstrap_uuid()
assert_raises(
error.DevopsCalledProcessError,
UnexpectedExitCode,
self.env.fuel_bootstrap_actions.delete_bootstrap_image,
uuid)