forked from openSUSE/openSUSE-release-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverify-repo-built-successful.py
executable file
·70 lines (59 loc) · 2.85 KB
/
verify-repo-built-successful.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
#!/usr/bin/python3
import argparse
import logging
import sys
import time
import osc
from osc.core import http_GET, makeurl
from osclib.core import target_archs
from lxml import etree as ET
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Check if all packages built fine')
parser.add_argument('--apiurl', '-A', type=str, help='API URL of OBS')
parser.add_argument('-p', '--project', type=str, help='Project to check',
required=True)
parser.add_argument('-r', '--repository', type=str,
help='Repository to check', required=True)
args = parser.parse_args()
osc.conf.get_config(override_apiurl=args.apiurl)
apiurl = osc.conf.config['apiurl']
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
# first check if repo is available
url = makeurl(apiurl, ['source', args.project, "_meta"])
root = ET.parse(http_GET(url)).getroot()
if not root.xpath(f'repository[@name="{args.repository}"]'):
logger.error(f'Repository {args.repository} is not available in {args.project}')
sys.exit(2)
# then check if repo is finished
archs = target_archs(apiurl, args.project, args.repository)
for arch in archs:
url = makeurl(apiurl, ['build', args.project, args.repository, arch], {'view': 'status'})
root = ET.parse(http_GET(url)).getroot()
if root.get('code') == 'finished':
continue
logger.error(f'Repository {args.project}/{args.repository}/{arch} is not yet finished')
logger.debug(ET.tostring(root).decode('utf-8'))
# scheduling means the scheduler had some reason to double check the repository state.
# this may or may not result in a restart of the build, but if it doesn't, we're in trouble.
# There won't arrive any new finished event - so better keep looking
if root.get('code') == 'scheduling' or root.get('dirty', 'false') == 'true':
time.sleep(60)
continue
sys.exit(1)
# now check if all packages built fine
url = makeurl(apiurl, ['build', args.project, '_result'],
{'view': 'summary', 'repository': args.repository})
root = ET.parse(http_GET(url)).getroot()
counts = {'succeeded': 0, 'disabled': 0, 'excluded': 0}
for count in root.findall('.//statuscount'):
if int(count.get('count', 0)) == 0:
continue
if count.get('code') in ['succeeded', 'excluded', 'disabled']:
counts[count.get('code')] = int(count.get('count'))
continue
logger.error(f"Repository {args.project}/{args.repository} has {count.get('code')} packages")
sys.exit(1)
if counts['disabled'] > counts['succeeded']:
logger.error(f'Repository {args.project}/{args.repository} has more disabled packages than succeeded')
sys.exit(1)