Raise exception instead of using TestRun.exception()

Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
Robert Baldyga 2019-11-29 10:54:50 +01:00
parent 18c77daec9
commit 263f3137da
3 changed files with 15 additions and 18 deletions

View File

@ -8,6 +8,7 @@ import logging
from tests import conftest
from core.test_run import TestRun
from test_utils.output import CmdException
def install_opencas():
@ -23,22 +24,19 @@ def install_opencas():
"./configure && "
"make -j")
if output.exit_code != 0:
TestRun.exception(
f"Make command executed with nonzero status: {output.stdout}\n{output.stderr}")
raise CmdException("Make command executed with nonzero status", output)
TestRun.LOGGER.info("Installing Open CAS")
output = TestRun.executor.run(
f"cd {TestRun.plugins['opencas'].working_dir} && "
f"make install")
if output.exit_code != 0:
TestRun.exception(
f"Error while installing Open CAS: {output.stdout}\n{output.stderr}")
raise CmdException("Error while installing Open CAS", output)
TestRun.LOGGER.info("Check if casadm is properly installed.")
output = TestRun.executor.run("casadm -V")
if output.exit_code != 0:
TestRun.exception(
f"'casadm -V' command returned an error: {output.stdout}\n{output.stderr}")
raise CmdException("'casadm -V' command returned an error", output)
else:
TestRun.LOGGER.info(output.stdout)
@ -47,14 +45,13 @@ def uninstall_opencas():
TestRun.LOGGER.info("Uninstalling Open CAS")
output = TestRun.executor.run("casadm -V")
if output.exit_code != 0:
TestRun.exception("Open CAS is not properly installed")
raise CmdException("Open CAS is not properly installed", output)
else:
TestRun.executor.run(
f"cd {TestRun.plugins['opencas'].working_dir} && "
f"make uninstall")
if output.exit_code != 0:
TestRun.exception(
f"There was an error during uninstall process: {output.stdout}\n{output.stderr}")
raise CmdException("There was an error during uninstall process", output)
def reinstall_opencas():

@ -1 +1 @@
Subproject commit c58510d62691ec0984dbbbf151f1bba86c65cff4
Subproject commit 1c075f00dd6b02e9c563b10d35dc497a61c59225

View File

@ -64,18 +64,18 @@ def pytest_runtest_setup(item):
try:
IP(dut_config['ip'])
except ValueError:
TestRun.exception(
raise ValueError(
"IP address from configuration file is in invalid format.")
try:
dut_config = test_wrapper.prepare(dut_config)
except Exception as ex:
TestRun.LOGGER.exception(f"Exception occurred on test wrapper prepare stage:\n"
f"{str(ex)}\n{traceback.format_exc()}")
raise Exception(f"Exception occurred on test wrapper prepare stage:\n"
f"{str(ex)}\n{traceback.format_exc()}")
try:
TestRun.setup(dut_config)
except Exception as ex:
TestRun.LOGGER.exception(f"Exception occurred during test setup:\n"
f"{str(ex)}\n{traceback.format_exc()}")
raise Exception(f"Exception occurred during test setup:\n"
f"{str(ex)}\n{traceback.format_exc()}")
if 'test_wrapper' in sys.modules:
test_wrapper.try_setup_serial_log(dut_config)
@ -85,8 +85,8 @@ def pytest_runtest_setup(item):
working_dir=dut_config['working_dir'])
except Exception as exception:
TestRun.LOGGER.exception(f"Conftest prepare exception:\n"
f"{str(exception)}\n{traceback.format_exc()}")
raise Exception(f"Conftest prepare exception:\n"
f"{str(exception)}\n{traceback.format_exc()}")
TestRun.LOGGER.info(f"DUT info: {TestRun.dut}")
base_prepare(item)
@ -197,7 +197,7 @@ def base_prepare(item):
for disk in TestRun.dut.disks:
disk.umount_all_partitions()
if not create_partition_table(disk, PartitionTable.gpt):
TestRun.exception(f"Failed to remove partitions from {disk}")
raise Exception(f"Failed to remove partitions from {disk}")
if get_force_param(item) and not TestRun.plugins['opencas'].already_updated:
installer.reinstall_opencas()