2019-05-18 17:25:26 +02:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import logging
|
|
|
|
import sys
|
2022-04-01 12:30:35 +02:00
|
|
|
import time
|
2019-05-18 17:25:26 +02:00
|
|
|
|
|
|
|
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')
|
2024-06-17 16:15:17 +02:00
|
|
|
parser.add_argument('-p', '--project', type=str, help='Project to check',
|
|
|
|
required=True)
|
2019-05-18 17:25:26 +02:00
|
|
|
parser.add_argument('-r', '--repository', type=str,
|
2024-06-17 16:15:17 +02:00
|
|
|
help='Repository to check', required=True)
|
2019-05-18 17:25:26 +02:00
|
|
|
|
|
|
|
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 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
|
2024-05-07 17:55:17 +02:00
|
|
|
logger.error(f'Repository {args.project}/{args.repository}/{arch} is not yet finished')
|
2019-05-31 12:05:53 +02:00
|
|
|
logger.debug(ET.tostring(root).decode('utf-8'))
|
2022-04-01 12:30:35 +02:00
|
|
|
# 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
|
2019-05-18 17:25:26 +02:00
|
|
|
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()
|
2022-03-18 08:00:52 +01:00
|
|
|
counts = {'succeeded': 0, 'disabled': 0, 'excluded': 0}
|
2019-05-18 17:25:26 +02:00
|
|
|
for count in root.findall('.//statuscount'):
|
|
|
|
if int(count.get('count', 0)) == 0:
|
|
|
|
continue
|
|
|
|
if count.get('code') in ['succeeded', 'excluded', 'disabled']:
|
2022-03-18 08:00:52 +01:00
|
|
|
counts[count.get('code')] = int(count.get('count'))
|
2019-05-18 17:25:26 +02:00
|
|
|
continue
|
2024-05-07 17:55:17 +02:00
|
|
|
logger.error(f"Repository {args.project}/{args.repository} has {count.get('code')} packages")
|
2019-05-18 17:25:26 +02:00
|
|
|
sys.exit(1)
|
2022-03-18 08:00:52 +01:00
|
|
|
|
|
|
|
if counts['disabled'] > counts['succeeded']:
|
2024-05-07 17:55:17 +02:00
|
|
|
logger.error(f'Repository {args.project}/{args.repository} has more disabled packages than succeeded')
|
2022-03-18 08:00:52 +01:00
|
|
|
sys.exit(1)
|