+ @skipIfNotAlive
+ def t_exitcode_ok(self, host, user):
+ command = "echo 'OK!'"
+
+ node, ec = create_node(host, user)
+
+ app_home = os.path.join(node.exp_home, "my-app")
+ node.mkdir(app_home, clean = True)
+
+ (out, err), proc = node.run_and_wait(command, app_home,
+ shfile = "cmd.sh",
+ pidfile = "pid",
+ ecodefile = "exitcode",
+ stdout = "stdout",
+ stderr = "stderr",
+ raise_on_error = True)
+
+ # get the pid of the process
+ ecode = node.exitcode(app_home)
+ self.assertEquals(ecode, ExitCode.OK)
+
+ @skipIfNotAlive
+ def t_exitcode_kill(self, host, user):
+ node, ec = create_node(host, user)
+
+ app_home = os.path.join(node.exp_home, "my-app")
+ node.mkdir(app_home, clean = True)
+
+ # Upload command that will not finish
+ command = "ping localhost"
+ (out, err), proc = node.upload_command(command, app_home,
+ shfile = "cmd.sh",
+ ecodefile = "exitcode")
+
+ (out, err), proc = node.run(command, app_home,
+ pidfile = "pidfile",
+ stdout = "stdout",
+ stderr = "stderr")
+
+ # Just wait to make sure the ping started
+ time.sleep(5)
+
+ # The process is still running, so no retfile has been created yet
+ ecode = node.exitcode(app_home)
+ self.assertEquals(ecode, ExitCode.FILENOTFOUND)
+
+ (out, err), proc = node.check_errors(app_home)
+ self.assertEquals(err, "")
+
+ # Now kill the app
+ pid, ppid = node.getpid(app_home)
+ node.kill(pid, ppid)
+
+ (out, err), proc = node.check_errors(app_home)
+ self.assertEquals(err, "")
+
+ @skipIfNotAlive
+ def t_exitcode_error(self, host, user):
+ # Try to execute a command that doesn't exist
+ command = "unexistent-command"
+
+ node, ec = create_node(host, user)
+
+ app_home = os.path.join(node.exp_home, "my-app")
+ node.mkdir(app_home, clean = True)
+
+ (out, err), proc = node.run_and_wait(command, app_home,
+ shfile = "cmd.sh",
+ pidfile = "pid",
+ ecodefile = "exitcode",
+ stdout = "stdout",
+ stderr = "stderr",
+ raise_on_error = False)
+
+ # get the pid of the process
+ ecode = node.exitcode(app_home)
+ # bash erro 127 - command not found
+ self.assertEquals(ecode, 127)
+
+ (out, err), proc = node.check_errors(app_home)
+ self.assertNotEquals(out, "")
+