Exemple #1
0
def reset(self, sp='SP', login=True):
    logging.info('Resetting ' + sp)
    self.sendline('reset -script /' + sp)
    i = self.expect(['reset: ', 'Performing reset on'])
    if i == 0:
        output = self.sync(debug=False).strip()
        raise ILOMError(output)
    for connection in self.current[0].connections[:]:
        if connection.origin and connection.origin[0][1].type == sp:
            if connection in SSH.CONNECTIONS:
                connection.close()
            self.current[0].connections.remove(connection)
        elif connection.current[1].type == sp:
            if connection in SSH.CONNECTIONS:
                connection.close()
            self.current[0].connections.remove(connection)
    if self.__class__ is not Console:
        log_empty('No reset output available because SSH connection was used',
                  level=logging.INFO,
                  logger=[debug_logger, file_logger])
        logging.info('Finished resetting ' + sp)
        return None
    login_list = ['(?i)Login:'******'\n'.join(lines).strip()
    if output.startswith(self.prompt):
        output = output[len(self.prompt):].strip()
    log_empty(output, level=logging.INFO, logger=[debug_logger, file_logger])
    if self.match_index == 1:
        raise ILOMError('Timed out in resetting ' + sp)
    if login:
        self.login()
    logging.info('Finished resetting ' + sp)
    return output
Exemple #2
0
 def _power(self, console=None, log=True, timeout=TIMEOUT):
     stack = inspect.stack()
     try:
         command = stack[1][3]
     except IndexError:
         raise EnvironmentError('Invalid command')
     if command != 'off' and command != 'on' and command != 'cycle':
         raise EnvironmentError('Invalid command')
     if self.VNC is None:
         raise EnvironmentError('VNC is not configured for this system')
     else:
         logging.info('Starting VNC ac ' + command)
         try:
             VNC_address, VNC_password, VNC_prompt = self.VNC
         except (ValueError, TypeError):
             raise EnvironmentError('VNC is not configured correctly')
         name = self.name + '@VNC'
         VNC = SSH(self.name,
                   VNC_address,
                   VNC_password,
                   VNC_prompt,
                   name,
                   log=log,
                   timeout=VNC_TIMEOUT)
     if command == 'off' or command == 'cycle':
         for connection in self.connections[:]:
             connection.close(log=log)
     output = VNC.sendcmd('ac ' + command, timeout=120)
     # TODO: Check for failed command
     VNC.close(log=log)
     logging.info('Finished VNC ac ' + command)
     if console is not None and command != 'off':
         logging.info('Waiting for ac ' + command +
                      '. This might take a while...')
         prompt = ['(?i)Login:'******'No output was available'
         log_empty(output,
                   level=logging.INFO,
                   logger=[debug_logger, file_logger])
         if console.match_index == 1:
             raise EnvironmentError('Timed out in ac ' + command)
         logging.info('Finished waiting for ac ' + command)
     else:
         output = None
     return output
Exemple #3
0
def reboot(self, login=True, log=True, timeout=REBOOT_TIMEOUT):
    if not hasattr(self, 'in_console'):
        raise SolarisError('Must be in console')
    if log:
        logging.info('Starting reboot')
    self.sendline('reboot')
    login_list = ['(?i)Console Login:'******'Timed out in reboot')
    if self.match_index == 1:
        raise OpenBootError('Returned to OpenBoot')
    if login:
        self.login(log=log)
    if log:
        logging.info('Finished reboot')
    return output
Exemple #4
0
    def sync(self,
             prompt=None,
             index=0,
             timeout=-1,
             log=False,
             debug=True,
             empty=False,
             after=False):
        """Syncs with the prompt and returns the output.

        :param str prompt: The prompt to expect. If this is `None`, the
            connection's default prompt is used.
        :param int index: The index of the line number of the output that is
            filtered from the start of the output.
        :param int timeout: The timeout value of expecting the prompt.
        :param bool log: The flag for allowing info messages.
        :param bool debug: The flag for allowing debug messages.
        :param bool empty: The flag for logging messages without the prefix.
        :returns: The output until the prompt.
        :rtype: str
        """
        if prompt is None:
            prompt = self.prompt
        self.expect(prompt, timeout=timeout)
        value = self.before.replace('\r', '')
        if after:
            if type(self.after) is str:
                value += self.after.replace('\r', '')
            values = value.split('\n')[index:]
        else:
            values = value.split('\n')[index:-1]
        string = '\n'.join(values)
        if log:
            if empty:
                log_empty(string, level=logging.INFO)
            else:
                logging.info('\n' + string)
        if debug and not log:
            if empty:
                log_empty(string, level=logging.DEBUG)
            else:
                logging.debug('\n' + string)
        return string
Exemple #5
0
def start_system(self,
                 system='System',
                 host='HOST',
                 user=None,
                 boot=True,
                 disk=None,
                 stop=True,
                 force=True,
                 console=False,
                 timeout=-1,
                 boot_timeout=-1,
                 verbose=True):
    """
    """
    if timeout == -1:
        if self.timeout < START_TIMEOUT:
            timeout = START_TIMEOUT
        else:
            timeout = self.timeout
    status = self.show('/' + host, 'status', debug=False)
    if status != 'Powered Off' and status not in STATUS_LIST:
        if stop:
            self.stop_system(system=system, force=force)
            status = self.show('/' + host, 'status', debug=False)
        else:
            raise ILOMError(system + ' is in state ' + status)
    bootmode = '/' + host + '/bootmode'
    if status == 'Powered Off':
        self.set(bootmode, script='setenv auto-boot? false', log=False)
        result = self.sendcmd('start -script /' + system)
        if not result.startswith('Starting'):
            raise ILOMError('Could not start ' + system + '\n' + result)
        if verbose:
            logging.info('Starting ' + system + '. This might take a while...')
    elif status in STATUS_LIST:
        if verbose:
            logging.info(system +
                         ' already started. This might take a while...')
    else:
        raise ILOMError(system + ' is in state ' + status)
    self.start_console(host=host, log=verbose)
    self.switch(user='******')
    self.sendline()
    start_list = [self.prompt, '(?i)Console Login:'******'No start output available'
        if self.match_index != 2:
            start_output += ' because ' + system + ' was already up'
    log_empty(start_output,
              level=logging.INFO,
              logger=[debug_logger, file_logger])
    boot_output = None
    if self.match_index == 2:
        raise ILOMError('Timed out in starting ' + system)
    if verbose:
        logging.info('Finished starting ' + system)
    if self.match_index == 1:
        if not boot or (boot and disk is not None):
            if verbose:
                logging.info('Switching to OpenBoot')
            self.stop_console(log=False)
            domain_control = '/' + host + '/domain/control'
            control_properties = {'auto-boot': 'disabled'}
            self.set(domain_control, log=False, **control_properties)
            self.sendcmd('reset -force -script ' + domain_control, debug=False)
            #self.set(bootmode, script='setenv auto-boot? false', log=False)
            #self.set('/' + host, send_break_action='break', log=False)
            self.start_console(host=host, log=False)
            #self.sendline()
            #i = self.expect_exact(['c)ontinue, s)ync, r)eset?', TimeoutError])
            #if i == 1:
            #    raise ILOMError('Timed out in break')
            #self.sendline('r')
            self.sync(start_list, timeout=TIMEOUT, debug=False)
            if self.match_index == 1:
                raise ILOMError('Returned to login prompt')
            elif self.match_index == 2:
                raise ILOMError('Timed out in resetting ' + system)
            self.switch(user='******', nopage=True)
            if verbose:
                logging.info('Finished switching to OpenBoot')
        if boot and disk is None:
            if verbose:
                logging.info('Starting to boot. This might take a while...')
            boot_output = ('No boot output available because ' + system +
                           ' was started with auto-boot?=true')
            log_empty(boot_output,
                      level=logging.INFO,
                      logger=[debug_logger, file_logger])
            if verbose:
                logging.info('Finished booting')
    if self.match_index == 0:
        if boot:
            boot_output = self.boot(disk=disk, timeout=boot_timeout)
        else:
            self.switch(user='******', nopage=True)
    if boot:
        if user is not None:
            self.switch(subsystem=host, user=user)
            self.login(log=verbose)
    if not console:
        self.stop_console(log=verbose)
    errors = []
    for line in start_output.splitlines():
        if 'ERROR:' in line:
            errors.append(line)
    return (start_output, boot_output, errors)