def getRemoteExecuteCmdArgs(self, test, runMachine, localArgs, postfix): scriptFileName = test.makeTmpFileName("run_test" + postfix + ".sh", forComparison=0) openType = "w" if os.name == "posix" else "wb" # the 'b' is necessary so we don't get \r\n written when we just want \n scriptFile = open(scriptFileName, openType) scriptFile.write("#!/bin/sh\n\n") # Need to change working directory remotely tmpDir = self.getTmpDirectory(test) scriptFile.write("cd " + plugins.quote(tmpDir) + "\n") # Must set the environment remotely remoteTmp = test.app.getRemoteTmpDirectory()[1] for arg, value in self.getEnvironmentArgs(test, remoteTmp, postfix): # Two step export process for compatibility with CYGWIN and older versions of 'sh' scriptFile.write(arg + "=" + value + "\n") scriptFile.write("export " + arg + "\n") if test.app.getConfigValue("remote_shell_program") == "ssh": # SSH doesn't kill remote processes, create a kill script scriptFile.write('echo "kill $$" > kill_test.sh\n') cmdString = " ".join(map(self.quoteLocalArg, localArgs)) if remoteTmp: cmdString = cmdString.replace(test.app.writeDirectory, remoteTmp) scriptFile.write("exec " + cmdString + "\n") scriptFile.close() os.chmod(scriptFileName, 0775) # make executable remoteTmp = test.app.getRemoteTestTmpDir(test)[1] if remoteTmp: test.app.copyFileRemotely(scriptFileName, "localhost", remoteTmp, runMachine) remoteScript = os.path.join(remoteTmp, os.path.basename(scriptFileName)) return test.app.getCommandArgsOn(runMachine, [ plugins.quote(remoteScript) ]) else: return test.app.getCommandArgsOn(runMachine, [ plugins.quote(scriptFileName) ])
def getEnvironmentArgs(self, test, remoteTmp, postfix): vars = self.getEnvironmentChanges(test, postfix) args = [] localTmpDir = test.app.writeDirectory builtinVars = [ "TEXTTEST_CHECKOUT", "TEXTTEST_CHECKOUT_NAME", "TEXTTEST_ROOT", "TEXTTEST_SANDBOX", "TEXTTEST_SANDBOX_ROOT", "STORYTEXT_HOME_LOCAL" ] for var, value in vars: if var in builtinVars: continue if remoteTmp: remoteValue = value.replace(localTmpDir, remoteTmp) else: remoteValue = value currentValue = os.getenv(var) if currentValue: remoteValue = remoteValue.replace(currentValue, "${" + var + "}") if var == "PATH" and os.name == "nt": # We assume cygwin paths, make sure we use POSIX path separators remoteValue = remoteValue.replace(";", ":") remoteValue = plugins.quote(remoteValue) args.append((var, remoteValue)) return args
def fetchRemoteFiles(self, test, machine, tmpDir): sourcePaths = os.path.join(plugins.quote(tmpDir, '"'), "*") test.app.copyFileRemotely(sourcePaths, machine, test.getDirectory(temporary=1), "localhost")
def killRemoteProcess(self, test, machine): tmpDir = self.getTmpDirectory(test) remoteScript = os.path.join(tmpDir, "kill_test.sh") test.app.runCommandOn(machine, [ "sh", plugins.quote(remoteScript) ])
def getSlaveCommand(self, test, submissionRules): cmdArgs = [ plugins.getTextTestProgram(), "-d", ":".join(self.optionMap.rootDirectories), "-a", test.app.name + test.app.versionSuffix(), "-l", "-tp", plugins.quote(test.getRelPath()) ] + \ self.getSlaveArgs(test) + self.getRunOptions(test.app, submissionRules) return " ".join(cmdArgs)