class PowerControlPlugin: def __init__(self, params, config): print("Power Control LibVirt Plugin initialization") try: self.ip = config['ip'] self.user = config['user'] except Exception: raise Exception("Missing fields in config! ('ip' and 'user' required)") def pre_setup(self): print("Power Control LibVirt Plugin pre setup") if self.config['connection_type'] == 'ssh': self.executor = SshExecutor( self.ip, self.user, self.config.get('port', 22) ) else: self.executor = LocalExecutor() def post_setup(self): pass def teardown(self): pass def power_cycle(self): self.executor.run(f"virsh reset {self.config['domain']}") TestRun.executor.wait_for_connection_loss() timeout = TestRun.config.get('reboot_timeout') if timeout: TestRun.executor.wait_for_connection(timedelta(seconds=int(timeout))) else: TestRun.executor.wait_for_connection()
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 in the config/configuration.py file there should be added path to it: # test_wrapper_dir = 'wrapper_path' LOGGER.info(f"**********Test {request.node.name} started!**********") try: dut_config = importlib.import_module(f"config.{request.config.getoption('--dut-config')}") except: dut_config = None if os.path.exists(c.test_wrapper_dir): if hasattr(dut_config, 'ip'): try: IP(dut_config.ip) except ValueError: raise Exception("IP address from configuration file is in invalid format.") TestProperties.dut = Dut(test_wrapper.prepare(request, dut_config)) elif dut_config is not None: if hasattr(dut_config, 'ip'): try: IP(dut_config.ip) if hasattr(dut_config, 'user') and hasattr(dut_config, 'password'): executor = SshExecutor(dut_config.ip, dut_config.user, dut_config.password) TestProperties.executor = executor else: raise Exception("There is no credentials in config file.") if hasattr(dut_config, 'disks'): TestProperties.dut = Dut({'ip': dut_config.ip, 'disks': dut_config.disks}) else: TestProperties.dut = Dut( {'ip': dut_config.ip, 'disks': disk_finder.find_disks()}) except ValueError: raise Exception("IP address from configuration file is in invalid format.") elif hasattr(dut_config, 'disks'): TestProperties.executor = LocalExecutor() TestProperties.dut = Dut({'disks': dut_config.disks}) else: TestProperties.executor = LocalExecutor() TestProperties.dut = Dut({'disks': disk_finder.find_disks()}) else: raise Exception( "There is neither configuration file nor test wrapper attached to tests execution.") yield TestProperties.LOGGER.info("Test cleanup") casadm.stop_all_caches() if os.path.exists(c.test_wrapper_dir): test_wrapper.cleanup(TestProperties.dut)
def pre_setup(self): print("Power Control LibVirt Plugin pre setup") if self.config['connection_type'] == 'ssh': self.executor = SshExecutor( self.ip, self.user, self.config.get('port', 22) ) else: self.executor = LocalExecutor()
def get_current_commit_hash(from_dut: bool = False): executor = TestRun.executor if from_dut else LocalExecutor() repo_path = TestRun.usr.working_dir if from_dut else TestRun.usr.repo_dir return executor.run( f"cd {repo_path} &&" f'git show HEAD -s --pretty=format:"%H"').stdout
def __setup(cls, dut_config): if not dut_config: TestRun.block("You need to specify DUT config!") if dut_config['type'] == 'ssh': try: IP(dut_config['ip']) except ValueError: TestRun.block("IP address from config is in invalid format.") port = dut_config.get('port', 22) if 'user' in dut_config and 'password' in dut_config: cls.executor = SshExecutor(dut_config['ip'], dut_config['user'], dut_config['password'], port) else: TestRun.block("There are no credentials in config.") elif dut_config['type'] == 'local': cls.executor = LocalExecutor() else: TestRun.block("Execution type (local/ssh) is missing in DUT config!") if list(cls.item.iter_markers(name="remote_only")): if not cls.executor.is_remote(): pytest.skip() if dut_config.get('allow_disk_autoselect', False): dut_config["disks"] = disk_finder.find_disks() try: cls.dut = Dut(dut_config) except Exception as ex: TestRun.LOGGER.exception(f"Failed to setup DUT instance:\n" f"{str(ex)}\n{traceback.format_exc()}") cls.__setup_disks()
def __presetup(cls): cls.plugin_manager = PluginManager(cls.item, cls.config) cls.plugin_manager.hook_pre_setup() if cls.config['type'] == 'ssh': try: IP(cls.config['ip']) except ValueError: TestRun.block("IP address from config is in invalid format.") port = cls.config.get('port', 22) if 'user' in cls.config and 'password' in cls.config: cls.executor = SshExecutor(cls.config['ip'], cls.config['user'], cls.config['password'], port) else: TestRun.block("There are no credentials in config.") elif cls.config['type'] == 'local': cls.executor = LocalExecutor() else: TestRun.block("Execution type (local/ssh) is missing in DUT config!")
def get_current_commit_hash(): local_executor = LocalExecutor() return local_executor.run("cd " + TestRun.plugins['iotrace'].repo_dir + " && " + 'git show HEAD -s --pretty=format:"%H"').stdout
def get_current_octf_hash(): local_executor = LocalExecutor() return local_executor.run("cd " + TestRun.plugins['iotrace'].repo_dir + "/modules/open-cas-telemetry-framework && " + 'git show HEAD -s --pretty=format:"%H"').stdout
def get_current_commit_message(): local_executor = LocalExecutor() return local_executor.run(f"cd {TestRun.plugins['iotrace'].repo_dir} &&" f'git show HEAD -s --pretty=format:"%B"').stdout
def get_current_commit_hash(): local_executor = LocalExecutor() return local_executor.run(f"cd {TestRun.plugins['opencas'].repo_dir} &&" f'git show HEAD -s --pretty=format:"%H"').stdout