Use "require_disk" mark
Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
@@ -36,8 +36,52 @@ pytest_options = {}
|
||||
def get_pytest_options(request):
|
||||
pytest_options["remote"] = request.config.getoption("--remote")
|
||||
pytest_options["branch"] = request.config.getoption("--repo-tag")
|
||||
pytest_options["force_reinstall"] = request.config.getoption("--force-reinstall")
|
||||
pytest_options["log_path"] = request.config.getoption("--log-path")
|
||||
|
||||
|
||||
def pytest_runtest_setup(item):
|
||||
# There should be dut config file added to config package and
|
||||
# pytest should be executed with option --dut-config=conf_name'.
|
||||
#
|
||||
# 'ip' field should be filled with valid IP string to use remote ssh executor
|
||||
# or it should be commented out when user want to execute tests on local machine
|
||||
#
|
||||
# User can also have own test wrapper, which runs test prepare, cleanup, etc.
|
||||
# Then it should be placed in plugins package
|
||||
|
||||
TestRun.prepare(item)
|
||||
|
||||
test_name = item.name.split('[')[0]
|
||||
TestRun.LOGGER = create_log(item.config.getoption('--log-path'), test_name)
|
||||
|
||||
with TestRun.LOGGER.step("Dut prepare"):
|
||||
try:
|
||||
try:
|
||||
with open(item.config.getoption('--dut-config')) as cfg:
|
||||
dut_config = yaml.safe_load(cfg)
|
||||
except Exception:
|
||||
dut_config = {}
|
||||
|
||||
if 'test_wrapper' in sys.modules:
|
||||
if 'ip' in dut_config:
|
||||
try:
|
||||
IP(dut_config['ip'])
|
||||
except ValueError:
|
||||
raise Exception("IP address from configuration file is in invalid format.")
|
||||
dut_config = test_wrapper.prepare(dut_config)
|
||||
|
||||
TestRun.setup(dut_config)
|
||||
|
||||
if 'test_wrapper' in sys.modules:
|
||||
test_wrapper.try_setup_serial_log(dut_config)
|
||||
|
||||
TestRun.plugins['opencas'] = {'already_updated': False}
|
||||
except Exception as e:
|
||||
TestRun.LOGGER.exception(f"{str(e)}\n{traceback.format_exc()}")
|
||||
TestRun.LOGGER.info(f"DUT info: {TestRun.dut}")
|
||||
|
||||
base_prepare(item)
|
||||
TestRun.LOGGER.write_to_command_log("Test body")
|
||||
TestRun.LOGGER.start_group("Test body")
|
||||
|
||||
|
||||
def pytest_runtest_teardown():
|
||||
@@ -69,54 +113,8 @@ def pytest_runtest_teardown():
|
||||
TestRun.LOGGER.get_additional_logs()
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def prepare_and_cleanup(request):
|
||||
"""
|
||||
This fixture returns the dictionary, which contains DUT ip, IPMI, spider, list of disks.
|
||||
This fixture also returns the executor of commands
|
||||
"""
|
||||
|
||||
# There should be dut config file added to config package and
|
||||
# pytest should be executed with option --dut-config=conf_name'.
|
||||
#
|
||||
# 'ip' field should be filled with valid IP string to use remote ssh executor
|
||||
# or it should be commented out when user want to execute tests on local machine
|
||||
#
|
||||
# User can also have own test wrapper, which runs test prepare, cleanup, etc.
|
||||
# Then it should be placed in plugins package
|
||||
|
||||
test_name = request.node.name.split('[')[0]
|
||||
TestRun.LOGGER = create_log(f'{get_log_path_param()}', test_name)
|
||||
|
||||
with TestRun.LOGGER.step("Dut prepare"):
|
||||
try:
|
||||
try:
|
||||
with open(request.config.getoption('--dut-config')) as cfg:
|
||||
dut_config = yaml.safe_load(cfg)
|
||||
except Exception:
|
||||
dut_config = {}
|
||||
|
||||
if 'test_wrapper' in sys.modules:
|
||||
if 'ip' in dut_config:
|
||||
try:
|
||||
IP(dut_config['ip'])
|
||||
except ValueError:
|
||||
raise Exception("IP address from configuration file is in invalid format.")
|
||||
dut_config = test_wrapper.prepare(request.param, dut_config)
|
||||
|
||||
TestRun.prepare(dut_config)
|
||||
|
||||
if 'test_wrapper' in sys.modules:
|
||||
test_wrapper.try_setup_serial_log(dut_config)
|
||||
|
||||
TestRun.plugins['opencas'] = {'already_updated': False}
|
||||
except Exception as e:
|
||||
TestRun.LOGGER.exception(f"{str(e)}\n{traceback.format_exc()}")
|
||||
TestRun.LOGGER.info(f"DUT info: {TestRun.dut}")
|
||||
|
||||
base_prepare()
|
||||
TestRun.LOGGER.write_to_command_log("Test body")
|
||||
TestRun.LOGGER.start_group("Test body")
|
||||
def pytest_configure(config):
|
||||
TestRun.configure(config)
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
@@ -137,14 +135,6 @@ def get_branch():
|
||||
return pytest_options["branch"]
|
||||
|
||||
|
||||
def get_force_param():
|
||||
return pytest_options["force_reinstall"]
|
||||
|
||||
|
||||
def get_log_path_param():
|
||||
return pytest_options["log_path"]
|
||||
|
||||
|
||||
def unmount_cas_devices():
|
||||
output = TestRun.executor.run("cat /proc/mounts | grep cas")
|
||||
# If exit code is '1' but stdout is empty, there is no mounted cas devices
|
||||
@@ -173,7 +163,11 @@ def kill_all_io():
|
||||
TestRun.executor.run("pkill --signal SIGKILL fio*")
|
||||
|
||||
|
||||
def base_prepare():
|
||||
def get_force_param(item):
|
||||
return item.config.getoption("--force-reinstall") is not "False"
|
||||
|
||||
|
||||
def base_prepare(item):
|
||||
with TestRun.LOGGER.step("Cleanup before test"):
|
||||
Udev.enable()
|
||||
kill_all_io()
|
||||
@@ -185,7 +179,7 @@ def base_prepare():
|
||||
except Exception:
|
||||
pass # TODO: Reboot DUT if test is executed remotely
|
||||
|
||||
if get_force_param() is not "False" and not TestRun.plugins['opencas']['already_updated']:
|
||||
if get_force_param(item) and not TestRun.plugins['opencas']['already_updated']:
|
||||
installer.reinstall_opencas()
|
||||
elif not installer.check_if_installed():
|
||||
installer.install_opencas()
|
||||
|
Reference in New Issue
Block a user