From 13b7ae9d8af8362466aae44b81adf2f10eee0018 Mon Sep 17 00:00:00 2001 From: Jimmy Berry Date: Wed, 8 Mar 2017 16:03:27 -0600 Subject: [PATCH] osc-staging: provide rebuild command. Often packages will fail to build after becoming stuck or other false negative cases and need to have a rebuild triggered. The process can be tedious if several packages failed in various stages. --- osc-staging.py | 8 ++++++++ osclib/rebuild_command.py | 17 +++++++++++++++++ osclib/stagingapi.py | 17 +++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 osclib/rebuild_command.py diff --git a/osc-staging.py b/osc-staging.py index 7a023f31..f11e915d 100644 --- a/osc-staging.py +++ b/osc-staging.py @@ -44,6 +44,7 @@ from osclib.stagingapi import StagingAPI from osclib.cache import Cache from osclib.unselect_command import UnselectCommand from osclib.repair_command import RepairCommand +from osclib.rebuild_command import RebuildCommand from osclib.request_splitter import RequestSplitter OSC_STAGING_VERSION = '0.0.1' @@ -205,6 +206,8 @@ def do_staging(self, subcmd, opts, *args): "unlock" will remove the staging lock in case it gets stuck + "rebuild" will rebuild broken packages in the given stagings or all + Usage: osc staging accept [--force] [--no-cleanup] [LETTER...] osc staging acheck @@ -223,6 +226,7 @@ def do_staging(self, subcmd, opts, *args): [STAGING...] [REQUEST...] osc staging unselect REQUEST... osc staging unlock + osc staging rebuild [STAGING...] osc staging repair REQUEST... """ if opts.version: @@ -252,6 +256,8 @@ def do_staging(self, subcmd, opts, *args): min_args, max_args = 0, 0 elif cmd == 'unlock': min_args, max_args = 0, 0 + elif cmd == 'rebuild': + min_args, max_args = 0, None else: raise oscerr.WrongArgs('Unknown command: %s' % cmd) if len(args) - 1 < min_args: @@ -466,5 +472,7 @@ def do_staging(self, subcmd, opts, *args): ListCommand(api).perform(args[1:], supersede=opts.supersede) elif cmd == 'adi': AdiCommand(api).perform(args[1:], move=opts.move, by_dp=opts.by_develproject, split=opts.split) + elif cmd == 'rebuild': + RebuildCommand(api).perform(args[1:]) elif cmd == 'repair': RepairCommand(api).perform(args[1:]) diff --git a/osclib/rebuild_command.py b/osclib/rebuild_command.py new file mode 100644 index 00000000..0d2b82bf --- /dev/null +++ b/osclib/rebuild_command.py @@ -0,0 +1,17 @@ +from osc.core import get_request +from osclib.comments import CommentAPI + + +class RebuildCommand(object): + def __init__(self, api): + self.api = api + + def perform(self, stagings=None): + if not stagings: + stagings = self.api.get_staging_projects_short() + + for staging in stagings: + status = self.api.project_status(staging) + rebuilt = self.api.rebuild_broken(status) + for key, code in rebuilt.items(): + print('rebuild {} {}'.format(key, code)) diff --git a/osclib/stagingapi.py b/osclib/stagingapi.py index 160c28c2..64d9cb57 100644 --- a/osclib/stagingapi.py +++ b/osclib/stagingapi.py @@ -35,6 +35,7 @@ from osc.core import makeurl from osc.core import http_GET from osc.core import http_POST from osc.core import http_PUT +from osc.core import rebuild from osclib.cache import Cache from osclib.comments import CommentAPI @@ -735,6 +736,22 @@ class StagingAPI(object): return False + def rebuild_broken(self, status): + """ Rebuild broken packages given a staging's status information. """ + rebuilt = {} + for package in status['broken_packages']: + package = {k: str(v) for k, v in package.items()} + code = rebuild(self.apiurl, package['project'], package['package'], + package['repository'], package['arch']) + key = '/'.join((package['project'], package['package'], package['repository'], package['arch'])) + rebuilt[key] = code + + for project in status['subprojects']: + if project: + rebuilt.update(self.rebuild_broken(project)) + + return rebuilt + def project_status(self, project): short = self.extract_staging_short(project) query = {'format': 'json'}