From 263f3137dafd20a8bc370476b2d7c0c05204ef07 Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Fri, 29 Nov 2019 10:54:50 +0100 Subject: [PATCH] Raise exception instead of using TestRun.exception() Signed-off-by: Robert Baldyga --- test/functional/api/cas/installer.py | 15 ++++++--------- test/functional/test-framework | 2 +- test/functional/tests/conftest.py | 16 ++++++++-------- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/test/functional/api/cas/installer.py b/test/functional/api/cas/installer.py index f3059a3..614dd47 100644 --- a/test/functional/api/cas/installer.py +++ b/test/functional/api/cas/installer.py @@ -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(): diff --git a/test/functional/test-framework b/test/functional/test-framework index c58510d..1c075f0 160000 --- a/test/functional/test-framework +++ b/test/functional/test-framework @@ -1 +1 @@ -Subproject commit c58510d62691ec0984dbbbf151f1bba86c65cff4 +Subproject commit 1c075f00dd6b02e9c563b10d35dc497a61c59225 diff --git a/test/functional/tests/conftest.py b/test/functional/tests/conftest.py index aad034e..9dd559a 100644 --- a/test/functional/tests/conftest.py +++ b/test/functional/tests/conftest.py @@ -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()