def runtest_setup(self, item) -> object: try: with open(item.config.getoption('--dut-config')) as cfg: dut_config = yaml.safe_load(cfg) except Exception: raise Exception("You need to specify DUT config. " "See the example_dut_config.py file.") try: TestRun.prepare(item, dut_config) test_name = item.name.split('[')[0] TestRun.LOGGER = create_log(item.config.getoption('--log-path'), test_name) TestRun.setup() self.working_dir = dut_config['working_dir'] self.reinstall = item.config.getoption('--force-reinstall') except Exception as ex: raise Exception(f"Exception occurred during test setup:\n" f"{str(ex)}\n{traceback.format_exc()}") TestRun.LOGGER.info(f"DUT info: {TestRun.dut}") # Prepare DUT for test TestRun.LOGGER.add_build_info(f'Commit hash:') TestRun.LOGGER.add_build_info(f"{get_current_commit_hash()}") TestRun.LOGGER.add_build_info(f'Commit message:') TestRun.LOGGER.add_build_info(f'{get_current_commit_message()}') TestRun.LOGGER.add_build_info(f'OCTF commit hash:') TestRun.LOGGER.add_build_info(f'{get_current_octf_hash()}') TestRun.LOGGER.info(f"DUT info: {TestRun.dut}") TestRun.LOGGER.write_to_command_log("Test body") TestRun.LOGGER.start_group("Test body")
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 try: with open(item.config.getoption('--dut-config')) as cfg: dut_config = yaml.safe_load(cfg) except Exception as ex: raise Exception( f"{ex}\nYou need to specify DUT config. See the example_dut_config.py file" ) dut_config['plugins_dir'] = os.path.join(os.path.dirname(__file__), "../lib") dut_config['opt_plugins'] = { "test_wrapper": {}, "serial_log": {}, "power_control": {} } dut_config['extra_logs'] = {"cas": "/var/log/opencas.log"} try: TestRun.prepare(item, dut_config) test_name = item.name.split('[')[0] TestRun.LOGGER = create_log(item.config.getoption('--log-path'), test_name) TestRun.presetup() try: TestRun.executor.wait_for_connection(timedelta(seconds=20)) except paramiko.AuthenticationException: raise except Exception: try: TestRun.plugin_manager.get_plugin( 'power_control').power_cycle() TestRun.executor.wait_for_connection() except Exception: raise Exception("Failed to connect to DUT.") TestRun.setup() except Exception as ex: raise Exception(f"Exception occurred during test setup:\n" f"{str(ex)}\n{traceback.format_exc()}") TestRun.usr = Opencas(repo_dir=os.path.join(os.path.dirname(__file__), "../../.."), working_dir=dut_config['working_dir']) 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_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: TestRun.block( "You need to specify DUT config. See the example_dut_config.py file." ) if 'test_wrapper' in sys.modules: if 'ip' in dut_config: try: IP(dut_config['ip']) except ValueError: raise ValueError( "IP address from configuration file is in invalid format." ) try: dut_config = test_wrapper.prepare(dut_config) except Exception as ex: 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: 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) TestRun.plugins['opencas'] = OpencasPlugin( repo_dir=os.path.join(os.path.dirname(__file__), "../../.."), working_dir=dut_config['working_dir']) except Exception as exception: 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) TestRun.LOGGER.write_to_command_log("Test body") TestRun.LOGGER.start_group("Test body")
def pytest_runtest_setup(item): TestRun.prepare(item) test_name = item.name.split('[')[0] TestRun.LOGGER = create_log(item.config.getoption('--log-path'), test_name) with TestRun.LOGGER.step("Test initialization"): try: # Open and parse yaml config file try: with open(item.config.getoption('--dut-config')) as cfg: dut_config = yaml.safe_load(cfg) except Exception as e: print(e) exit(1) # Setup from dut config TestRun.setup(dut_config) TestRun.plugins['iotrace'] = IotracePlugin( repo_dir=os.path.join(os.path.dirname(__file__), "../"), working_dir=dut_config['working_dir']) except Exception as e: TestRun.LOGGER.exception(f"{str(e)}\n{traceback.format_exc()}") TestRun.LOGGER.info(f"DUT info: {TestRun.dut}") # Prepare DUT for test with TestRun.LOGGER.step("DUT prepare"): TestRun.LOGGER.add_build_info(f'Commit hash:') TestRun.LOGGER.add_build_info(f"{get_current_commit_hash()}") TestRun.LOGGER.add_build_info(f'Commit message:') TestRun.LOGGER.add_build_info(f'{get_current_commit_message()}') TestRun.LOGGER.add_build_info(f'OCTF commit hash:') TestRun.LOGGER.add_build_info(f'{get_current_octf_hash()}') dut_prepare(item) TestRun.LOGGER.start_group("Test body")