def device(mock_con, request): dev = Device(args['target'], no_probe=True, no_gather_facts=True) dev.facts = request.param return dev
def wait_for_device(self, countdown, poll_delay): dev = None # first we need to wait for the device to be 'reachable' via the API. # we'll use the probe error to detect if it is or not while not dev: msg = 'reload-countdown at: {} seconds'.format(countdown) self.post_device_status(message=msg, state='AWAIT-ONLINE') self.log.info(msg) try: dev = Device(self.target, user=self.user, passwd=self.passwd, timeout=poll_delay) except ProbeError: countdown -= poll_delay if countdown <= 0: errmsg = 'Failed to probe target %s within reload countdown' % self.target self.exit_results(results=dict(ok=False, error_type='login', message=errmsg), exit_error=errmsg) except UnauthorizedError: errmsg = 'Unauthorized - check user/password' self.exit_results(results=dict(ok=False, error_type='login', message=errmsg), exit_error=errmsg) self.dev = dev self.post_device_facts() msg = 'device reachable, waiting for System ready' self.post_device_status(message=msg, state='AWAIT-SYSTEM-READY') self.log.info(msg) while countdown >= 0: msg = 'ready-countdown at: {} seconds'.format(countdown) self.post_device_status(message=msg) self.log.info(msg) try: match = dev.api.exec_opcmd( "show logging | grep 'CONF_CONTROL: System ready'", msg_type='cli_show_ascii') assert len(match) > 0 return except AssertionError: # means that the file does not exist yet, so wait some time # and try again time.sleep(poll_delay) countdown -= poll_delay self.exit_results(results=dict( ok=False, error_type='login', message='%s failed to find "System ready" within reload countdown' % self.target))