}
private static boolean startOrStopSUT(boolean start, TestResult tr) {
needToRestartSUT = !start;
String startOrStop = start ? "start" : "stop";
TestBedConfiguration config = TestBedConfiguration.getInstance();
if (hasControlScript()) {
if (isStartStopSUTCancelled) {
if (tr != null) {
tr.setStatus(Status.FAIL);
tr.setExtraResultDetails("SUT " + startOrStop + " command cancelled");
}
return false;
}
String scriptFilename = config.getControlScriptFileName();
String scriptEngine = null;
if (scriptFilename.endsWith(".py")) {
final String jythonHome = StaticConfiguration.JYTHON_HOME;
final String jythonJar = jythonHome + "/jython.jar";
final String jythonLib = StaticConfiguration.JYTHON_LIB.trim();
final String additionnalJythonLib = StaticConfiguration.ADDITIONNAL_JYTHON_LIB.trim();
final String classPath = System.getProperties().getProperty("java.class.path", "").trim();
scriptEngine = "java -Dpython.path=" + jythonJar + File.pathSeparator + jythonLib + File.pathSeparator + additionnalJythonLib
+ " -cp \"" + jythonHome + "/../build/jython-engine.jar" + File.pathSeparator
+ jythonJar + File.pathSeparator + classPath + "\" org.python.util.jython";
}
String scriptArguments = config.getControlScriptArguments();
String startOrStopCommand = scriptFilename + " " + startOrStop + " " + (scriptArguments != null ? scriptArguments : "") + (isRestartingSUT ? "-restart true" : "");
logger.info((start ? "Starting" : "Stopping") + " SUT using command '" + startOrStopCommand + "'");
// report the control script
try {
ByteArrayOutputStream output = new ByteArrayOutputStream();
Map<String, String> env = new HashMap<String, String>(
System.getenv());
env.put("TESTBED", config.getFileName());
String startOrStopFullCommand = (scriptEngine != null ? scriptEngine + " " + startOrStopCommand : startOrStopCommand);
logger.trace("FULL COMMAND : '" + startOrStopFullCommand + "'");
int exitCode = sutStartStopExec.exec(startOrStopFullCommand, env, output);
if (exitCode == 0) {
logger.info("SUT " + (start ? "started" : "stopped"));