Пример #1
0
    def exit_status(self):
        # find the .autoserv_execute path
        top_dir = tko_utils.find_toplevel_job_dir(self.dir)
        if not top_dir:
            return "ABORT"
        execute_path = os.path.join(top_dir, ".autoserv_execute")

        # if for some reason we can't read the status code, assume disaster
        if not os.path.exists(execute_path):
            return "ABORT"
        lines = open(execute_path).readlines()
        if len(lines) < 2:
            return "ABORT"
        try:
            status_code = int(lines[1])
        except ValueError:
            return "ABORT"

        if not os.WIFEXITED(status_code):
            # looks like a signal - an ABORT
            return "ABORT"
        elif os.WEXITSTATUS(status_code) != 0:
            # looks like a non-zero exit - a failure
            return "FAIL"
        else:
            # looks like exit code == 0
            return "GOOD"
Пример #2
0
 def test_parent_is_toplevel(self):
     jobdir = "/results/job2"
     os.path.exists.expect_call(jobdir +
                                "/sub/.autoserv_execute").and_return(False)
     os.path.exists.expect_call(jobdir +
                                "/.autoserv_execute").and_return(True)
     self.assertEqual(utils.find_toplevel_job_dir(jobdir + "/sub"), jobdir)
Пример #3
0
    def read_keyval(dir):
        dir = os.path.normpath(dir)
        top_dir = tko_utils.find_toplevel_job_dir(dir)
        if not top_dir:
            top_dir = dir
        assert(dir.startswith(top_dir))

        # pull in and merge all the keyval files, with higher-level
        # overriding values in the lower-level ones
        keyval = {}
        while True:
            try:
                upper_keyval = utils.read_keyval(dir)
                # HACK: exclude hostname from the override - this is a special
                # case where we want lower to override higher
                if "hostname" in upper_keyval and "hostname" in keyval:
                    del upper_keyval["hostname"]
                keyval.update(upper_keyval)
            except IOError:
                pass  # if the keyval can't be read just move on to the next
            if dir == top_dir:
                break
            else:
                assert(dir != "/")
                dir = os.path.dirname(dir)
        return keyval
Пример #4
0
 def test_parent_is_toplevel(self):
     jobdir = "/results/job2"
     os.path.exists.expect_call(
         jobdir + "/sub/.autoserv_execute").and_return(False)
     os.path.exists.expect_call(
         jobdir + "/.autoserv_execute").and_return(True)
     self.assertEqual(utils.find_toplevel_job_dir(jobdir + "/sub"), jobdir)
Пример #5
0
    def exit_status(self):
        # find the .autoserv_execute path
        top_dir = tko_utils.find_toplevel_job_dir(self.dir)
        if not top_dir:
            return "ABORT"
        execute_path = os.path.join(top_dir, ".autoserv_execute")

        # if for some reason we can't read the status code, assume disaster
        if not os.path.exists(execute_path):
            return "ABORT"
        lines = open(execute_path).readlines()
        if len(lines) < 2:
            return "ABORT"
        try:
            status_code = int(lines[1])
        except ValueError:
            return "ABORT"

        if not os.WIFEXITED(status_code):
            # looks like a signal - an ABORT
            return "ABORT"
        elif os.WEXITSTATUS(status_code) != 0:
            # looks like a non-zero exit - a failure
            return "FAIL"
        else:
            # looks like exit code == 0
            return "GOOD"
Пример #6
0
 def test_no_toplevel(self):
     jobdir = "/results/job5"
     os.path.exists.expect_call(jobdir +
                                "/.autoserv_execute").and_return(False)
     os.path.exists.expect_call("/results/.autoserv_execute").and_return(
         False)
     os.path.exists.expect_call("/.autoserv_execute").and_return(False)
     self.assertEqual(utils.find_toplevel_job_dir(jobdir), None)
Пример #7
0
 def test_no_toplevel(self):
     jobdir = "/results/job5"
     os.path.exists.expect_call(
         jobdir + "/.autoserv_execute").and_return(False)
     os.path.exists.expect_call(
         "/results/.autoserv_execute").and_return(False)
     os.path.exists.expect_call("/.autoserv_execute").and_return(False)
     self.assertEqual(utils.find_toplevel_job_dir(jobdir), None)
Пример #8
0
    def parse_host_keyval(job_dir, hostname):
        # the "real" job dir may be higher up in the directory tree
        job_dir = tko_utils.find_toplevel_job_dir(job_dir)
        if not job_dir:
            return {}  # we can't find a top-level job dir with host keyvals

        # the keyval is <job_dir>/host_keyvals/<hostname> if it exists
        keyval_path = os.path.join(job_dir, "host_keyvals", hostname)
        if os.path.isfile(keyval_path):
            return utils.read_keyval(keyval_path)
        else:
            return {}