Commit cf27f241 authored by Luis Araujo's avatar Luis Araujo

Add the output method to the job API

This will serve as a higher level method to fetch the job
output log directly from a job object.

This commit also adapts the output command code to use this
new method.
Signed-off-by: Luis Araujo's avatarLuis Araujo <luis.araujo@collabora.co.uk>
parent c7799850
###################################################################################
# LAVA QA api - This class represents a LAVA job object.
# Copyright (C) 2015 Collabora Ltd.
# LAVA QA API - This class represents a LAVA job object.
# Copyright (C) 2015, 2016 Collabora Ltd.
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
......@@ -163,6 +163,9 @@ class Job(object):
self._fetch_tests()
return self._tests
def output(self, offset=0):
return self._server.job_output(self.id, offset)
def has_bundle(self):
return self.bundle_link is not None
......
###################################################################################
# LAVA QA tool
# Copyright (C) 2015 Collabora Ltd.
# LAVA QA tool - Command to show the job output (log)
# Copyright (C) 2015, 2016 Collabora Ltd.
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
......@@ -39,11 +39,10 @@ class OutputCmd(Command):
exit(APPLICATION_ERROR)
def _run(self):
job = Job(self.args.job_id, self.server)
if self.args.live:
# If the --live option is passed, read incrementing offset of the
# output to show live.
job = Job(self.args.job_id, self.server)
# Wait for the job to start if it is in a submitted state.
if job.is_submitted():
lqa_logger.info("Waiting for job to start: {}".format(job))
......@@ -60,7 +59,7 @@ class OutputCmd(Command):
else:
# Otherwise just fetch and show the output file at once.
try:
output_data = self.server.job_output(self.args.job_id)
output_data = job.output()
if self.args.file:
with open(self.args.file, 'w+') as f:
f.write(output_data)
......@@ -71,7 +70,6 @@ class OutputCmd(Command):
except Fault as e:
# 404 Job output not found.
if e.faultCode == 404:
job = Job(self.args.job_id, self.server)
err_msg(e, job)
else:
lqa_logger.error("lqa output: error: {}".format(e))
......@@ -79,7 +77,7 @@ class OutputCmd(Command):
def _fetch_and_write_output(self, offset, job):
try:
output_data = self.server.job_output(self.args.job_id, offset)
output_data = job.output(offset)
if output_data:
sys.stdout.write(output_data)
offset = offset + len(output_data)
......@@ -96,5 +94,5 @@ class OutputCmd(Command):
return offset
def err_msg(e, job):
lqa_logger.error("{}: Status for job '{}': {}" \
.format(e.faultString, job, job.status))
lqa_logger.error("{}: Status for job '{}': {}"\
.format(e.faultString, job, job.status))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment