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
|
|
|
|
|
|
|
|
import os
|
|
|
|
import os.path
|
|
|
|
import sys
|
|
|
|
import json
|
|
|
|
|
2014-05-28 15:14:58 +02:00
|
|
|
from datetime import date
|
|
|
|
|
2014-05-27 11:14:35 +02:00
|
|
|
from osc import cmdln, oscerr
|
|
|
|
|
|
|
|
# Expand sys.path to search modules inside the pluging directory
|
|
|
|
_plugin_dir = os.path.expanduser('~/.osc-plugins')
|
|
|
|
sys.path.append(_plugin_dir)
|
|
|
|
|
|
|
|
from osclib.stagingapi import StagingAPI
|
|
|
|
from osclib.comments import CommentAPI
|
|
|
|
|
2014-05-27 13:26:29 +02:00
|
|
|
def tt_get_current_snapshot(self):
|
2014-05-27 11:14:35 +02:00
|
|
|
"""Return the current snapshot in Factory:ToTest"""
|
|
|
|
|
|
|
|
# for now we hardcode all kind of things
|
2014-06-03 10:27:13 +02:00
|
|
|
url = self.api.makeurl(['build', 'openSUSE:Factory:ToTest', 'images', 'local', '_product:openSUSE-cd-mini-i586'])
|
|
|
|
f = self.api.retried_GET(url)
|
2014-05-27 11:14:35 +02:00
|
|
|
root = ET.parse(f).getroot()
|
|
|
|
for binary in root.findall('binary'):
|
|
|
|
result = re.match(r'openSUSE-Factory-NET-i586-Snapshot(.*)-Media.iso', binary.get('filename'))
|
|
|
|
if result:
|
|
|
|
return result.group(1)
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
2014-05-27 13:26:29 +02:00
|
|
|
def tt_find_openqa_results(self, snapshot):
|
2014-05-27 11:14:35 +02:00
|
|
|
""" Return the openqa jobs of a given snapshot
|
|
|
|
and filter out the cloned jobs
|
|
|
|
"""
|
|
|
|
|
2014-06-18 08:48:41 +02:00
|
|
|
url = "https://openqa.opensuse.org/api/v1/jobs?version=FTT&build={}&distri=opensuse".format(snapshot)
|
2014-06-03 10:27:13 +02:00
|
|
|
f = self.api.retried_GET(url)
|
2014-05-27 11:14:35 +02:00
|
|
|
jobs = []
|
|
|
|
for job in json.load(f)['jobs']:
|
|
|
|
if job['clone_id']: continue
|
|
|
|
job['name'] = job['name'].replace(snapshot, '')
|
|
|
|
jobs.append(job)
|
|
|
|
return jobs
|
|
|
|
|
|
|
|
class QAResult: # no python 3.4
|
|
|
|
InProgress = 1
|
|
|
|
Failed = 2
|
|
|
|
Passed = 3
|
|
|
|
|
2014-06-03 10:27:13 +02:00
|
|
|
def tt_result2str(result):
|
|
|
|
if result == QAResult.InProgress:
|
|
|
|
return 'inprogress'
|
|
|
|
elif result == QAResult.Failed:
|
|
|
|
return 'failed'
|
|
|
|
else:
|
|
|
|
return 'passed'
|
|
|
|
|
2014-05-27 13:26:29 +02:00
|
|
|
def tt_overall_result(self, snapshot):
|
2014-05-27 11:14:35 +02:00
|
|
|
""" Analyze the openQA jobs of a given snapshot
|
|
|
|
Returns a QAResult
|
|
|
|
"""
|
|
|
|
|
2014-05-27 13:26:29 +02:00
|
|
|
jobs = self.tt_find_openqa_results(snapshot)
|
2014-05-27 11:14:35 +02:00
|
|
|
|
|
|
|
known_failures = [
|
2014-07-22 20:28:00 +02:00
|
|
|
'opensuse-FTT-DVD-i586-Build-kde@USBboot_32',
|
|
|
|
'opensuse-FTT-DVD-i586-Build-textmode@32bit',
|
|
|
|
'opensuse-FTT-DVD-i586-Build-update_13.1-kde@32bit',
|
|
|
|
'opensuse-FTT-DVD-x86_64-Build-dual_windows8@64bit',
|
|
|
|
'opensuse-FTT-DVD-x86_64-Build-gnome@Laptop_64',
|
|
|
|
'opensuse-FTT-DVD-x86_64-Build-kde@Laptop_64',
|
|
|
|
'opensuse-FTT-DVD-x86_64-Build-kde@USBboot_64',
|
|
|
|
'opensuse-FTT-DVD-x86_64-Build-splitusr@64bit',
|
2014-05-27 11:14:35 +02:00
|
|
|
'opensuse-FTT-DVD-x86_64-Build-update_123@64bit',
|
|
|
|
'opensuse-FTT-GNOME-Live-i686-Build-gnome-live@32bit',
|
|
|
|
'opensuse-FTT-GNOME-Live-x86_64-Build-gnome-live@64bit',
|
|
|
|
'opensuse-FTT-GNOME-Live-x86_64-Build-gnome-live@USBboot_64',
|
|
|
|
'opensuse-FTT-KDE-Live-x86_64-Build-kde-live@64bit',
|
|
|
|
'opensuse-FTT-KDE-Live-x86_64-Build-kde-live@USBboot_64',
|
2014-07-22 20:28:00 +02:00
|
|
|
'opensuse-FTT-NET-i586-Build-textmode@32bit',
|
|
|
|
'opensuse-FTT-NET-x86_64-Build-dual_windows8@64bit',
|
|
|
|
'opensuse-FTT-NET-x86_64-Build-gnome@Laptop_64',
|
|
|
|
'opensuse-FTT-NET-x86_64-Build-kde@Laptop_64',
|
|
|
|
'opensuse-FTT-NET-x86_64-Build-kde@Laptop_64',
|
|
|
|
'opensuse-FTT-NET-x86_64-Build-kde@USBboot_64',
|
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-07-29 14:00:31 +02:00
|
|
|
'opensuse-FTT-DVD-i586-Build-lxde@32bit',
|
|
|
|
'opensuse-FTT-DVD-x86_64-Build-lxde@64bit'
|
|
|
|
'opensuse-FTT-KDE-Live-i686-Build-kde-live@32bit',
|
|
|
|
'opensuse-FTT-DVD-x86_64-Build-lxde@64bit',
|
|
|
|
'opensuse-FTT-KDE-Live-i686-Build-kde-live@32bit',
|
|
|
|
'opensuse-FTT-DVD-x86_64-Build-textmode@64bit',
|
|
|
|
'opensuse-FTT-DVD-i586-Build-xfce@32bit',
|
|
|
|
'opensuse-FTT-DVD-x86_64-Build-xfce@64bit',
|
|
|
|
'opensuse-FTT-DVD-x86_64-Build-lvm@64bit',
|
2014-05-27 11:14:35 +02:00
|
|
|
]
|
|
|
|
|
2014-05-28 19:25:46 +02:00
|
|
|
if len(jobs) < 80: # not yet scheduled
|
2014-06-18 08:48:41 +02:00
|
|
|
print "we have only", len(jobs), "jobs"
|
2014-05-28 19:25:46 +02:00
|
|
|
return QAResult.InProgress
|
|
|
|
|
2014-06-03 17:10:13 +02:00
|
|
|
number_of_fails = 0
|
2014-05-27 11:14:35 +02:00
|
|
|
for job in jobs:
|
|
|
|
#print json.dumps(job, sort_keys=True, indent=4)
|
2014-06-03 17:10:13 +02:00
|
|
|
if job['result'] == 'failed' or job['result'] == 'incomplete' :
|
2014-06-18 08:48:41 +02:00
|
|
|
jobname = job['name'] + "@" + job['settings']['MACHINE']
|
2014-05-27 11:14:35 +02:00
|
|
|
if jobname in known_failures:
|
|
|
|
known_failures.remove(jobname)
|
|
|
|
continue
|
2014-06-03 17:10:13 +02:00
|
|
|
number_of_fails += 1
|
2014-06-18 08:48:41 +02:00
|
|
|
#print json.dumps(job, sort_keys=True, indent=4), jobname
|
|
|
|
print jobname, "https://openqa.opensuse.org/tests/{}".format(job['id'])
|
2014-06-03 17:10:13 +02:00
|
|
|
if number_of_fails < 3: continue
|
2014-05-27 11:14:35 +02:00
|
|
|
return QAResult.Failed
|
|
|
|
elif job['result'] == 'passed':
|
|
|
|
continue
|
|
|
|
elif job['result'] == 'none':
|
|
|
|
return QAResult.InProgress
|
|
|
|
else:
|
|
|
|
raise Exception(job['result'])
|
|
|
|
|
|
|
|
if known_failures:
|
|
|
|
print "Some are now passing", known_failures
|
|
|
|
return QAResult.Passed
|
|
|
|
|
2014-05-30 11:00:36 +02:00
|
|
|
def tt_all_repos_done(self, project, codes=['published', 'unpublished']):
|
2014-05-27 13:26:29 +02:00
|
|
|
"""
|
|
|
|
Check the build result of the project and only return True if all
|
|
|
|
repos of that project are either published or unpublished
|
|
|
|
"""
|
2014-06-03 10:27:13 +02:00
|
|
|
url = self.api.makeurl(['build', project, '_result'], {'code': 'failed' })
|
|
|
|
f = self.api.retried_GET(url)
|
2014-05-27 13:26:29 +02:00
|
|
|
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
|
2014-05-30 11:00:36 +02:00
|
|
|
if repo.get('code') not in codes:
|
2014-05-27 13:26:29 +02:00
|
|
|
print repo.get('project'), repo.get('repository'), repo.get('arch'), repo.get('code')
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
2014-05-27 16:24:34 +02:00
|
|
|
def tt_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
|
|
|
|
|
|
|
|
raise Exception('No maxsize for {}'.format(package))
|
|
|
|
|
|
|
|
def tt_package_ok(self, project, package, repository, arch):
|
2014-05-27 13:26:29 +02:00
|
|
|
"""
|
|
|
|
Checks one package in a project and returns True if it's succeeded
|
|
|
|
"""
|
2014-05-27 16:24:34 +02:00
|
|
|
query = {'package': package, 'repository': repository, 'arch': arch }
|
2014-05-27 13:26:29 +02:00
|
|
|
|
2014-06-03 10:27:13 +02:00
|
|
|
url = self.api.makeurl(['build', project, '_result'], query)
|
|
|
|
f = self.api.retried_GET(url)
|
2014-05-27 13:26:29 +02:00
|
|
|
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
|
2014-05-27 16:24:34 +02:00
|
|
|
|
|
|
|
maxsize = self.tt_maxsize_for_package(package)
|
|
|
|
if not maxsize:
|
|
|
|
return True
|
|
|
|
|
2014-06-03 10:27:13 +02:00
|
|
|
url = self.api.makeurl(['build', project, repository, arch, package])
|
|
|
|
f = self.api.retried_GET(url)
|
2014-05-27 16:24:34 +02:00
|
|
|
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 {} bytes'.format(isosize-maxsize)
|
|
|
|
return False
|
|
|
|
|
2014-05-27 13:26:29 +02:00
|
|
|
return True
|
|
|
|
|
|
|
|
def tt_factory_snapshottable(self):
|
|
|
|
"""
|
|
|
|
Check various conditions required for factory to be snapshotable
|
|
|
|
"""
|
|
|
|
|
|
|
|
if not self.tt_all_repos_done('openSUSE:Factory'):
|
|
|
|
return False
|
|
|
|
|
|
|
|
for product in ['_product:openSUSE-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']:
|
2014-05-27 16:24:34 +02:00
|
|
|
if not self.tt_package_ok('openSUSE:Factory', product, 'images', 'local'):
|
2014-05-27 13:26:29 +02:00
|
|
|
return False
|
|
|
|
|
|
|
|
if not self.tt_all_repos_done('openSUSE:Factory:Live'):
|
|
|
|
return False
|
|
|
|
|
|
|
|
for product in ['kiwi-image-livecd-kde.i586',
|
|
|
|
'kiwi-image-livecd-gnome.i586',
|
|
|
|
'kiwi-image-livecd-x11']:
|
2014-05-27 16:24:34 +02:00
|
|
|
if not self.tt_package_ok('openSUSE:Factory:Live', product, 'standard', 'i586'):
|
2014-05-27 13:26:29 +02:00
|
|
|
return False
|
|
|
|
|
|
|
|
for product in ['kiwi-image-livecd-kde.x86_64',
|
|
|
|
'kiwi-image-livecd-gnome.x86_64',
|
|
|
|
'kiwi-image-livecd-x11']:
|
2014-05-27 16:24:34 +02:00
|
|
|
if not self.tt_package_ok('openSUSE:Factory:Live', product, 'standard', 'x86_64'):
|
2014-05-27 13:26:29 +02:00
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
2014-05-28 10:48:23 +02:00
|
|
|
def tt_release_package(self, project, package, set_release=None):
|
|
|
|
query = { 'cmd': 'release' }
|
|
|
|
|
|
|
|
if set_release:
|
|
|
|
query["setrelease"] = set_release
|
|
|
|
|
|
|
|
baseurl = ['source', project, package]
|
|
|
|
|
2014-06-03 10:27:13 +02:00
|
|
|
url = self.api.makeurl(baseurl, query=query)
|
|
|
|
self.api.retried_POST(url)
|
2014-05-28 10:48:23 +02:00
|
|
|
|
|
|
|
def tt_update_totest(self, snapshot):
|
2014-05-30 10:41:10 +02:00
|
|
|
print "Updating snapshot {}".format(snapshot)
|
2014-05-28 15:14:58 +02:00
|
|
|
self.api.switch_flag_in_prj('openSUSE:Factory:ToTest', flag='publish', state='disable')
|
|
|
|
|
2014-05-28 10:48:23 +02:00
|
|
|
self.tt_release_package('openSUSE:Factory', '_product:openSUSE-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.tt_release_package('openSUSE:Factory:Live', cd, set_release='Snapshot{}'.format(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.tt_release_package('openSUSE:Factory', cd, set_release='Snapshot{}'.format(snapshot))
|
|
|
|
|
2014-05-28 15:14:58 +02:00
|
|
|
def tt_publish_factory_totest(self):
|
2014-05-30 10:41:10 +02:00
|
|
|
print "Publish ToTest"
|
2014-05-28 15:14:58 +02:00
|
|
|
self.api.switch_flag_in_prj('openSUSE:Factory:ToTest', flag='publish', state='enable')
|
|
|
|
|
|
|
|
def tt_totest_is_publishing(self):
|
|
|
|
"""Find out if the publishing flag is set in totest's _meta"""
|
|
|
|
|
2014-06-03 10:27:13 +02:00
|
|
|
url = self.api.makeurl(['source', 'openSUSE:Factory:ToTest', '_meta'])
|
|
|
|
f = self.api.retried_GET(url)
|
2014-05-28 15:14:58 +02:00
|
|
|
root = ET.parse(f).getroot()
|
2014-06-17 12:02:59 +02:00
|
|
|
if not root.find('publish'): # default true
|
|
|
|
return True
|
|
|
|
|
2014-05-28 15:14:58 +02:00
|
|
|
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
|
|
|
|
|
2014-07-15 14:21:57 +02:00
|
|
|
def tt_current_factory_version(self):
|
|
|
|
url = self.api.makeurl(['build', 'openSUSE:Factory', '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")
|
|
|
|
|
2014-05-27 11:14:35 +02:00
|
|
|
def do_totest(self, subcmd, opts, *args):
|
|
|
|
"""${cmd_name}: Commands to work with staging projects
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
osc totest
|
|
|
|
"""
|
|
|
|
|
|
|
|
# verify the argument counts match the commands
|
|
|
|
if len(args) != 0:
|
|
|
|
raise oscerr.WrongArgs("we don't need arguments")
|
|
|
|
|
|
|
|
# init the obs access
|
|
|
|
opts.apiurl = self.get_api_url()
|
|
|
|
opts.verbose = False
|
|
|
|
self.api = StagingAPI(opts.apiurl)
|
|
|
|
|
2014-05-28 15:14:58 +02:00
|
|
|
current_snapshot = self.tt_get_current_snapshot()
|
2014-07-15 14:21:57 +02:00
|
|
|
new_snapshot = self.tt_current_factory_version()
|
2014-05-28 15:14:58 +02:00
|
|
|
|
|
|
|
current_result = self.tt_overall_result(current_snapshot)
|
2014-06-03 10:27:13 +02:00
|
|
|
print "current_snapshot", current_snapshot, tt_result2str(current_result)
|
2014-05-30 10:41:10 +02:00
|
|
|
if current_result == QAResult.Failed:
|
2014-07-15 10:43:11 +02:00
|
|
|
pass
|
2014-05-28 15:14:58 +02:00
|
|
|
can_release = current_result != QAResult.InProgress and self.tt_factory_snapshottable()
|
|
|
|
|
|
|
|
# not overwriting
|
|
|
|
if new_snapshot == current_snapshot:
|
|
|
|
can_release = False
|
2014-05-30 11:00:36 +02:00
|
|
|
elif not self.tt_all_repos_done('openSUSE:Factory:ToTest'):
|
|
|
|
# the repos have to be done, otherwise we better not touch them with a new release
|
|
|
|
can_release = False
|
|
|
|
|
2014-05-28 15:14:58 +02:00
|
|
|
can_publish = current_result == QAResult.Passed
|
|
|
|
|
|
|
|
# already published
|
|
|
|
if self.tt_totest_is_publishing():
|
|
|
|
can_publish = False
|
|
|
|
|
|
|
|
if can_publish:
|
|
|
|
self.tt_publish_factory_totest()
|
|
|
|
can_release = False # we have to wait
|
2014-05-27 13:26:29 +02:00
|
|
|
|
2014-05-28 15:14:58 +02:00
|
|
|
if can_release:
|
|
|
|
self.tt_update_totest(new_snapshot)
|