def run_commands(exec_dir, kind_bench, commands, stdout_tee=None, stderr_tee=None, target=None): returncode = -1 output = '' pwd = os.getcwd() os.chdir(exec_dir) try: # the commands is multiple lines, and was included by Quotation actual_commands = get_actual_commands(commands, target) try: logging.debug("the actual commands running in local is: %s" % actual_commands) result = utils.run(actual_commands, stdout_tee=stdout_tee, stderr_tee=stderr_tee, verbose=True) except error.CmdError, e: raise error.ServRunError(e.args[0], e.args[1]) except Exception, e: logging.debug(e)
def judge_target_crash(): result = -1 try: client = settings.get_value('CLIENT', 'ip', type=str) commands = 'ping -c 10 %s' % client result = utils.run(commands) except error.CmdError: return True else: if result.exit_status: return True else: output = result.stdout if re.search("100%\spacket\sloss", output): return True else: return False
def run_commands(exec_dir, classify, bench_name, commands, stdout_tee=None, stderr_tee=None): returncode = -1 output = '' pwd = os.getcwd() os.chdir(exec_dir) caliper_dir = os.path.abspath(os.path.join(exec_dir, "..", "..")) try: # the commands is multiple lines, and was included by Quotation if commands[0] == '\'' or commands[0] == '\"': actual_commands = commands[1:-1] try: logging.debug("the actual commands running is: %s" % actual_commands) result = utils.run(actual_commands, stdout_tee=stdout_tee, stderr_tee=stderr_tee, verbose=True) except error.CmdError, e: raise error.ServRunError(e.args[0], e.args[1]) #elif re.search('\.py', commands ) or re.search('\.sh', commands): # script_file_path = os.path.join(caliper_dir, TEST_CFG_DIR, classify, bench_name, commands) # if re.search(".*?\.py", commands): # try: # result = utils.run("python %s" % script_file_path, stdout_tee=stdout_tee, # stderr_tee=stderr_tee, verbose=True) # except error.CmdError, e: # raise error.ServRunError(e.args[0], e.args[1]) # else: # if re.search(".*?\.sh", commands): # try: # result = utils.run("%s %s" % (shell_path, script_file_path), # stdout_tee= stdout_tee, stderr_tee=stderr_tee, verbose=True) # except error.CmdError, e: # raise error.ServRunError(e.args[0], e.args[1]) else:
# try: # result = utils.run("python %s" % script_file_path, stdout_tee=stdout_tee, # stderr_tee=stderr_tee, verbose=True) # except error.CmdError, e: # raise error.ServRunError(e.args[0], e.args[1]) # else: # if re.search(".*?\.sh", commands): # try: # result = utils.run("%s %s" % (shell_path, script_file_path), # stdout_tee= stdout_tee, stderr_tee=stderr_tee, verbose=True) # except error.CmdError, e: # raise error.ServRunError(e.args[0], e.args[1]) else: try: result = utils.run(commands, stdout_tee=stdout_tee, stderr_tee=stderr_tee, verbose=True) except error.CmdError, e: raise error.ServRunError(e.args[0], e.args[1]) except Exception, e: logging.info(e) else: returncode = result.exit_status try: output = result.stdout except Exception: output = result.stderr os.chdir(pwd) return [output, returncode]