How to use _recover_hosts method in autotest

Best Python code snippet using autotest_python

recover_hosts.py

Source:recover_hosts.py Github

copy

Full Screen

...12 def recover_():13 hosts = HostsToRecover._get_hosts_to_recover(scope='function')14 if hosts:15 HostsToRecover._reset('function')16 HostsToRecover._recover_hosts(hosts, 'function')17 request.addfinalizer(recover_)18@fixture(scope='class', autouse=True)19def hosts_recover_class(request):20 def recover_hosts():21 hosts = HostsToRecover._get_hosts_to_recover(scope='class')22 if hosts:23 HostsToRecover._reset('class')24 HostsToRecover._recover_hosts(hosts, 'class')25 request.addfinalizer(recover_hosts)26@fixture(scope='module', autouse=True)27def hosts_recover_module(request):28 def recover_hosts():29 hosts = HostsToRecover._get_hosts_to_recover(scope='module')30 if hosts:31 HostsToRecover._reset('module')32 HostsToRecover._recover_hosts(hosts, 'module')33 request.addfinalizer(recover_hosts)34class HostsToRecover():35 __hosts_to_recover = {36 'function': [],37 'class': [],38 'module': [],39 }40 @classmethod41 def __check_scope(cls, scope):42 valid_scope = cls.__hosts_to_recover.keys()43 if scope not in valid_scope:44 raise ValueError(45 "scope has to be one of the following: {}".format(valid_scope))46 @classmethod47 def add(cls, hostnames, scope='function'):48 """49 Add host(s) to recover list. Will wait for host(s) to recover as test50 teardown.51 Args:52 hostnames (str|list):53 scope54 """55 if scope is None:56 return57 cls.__check_scope(scope)58 if isinstance(hostnames, str):59 hostnames = [hostnames]60 cls.__hosts_to_recover[scope] += hostnames61 @classmethod62 def remove(cls, hostnames, scope='function'):63 """64 Remove host(s) from recover list. Only remove one instance if host65 has multiple occurances in the recover list.66 Args:67 hostnames (str|list|tuple):68 scope:69 """70 if scope is None:71 return72 cls.__check_scope(scope)73 if isinstance(hostnames, str):74 hostnames = [hostnames]75 for host in hostnames:76 cls.__hosts_to_recover[scope].remove(host)77 @classmethod78 def _reset(cls, scope):79 cls.__hosts_to_recover[scope] = []80 @classmethod81 def _get_hosts_to_recover(cls, scope):82 return list(cls.__hosts_to_recover[scope])83 @staticmethod84 def _recover_hosts(hostnames, scope):85 if system_helper.is_aio_simplex():86 LOG.fixture_step('{} Recover simplex host'.format(scope))87 host_helper.recover_simplex(fail_ok=False)88 return89 # Recover hosts for non-simplex system90 hostnames = sorted(set(hostnames))91 table_ = table_parser.table(cli.system('host-list')[1])92 table_ = table_parser.filter_table(table_, hostname=hostnames)93 # unlocked_hosts = table_parser.get_values(table_, 'hostname',94 # administrative='unlocked')95 locked_hosts = table_parser.get_values(table_, 'hostname',96 administrative='locked')97 err_msg = []98 if locked_hosts:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful