def minimal_needed_configuration(node, timeout=60, extra_sls=[]): full_sls = sls_list + extra_sls logging.debug('Executing salt script[{}]'.format(full_sls)) for sls in full_sls: local = LocalNode() local.pwd() try: local.shell(get_salt_cmd(sls, get_provision_ip(node))) except: raise Exception('Salt execution failed: ' + sys.exc_info()[1]) finally: logging.debug('Salt Status:' + str(local.status)) logging.debug('Satl Output:' + local.stdout.rstrip()) logging.debug('Salt Errors:' + local.stderr) logging.debug('Executed salt script[{}]'.format(full_sls))
def last_nonempty_line(filepath): """Return last non empty and not auxillary conman line filepath: path to file for finding last line Function is using some magic string which are defined in conman. """ tail = LocalNode() tail.shell('tail -n 100 ' + filepath, stop=True, quiet=True, die=False) for str in reversed(tail.stdout.rstrip().splitlines()): if str == '' or \ str.startswith('<ConMan> Console') or \ re.search(r'\d\d\d\d-\d\d-\d\d\s+\d\d:\d\d:\d\d\s*$', str): continue else: return str return 'no_meaningful_line_found'
def exec_bmc_command(node, ipmi_command): cmd = get_ipmi_cmd(node['bmc_ip'], ipmi_command) local = LocalNode() try: logging.debug('Execute command: ' + cmd) local.shell(cmd, trace=True) except: BMCException(sys.exc_info()[1]) logging.debug('Status:' + str(local.status)) logging.debug('Output:' + local.stdout.rstrip()) logging.debug('Errors:' + local.stderr) if local.status == 0: logging.debug("Command '%s' executed successfully" % cmd) # TODO check retrun results from results else: logging.debug("Command '%s' failed, raise exception" % cmd) raise BMCException( "ipmitool call failed with status[{}], stdout [{}], stderr[{}]". format(local.status, local.stdout.rstrip(), local.stderr))