示例#1
0
    def load_from_dir(cls, dir):
        keyval = cls.read_keyval(dir)
        tko_utils.dprint(str(keyval))

        user = keyval.get("user", None)
        label = keyval.get("label", None)
        queued_time = tko_utils.get_timestamp(keyval, "job_queued")
        started_time = tko_utils.get_timestamp(keyval, "job_started")
        finished_time = tko_utils.get_timestamp(keyval, "job_finished")
        machine = cls.determine_hostname(keyval, dir)
        machine_group = cls.determine_machine_group(machine, dir)
        machine_owner = keyval.get("owner", None)

        aborted_by = keyval.get("aborted_by", None)
        aborted_at = tko_utils.get_timestamp(keyval, "aborted_on")

        return {
            "user": user,
            "label": label,
            "machine": machine,
            "queued_time": queued_time,
            "started_time": started_time,
            "finished_time": finished_time,
            "machine_owner": machine_owner,
            "machine_group": machine_group,
            "aborted_by": aborted_by,
            "aborted_on": aborted_at,
            "keyval_dict": keyval
        }
示例#2
0
 def test_date_can_be_string_or_integer(self):
     int_times = [1, 12, 123, 1234, 12345, 123456]
     str_times = [str(t) for t in int_times]
     for int_t, str_t in itertools.izip(int_times, str_times):
         date_int = utils.get_timestamp({"key": int_t}, "key")
         date_str = utils.get_timestamp({"key": str_t}, "key")
         self.assertEquals(date_int, date_str)
示例#3
0
 def test_date_can_be_string_or_integer(self):
     int_times = [1, 12, 123, 1234, 12345, 123456]
     str_times = [str(t) for t in int_times]
     for int_t, str_t in zip(int_times, str_times):
         date_int = utils.get_timestamp({"key": int_t}, "key")
         date_str = utils.get_timestamp({"key": str_t}, "key")
         self.assertEqual(date_int, date_str)
示例#4
0
    def load_from_dir(cls, dir):
        keyval = cls.read_keyval(dir)
        logging.debug(str(keyval))

        user = keyval.get("user", None)
        label = keyval.get("label", None)
        queued_time = tko_utils.get_timestamp(keyval, "job_queued")
        started_time = tko_utils.get_timestamp(keyval, "job_started")
        finished_time = tko_utils.get_timestamp(keyval, "job_finished")
        machine = cls.determine_hostname(keyval, dir)
        machine_group = cls.determine_machine_group(machine, dir)
        machine_owner = keyval.get("owner", None)

        aborted_by = keyval.get("aborted_by", None)
        aborted_at = tko_utils.get_timestamp(keyval, "aborted_on")

        return {"user": user, "label": label, "machine": machine,
                "queued_time": queued_time, "started_time": started_time,
                "finished_time": finished_time, "machine_owner": machine_owner,
                "machine_group": machine_group, "aborted_by": aborted_by,
                "aborted_on": aborted_at, "keyval_dict": keyval}
示例#5
0
 def test_zero_time(self):
     date = utils.get_timestamp({"key": "0"}, "key")
     timezone = datetime.timedelta(seconds=time.timezone)
     utc_date = date + timezone
     # should be equal to epoch, i.e. Jan 1, 1970
     self.assertEqual(utc_date.year, 1970)
     self.assertEqual(utc_date.month, 1)
     self.assertEqual(utc_date.day, 1)
     self.assertEqual(utc_date.hour, 0)
     self.assertEqual(utc_date.minute, 0)
     self.assertEqual(utc_date.second, 0)
     self.assertEqual(utc_date.microsecond, 0)
示例#6
0
 def test_zero_time(self):
     date = utils.get_timestamp({"key": "0"}, "key")
     timezone = datetime.timedelta(seconds=time.timezone)
     utc_date = date + timezone
     # should be equal to epoch, i.e. Jan 1, 1970
     self.assertEquals(utc_date.year, 1970)
     self.assertEquals(utc_date.month, 1)
     self.assertEquals(utc_date.day, 1)
     self.assertEquals(utc_date.hour, 0)
     self.assertEquals(utc_date.minute, 0)
     self.assertEquals(utc_date.second, 0)
     self.assertEquals(utc_date.microsecond, 0)
示例#7
0
 def get_timestamp(self):
     return tko_utils.get_timestamp(self.optional_fields, "timestamp")
示例#8
0
    def state_iterator(self, buffer):
        new_tests = []
        boot_count = 0
        group_subdir = None
        sought_level = 0
        stack = status_lib.status_stack()
        current_kernel = kernel(self.job)
        boot_in_progress = False
        alert_pending = None
        started_time = None

        while not self.finished or buffer.size():
            # stop processing once the buffer is empty
            if buffer.size() == 0:
                yield new_tests
                new_tests = []
                continue

            # parse the next line
            line = buffer.get()
            logging.debug('STATUS: %s', line.strip())
            line = status_line.parse_line(line)
            if line is None:
                logging.debug('non-status line, ignoring')
                continue # ignore non-status lines

            # have we hit the job start line?
            if (line.type == "START" and not line.subdir and
                not line.testname):
                sought_level = 1
                logging.debug("found job level start "
                                 "marker, looking for level "
                                 "1 groups now")
                continue

            # have we hit the job end line?
            if (line.type == "END" and not line.subdir and
                not line.testname):
                logging.debug("found job level end "
                                 "marker, looking for level "
                                 "0 lines now")
                sought_level = 0

            # START line, just push another layer on to the stack
            # and grab the start time if this is at the job level
            # we're currently seeking
            if line.type == "START":
                group_subdir = None
                stack.start()
                if line.indent == sought_level:
                    started_time = \
                                 tko_utils.get_timestamp(
                        line.optional_fields, "timestamp")
                logging.debug("start line, ignoring")
                continue
            # otherwise, update the status on the stack
            else:
                logging.debug("GROPE_STATUS: %s" %
                                 [stack.current_status(),
                                  line.status, line.subdir,
                                  line.testname, line.reason])
                stack.update(line.status)

            if line.status == "ALERT":
                logging.debug("job level alert, recording")
                alert_pending = line.reason
                continue

            # ignore Autotest.install => GOOD lines
            if (line.testname == "Autotest.install" and
                line.status == "GOOD"):
                logging.debug("Successful Autotest "
                                 "install, ignoring")
                continue

            # ignore END lines for a reboot group
            if (line.testname == "reboot" and line.type == "END"):
                logging.debug("reboot group, ignoring")
                continue

            # convert job-level ABORTs into a 'CLIENT_JOB' test, and
            # ignore other job-level events
            if line.testname is None:
                if (line.status == "ABORT" and
                    line.type != "END"):
                    line.testname = "CLIENT_JOB"
                else:
                    logging.debug("job level event, "
                                    "ignoring")
                    continue

            # use the group subdir for END lines
            if line.type == "END":
                line.subdir = group_subdir

            # are we inside a block group?
            if (line.indent != sought_level and
                line.status != "ABORT" and
                not line.testname.startswith('reboot.')):
                if line.subdir:
                    logging.debug("set group_subdir: "
                                     + line.subdir)
                    group_subdir = line.subdir
                logging.debug("ignoring incorrect indent "
                                 "level %d != %d," %
                                 (line.indent, sought_level))
                continue

            # use the subdir as the testname, except for
            # boot.* and kernel.* tests
            if (line.testname is None or
                not re.search(r"^(boot(\.\d+)?$|kernel\.)",
                              line.testname)):
                if line.subdir and '.' in line.subdir:
                    line.testname = line.subdir

            # has a reboot started?
            if line.testname == "reboot.start":
                started_time = tko_utils.get_timestamp(
                    line.optional_fields, "timestamp")
                logging.debug("reboot start event, "
                                 "ignoring")
                boot_in_progress = True
                continue

            # has a reboot finished?
            if line.testname == "reboot.verify":
                line.testname = "boot.%d" % boot_count
                logging.debug("reboot verified")
                boot_in_progress = False
                verify_ident = line.reason.strip()
                current_kernel = kernel(self.job, verify_ident)
                boot_count += 1

            if alert_pending:
                line.status = "ALERT"
                line.reason = alert_pending
                alert_pending = None

            # create the actual test object
            finished_time = tko_utils.get_timestamp(
                line.optional_fields, "timestamp")
            final_status = stack.end()
            logging.debug("Adding: "
                             "%s\nSubdir:%s\nTestname:%s\n%s" %
                             (final_status, line.subdir,
                              line.testname, line.reason))
            new_test = test.parse_test(self.job, line.subdir,
                                       line.testname,
                                       final_status, line.reason,
                                       current_kernel,
                                       started_time,
                                       finished_time)
            started_time = None
            new_tests.append(new_test)

        # the job is finished, but we never came back from reboot
        if boot_in_progress:
            testname = "boot.%d" % boot_count
            reason = "machine did not return from reboot"
            logging.debug(("Adding: ABORT\nSubdir:----\n"
                              "Testname:%s\n%s")
                             % (testname, reason))
            new_test = test.parse_test(self.job, None, testname,
                                       "ABORT", reason,
                                       current_kernel, None, None)
            new_tests.append(new_test)
        yield new_tests
示例#9
0
    def state_iterator(self, buffer):
        new_tests = []
        boot_count = 0
        group_subdir = None
        sought_level = 0
        stack = status_lib.status_stack()
        current_kernel = kernel(self.job)
        boot_in_progress = False
        alert_pending = None
        started_time = None

        while not self.finished or buffer.size():
            # stop processing once the buffer is empty
            if buffer.size() == 0:
                yield new_tests
                new_tests = []
                continue

            # parse the next line
            line = buffer.get()
            tko_utils.dprint('\nSTATUS: ' + line.strip())
            line = status_line.parse_line(line)
            if line is None:
                tko_utils.dprint('non-status line, ignoring')
                continue  # ignore non-status lines

            # have we hit the job start line?
            if (line.type == "START" and not line.subdir
                    and not line.testname):
                sought_level = 1
                tko_utils.dprint("found job level start "
                                 "marker, looking for level "
                                 "1 groups now")
                continue

            # have we hit the job end line?
            if (line.type == "END" and not line.subdir and not line.testname):
                tko_utils.dprint("found job level end "
                                 "marker, looking for level "
                                 "0 lines now")
                sought_level = 0

            # START line, just push another layer on to the stack
            # and grab the start time if this is at the job level
            # we're currently seeking
            if line.type == "START":
                group_subdir = None
                stack.start()
                if line.indent == sought_level:
                    started_time = \
                                 tko_utils.get_timestamp(
                        line.optional_fields, "timestamp")
                tko_utils.dprint("start line, ignoring")
                continue
            # otherwise, update the status on the stack
            else:
                tko_utils.dprint("GROPE_STATUS: %s" % [
                    stack.current_status(), line.status, line.subdir,
                    line.testname, line.reason
                ])
                stack.update(line.status)

            if line.status == "ALERT":
                tko_utils.dprint("job level alert, recording")
                alert_pending = line.reason
                continue

            # ignore Autotest.install => GOOD lines
            if (line.testname == "Autotest.install" and line.status == "GOOD"):
                tko_utils.dprint("Successful Autotest " "install, ignoring")
                continue

            # ignore END lines for a reboot group
            if (line.testname == "reboot" and line.type == "END"):
                tko_utils.dprint("reboot group, ignoring")
                continue

            # convert job-level ABORTs into a 'CLIENT_JOB' test, and
            # ignore other job-level events
            if line.testname is None:
                if (line.status == "ABORT" and line.type != "END"):
                    line.testname = "CLIENT_JOB"
                else:
                    tko_utils.dprint("job level event, " "ignoring")
                    continue

            # use the group subdir for END lines
            if line.type == "END":
                line.subdir = group_subdir

            # are we inside a block group?
            if (line.indent != sought_level and line.status != "ABORT"
                    and not line.testname.startswith('reboot.')):
                if line.subdir:
                    tko_utils.dprint("set group_subdir: " + line.subdir)
                    group_subdir = line.subdir
                tko_utils.dprint("ignoring incorrect indent "
                                 "level %d != %d," %
                                 (line.indent, sought_level))
                continue

            # use the subdir as the testname, except for
            # boot.* and kernel.* tests
            if (line.testname is None or not re.search(
                    r"^(boot(\.\d+)?$|kernel\.)", line.testname)):
                if line.subdir and '.' in line.subdir:
                    line.testname = line.subdir

            # has a reboot started?
            if line.testname == "reboot.start":
                started_time = tko_utils.get_timestamp(line.optional_fields,
                                                       "timestamp")
                tko_utils.dprint("reboot start event, " "ignoring")
                boot_in_progress = True
                continue

            # has a reboot finished?
            if line.testname == "reboot.verify":
                line.testname = "boot.%d" % boot_count
                tko_utils.dprint("reboot verified")
                boot_in_progress = False
                verify_ident = line.reason.strip()
                current_kernel = kernel(self.job, verify_ident)
                boot_count += 1

            if alert_pending:
                line.status = "ALERT"
                line.reason = alert_pending
                alert_pending = None

            # create the actual test object
            finished_time = tko_utils.get_timestamp(line.optional_fields,
                                                    "timestamp")
            final_status = stack.end()
            tko_utils.dprint(
                "Adding: "
                "%s\nSubdir:%s\nTestname:%s\n%s" %
                (final_status, line.subdir, line.testname, line.reason))
            new_test = test.parse_test(self.job, line.subdir, line.testname,
                                       final_status, line.reason,
                                       current_kernel, started_time,
                                       finished_time)
            started_time = None
            new_tests.append(new_test)

        # the job is finished, but we never came back from reboot
        if boot_in_progress:
            testname = "boot.%d" % boot_count
            reason = "machine did not return from reboot"
            tko_utils.dprint(("Adding: ABORT\nSubdir:----\n"
                              "Testname:%s\n%s") % (testname, reason))
            new_test = test.parse_test(self.job, None, testname, "ABORT",
                                       reason, current_kernel, None, None)
            new_tests.append(new_test)
        yield new_tests
示例#10
0
 def test_returns_none_on_missing_value(self):
     date = utils.get_timestamp({}, "missing_key")
     self.assertEqual(date, None)
示例#11
0
 def test_returns_none_on_missing_value(self):
     date = utils.get_timestamp({}, "missing_key")
     self.assertEquals(date, None)
示例#12
0
 def get_timestamp(self):
     return tko_utils.get_timestamp(self.optional_fields,
                                    "timestamp")