2019-03-26 07:51:53 +01:00
|
|
|
# -*- 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
|
|
|
|
# (C) 2017 okurz@suse.de, openSUSE.org
|
|
|
|
# (C) 2018 dheidler@suse.de, openSUSE.org
|
|
|
|
# Distribute under GPLv2 or GPLv3
|
|
|
|
|
|
|
|
import ToolBase
|
|
|
|
import logging
|
|
|
|
import re
|
2019-04-04 15:11:29 +02:00
|
|
|
import yaml
|
2019-04-15 10:19:03 +02:00
|
|
|
from enum import IntEnum
|
2022-02-18 10:16:17 +01:00
|
|
|
from lxml import etree as ET
|
2019-04-01 16:17:45 +02:00
|
|
|
from osclib.stagingapi import StagingAPI
|
2019-05-15 20:47:21 +02:00
|
|
|
from urllib.error import HTTPError
|
2019-03-26 07:51:53 +01:00
|
|
|
from ttm.totest import ToTest
|
|
|
|
|
|
|
|
class NotFoundException(Exception):
|
|
|
|
pass
|
|
|
|
|
2019-04-15 10:19:03 +02:00
|
|
|
class QAResult(IntEnum):
|
2019-04-08 09:07:27 +02:00
|
|
|
inprogress = 1
|
|
|
|
failed = 2
|
|
|
|
passed = 3
|
|
|
|
|
|
|
|
def __str__(self):
|
2019-04-15 10:19:03 +02:00
|
|
|
if self == QAResult.inprogress:
|
2019-04-08 09:07:27 +02:00
|
|
|
return 'inprogress'
|
2019-04-15 10:19:03 +02:00
|
|
|
elif self == QAResult.failed:
|
2019-04-08 09:07:27 +02:00
|
|
|
return 'failed'
|
|
|
|
else:
|
|
|
|
return 'passed'
|
|
|
|
|
2019-03-26 07:51:53 +01:00
|
|
|
class ToTestManager(ToolBase.ToolBase):
|
|
|
|
|
2019-04-01 16:17:45 +02:00
|
|
|
def __init__(self, tool):
|
2019-03-26 07:51:53 +01:00
|
|
|
ToolBase.ToolBase.__init__(self)
|
2019-04-01 16:17:45 +02:00
|
|
|
# copy attributes
|
2019-03-26 07:51:53 +01:00
|
|
|
self.logger = logging.getLogger(__name__)
|
2019-04-01 16:17:45 +02:00
|
|
|
self.apiurl = tool.apiurl
|
|
|
|
self.debug = tool.debug
|
|
|
|
self.caching = tool.caching
|
|
|
|
self.dryrun = tool.dryrun
|
2019-03-26 07:51:53 +01:00
|
|
|
|
|
|
|
def setup(self, project):
|
2019-04-01 16:17:45 +02:00
|
|
|
self.project = ToTest(project, self.apiurl)
|
|
|
|
self.api = StagingAPI(self.apiurl, project=project)
|
2019-03-26 07:51:53 +01:00
|
|
|
|
2019-03-27 17:23:59 +01:00
|
|
|
def version_file(self, target):
|
2019-03-28 13:54:29 +01:00
|
|
|
return 'version_%s' % target
|
2019-03-27 17:23:59 +01:00
|
|
|
|
|
|
|
def write_version_to_dashboard(self, target, version):
|
2019-03-28 08:34:26 +01:00
|
|
|
if self.dryrun or self.project.do_not_release:
|
2019-03-27 17:23:59 +01:00
|
|
|
return
|
|
|
|
self.api.pseudometa_file_ensure(self.version_file(target), version,
|
|
|
|
comment='Update version')
|
2019-03-26 07:51:53 +01:00
|
|
|
|
2019-04-01 16:17:45 +02:00
|
|
|
def current_qa_version(self):
|
|
|
|
return self.api.pseudometa_file_load(self.version_file('totest'))
|
2019-03-26 07:51:53 +01:00
|
|
|
|
2019-04-01 16:17:45 +02:00
|
|
|
def iso_build_version(self, project, tree, repo=None, arch=None):
|
|
|
|
for binary in self.binaries_of_product(project, tree, repo=repo, arch=arch):
|
2021-06-18 14:03:48 +02:00
|
|
|
result = re.match(r'.*-(?:Build|Snapshot)([0-9.]+)(?:-Media.*\.iso|\.docker\.tar\.xz|\.tar\.xz|\.raw\.xz|\.appx)', binary)
|
2019-03-26 07:51:53 +01:00
|
|
|
if result:
|
|
|
|
return result.group(1)
|
2019-04-01 16:17:45 +02:00
|
|
|
raise NotFoundException("can't find %s iso version" % project)
|
2019-03-26 07:51:53 +01:00
|
|
|
|
2019-04-01 16:17:45 +02:00
|
|
|
def version_from_totest_project(self):
|
2019-03-27 14:36:11 +01:00
|
|
|
if len(self.project.main_products):
|
2019-04-01 16:17:45 +02:00
|
|
|
return self.iso_build_version(self.project.test_project, self.project.main_products[0])
|
2019-03-27 14:36:11 +01:00
|
|
|
|
2019-04-01 16:17:45 +02:00
|
|
|
return self.iso_build_version(self.project.test_project, self.project.image_products[0].package,
|
2019-03-27 14:36:11 +01:00
|
|
|
arch=self.project.image_products[0].archs[0])
|
2019-03-26 07:51:53 +01:00
|
|
|
|
|
|
|
def binaries_of_product(self, project, product, repo=None, arch=None):
|
|
|
|
if repo is None:
|
2019-03-26 08:21:47 +01:00
|
|
|
repo = self.project.product_repo
|
2019-03-26 07:51:53 +01:00
|
|
|
if arch is None:
|
2019-03-26 08:21:47 +01:00
|
|
|
arch = self.project.product_arch
|
2019-03-26 07:51:53 +01:00
|
|
|
|
|
|
|
url = self.api.makeurl(['build', project, repo, arch, product])
|
|
|
|
try:
|
|
|
|
f = self.api.retried_GET(url)
|
|
|
|
except HTTPError:
|
|
|
|
return []
|
|
|
|
|
|
|
|
ret = []
|
|
|
|
root = ET.parse(f).getroot()
|
|
|
|
for binary in root.findall('binary'):
|
|
|
|
ret.append(binary.get('filename'))
|
|
|
|
|
|
|
|
return ret
|
|
|
|
|
|
|
|
def ftp_build_version(self, project, tree):
|
|
|
|
for binary in self.binaries_of_product(project, tree):
|
|
|
|
result = re.match(r'.*-Build(.*)-Media1.report', binary)
|
|
|
|
if result:
|
|
|
|
return result.group(1)
|
|
|
|
raise NotFoundException("can't find %s ftp version" % project)
|
2019-04-04 15:11:29 +02:00
|
|
|
|
2019-04-10 07:37:10 +02:00
|
|
|
# make sure to update the attribute as atomic as possible - as such
|
2019-04-08 09:07:27 +02:00
|
|
|
# only update the snapshot and don't erase anything else. The snapshots
|
|
|
|
# have very different update times within the pipeline, so there is
|
|
|
|
# normally no chance that releaser and publisher overwrite states
|
2019-04-04 15:11:29 +02:00
|
|
|
def update_status(self, status, snapshot):
|
|
|
|
status_dict = self.get_status_dict()
|
2019-04-08 09:07:27 +02:00
|
|
|
if self.dryrun:
|
|
|
|
self.logger.info('setting {} snapshot to {}'.format(status, snapshot))
|
|
|
|
return
|
2019-04-10 07:37:10 +02:00
|
|
|
if status_dict.get(status) != snapshot:
|
2019-04-04 15:11:29 +02:00
|
|
|
status_dict[status] = snapshot
|
|
|
|
text = yaml.safe_dump(status_dict)
|
|
|
|
self.api.attribute_value_save('ToTestManagerStatus', text)
|
|
|
|
|
|
|
|
def get_status_dict(self):
|
|
|
|
text = self.api.attribute_value_load('ToTestManagerStatus')
|
|
|
|
if text:
|
|
|
|
return yaml.safe_load(text)
|
|
|
|
return dict()
|
|
|
|
|
|
|
|
def get_status(self, status):
|
2019-04-08 09:07:27 +02:00
|
|
|
return self.get_status_dict().get(status)
|
2019-04-04 18:42:26 +02:00
|
|
|
|
2022-02-02 11:41:47 +01:00
|
|
|
def get_product_version(self):
|
|
|
|
return self.api.attribute_value_load('ProductVersion')
|
|
|
|
|
2019-04-04 18:42:26 +02:00
|
|
|
def release_package(self, project, package, set_release=None, repository=None,
|
|
|
|
target_project=None, target_repository=None):
|
|
|
|
query = {'cmd': 'release'}
|
|
|
|
|
|
|
|
if set_release:
|
|
|
|
query['setrelease'] = set_release
|
|
|
|
|
|
|
|
if repository is not None:
|
|
|
|
query['repository'] = repository
|
|
|
|
|
|
|
|
if target_project is not None:
|
|
|
|
# Both need to be set
|
|
|
|
query['target_project'] = target_project
|
|
|
|
query['target_repository'] = target_repository
|
|
|
|
|
|
|
|
baseurl = ['source', project, package]
|
|
|
|
|
|
|
|
url = self.api.makeurl(baseurl, query=query)
|
|
|
|
if self.dryrun or self.project.do_not_release:
|
|
|
|
self.logger.info('release %s/%s (%s)' % (project, package, query))
|
|
|
|
else:
|
|
|
|
self.api.retried_POST(url)
|
|
|
|
|
2019-04-08 09:07:27 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
# coolo's experience says that 'finished' won't be
|
|
|
|
# sufficient here, so don't try to add it :-)
|
|
|
|
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()
|
|
|
|
ready = True
|
|
|
|
for repo in root.findall('result'):
|
|
|
|
# ignore ports. 'factory' is used by arm for repos that are not
|
|
|
|
# meant to use the totest manager.
|
|
|
|
if repo.get('repository') in ('ports', 'factory', 'images_staging'):
|
|
|
|
continue
|
2019-04-10 07:37:10 +02:00
|
|
|
if repo.get('dirty') == 'true':
|
2019-04-08 09:07:27 +02:00
|
|
|
self.logger.info('%s %s %s -> %s' % (repo.get('project'),
|
|
|
|
repo.get('repository'), repo.get('arch'), 'dirty'))
|
|
|
|
ready = False
|
|
|
|
if repo.get('code') not in codes:
|
|
|
|
self.logger.info('%s %s %s -> %s' % (repo.get('project'),
|
|
|
|
repo.get('repository'), repo.get('arch'), repo.get('code')))
|
|
|
|
ready = False
|
|
|
|
return ready
|