1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-12-28 10:46:15 +01:00

Merge branch 'prjresults-watch' of https://github.com/JanZerebecki/osc

Add "--watch" option to "osc prjresults" ("--watch" can only be used
in combination with "--xml").
This commit is contained in:
Marcus Huewe 2018-11-06 16:44:50 +01:00
commit aa88b6b795
7 changed files with 205 additions and 3 deletions

View File

@ -5156,7 +5156,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
help='Disable results for all direct affect packages inside of the project')
@cmdln.option('-M', '--multibuild-package', action='append', default=[],
help='Only show results for the specified multibuild package')
@cmdln.option('-w', '--watch', action='store_true', default=False,
@cmdln.option('-w', '--watch', action='store_true',
help='watch the results until all finished building')
@cmdln.option('', '--xml', action='store_true', default=False,
help='generate output in XML (former results_meta)')
@ -5239,6 +5239,8 @@ Please submit there instead, or use --nodevelproject to force direct submission.
# as well when adding a new option!
@cmdln.option('-q', '--hide-legend', action='store_true',
help='hide the legend')
@cmdln.option('-w', '--watch', action='store_true',
help='watch the results until all finished building, only supported with --xml')
@cmdln.option('-c', '--csv', action='store_true',
help='csv output')
@cmdln.option('', '--xml', action='store_true', default=False,
@ -5277,9 +5279,20 @@ Please submit there instead, or use --nodevelproject to force direct submission.
project = store_read_project(wd)
if opts.xml:
print(''.join(show_prj_results_meta(apiurl, project, opts.repo, opts.arch)))
kwargs = {}
if opts.repo:
kwargs['repository'] = opts.repo
if opts.arch:
kwargs['arch'] = opts.arch
kwargs['wait'] = opts.watch
for results in get_package_results(apiurl, project, **kwargs):
print(results)
return
if opts.watch:
print('Please implement support for osc prjresults --watch without --xml.')
return 2
print('\n'.join(get_prj_results(apiurl, project, hide_legend=opts.hide_legend, \
csv=opts.csv, status_filter=opts.status_filter, \
name_filter=opts.name_filter, repo=opts.repo, \

View File

@ -5735,7 +5735,7 @@ def get_results(apiurl, project, package, verbose=False, printJoin='', *args, **
return r
def get_package_results(apiurl, project, package, wait=False, *args, **kwargs):
def get_package_results(apiurl, project, package=None, wait=False, *args, **kwargs):
"""generator that returns a the package results as an xml structure"""
xml = ''
waiting_states = ('blocked', 'scheduled', 'dispatching', 'building',

View File

@ -0,0 +1,103 @@
[general]
# URL to access API server, e.g. https://api.opensuse.org
# you also need a section [https://api.opensuse.org] with the credentials
apiurl = http://localhost
# Downloaded packages are cached here. Must be writable by you.
#packagecachedir = /var/tmp/osbuild-packagecache
# Wrapper to call build as root (sudo, su -, ...)
#su-wrapper = su -c
# rootdir to setup the chroot environment
# can contain %(repo)s, %(arch)s, %(project)s and %(package)s for replacement, e.g.
# /srv/oscbuild/%(repo)s-%(arch)s or
# /srv/oscbuild/%(repo)s-%(arch)s-%(project)s-%(package)s
#build-root = /var/tmp/build-root
# compile with N jobs (default: "getconf _NPROCESSORS_ONLN")
#build-jobs = N
# build-type to use - values can be (depending on the capabilities of the 'build' script)
# empty - chroot build
# kvm - kvm VM build (needs build-device, build-swap, build-memory)
# xen - xen VM build (needs build-device, build-swap, build-memory)
# experimental:
# qemu - qemu VM build
# lxc - lxc build
#build-type =
# build-device is the disk-image file to use as root for VM builds
# e.g. /var/tmp/FILE.root
#build-device = /var/tmp/FILE.root
# build-swap is the disk-image to use as swap for VM builds
# e.g. /var/tmp/FILE.swap
#build-swap = /var/tmp/FILE.swap
# build-memory is the amount of memory used in the VM
# value in MB - e.g. 512
#build-memory = 512
# build-vmdisk-rootsize is the size of the disk-image used as root in a VM build
# values in MB - e.g. 4096
#build-vmdisk-rootsize = 4096
# build-vmdisk-swapsize is the size of the disk-image used as swap in a VM build
# values in MB - e.g. 1024
#build-vmdisk-swapsize = 1024
# Numeric uid:gid to assign to the "abuild" user in the build-root
# or "caller" to use the current users uid:gid
# This is convenient when sharing the buildroot with ordinary userids
# on the host.
# This should not be 0
# build-uid =
# extra packages to install when building packages locally (osc build)
# this corresponds to osc build's -x option and can be overridden with that
# -x '' can also be given on the command line to override this setting, or
# you can have an empty setting here.
#extra-pkgs = vim gdb strace
# build platform is used if the platform argument is omitted to osc build
#build_repository = openSUSE_Factory
# default project for getpac or bco
#getpac_default_project = openSUSE:Factory
# alternate filesystem layout: have multiple subdirs, where colons were.
#checkout_no_colon = 0
# local files to ignore with status, addremove, ....
#exclude_glob = .osc CVS .svn .* _linkerror *~ #*# *.orig *.bak *.changes.*
# keep passwords in plaintext. If you see this comment, your osc
# already uses the encrypted password, and only keeps them in plain text
# for backwards compatibility. Default will change to 0 in future releases.
# You can remove the plaintext password without harm, if you do not need
# backwards compatibility.
#plaintext_passwd = 1
# limit the age of requests shown with 'osc req list'.
# this is a default only, can be overridden by 'osc req list -D NNN'
# Use 0 for unlimted.
#request_list_days = 0
# show info useful for debugging
#debug = 1
# show HTTP traffic useful for debugging
#http_debug = 1
# Skip signature verification of packages used for build.
#no_verify = 1
# jump into the debugger in case of errors
#post_mortem = 1
# print call traces in case of errors
#traceback = 1
# use KDE/Gnome/MacOS/Windows keyring for credentials if available
#use_keyring = 1
# check for unversioned/removed files before commit
#check_filelist = 1
# check for pending requests after executing an action (e.g. checkout, update, commit)
#check_for_request_on_action = 0
# what to do with the source package if the submitrequest has been accepted. If
# nothing is specified the API default is used
#submitrequest_on_accept_action = cleanup|update|noupdate
#review requests interactively (default: off)
#request_show_review = 1
# Directory with executables to validate sources, esp before committing
#source_validator_directory = /usr/lib/osc/source_validators
[http://localhost]
user=Admin
pass=opensuse
# set aliases for this apiurl
# aliases = foo, bar
# email used in .changes, unless the one from osc meta prj <user> will be used
# email =
# additional headers to pass to a request, e.g. for special authentication
#http_headers = Host: foofoobar,
# User: mumblegack
# Force using of keyring for this API
#keyring = 1

View File

@ -0,0 +1,14 @@
<resultlist state="c57e2ee592dbbf26ebf19cc4f1bc1e83">
<result project="testproject" repository="openSUSE_Leap_42.3" arch="x86_64" code="published" state="published">
<status package="python-MarkupSafe" code="disabled" />
</result>
<result project="testproject" repository="openSUSE_Leap_15.0" arch="x86_64" code="broken" state="broken" details="repository 'inheritedproject/openSUSE_Leap_15.0' is unavailable">
<status package="python-MarkupSafe" code="disabled" />
</result>
<result project="testproject" repository="SLE_12_SP4" arch="x86_64" code="publishing" state="publishing">
<status package="python-MarkupSafe" code="disabled" />
</result>
<result project="testproject" repository="SLE_12_SP3" arch="x86_64" code="blocked" state="blocked" details="suspendproject" dirty="true">
<status package="python-MarkupSafe" code="disabled" />
</result>
</resultlist>

View File

@ -0,0 +1,14 @@
<resultlist state="f1cfebfd13354bcb8e792cb85f6218d8">
<result project="testproject" repository="openSUSE_Leap_42.3" arch="x86_64" code="published" state="published">
<status package="python-MarkupSafe" code="disabled" />
</result>
<result project="testproject" repository="openSUSE_Leap_15.0" arch="x86_64" code="published" state="published">
<status package="python-MarkupSafe" code="disabled" />
</result>
<result project="testproject" repository="SLE_12_SP4" arch="x86_64" code="published" state="published">
<status package="python-MarkupSafe" code="disabled" />
</result>
<result project="testproject" repository="SLE_12_SP3" arch="x86_64" code="published" state="published">
<status package="python-MarkupSafe" code="disabled" />
</result>
</resultlist>

View File

@ -23,6 +23,7 @@ import test_request
import test_setlinkrev
import test_prdiff
import test_conf
import test_results
suite = unittest.TestSuite()
suite.addTests(test_addfiles.suite())
@ -40,6 +41,7 @@ suite.addTests(test_request.suite())
suite.addTests(test_setlinkrev.suite())
suite.addTests(test_prdiff.suite())
suite.addTests(test_conf.suite())
suite.addTests(test_results.suite())
if have_xmlrunner:
result = xmlrunner.XMLTestRunner(output=os.path.join(os.getcwd(), 'junit-xml-results')).run(suite)

56
tests/test_results.py Normal file
View File

@ -0,0 +1,56 @@
import osc.commandline
from common import GET, OscTestCase
import os
import sys
def suite():
import unittest
return unittest.makeSuite(TestResults)
class TestResults(OscTestCase):
def setUp(self):
OscTestCase.setUp(self, copytree=False)
def _get_fixtures_name(self):
return 'results_fixtures'
def _get_fixtures_dir(self):
return os.path.join(os.path.dirname(__file__), self._get_fixtures_name())
def _run_osc(self, *args):
"""Runs osc, returning captured STDOUT as a string."""
cli = osc.commandline.Osc()
argv = ['osc', '--no-keyring', '--no-gnome-keyring']
argv.extend(args)
cli.main(argv=argv)
return sys.stdout.getvalue()
def _get_fixture(self, filename):
return open(os.path.join(self._get_fixtures_dir(), filename), 'r').read()
@GET('http://localhost/build/testproject/_result', file='result.xml')
def testPrjresults(self):
out = self._run_osc('prjresults', '--xml', 'testproject')
self.assertEqualMultiline(out, self._get_fixture('result.xml')+'\n')
@GET('http://localhost/build/testproject/_result', file='result-dirty.xml')
@GET('http://localhost/build/testproject/_result?oldstate=c57e2ee592dbbf26ebf19cc4f1bc1e83', file='result.xml')
def testPrjresultsWatch(self):
out = self._run_osc('prjresults', '--watch', '--xml', 'testproject')
self.assertEqualMultiline(out, self._get_fixture('result-dirty.xml')+'\n'+self._get_fixture('result.xml')+'\n')
@GET('http://localhost/build/testproject/_result?package=python-MarkupSafe&multibuild=1&locallink=1', file='result.xml')
def testResults(self):
out = self._run_osc('results', '--xml', 'testproject', 'python-MarkupSafe')
self.assertEqualMultiline(out, self._get_fixture('result.xml'))
@GET('http://localhost/build/testproject/_result?package=python-MarkupSafe&multibuild=1&locallink=1', file='result-dirty.xml')
@GET('http://localhost/build/testproject/_result?package=python-MarkupSafe&oldstate=c57e2ee592dbbf26ebf19cc4f1bc1e83&multibuild=1&locallink=1', file='result.xml')
def testResultsWatch(self):
out = self._run_osc('results', '--watch', '--xml', 'testproject', 'python-MarkupSafe')
self.assertEqualMultiline(out, self._get_fixture('result-dirty.xml')+self._get_fixture('result.xml'))
if __name__ == '__main__':
import unittest
unittest.main()