2014-05-27 11:14:35 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# (C) 2014 mhrusecky@suse.cz, openSUSE.org
|
|
|
|
# (C) 2014 tchvatal@suse.cz, openSUSE.org
|
|
|
|
# (C) 2014 aplanas@suse.de, openSUSE.org
|
|
|
|
# (C) 2014 coolo@suse.de, openSUSE.org
|
|
|
|
# Distribute under GPLv2 or GPLv3
|
|
|
|
|
2014-09-12 11:42:42 +02:00
|
|
|
import argparse
|
|
|
|
import json
|
2014-05-27 11:14:35 +02:00
|
|
|
import os
|
2014-09-12 11:42:42 +02:00
|
|
|
import re
|
2014-05-27 11:14:35 +02:00
|
|
|
import sys
|
2014-09-12 11:42:42 +02:00
|
|
|
from xml.etree import cElementTree as ET
|
2014-05-27 11:14:35 +02:00
|
|
|
|
2014-09-12 11:42:42 +02:00
|
|
|
import osc
|
2014-05-28 15:14:58 +02:00
|
|
|
|
2014-05-27 11:14:35 +02:00
|
|
|
|
|
|
|
# Expand sys.path to search modules inside the pluging directory
|
2014-09-01 14:17:23 +02:00
|
|
|
PLUGINDIR = os.path.expanduser(os.path.dirname(os.path.realpath(__file__)))
|
|
|
|
sys.path.append(PLUGINDIR)
|
2014-05-27 11:14:35 +02:00
|
|
|
|
|
|
|
from osclib.stagingapi import StagingAPI
|
|
|
|
|
2014-09-12 11:42:42 +02:00
|
|
|
|
|
|
|
# QA Results
|
|
|
|
QA_INPROGRESS = 1
|
|
|
|
QA_FAILED = 2
|
|
|
|
QA_PASSED = 3
|
|
|
|
|
|
|
|
|
|
|
|
class ToTestBase(object):
|
|
|
|
"""Base class to store the basic interface"""
|
|
|
|
|
|
|
|
def __init__(self, project):
|
|
|
|
self.project = project
|
|
|
|
if project == 'Factory':
|
|
|
|
self.version = 'FTT'
|
|
|
|
else:
|
|
|
|
self.version = project
|
|
|
|
self.api = StagingAPI(osc.conf.config['apiurl'])
|
|
|
|
|
|
|
|
def get_current_snapshot(self):
|
|
|
|
"""Return the current snapshot in :ToTest"""
|
|
|
|
|
|
|
|
# for now we hardcode all kind of things
|
|
|
|
url = self.api.makeurl(['build', 'openSUSE:%s:ToTest' % self.project,
|
|
|
|
'images', 'local', '_product:openSUSE-cd-mini-i586'])
|
|
|
|
f = self.api.retried_GET(url)
|
|
|
|
root = ET.parse(f).getroot()
|
|
|
|
for binary in root.findall('binary'):
|
|
|
|
result = re.match(r'openSUSE-%s-NET-i586-Snapshot(.*)-Media.iso' % self.project,
|
|
|
|
binary.get('filename'))
|
|
|
|
if result:
|
|
|
|
return result.group(1)
|
|
|
|
|
|
|
|
def find_openqa_results(self, snapshot):
|
|
|
|
"""Return the openqa jobs of a given snapshot and filter out the
|
|
|
|
cloned jobs
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
url = 'https://openqa.opensuse.org/api/v1/' \
|
|
|
|
'jobs?version={}&build={}&distri=opensuse'.format(self.version, snapshot)
|
|
|
|
f = self.api.retried_GET(url)
|
|
|
|
jobs = []
|
|
|
|
for job in json.load(f)['jobs']:
|
|
|
|
if job['clone_id']:
|
|
|
|
continue
|
|
|
|
job['name'] = job['name'].replace(snapshot, '')
|
|
|
|
jobs.append(job)
|
|
|
|
return jobs
|
|
|
|
|
|
|
|
def _result2str(self, result):
|
|
|
|
if result == QA_INPROGRESS:
|
|
|
|
return 'inprogress'
|
|
|
|
elif result == QA_FAILED:
|
|
|
|
return 'failed'
|
|
|
|
else:
|
|
|
|
return 'passed'
|
|
|
|
|
|
|
|
def find_failed_module(self, result):
|
|
|
|
# print json.dumps(result, sort_keys=True, indent=4)
|
|
|
|
for module in result['testmodules']:
|
|
|
|
if module['result'] != 'fail':
|
|
|
|
continue
|
|
|
|
flags = module['flags']
|
|
|
|
if 'fatal' in flags or 'important' in flags:
|
|
|
|
return module['name']
|
|
|
|
break
|
|
|
|
print module['name'], module['result'], module['flags']
|
|
|
|
|
|
|
|
def overall_result(self, snapshot):
|
|
|
|
"""Analyze the openQA jobs of a given snapshot Returns a QAResult"""
|
|
|
|
|
|
|
|
jobs = self.find_openqa_results(snapshot)
|
|
|
|
|
|
|
|
if len(jobs) < 90: # not yet scheduled
|
|
|
|
print 'we have only %s jobs' % len(jobs)
|
|
|
|
return QA_INPROGRESS
|
|
|
|
|
|
|
|
number_of_fails = 0
|
|
|
|
in_progress = False
|
|
|
|
for job in jobs:
|
|
|
|
# print json.dumps(job, sort_keys=True, indent=4)
|
|
|
|
if job['result'] in ('failed', 'incomplete'):
|
|
|
|
jobname = job['name'] + '@' + job['settings']['MACHINE']
|
|
|
|
if jobname in self.known_failures:
|
|
|
|
self.known_failures.remove(jobname)
|
|
|
|
continue
|
|
|
|
number_of_fails += 1
|
|
|
|
# print json.dumps(job, sort_keys=True, indent=4), jobname
|
|
|
|
url = 'https://openqa.opensuse.org/tests/%s' % job['id']
|
|
|
|
result = json.load(self.api.retried_GET(url + '/file/results.json'))
|
|
|
|
failedmodule = self.find_failed_module(result)
|
|
|
|
print jobname, url, failedmodule, job['retry_avbl']
|
|
|
|
# if number_of_fails < 3: continue
|
|
|
|
elif job['result'] == 'passed':
|
|
|
|
continue
|
|
|
|
elif job['result'] == 'none':
|
|
|
|
if job['state'] != 'cancelled':
|
|
|
|
in_progress = True
|
|
|
|
else:
|
|
|
|
raise Exception(job['result'])
|
|
|
|
|
|
|
|
if number_of_fails > 0:
|
|
|
|
return QA_FAILED
|
|
|
|
|
|
|
|
if in_progress:
|
|
|
|
return QA_INPROGRESS
|
|
|
|
|
|
|
|
if self.known_failures:
|
|
|
|
print 'Some are now passing', self.known_failures
|
|
|
|
return QA_PASSED
|
|
|
|
|
|
|
|
def all_repos_done(self, project, codes=None):
|
|
|
|
"""Check the build result of the project and only return True if all
|
|
|
|
repos of that project are either published or unpublished
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
codes = ['published', 'unpublished'] if not codes else codes
|
|
|
|
|
|
|
|
url = self.api.makeurl(['build', project, '_result'], {'code': 'failed'})
|
|
|
|
f = self.api.retried_GET(url)
|
|
|
|
root = ET.parse(f).getroot()
|
|
|
|
for repo in root.findall('result'):
|
|
|
|
if repo.get('dirty', '') == 'true':
|
|
|
|
print repo.get('project'), repo.get('repository'), repo.get('arch'), 'dirty'
|
|
|
|
return False
|
|
|
|
if repo.get('code') not in codes:
|
|
|
|
print repo.get('project'), repo.get('repository'), repo.get('arch'), repo.get('code')
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
def maxsize_for_package(self, package):
|
|
|
|
if re.match(r'.*-mini-.*', package):
|
|
|
|
return 737280000 # a CD needs to match
|
|
|
|
|
|
|
|
if re.match(r'.*-dvd5-.*', package):
|
|
|
|
return 4700372992 # a DVD needs to match
|
|
|
|
|
|
|
|
if re.match(r'.*-image-livecd-x11.*', package):
|
|
|
|
return 681574400 # not a full CD
|
|
|
|
|
|
|
|
if re.match(r'.*-image-livecd.*', package):
|
|
|
|
return 999999999 # a GB stick
|
|
|
|
|
|
|
|
if package == '_product:openSUSE-ftp-ftp-i586_x86_64':
|
|
|
|
return None
|
|
|
|
|
|
|
|
if package == '_product:openSUSE-Addon-NonOss-ftp-ftp-i586_x86_64':
|
|
|
|
return None
|
|
|
|
|
|
|
|
raise Exception('No maxsize for {}'.format(package))
|
|
|
|
|
|
|
|
def package_ok(self, project, package, repository, arch):
|
|
|
|
"""Checks one package in a project and returns True if it's succeeded
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
query = {'package': package, 'repository': repository, 'arch': arch}
|
|
|
|
|
|
|
|
url = self.api.makeurl(['build', project, '_result'], query)
|
|
|
|
f = self.api.retried_GET(url)
|
|
|
|
root = ET.parse(f).getroot()
|
|
|
|
for repo in root.findall('result'):
|
|
|
|
status = repo.find('status')
|
|
|
|
if status.get('code') != 'succeeded':
|
|
|
|
print project, package, repository, arch, status.get('code')
|
|
|
|
return False
|
|
|
|
|
|
|
|
maxsize = self.tt_maxsize_for_package(package)
|
|
|
|
if not maxsize:
|
|
|
|
return True
|
|
|
|
|
|
|
|
url = self.api.makeurl(['build', project, repository, arch, package])
|
|
|
|
f = self.api.retried_GET(url)
|
|
|
|
root = ET.parse(f).getroot()
|
|
|
|
for binary in root.findall('binary'):
|
|
|
|
if not binary.get('filename', '').endswith('.iso'):
|
|
|
|
continue
|
|
|
|
isosize = int(binary.get('size', 0))
|
|
|
|
if isosize > maxsize:
|
|
|
|
print project, package, repository, arch, 'too large by %s bytes' % isosize-maxsize
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
def factory_snapshottable(self):
|
|
|
|
"""Check various conditions required for factory to be snapshotable
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
if not self.all_repos_done('openSUSE:%s' % self.project):
|
|
|
|
return False
|
|
|
|
|
|
|
|
for product in ['_product:openSUSE-ftp-ftp-i586_x86_64',
|
|
|
|
'_product:openSUSE-Addon-NonOss-ftp-ftp-i586_x86_64',
|
|
|
|
'_product:openSUSE-dvd5-dvd-i586',
|
|
|
|
'_product:openSUSE-dvd5-dvd-x86_64',
|
|
|
|
'_product:openSUSE-cd-mini-i586',
|
|
|
|
'_product:openSUSE-cd-mini-x86_64']:
|
|
|
|
if not self.package_ok('openSUSE:%s' % self.project, product, 'images', 'local'):
|
|
|
|
return False
|
|
|
|
|
|
|
|
if not self.all_repos_done('openSUSE:%s:Live' % self.project):
|
|
|
|
return False
|
|
|
|
|
|
|
|
for product in ['kiwi-image-livecd-kde.i586',
|
|
|
|
'kiwi-image-livecd-gnome.i586',
|
|
|
|
'kiwi-image-livecd-x11']:
|
|
|
|
if not self.package_ok('openSUSE:%s:Live' % self.project, product, 'standard', 'i586'):
|
|
|
|
return False
|
|
|
|
|
|
|
|
for product in ['kiwi-image-livecd-kde.x86_64',
|
|
|
|
'kiwi-image-livecd-gnome.x86_64',
|
|
|
|
'kiwi-image-livecd-x11']:
|
|
|
|
if not self.package_ok('openSUSE:%s:Live' % self.project, product, 'standard', 'x86_64'):
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
def release_package(self, project, package, set_release=None):
|
|
|
|
query = {'cmd': 'release'}
|
|
|
|
|
|
|
|
if set_release:
|
|
|
|
query['setrelease'] = set_release
|
|
|
|
|
|
|
|
baseurl = ['source', project, package]
|
|
|
|
|
|
|
|
url = self.api.makeurl(baseurl, query=query)
|
|
|
|
self.api.retried_POST(url)
|
|
|
|
|
|
|
|
def update_totest(self, snapshot):
|
|
|
|
print 'Updating snapshot %s' % snapshot
|
|
|
|
self.api.switch_flag_in_prj('openSUSE:%s:ToTest' % self.project, flag='publish', state='disable')
|
|
|
|
|
|
|
|
self.release_package('openSUSE:%s' % self.project, '_product:openSUSE-ftp-ftp-i586_x86_64')
|
|
|
|
self.release_package('openSUSE:%s' % self.project, '_product:openSUSE-Addon-NonOss-ftp-ftp-i586_x86_64')
|
|
|
|
for cd in ['kiwi-image-livecd-kde.i586',
|
|
|
|
'kiwi-image-livecd-kde.x86_64',
|
|
|
|
'kiwi-image-livecd-gnome.i586',
|
|
|
|
'kiwi-image-livecd-gnome.x86_64',
|
|
|
|
'kiwi-image-livecd-x11']:
|
|
|
|
self.release_package('openSUSE:%s:Live' % self.project, cd, set_release='Snapshot%s' % snapshot)
|
|
|
|
|
|
|
|
for cd in ['_product:openSUSE-dvd5-dvd-i586',
|
|
|
|
'_product:openSUSE-dvd5-dvd-x86_64',
|
|
|
|
'_product:openSUSE-cd-mini-i586',
|
|
|
|
'_product:openSUSE-cd-mini-x86_64']:
|
|
|
|
self.release_package('openSUSE:%s' % self.project, cd, set_release='Snapshot%s' % snapshot)
|
|
|
|
|
|
|
|
def publish_factory_totest(self):
|
|
|
|
print 'Publish ToTest'
|
|
|
|
self.api.switch_flag_in_prj('openSUSE:%s:ToTest' % self.project, flag='publish', state='enable')
|
|
|
|
|
|
|
|
def totest_is_publishing(self):
|
|
|
|
"""Find out if the publishing flag is set in totest's _meta"""
|
|
|
|
|
|
|
|
url = self.api.makeurl(['source', 'openSUSE:%s:ToTest' % self.project, '_meta'])
|
|
|
|
f = self.api.retried_GET(url)
|
|
|
|
root = ET.parse(f).getroot()
|
|
|
|
if not root.find('publish'): # default true
|
|
|
|
return True
|
|
|
|
|
|
|
|
for flag in root.find('publish'):
|
|
|
|
if flag.get('repository', None) or flag.get('arch', None):
|
|
|
|
continue
|
|
|
|
if flag.tag == 'enable':
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def current_factory_version(self):
|
|
|
|
url = self.api.makeurl(['build', 'openSUSE:%s' % self.project, 'standard', 'x86_64',
|
|
|
|
'_product:openSUSE-release'])
|
|
|
|
f = self.api.retried_GET(url)
|
|
|
|
root = ET.parse(f).getroot()
|
|
|
|
for binary in root.findall('binary'):
|
|
|
|
binary = binary.get('filename', '')
|
|
|
|
result = re.match(r'.*-([^-]*)-[^-]*.src.rpm', binary)
|
|
|
|
if result:
|
|
|
|
return result.group(1)
|
|
|
|
raise Exception("can't find factory version")
|
|
|
|
|
|
|
|
def totest(self):
|
|
|
|
current_snapshot = self.get_current_snapshot()
|
|
|
|
new_snapshot = self.current_factory_version()
|
|
|
|
|
|
|
|
current_result = self.overall_result(current_snapshot)
|
|
|
|
print 'current_snapshot', current_snapshot, self._result2str(current_result)
|
|
|
|
if current_result == QA_FAILED:
|
|
|
|
pass
|
|
|
|
can_release = (current_result != QA_INPROGRESS and self.factory_snapshottable())
|
|
|
|
|
|
|
|
# not overwriting
|
|
|
|
if new_snapshot == current_snapshot:
|
|
|
|
can_release = False
|
|
|
|
elif not self.all_repos_done('openSUSE:%s:ToTest' % self.project):
|
|
|
|
# the repos have to be done, otherwise we better not touch them with a new release
|
|
|
|
can_release = False
|
|
|
|
|
|
|
|
can_publish = (current_result == QA_PASSED)
|
|
|
|
|
|
|
|
# already published
|
|
|
|
if self.totest_is_publishing():
|
|
|
|
can_publish = False
|
|
|
|
|
|
|
|
if can_publish:
|
|
|
|
self.publish_factory_totest()
|
|
|
|
can_release = False # we have to wait
|
|
|
|
|
|
|
|
if can_release:
|
|
|
|
self.tt_update_totest(new_snapshot)
|
|
|
|
|
|
|
|
|
|
|
|
class ToTestFactory(ToTestBase):
|
2014-05-27 11:14:35 +02:00
|
|
|
known_failures = [
|
2014-07-29 14:31:32 +02:00
|
|
|
'opensuse-FTT-DVD-i586-Build-lxde@32bit',
|
2014-07-22 20:28:00 +02:00
|
|
|
'opensuse-FTT-DVD-i586-Build-update_13.1-kde@32bit',
|
2014-07-29 14:31:32 +02:00
|
|
|
'opensuse-FTT-DVD-x86_64-Build-lvm@64bit',
|
|
|
|
'opensuse-FTT-DVD-x86_64-Build-lxde@64bit',
|
2014-05-27 11:14:35 +02:00
|
|
|
'opensuse-FTT-DVD-x86_64-Build-update_123@64bit',
|
2014-07-29 14:31:32 +02:00
|
|
|
'opensuse-FTT-NET-i586-Build-lvm@32bit',
|
2014-07-29 15:16:43 +02:00
|
|
|
'opensuse-FTT-NET-i586-Build-lxde@32bit',
|
2014-07-29 14:31:32 +02:00
|
|
|
'opensuse-FTT-NET-x86_64-Build-lxde@64bit',
|
2014-05-27 11:14:35 +02:00
|
|
|
'opensuse-FTT-NET-x86_64-Build-update_121@64bit',
|
|
|
|
'opensuse-FTT-NET-x86_64-Build-update_122@64bit',
|
|
|
|
'opensuse-FTT-NET-x86_64-Build-update_123@64bit',
|
|
|
|
'opensuse-FTT-Rescue-CD-i686-Build-rescue@32bit',
|
2014-05-30 10:41:10 +02:00
|
|
|
'opensuse-FTT-Rescue-CD-x86_64-Build-rescue@64bit',
|
2014-09-12 11:42:42 +02:00
|
|
|
'opensuse-FTT-KDE-Live-x86_64-Build-kde-live@USBboot_64', # broken in 20140828
|
|
|
|
'opensuse-FTT-GNOME-Live-x86_64-Build-gnome-live@USBboot_64', # broken in 20140828
|
|
|
|
'opensuse-FTT-GNOME-Live-i686-Build-memtest@32bit', # broken in 20140904
|
|
|
|
'opensuse-FTT-Rescue-CD-x86_64-Build-mediacheck@64bit', # broken in 20140904
|
|
|
|
'opensuse-FTT-KDE-Live-x86_64-Build-mediacheck@64bit', # broken in 20140904
|
|
|
|
'opensuse-FTT-GNOME-Live-x86_64-Build-mediacheck@64bit', # broken in 20140904
|
|
|
|
'opensuse-FTT-DVD-i586-Build-memtest@32bit', # broken in 20140904
|
|
|
|
'opensuse-FTT-NET-i586-Build-memtest@32bit', # broken in 20140904
|
|
|
|
'opensuse-FTT-Rescue-CD-i686-Build-mediacheck@32bit', # broken in 20140904
|
|
|
|
'opensuse-FTT-Rescue-CD-i686-Build-memtest@32bit', # broken in 20140904
|
|
|
|
'opensuse-FTT-KDE-Live-i686-Build-memtest@32bit', # broken in 20140904
|
|
|
|
'opensuse-FTT-GNOME-Live-x86_64-Build-gnome-live@64bit', # broken in 20140904
|
|
|
|
'opensuse-FTT-Rescue-CD-x86_64-Build-rescue@64bit', # broken in 20140909
|
2014-05-27 11:14:35 +02:00
|
|
|
]
|
|
|
|
|
2014-05-27 13:26:29 +02:00
|
|
|
|
2014-09-12 11:42:42 +02:00
|
|
|
class ToTest132(ToTestBase):
|
|
|
|
known_failures = [
|
|
|
|
]
|
2014-05-27 13:26:29 +02:00
|
|
|
|
|
|
|
|
2014-09-12 11:42:42 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description='Commands to work with staging projects')
|
|
|
|
parser.add_argument('project', metavar='P', type=str, default='Factory',
|
|
|
|
help='openSUSE version to make the check (Factory, 13.2)')
|
2014-05-27 13:26:29 +02:00
|
|
|
|
2014-09-12 11:42:42 +02:00
|
|
|
args = parser.parse_args()
|
2014-05-27 13:26:29 +02:00
|
|
|
|
2014-09-12 11:42:42 +02:00
|
|
|
totest_class = {
|
|
|
|
'Factory': ToTestFactory,
|
|
|
|
'13.2': ToTest132,
|
|
|
|
}
|
2014-05-27 13:26:29 +02:00
|
|
|
|
2014-09-12 11:42:42 +02:00
|
|
|
if args.project not in totest_class:
|
|
|
|
print 'Project %s not recognized. Possible values [%s]' % (args.project,
|
|
|
|
', '.join(totest_class))
|
|
|
|
parser.print_help()
|
|
|
|
exit(-1)
|
2014-06-17 12:02:59 +02:00
|
|
|
|
2014-09-12 11:42:42 +02:00
|
|
|
osc.conf.get_config()
|
2014-05-28 15:14:58 +02:00
|
|
|
|
2014-09-12 11:42:42 +02:00
|
|
|
totest = totest_class[args.project](args.project)
|
|
|
|
totest.totest()
|