def run(self, connection, args=None): # Prompts commonly include # - when logging such strings, # use lazy logging or the string will not be quoted correctly. def check_prompt_characters(prompt): if not any([True for c in DISTINCTIVE_PROMPT_CHARACTERS if c in prompt]): self.logger.warning(self.check_prompt_characters_warning % prompt) # pylint: disable=logging-not-lazy # Skip auto login if the configuration is not found params = self.parameters.get('auto_login', None) if params is None: self.logger.debug("Skipping of auto login") else: self.logger.debug("Waiting for the login prompt") connection.prompt_str = params['login_prompt'] self.wait(connection) connection.sendline(params['username']) if 'password_prompt' in params: self.logger.debug("Waiting for password prompt") connection.prompt_str = params['password_prompt'] self.wait(connection) connection.sendline(params['password']) # prompt_str can be a list or str connection.prompt_str = [DEFAULT_SHELL_PROMPT] prompts = self.parameters.get('prompts', None) if isinstance(prompts, list): connection.prompt_str.extend(prompts) for prompt in prompts: check_prompt_characters(prompt) self.logger.debug("Setting shell prompt(s) to %s" % ', '.join(connection.prompt_str)) # pylint: disable=logging-not-lazy else: connection.prompt_str.extend([prompts]) check_prompt_characters(prompts) self.logger.debug("Setting shell prompt(s) to %s" % connection.prompt_str) # pylint: disable=logging-not-lazy # may need to force a prompt here. wait_for_prompt(connection.raw_connection, connection.prompt_str, connection.timeout.duration, '#') # self.wait(connection) connection.sendline('export PS1="%s"' % DEFAULT_SHELL_PROMPT) return connection
def run(self, connection, args=None): def check_prompt_characters(prompt): if not any([True for c in DISTINCTIVE_PROMPT_CHARACTERS if c in prompt]): self.logger.warning(self.check_prompt_characters_warning % prompt) # Skip auto login if the configuration is not found params = self.parameters.get('auto_login', None) if params is None: self.logger.debug("Skipping of auto login") else: self.logger.debug("Waiting for the login prompt") connection.prompt_str = params['login_prompt'] self.wait(connection) connection.sendline(params['username']) if 'password_prompt' in params: self.logger.debug("Waiting for password prompt") connection.prompt_str = params['password_prompt'] self.wait(connection) connection.sendline(params['password']) # prompt_str can be a list or str connection.prompt_str = [DEFAULT_SHELL_PROMPT] prompts = self.parameters.get('prompts', None) if isinstance(prompts, list): connection.prompt_str.extend(prompts) for prompt in prompts: check_prompt_characters(prompt) else: connection.prompt_str.extend([prompts]) check_prompt_characters(prompts) self.logger.debug("Setting shell prompt") # may need to force a prompt here. wait_for_prompt(connection.raw_connection, connection.prompt_str, connection.timeout.duration, '#') # self.wait(connection) connection.sendline('export PS1="%s"' % DEFAULT_SHELL_PROMPT) return connection
def run(self, connection, args=None): self.logger.debug("%s: Waiting for prompt %s", self.name, ' '.join(connection.prompt_str)) wait_for_prompt(connection.raw_connection, connection.prompt_str, connection.timeout.duration, '#') return connection
def wait_for_prompt(self, timeout=-1): wait_for_prompt(self._connection, self._prompt_str, timeout)
def wait_for_prompt(self, timeout=-1, check_char='#'): wait_for_prompt(self._connection, self._prompt_str, timeout, check_char)
def wait_for_prompt(self, timeout=-1, check_char='#'): return wait_for_prompt(self._connection, self._prompt_str, timeout, check_char)