Commit 49c0f353 authored by Andrej Shadura's avatar Andrej Shadura

Port to Python 3

Signed-off-by: Andrej Shadura's avatarAndrew Shadura <andrew.shadura@collabora.co.uk>
parent 74d2d745
#!/usr/bin/env python
#!/usr/bin/env python3
###################################################################################
# LAVA QA tool
# Copyright (C) 2015 Luis Araujo <luis.araujo@collabora.co.uk>
......@@ -19,11 +19,7 @@
###################################################################################
from lqa_api.exit_codes import SUCCESS
from lqa_tool import Cli
def main():
lqa = Cli()
lqa.run()
from lqa_tool import main
if __name__ == '__main__':
main()
......
......@@ -17,7 +17,10 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 US
###################################################################################
from xmlrpclib import ServerProxy
try:
from xmlrpc.client import ServerProxy
except ImportError:
from xmlrpclib import ServerProxy
class Connection(object):
"""Class handling the connection to the LAVA server."""
......
......@@ -19,7 +19,10 @@
import json
import yaml
from xmlrpclib import Fault
try:
from xmlrpc.client import Fault
except ImportError:
from xmlrpclib import Fault
from lqa_api.test import Test
from lqa_api.exit_codes import SUCCESS, \
EXIT_CODE_INCOMPLETE_JOB, \
......
......@@ -19,7 +19,10 @@
import sys
import time
from xmlrpclib import Fault
try:
from xmlrpc.client import Fault
except ImportError:
from xmlrpclib import Fault
from lqa_api.job import Job
......
......@@ -20,7 +20,10 @@
import sys
import unittest
from cStringIO import StringIO
try:
from io import StringIO
except ImportError:
from cStringIO import StringIO
from lqa_tool import Cli
from lqa_tool.settings import settings
from lqa_tool.exceptions import ProfileNotFound
......
......@@ -19,8 +19,13 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 US
###################################################################################
from __future__ import unicode_literals
import sys
import xmlrpclib
try:
import xmlrpc.client as xmlrpclib
except ImportError:
import xmlrpclib
from argparse import ArgumentParser
from lqa_api.waitqueue import WAIT_DEFAULT_TIMEOUT
......@@ -336,6 +341,10 @@ class Cli(object):
return self.parser.parse_args(args)
def main():
lqa = Cli()
lqa.run()
def submit(args):
from lqa_tool.commands.submit import SubmitCmd
SubmitCmd(args).run()
......
......@@ -18,6 +18,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 US
###################################################################################
from __future__ import print_function
from lqa_tool.commands import QueueCommand
from lqa_tool.commands.cancel import cancel
......@@ -30,5 +32,5 @@ class CleanQueueCmd(QueueCommand):
QueueCommand.run(self, _cleanqueue)
def _cleanqueue(job, server, *_):
print "Canceling:", job
print("Canceling:", job)
cancel(job.id, server)
......@@ -17,6 +17,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 US
###################################################################################
from __future__ import print_function
from lqa_tool.commands import Command
class DevicesCmd(Command):
......@@ -27,7 +29,7 @@ class DevicesCmd(Command):
def run(self):
# device hostname, device type, device state and current running job id
devices = self.server.all_devices()
print " Hostname \ \tDevice Type \ \tDevice State \ \tRunning Job"
print ("=" * 63)
print( " Hostname \ \tDevice Type \ \tDevice State \ \tRunning Job")
print("=" * 63)
for device in devices:
print "-- {}".format(" \ ".join([ str(x) for x in device]))
print("-- {}".format(" \ ".join([ str(x) for x in device])))
......@@ -17,6 +17,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 US
###################################################################################
from __future__ import print_function
from lqa_api.job import Job, JobError
from lqa_api.exit_codes import SUCCESS, APPLICATION_ERROR, OPERATION_FAILED
from lqa_tool.commands import Command
......@@ -35,8 +37,8 @@ class DiffResultsCmd(Command):
self._exit_code = SUCCESS
def run(self):
print '(1)', self.job1
print '(2)', self.job2
print('(1)', self.job1)
print('(2)', self.job2)
for test_job1 in self.job1.tests:
# Include lava tests if --infra passed.
if test_job1.name == 'lava' and not self.args.infra:
......@@ -47,7 +49,7 @@ class DiffResultsCmd(Command):
# Show if there are missing tests in job2 from job1.
if not job2tests:
print "!! {}".format(test_job1.name)
print("!! {}".format(test_job1.name))
continue
for test_job2 in job2tests:
......@@ -64,14 +66,14 @@ class DiffResultsCmd(Command):
def _print_diff(tj1, tj2, tc1, result1, tc2, result2):
# Make sure to print the test name only once for all the results.
if not self._is_test_name_printed:
print "1:", tj1
print "2:", tj2
print("1:", tj1)
print("2:", tj2)
self._is_test_name_printed = True
# Set to FAILED only once.
if self._exit_code == SUCCESS:
self._exit_code = OPERATION_FAILED
print " 1> {}:{}".format(tc1, result1)
print " 2> {}:{}".format(tc2, result2)
print(" 1> {}:{}".format(tc1, result1))
print(" 2> {}:{}".format(tc2, result2))
if tc_job1['test_case_id'] == tc_job2['test_case_id']:
# Only print results if there are differences.
......
......@@ -17,6 +17,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 US
###################################################################################
from __future__ import print_function
from lqa_api.job import Job, JobError
from lqa_api.exit_codes import APPLICATION_ERROR
from lqa_tool.commands import Command
......@@ -31,30 +33,30 @@ class JobCmd(Command):
for job_id in self.job_ids:
job = Job(job_id, self.server)
try:
print job
print(job)
# Show further job metadata with --info
if self.args.info:
print " status: {}".format(job.status)
print " bundle: {}".format(job.bundle_link)
print(" status: {}".format(job.status))
print(" bundle: {}".format(job.bundle_link))
if job.sha1:
print " sha1: {}".format(job.sha1)
print " submit time: {}".format(job.submit_time)
print(" sha1: {}".format(job.sha1))
print(" submit time: {}".format(job.submit_time))
if job.start_time:
print " start time: {}".format(job.start_time)
print(" start time: {}".format(job.start_time))
if job.end_time:
print " end time: {}".format(job.end_time)
print(" end time: {}".format(job.end_time))
# If there is an end_time, there _should_ be a start_time
# so it is good to calculate duration here.
print " duration: {}" \
.format(job.end_time - job.start_time)
print " priority: {}".format(job.priority)
print " device type: {}".format(job.device_type)
print " hostname: {}".format(job.hostname)
print " worker: {}".format(job.worker_host)
print(" duration: {}" \
.format(job.end_time - job.start_time))
print(" priority: {}".format(job.priority))
print(" device type: {}".format(job.device_type))
print(" hostname: {}".format(job.hostname))
print(" worker: {}".format(job.worker_host))
# Skip tests if --no-tests passed
if self.args.tests:
for test in job.tests:
print "|", test
print("|", test)
except JobError as err:
lqa_logger.error("job command: job {}: {} {}" \
.format(job_id, err.code, err.msg))
......
......@@ -17,6 +17,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 US
###################################################################################
from __future__ import print_function
from lqa_api.job import Job, JobError
from lqa_api.exit_codes import APPLICATION_ERROR
from lqa_tool.commands import Command
......@@ -32,7 +34,7 @@ class JobDefCmd(Command):
try:
for job_id in self.job_ids:
print Job(job_id, self.server).job_definition
print(Job(job_id, self.server).job_definition)
except JobError as err:
lqa_logger.error("jobdef command: {}".format(err))
exit(APPLICATION_ERROR)
......@@ -17,6 +17,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 US
###################################################################################
from __future__ import print_function
from lqa_tool.commands import Command
class ListStreamsCmd(Command):
......@@ -26,10 +27,10 @@ class ListStreamsCmd(Command):
def run(self):
for stream in self.server.streams():
print "{}{}{}{}{}" \
print("{}{}{}{}{}" \
.format(stream['pathname'],
stream['name'] and ' | name: ' + stream['name'],
stream['user'] and ' | user: ' + stream['user'],
stream['group'] and ' | group: ' + stream['group'],
str(stream['bundle_count']) and
' | bundles: ' + str(stream['bundle_count']))
' | bundles: ' + str(stream['bundle_count'])))
......@@ -18,6 +18,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 US
###################################################################################
from __future__ import print_function
from lqa_tool.commands import QueueCommand
class QueueCmd(QueueCommand):
......@@ -37,4 +38,4 @@ def _showqueue(job, _, job_data, args):
elif status == 'running':
time_fmt = "(running since: {})".format(job.start_time)
# Print queued job
print job, time_fmt
print(job, time_fmt)
......@@ -17,6 +17,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 US
###################################################################################
from __future__ import print_function
from datetime import datetime
from lqa_tool.commands import Command
......@@ -41,8 +43,8 @@ class ReportCmd(Command):
exit(self._exit_code)
def _print_report(self):
print "/========= LQA Report v{} ({}) =========/\n" \
.format(__version__, _set_datetime())
print("/========= LQA Report v{} ({}) =========/\n" \
.format(__version__, _set_datetime()))
if self.args.all_results:
# If --all-results passed then show all results both for failed and
......@@ -59,7 +61,7 @@ class ReportCmd(Command):
if jobs_count:
# Exit with failed code if there is any failed job.
self._exit_code = OPERATION_FAILED
print "========== Failed jobs [{}] ==========\n".format(jobs_count)
print("========== Failed jobs [{}] ==========\n".format(jobs_count))
self._print_jobs(self._jobs_by_status['complete']['failed'],
"Complete jobs with failures", show_failed)
self._print_jobs(self._jobs_by_status['incomplete']['bundles'],
......@@ -71,7 +73,7 @@ class ReportCmd(Command):
jobs_count = len(self._jobs_by_status['pending']['submitted'] +
self._jobs_by_status['pending']['running'])
if jobs_count:
print "========== Pending jobs [{}] ==========\n".format(jobs_count)
print("========== Pending jobs [{}] ==========\n".format(jobs_count))
self._print_jobs(self._jobs_by_status['pending']['submitted'],
"Submitted jobs")
self._print_jobs(self._jobs_by_status['pending']['running'],
......@@ -81,7 +83,7 @@ class ReportCmd(Command):
jobs_count = len(self._jobs_by_status['canceled']['canceled'] +
self._jobs_by_status['canceled']['canceling'])
if jobs_count:
print "========== Canceled jobs [{}] ==========\n".format(jobs_count)
print("========== Canceled jobs [{}] ==========\n".format(jobs_count))
self._print_jobs(self._jobs_by_status['canceled']['canceling'],
"Canceling jobs")
self._print_jobs(self._jobs_by_status['canceled']['canceled'],
......@@ -90,13 +92,13 @@ class ReportCmd(Command):
# Successful jobs
jobs_count = len(self._jobs_by_status['complete']['successful'])
if jobs_count:
print "========== Successful jobs [{}] ==========\n".format(jobs_count)
print("========== Successful jobs [{}] ==========\n".format(jobs_count))
self._print_jobs(self._jobs_by_status['complete']['successful'],
"Successful jobs (no failures)", show_success)
def _print_jobs(self, jobs, section_header, results_status=[]):
if jobs:
print "[ --- {} --- ]\n".format(section_header)
print("[ --- {} --- ]\n".format(section_header))
for job in jobs:
_print_job_header(job)
if results_status:
......@@ -104,12 +106,12 @@ class ReportCmd(Command):
def _print_job_header(job):
space = " "
print space, job
print space, len(str(job)) * "="
print(space, job)
print(space, len(str(job)) * "=")
if job.failure_comment:
print space, "Failure:", job.failure_comment.strip()
print space, "Bundle Link:", job.bundle_link
print
print(space, "Failure:", job.failure_comment.strip())
print(space, "Bundle Link:", job.bundle_link)
print()
def _print_tests(tests, results_status, limit):
for test in tests:
......@@ -126,19 +128,19 @@ def _print_tests(tests, results_status, limit):
# Print test name only once for all its results.
if not is_test_printed:
print "\t", test
print("\t", test)
is_test_printed = True
for i, test_case in enumerate(results, 1):
if i > limit:
print "\t[* NOTE: {} test cases with status {}." \
print("\t[* NOTE: {} test cases with status {}." \
" Visit bundle link for complete list of" \
" results or set a new limit with the --limit option *]"\
.format(limit, status.upper())
.format(limit, status.upper()))
break
print "\t {} - {}".format(test_case['result'].upper(),
test_case['test_case_id'])
print
print("\t {} - {}".format(test_case['result'].upper(),
test_case['test_case_id']))
print()
def _set_datetime():
return datetime.today().strftime("%a %b %d %H:%M:%S %Y")
......@@ -34,7 +34,7 @@ class ResultsCmd(Command):
try:
job = Job(job_id, self.server)
for result_line in job.results:
print result_line
print(result_line)
except JobError as err:
lqa_logger.error("results command: {}".format(err))
exit(APPLICATION_ERROR)
......@@ -17,6 +17,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 US
###################################################################################
from __future__ import print_function
from lqa_api.job import Job, JobError
from lqa_api.exit_codes import APPLICATION_ERROR
from lqa_tool.commands import Command
......@@ -31,7 +33,7 @@ class StatusCmd(Command):
for job_id in self.job_ids:
try:
job = Job(job_id, self.server)
print "{}: {}".format(job.status, job)
print("{}: {}".format(job.status, job))
except JobError as err:
lqa_logger.error("status command: {}".format(err))
exit(APPLICATION_ERROR)
......@@ -17,16 +17,24 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 US
###################################################################################
from __future__ import print_function
import re
import yaml
import json
import os
import os.path
import urlparse
try:
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse
import jinja2.exceptions
import requests
from xmlrpclib import Fault
try:
from xmlrpc.client import Fault
except ImportError:
from xmlrpclib import Fault
from jinja2 import Environment, FileSystemLoader, \
StrictUndefined, DebugUndefined
from lqa_api.exit_codes import APPLICATION_ERROR
......@@ -202,7 +210,7 @@ class SubmitCmd(Command):
.format(job_file))
if self.args.verbose:
print data
print(data)
if not self.args.dry_run:
try:
......@@ -241,7 +249,7 @@ class SubmitCmd(Command):
image = action['parameters'].get('image', None)
if image:
# Test for local url path
url = urlparse.urlparse(image)
url = urlparse(image)
if url.scheme == 'file':
if os.path.exists(url.path):
return
......
......@@ -26,4 +26,4 @@ class SVersionCmd(Command):
Command.__init__(self, args)
def run(self):
print self.server.version()
print(self.server.version())
......@@ -17,6 +17,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 US
###################################################################################
from __future__ import print_function
import base64
import os.path
......@@ -47,28 +49,28 @@ class TestCmd(Command):
if (not self.args.test_name) or \
test.name in self.args.test_name or \
test.uuid in self.args.test_name:
print test
print(test)
# Show further job metadata with --info
if self.args.info:
print " description: {}".format(test.description)
print " version: {}".format(test.version)
print " format: {}".format(test.format)
print " params: {}".format(test.params)
print " project: {}".format(test.project)
print(" description: {}".format(test.description))
print(" version: {}".format(test.version))
print(" format: {}".format(test.format))
print(" params: {}".format(test.params))
print(" project: {}".format(test.project))
# Strip image field (if it exists) since it can contain newline
if test.image:
print " image: {}".format(test.image.strip())
print(" image: {}".format(test.image.strip()))
else:
print " image: {}".format(test.image)
print " location: {}".format(test.location)
print " branch_url: {}".format(test.branch_url)
print " branch_rev: {}".format(test.branch_rev)
print " branch_vcs: {}".format(test.branch_vcs)
print(" image: {}".format(test.image))
print(" location: {}".format(test.location))
print(" branch_url: {}".format(test.branch_url))
print(" branch_rev: {}".format(test.branch_rev))
print(" branch_vcs: {}".format(test.branch_vcs))
# Show installed packages (package environment) for this test
if self.args.show_packages and test.packages:
for pkg in test.packages:
print "P: {} {}".format(pkg['name'], pkg['version'])
print("P: {} {}".format(pkg['name'], pkg['version']))
# Save test run attachments if --attachments is true
# and there are attachments available.
......@@ -87,9 +89,9 @@ class TestCmd(Command):
if self.args.results:
ms = ("{} {}".format(result.get('measurement', ''),
result.get('units', ''))).strip()
print "- {}: {} {}".format(result['test_case_id'],
print("- {}: {} {}".format(result['test_case_id'],
result['result'],
(ms and '/ '+ ms) or '')
(ms and '/ '+ ms) or ''))
# Save test case attachments if --attachments is true
# and there are attachments available.
......
......@@ -25,4 +25,4 @@ class WhoAmICmd(Command):
Command.__init__(self, args)
def run(self):
print self.server.whoami()
print(self.server.whoami())
......@@ -21,7 +21,10 @@ import os
import yaml
import logging
import os.path
from urlparse import urlsplit, urlunsplit
try:
from urllib.parse import urlsplit, urlunsplit
except ImportError:
from urlparse import urlsplit, urlunsplit
from lqa_api.exit_codes import APPLICATION_ERROR
CONFIG_PATH=os.getenv("HOME") + '/.config/'
......
......@@ -18,13 +18,15 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 US
###################################################################################
from __future__ import print_function
import copy
def merge_profiles(original, update):
"""Merge two hashes. This is used to merge profiles."""
def _merge_profiles(original, update):
for k, v in update.iteritems():
for k, v in update.items():
if type(v) == dict and (k in original and type(original[k]) == dict):
_merge_profiles(original[k], update[k])
else:
......@@ -37,19 +39,19 @@ def merge_profiles(original, update):
# Convenient callback functions that can be used by the wait command.
def print_add_msg(q, job):
"""Convenient function to print message after adding job to the queue."""
print "({}) <= Job added to wait queue | {}: {}" \
.format(len(q), job.status, job)
print("({}) <= Job added to wait queue | {}: {}" \
.format(len(q), job.status, job))
def print_wait_msg(q, job):
"""Convenient function to print message after polling job."""
print "({}) Waiting job | {}: {}".format(len(q), job.status, job)
print("({}) Waiting job | {}: {}".format(len(q), job.status, job))
def print_remove_msg(q, job):
"""Convenient function to print message after removing job from the queue."""
print "({}) => Job done | {}: {}".format(len(q), job.status, job)
print("({}) => Job done | {}: {}".format(len(q), job.status, job))
def print_timeout_msg(q, timeout):
"""Convenient function to print message after timeout has been reached."""
for job in q:
print "({}) !! Wait timeout of {}s reached for job | {}: {}" \
.format(len(q), timeout, job.status, job)
print("({}) !! Wait timeout of {}s reached for job | {}: {}" \
.format(len(q), timeout, job.status, job))
......@@ -20,8 +20,8 @@
from setuptools import setup, find_packages
from lqa_tool.version import __version__
execfile('lqa_tool/version.py')
setup(
name='lqa',
version=__version__,
......@@ -31,7 +31,17 @@ setup(
author_email='luis.araujo@collabora.co.uk',
url='http://cgit.collabora.com/git/singularity/tools/lqa.git/',
packages=find_packages(),
scripts=['lqa'],
classifiers = [
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.6',
],
entry_points = {
'console_scripts': [
'lqa = lqa_tool:main'
]
},
include_package_data=False,
install_requires=['PyYaml', 'jinja2', 'requests'],
zip_safe=False,
......
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