-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for retrieval of a jobid for a given test (#14)
For some tests, we want to retrieve a specific job ID for a test. For example, if we want to retrieve a prepared qcow2 image from openQA to use with libvirt on a local machine. To support this, add a new API endpoint: /v1/latest_job/<arch>/<distri>/<flavor>/<version>/<test> for example: /v1/latest_job/x86_64/sle/Online/15-SP2/create_hdd_minimal_base+sdk If successful, the openQA job ID is returned. If no job can be found, an error 404 is returned. Signed-off-by: Michael Moese <[email protected]>
- Loading branch information
1 parent
68b8f6c
commit 814360d
Showing
7 changed files
with
136 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Copyright (C) 2020 SUSE LLC | ||
# SPDX-License-Identifier: GPL-3.0 | ||
|
||
import os | ||
import bottle | ||
import socket | ||
from openqa_client.client import OpenQA_Client | ||
|
||
class LatestJobNotFound(Exception): | ||
"""Raised when no job is found""" | ||
pass | ||
|
||
|
||
class LatestJob: | ||
def __init__(self, app, instance='http://openqa.suse.de'): | ||
self.bootscript = {} | ||
self._instance = instance | ||
self._app = app | ||
self._app.route('/v1/latest_job/<arch>/<distri>/<flavor>/<version>/<test>', | ||
method="GET", | ||
callback=self.http_get_latest_job) | ||
|
||
def get_latest_job(self, filter): | ||
try: | ||
client = OpenQA_Client(server=self._instance) | ||
result = client.openqa_request('GET', 'jobs', filter) | ||
jobs = sorted(result['jobs'], key=lambda x: str(x['t_finished'])) | ||
if jobs: | ||
return ([[job] for job in jobs if job['result'] in ['passed', 'softfailed']][-1][0]) | ||
else: | ||
raise LatestJobNotFound("no such job found"); | ||
except Exception: | ||
raise LatestJobNotFound("no such job found"); | ||
|
||
def http_get_latest_job(self, arch, distri, flavor, version, test): | ||
filter = {} | ||
filter['arch'] = arch | ||
filter['distri'] = distri | ||
filter['flavor'] = flavor | ||
filter['version'] = version | ||
filter['test'] = test | ||
|
||
try: | ||
job = self.get_latest_job(filter) | ||
bottle.response.content_type = 'text/text; charset=utf-8' | ||
result = job['id'] | ||
return str(result) | ||
except LatestJobNotFound: | ||
bottle.response.body = 'not found' | ||
bootle.respons.status = '404 Not Found' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ pytest-cov>=2.6.1 | |
requests>=2.21.0 | ||
pycodestyle>=2.5.0 | ||
codecov | ||
openqa_client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Copyright (C) 2019 SUSE LLC | ||
# SPDX-License-Identifier: GPL-3.0 | ||
|
||
from bottle import Bottle | ||
from pytest import raises | ||
|
||
from baremetal_support.jobid import LatestJob, LatestJobNotFound | ||
|
||
|
||
def test_exception(): | ||
app = Bottle() | ||
# retrieve value after setting it | ||
lj = LatestJob(app) | ||
|
||
filter = {} | ||
filter['arch'] = 'MIPS' | ||
filter['distri'] = 'gentoo' | ||
filter['flavor'] = 'hardened' | ||
filter['version'] = '1.0' | ||
filter['test'] = 'install_gentoo_mips' | ||
with raises(LatestJobNotFound): | ||
res = lj.get_latest_job(filter) | ||
|
||
def test_get(): | ||
app = Bottle() | ||
lj = LatestJob(app, 'http://openqa.opensuse.org') | ||
filter = {} | ||
filter['arch'] = 'x86_64' | ||
filter['distri'] = 'opensuse' | ||
filter['flavor'] = 'DVD' | ||
filter['version'] = 'Tumbleweed' | ||
filter['test'] = 'create_hdd_textmode' | ||
|
||
res = lj.get_latest_job(filter) | ||
assert res |