'Given a job and the basic metadata about the test that
can be extracted from the status logs, parse the test
keyval files and use it to construct a complete test
instance.'

@classmethod
def parse_test(cls, job, subdir, testname, status, reason, test_kernel, started_time, finished_time, existing_instance=None):

    logging.info(('parsing    test    %s    %s' % (subdir, testname)))
    if subdir:
        iteration_keyval = os.path.join(job.dir, subdir, 'results', 'keyval')
        iterations = cls.load_iterations(iteration_keyval)
        test_keyval = os.path.join(job.dir, subdir, 'keyval')
        attributes = test.load_attributes(test_keyval)
    else:
        iterations = []
        attributes = {}
    host_keyval = cls.parse_host_keyval(job.dir, job.machine)
    attributes.update(dict(((('host-%s' % k), v) for (k, v) in host_keyval.iteritems())))
    if existing_instance:
        def constructor(*args, **dargs):
            existing_instance.__init__(*args, **dargs)
            return existing_instance
    else:
        constructor = cls
    return constructor(subdir, testname, status, reason, test_kernel, job.machine, started_time, finished_time, iterations, attributes, [])
