forked from openSUSE/openSUSE-release-tools
/
openqa-maintenance.py
executable file
·713 lines (614 loc) · 26.3 KB
/
openqa-maintenance.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
#!/usr/bin/python
# Copyright (c) 2015,2016 SUSE LLC
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
from optparse import OptionParser
from pprint import pformat, pprint
import cmdln
import logging
import os
import re
import sys
import time
from datetime import date
import md5
from simplejson import JSONDecodeError
from collections import namedtuple
try:
from xml.etree import cElementTree as ET
except ImportError:
import cElementTree as ET
import osc.conf
import osc.core
from osclib.comments import CommentAPI
import ReviewBot
from openqa_client.client import OpenQA_Client
from openqa_client import exceptions as openqa_exceptions
Package = namedtuple('Package', ('name', 'version', 'release'))
pkgname_re = re.compile(r'(?P<name>.+)-(?P<version>[^-]+)-(?P<release>[^-]+)\.(?P<arch>[^.]+)\.rpm')
# QA Results
QA_UNKNOWN = 0
QA_INPROGRESS = 1
QA_FAILED = 2
QA_PASSED = 3
comment_marker_re = re.compile(r'<!-- openqa state=(?P<state>done|seen)(?: result=(?P<result>accepted|declined))? -->')
logger = None
request_name_cache = {}
# old stuff, for reference
# def filterchannel(self, apiurl, prj, packages):
# """ filter list of package objects to only include those actually released into prj"""
#
# prefix = 'SUSE:Updates:'
# logger.debug(prj)
# if not prj.startswith(prefix):
# return packages
#
# channel = prj[len(prefix):].replace(':', '_')
#
# url = osc.core.makeurl(apiurl, ('source', 'SUSE:Channels', channel, '_channel'))
# root = ET.parse(osc.core.http_GET(url)).getroot()
#
# package_names = set([p.name for p in packages])
# in_channel = set([p.attrib['name'] for p in root.iter('binary') if p.attrib['name'] in package_names])
#
# return [p for p in packages if p.name in in_channel]
class Update(object):
def __init__(self, settings):
self._settings = settings
self._settings['_NOOBSOLETEBUILD'] = '1'
def settings(self, src_prj, dst_prj, packages, req=None):
return self._settings.copy()
class SUSEUpdate(Update):
# take the first package name we find - often enough correct
def request_name(self, req):
if req.reqid not in request_name_cache:
request_name_cache[req.reqid] = self._request_name(req)
return request_name_cache[req.reqid]
def _request_name(self, req):
for action in req.get_actions('maintenance_release'):
if action.tgt_package.startswith('patchinfo'):
continue
url = osc.core.makeurl(
req.apiurl,
('source', action.src_project, action.src_package, '_link'))
root = ET.parse(osc.core.http_GET(url)).getroot()
if root.attrib.get('cicount'):
continue
return action.tgt_package
return 'unknown'
def settings(self, src_prj, dst_prj, packages, req=None):
settings = super(SUSEUpdate, self).settings(src_prj, dst_prj, packages, req)
# start with a colon so it looks cool behind 'Build' :/
settings['BUILD'] = ':' + req.reqid + '.' + self.request_name(req)
repo = 'http://download.suse.de/ibs/%s/%s/' % (src_prj.replace(':', ':/'), dst_prj.replace(':', '_'))
settings['MINIMAL_TEST_REPO'] = repo
return settings
class openSUSEUpdate(Update):
def settings(self, src_prj, dst_prj, packages, req=None):
settings = super(openSUSEUpdate, self).settings(src_prj, dst_prj, packages, req)
settings['BUILD'] = src_prj
if req:
settings['BUILD'] += ':' + req.reqid
# openSUSE:Maintenance key
settings['IMPORT_GPG_KEYS'] = 'gpg-pubkey-b3fd7e48-5549fd0f'
settings['ZYPPER_ADD_REPO_PREFIX'] = 'incident'
if packages:
# XXX: this may fail in various ways
# - conflicts between subpackages
# - added packages
# - conflicts with installed packages (e.g sendmail vs postfix)
settings['INSTALL_PACKAGES'] = ' '.join(set([p.name for p in packages]))
settings['VERIFY_PACKAGE_VERSIONS'] = ' '.join(['{} {}-{}'.format(p.name, p.version, p.release) for p in packages])
settings['ZYPPER_ADD_REPOS'] = 'http://download.opensuse.org/repositories/%s/%s/' % (src_prj.replace(':', ':/'), dst_prj.replace(':', '_'))
settings['ADDONURL'] = settings['ZYPPER_ADD_REPOS']
settings['ISO'] = 'openSUSE-Leap-42.1-DVD-x86_64.iso'
settings['WITH_MAIN_REPO'] = 1
settings['WITH_UPDATE_REPO'] = 1
return settings
class TestUpdate(openSUSEUpdate):
def settings(self, src_prj, dst_prj, packages, req=None):
settings = super(TestUpdate, self).settings(src_prj, dst_prj, packages, req)
settings['IMPORT_GPG_KEYS'] = 'testkey'
return settings
TARGET_REPO_SETTINGS = {
'SUSE:Updates:SLE-SERVER:12:x86_64': {
'repos': [
'http://download.suse.de/ibs/SUSE:/Maintenance:/Test:/SLE-SERVER:/12:/x86_64/update',
'http://download.suse.de/ibs/SUSE:/Maintenance:/Test:/SLE-SDK:/12:/x86_64/update/'
],
'settings': {
'DISTRI': 'sle',
'VERSION': '12',
'FLAVOR': 'Server-DVD-UpdateTest',
'ARCH': 'x86_64',
},
'test': 'qam-gnome'
},
'SUSE:Updates:SLE-SERVER:12-SP1:x86_64': {
'repos' : [
'http://download.suse.de/ibs/SUSE:/Maintenance:/Test:/SLE-SERVER:/12-SP1:/x86_64/update',
'http://download.suse.de/ibs/SUSE:/Maintenance:/Test:/SLE-SDK:/12-SP1:/x86_64/update/'
],
'settings': {
'DISTRI': 'sle',
'VERSION': '12-SP1',
'FLAVOR': 'Server-DVD-UpdateTest',
'ARCH': 'x86_64'
},
'test': 'qam-gnome'
},
'SUSE:Updates:SLE-DESKTOP:12:x86_64': {
'repos': [
'http://download.suse.de/ibs/SUSE:/Maintenance:/Test:/SLE-DESKTOP:/12:/x86_64/update',
'http://download.suse.de/ibs/SUSE:/Maintenance:/Test:/SLE-SDK:/12:/x86_64/update/'
],
'settings': {
'DISTRI': 'sle',
'VERSION': '12',
'FLAVOR': 'Desktop-DVD-UpdateTest',
'ARCH': 'x86_64',
},
'test': 'qam-gnome'
},
'SUSE:Updates:SLE-DESKTOP:12-SP1:x86_64': {
'repos': [
'http://download.suse.de/ibs/SUSE:/Maintenance:/Test:/SLE-DESKTOP:/12-SP1:/x86_64/update',
'http://download.suse.de/ibs/SUSE:/Maintenance:/Test:/SLE-SDK:/12:/x86_64/update/'
],
'settings': {
'DISTRI': 'sle',
'VERSION': '12-SP1',
'FLAVOR': 'Desktop-DVD-UpdateTest',
'ARCH': 'x86_64',
},
'test': 'qam-gnome'
},
}
PROJECT_OPENQA_SETTINGS = {
'openSUSE:13.2:Update': [
openSUSEUpdate(
{
'DISTRI': 'opensuse',
'VERSION': '13.2',
'FLAVOR': 'Maintenance',
'ARCH': 'x86_64',
}),
openSUSEUpdate(
{
'DISTRI': 'opensuse',
'VERSION': '13.2',
'FLAVOR': 'Maintenance',
'ARCH': 'i586',
}),
],
'SUSE:Updates:SLE-SERVER:12:x86_64': [
SUSEUpdate(
{
'DISTRI': 'sle',
'VERSION': '12',
'FLAVOR': 'Server-DVD-Incidents',
'ARCH': 'x86_64'
}),
],
'SUSE:Updates:SLE-SERVER:12:ppc64le': [
SUSEUpdate(
{
'DISTRI': 'sle',
'VERSION': '12',
'FLAVOR': 'Server-DVD-Incidents',
'ARCH': 'ppc64le'
}),
],
'SUSE:Updates:SLE-SERVER:12:s390x': [
SUSEUpdate(
{
'DISTRI': 'sle',
'VERSION': '12',
'FLAVOR': 'Server-DVD-Incidents',
'ARCH': 's390x'
}),
],
'SUSE:Updates:SLE-SERVER:12-SP1:x86_64': [
SUSEUpdate(
{
'DISTRI': 'sle',
'VERSION': '12-SP1',
'FLAVOR': 'Server-DVD-Incidents',
'ARCH': 'x86_64'
}),
],
'SUSE:Updates:SLE-SERVER:12-SP1:ppc64le': [
SUSEUpdate(
{
'DISTRI': 'sle',
'VERSION': '12-SP1',
'FLAVOR': 'Server-DVD-Incidents',
'ARCH': 'ppc64le'
}),
],
'SUSE:Updates:SLE-SERVER:12-SP1:s390x': [
SUSEUpdate(
{
'DISTRI': 'sle',
'VERSION': '12-SP1',
'FLAVOR': 'Server-DVD-Incidents',
'ARCH': 's390x'
}),
],
'openSUSE:Leap:42.1:Update': [
openSUSEUpdate(
{
'DISTRI': 'opensuse',
'VERSION': '42.1',
'FLAVOR': 'Maintenance',
'ARCH': 'x86_64',
}),
],
}
class OpenQABot(ReviewBot.ReviewBot):
""" check ABI of library packages
"""
def __init__(self, *args, **kwargs):
self.force = False
self.openqa = None
self.do_comments = True
if 'force' in kwargs:
if kwargs['force'] is True:
self.force = True
del kwargs['force']
if 'openqa' in kwargs:
self.openqa = OpenQA_Client(server=kwargs['openqa'])
del kwargs['openqa']
if 'do_comments' in kwargs:
if kwargs['do_comments'] is not None:
self.do_comments = kwargs['do_comments']
del kwargs['do_comments']
ReviewBot.ReviewBot.__init__(self, *args, **kwargs)
self.logger.debug(self.do_comments)
self.commentapi = CommentAPI(self.apiurl)
self.update_test_builds = dict()
def prepare_review(self):
for prj, u in TARGET_REPO_SETTINGS.items():
self.trigger_build_for_target(prj, u)
def check_action_maintenance_release(self, req, a):
# we only look at the binaries of the patchinfo
if a.src_package != 'patchinfo':
return None
if a.tgt_project not in PROJECT_OPENQA_SETTINGS:
self.logger.warn("not handling %s" % a.tgt_project)
return None
packages = []
# patchinfo collects the binaries and is build for an
# unpredictable architecture so we need iterate over all
url = osc.core.makeurl(
self.apiurl,
('build', a.src_project, a.tgt_project.replace(':', '_')))
root = ET.parse(osc.core.http_GET(url)).getroot()
for arch in [n.attrib['name'] for n in root.findall('entry')]:
query = {'nosource': 1}
url = osc.core.makeurl(
self.apiurl,
('build', a.src_project, a.tgt_project.replace(':', '_'), arch, a.src_package),
query=query)
root = ET.parse(osc.core.http_GET(url)).getroot()
for binary in root.findall('binary'):
m = pkgname_re.match(binary.attrib['filename'])
if m:
# can't use arch here as the patchinfo mixes all
# archs
packages.append(Package(m.group('name'), m.group('version'), m.group('release')))
if not packages:
raise Exception("no packages found")
self.logger.debug('found packages %s', ' '.join(set([p.name for p in packages])))
for update in PROJECT_OPENQA_SETTINGS[a.tgt_project]:
settings = update.settings(a.src_project, a.tgt_project, packages, req)
if settings is not None:
self.logger.info("posting %s %s %s", settings['VERSION'], settings['ARCH'], settings['BUILD'])
self.logger.debug('\n'.join([" %s=%s" % i for i in settings.items()]))
if not self.dryrun:
try:
ret = self.openqa.openqa_request('POST', 'isos', data=settings, retries=1)
self.logger.info(pformat(ret))
except JSONDecodeError, e:
self.logger.error(e)
# TODO: record error
except openqa_exceptions.RequestError, e:
self.logger.error(e)
return None
# check a set of repos for their primary checksums
def calculate_repo_hash(self, repos):
m = md5.new()
# if you want to force it, increase this number
m.update('2')
for url in repos:
url += '/repodata/repomd.xml'
root = ET.parse(osc.core.http_GET(url)).getroot()
cs = root.find('.//{http://linux.duke.edu/metadata/repo}data[@type="primary"]/{http://linux.duke.edu/metadata/repo}checksum')
m.update(cs.text)
return m.hexdigest()
# we don't know the current BUILD and querying all jobs is too expensive
# so we need to check for one known TEST first
# if that job doesn't contain the proper hash, we trigger a new one
# and then we know the build
def trigger_build_for_target(self, prj, u):
today=date.today().strftime("%Y%m%d")
repohash=self.calculate_repo_hash(u['repos'])
s = u['settings']
j = self.openqa.openqa_request(
'GET', 'jobs',
{
'distri': s['DISTRI'],
'version': s['VERSION'],
'arch': s['ARCH'],
'flavor': s['FLAVOR'],
'test': u['test'],
'latest': '1',
})['jobs']
buildnr = None
for job in j:
if job['settings'].get('REPOHASH', '') == repohash:
# take the last in the row
buildnr = job['settings']['BUILD']
self.update_test_builds[prj] = buildnr
# ignore old build numbers, we want a fresh run every day
# to find regressions in the tests and to get data about
# randomly failing tests
if buildnr and buildnr.startswith(today):
return
buildnr = 0
# not found, then check for the next free build nr
for job in j:
build = job['settings']['BUILD']
if build and build.startswith(today):
try:
nr = int(build.split('-')[1])
except:
continue
if nr > buildnr:
buildnr = nr
buildnr = "%s-%d" % (today, buildnr + 1)
# now schedule it for real
s['BUILD'] = buildnr
s['REPOHASH'] = repohash
self.openqa.openqa_request('POST', 'isos', data=s, retries=1)
self.update_test_builds[prj] = buildnr
def check_source_submission(self, src_project, src_package, src_rev, dst_project, dst_package):
ReviewBot.ReviewBot.check_source_submission(self, src_project, src_package, src_rev, dst_project, dst_package)
def request_get_openqa_jobs(self, req):
ret = None
types = set([a.type for a in req.actions])
if 'maintenance_release' in types:
src_prjs = set([a.src_project for a in req.actions])
if len(src_prjs) != 1:
raise Exception("can't handle maintenance_release from different incidents")
build = src_prjs.pop()
tgt_prjs = set([a.tgt_project for a in req.actions])
ret = []
for prj in tgt_prjs:
if prj in PROJECT_OPENQA_SETTINGS:
for u in PROJECT_OPENQA_SETTINGS[prj]:
s = u.settings(build, prj, [], req=req)
ret += self.openqa.openqa_request(
'GET', 'jobs',
{
'distri': s['DISTRI'],
'version': s['VERSION'],
'arch': s['ARCH'],
'flavor': s['FLAVOR'],
'build': s['BUILD'],
'scope': 'relevant',
})['jobs']
if prj in TARGET_REPO_SETTINGS:
u = TARGET_REPO_SETTINGS[prj]
s = u['settings']
ret += self.openqa.openqa_request(
'GET', 'jobs',
{
'distri': s['DISTRI'],
'version': s['VERSION'],
'arch': s['ARCH'],
'flavor': s['FLAVOR'],
'build': self.update_test_builds[prj],
'scope': 'relevant',
})['jobs']
return ret
def calculate_qa_status(self, jobs=None):
if not jobs:
return QA_UNKNOWN
j = dict()
has_failed = False
in_progress = False
for job in jobs:
if job['clone_id']:
continue
name = job['name']
if name in j and int(job['id']) < int(j[name]['id']):
continue
j[name] = job
self.logger.debug('job %s in openQA: %s %s %s %s', job['id'], job['settings']['VERSION'], job['settings']['TEST'], job['state'], job['result'])
if job['state'] not in ('cancelled', 'done'):
in_progress = True
else:
if job['result'] != 'passed':
has_failed = True
if not j:
return QA_UNKNOWN
if in_progress:
return QA_INPROGRESS
if has_failed:
return QA_FAILED
return QA_PASSED
def check_publish_enabled(self, project):
url = osc.core.makeurl(self.apiurl, ('source', project, '_meta'))
root = ET.parse(osc.core.http_GET(url)).getroot()
node = root.find('publish')
if node is not None and node.find('disable') is not None:
return False
return True
def add_comment(self, req, msg, state, result=None):
if not self.do_comments:
return
comment = "<!-- openqa state=%s%s -->\n" % (state, ' result=%s' % result if result else '')
comment += "\n" + msg
(comment_id, comment_state, comment_result, comment_text) = self.find_obs_request_comment(req, state)
if comment_id is not None and state == comment_state:
lines_before = len(comment_text.split('\n'))
lines_after = len(comment.split('\n'))
if lines_before == lines_after:
self.logger.debug("not worth the update, previous comment %s is state %s", comment_id, comment_state)
return
self.logger.debug("adding comment to %s, state %s result %s", req.reqid, state, result)
self.logger.debug("message: %s", msg)
if not self.dryrun:
if comment_id is not None:
self.commentapi.delete(comment_id)
self.commentapi.add_comment(request_id=req.reqid, comment=str(comment))
def openqa_overview_url_from_settings(self, settings):
return osc.core.makeurl(self.openqa.baseurl, ['tests'], {'match': settings['BUILD']})
def find_failed_modules(self, job):
failed = []
for module in job['modules']:
if module['result'] != 'failed':
continue
failed.append(module['name'])
return failed
# escape markdown
def emd(self, str):
return str.replace('_', '\_')
def check_one_request(self, req):
ret = None
# just patch apiurl in to avoid having to pass it around
req.apiurl = self.apiurl
try:
jobs = self.request_get_openqa_jobs(req)
qa_state = self.calculate_qa_status(jobs)
self.logger.debug("request %s state %s", req.reqid, qa_state)
msg = None
if self.force or qa_state == QA_UNKNOWN:
ret = ReviewBot.ReviewBot.check_one_request(self, req)
jobs = self.request_get_openqa_jobs(req)
if self.force:
# make sure to delete previous comments if we're forcing
(comment_id, comment_state, comment_result, comment_text) = self.find_obs_request_comment(req)
if comment_id is not None:
self.logger.debug("deleting old comment %s", comment_id)
if not self.dryrun:
self.commentapi.delete(comment_id)
if not jobs:
msg = "no openQA tests defined"
self.add_comment(req, msg, 'done', 'accepted')
ret = True
else:
url = self.openqa_overview_url_from_settings(jobs[0]['settings'])
self.logger.debug("url %s", url)
msg = "now testing in [openQA](%s)" % url
self.add_comment(req, msg, 'seen')
elif qa_state == QA_FAILED or qa_state == QA_PASSED:
url = self.openqa_overview_url_from_settings(jobs[0]['settings'])
if qa_state == QA_PASSED:
self.logger.debug("request %s passed", req.reqid)
msg = "openQA test [passed](%s)\n" % url
state = 'accepted'
ret = True
else:
self.logger.debug("request %s failed", req.reqid)
msg = "openQA test *[FAILED](%s)*\n" % url
state = 'declined'
ret = False
groups = dict()
for job in jobs:
modules = self.find_failed_modules(job)
if modules != []:
modstrings = []
for mod in modules:
modurl = osc.core.makeurl(self.openqa.baseurl, ['tests', str(job['id'])])
modstrings.append("[%s](%s#step/%s/1)" % (self.emd(mod), modurl, mod))
gl = "%s@%s" % (self.emd(job['group']), self.emd(job['settings']['FLAVOR']))
if not gl in groups:
groupurl = osc.core.makeurl(self.openqa.baseurl, ['tests', 'overview' ],
{ 'version': job['settings']['VERSION'],
'groupid': job['group_id'],
'flavor': job['settings']['FLAVOR'],
'distri': job['settings']['DISTRI'],
'build': job['settings']['BUILD'],
})
gmsg = "__Group [%s](%s)__\n" % (gl, groupurl)
else:
gmsg = groups[gl]
gmsg += '\n- [%s](%s) failed in %s' % (
self.emd(job['settings']['TEST']),
osc.core.makeurl(self.openqa.baseurl, ['tests', str(job['id'])]),
','.join(modstrings))
groups[gl] = gmsg
for group in sorted(groups.keys()):
msg += "\n\n" + groups[group]
self.add_comment(req, msg, 'done', state)
elif qa_state == QA_INPROGRESS:
self.logger.debug("request %s still in progress", req.reqid)
else:
raise Exception("unknown QA state %d", qa_state)
except Exception, e:
import traceback
self.logger.error("unhandled exception in openQA Bot")
self.logger.error(traceback.format_exc())
ret = None
return ret
def find_obs_request_comment(self, req, state=None):
"""Return previous comments (should be one)."""
if self.do_comments:
comments = self.commentapi.get_comments(request_id=req.reqid)
for c in comments.values():
m = comment_marker_re.match(c['comment'])
if m and (state is None or state == m.group('state')):
return c['id'], m.group('state'), m.group('result'), c['comment']
return None, None, None, None
class CommandLineInterface(ReviewBot.CommandLineInterface):
def __init__(self, *args, **kwargs):
ReviewBot.CommandLineInterface.__init__(self, args, kwargs)
def get_optparser(self):
parser = ReviewBot.CommandLineInterface.get_optparser(self)
parser.add_option("--force", action="store_true", help="recheck requests that are already considered done")
parser.add_option("--no-comment", dest='comment', action="store_false", help="don't actually post comments to obs")
parser.add_option("--openqa", metavar='HOST', help="openqa api host")
return parser
def setup_checker(self):
apiurl = osc.conf.config['apiurl']
if apiurl is None:
raise osc.oscerr.WrongArgs("missing apiurl")
user = self.options.user
group = self.options.group
if user is None and group is None:
user = osc.conf.get_apiurl_usr(apiurl)
if not self.options.openqa:
raise osc.oscerr.WrongArgs("missing openqa url")
global logger
logger = self.logger
return OpenQABot(
apiurl=apiurl,
dryrun=self.options.dry,
user=user,
group=group,
do_comments=self.options.comment,
openqa=self.options.openqa,
force=self.options.force,
logger=self.logger)
if __name__ == "__main__":
app = CommandLineInterface()
sys.exit(app.main())
# vim: sw=4 et