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.
This commit is contained in:
Jimmy Berry 2017-03-08 16:03:27 -06:00
parent 19a37c0553
commit 13b7ae9d8a
3 changed files with 42 additions and 0 deletions

View File

@ -44,6 +44,7 @@ from osclib.stagingapi import StagingAPI
from osclib.cache import Cache from osclib.cache import Cache
from osclib.unselect_command import UnselectCommand from osclib.unselect_command import UnselectCommand
from osclib.repair_command import RepairCommand from osclib.repair_command import RepairCommand
from osclib.rebuild_command import RebuildCommand
from osclib.request_splitter import RequestSplitter from osclib.request_splitter import RequestSplitter
OSC_STAGING_VERSION = '0.0.1' 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 "unlock" will remove the staging lock in case it gets stuck
"rebuild" will rebuild broken packages in the given stagings or all
Usage: Usage:
osc staging accept [--force] [--no-cleanup] [LETTER...] osc staging accept [--force] [--no-cleanup] [LETTER...]
osc staging acheck osc staging acheck
@ -223,6 +226,7 @@ def do_staging(self, subcmd, opts, *args):
[STAGING...] [REQUEST...] [STAGING...] [REQUEST...]
osc staging unselect REQUEST... osc staging unselect REQUEST...
osc staging unlock osc staging unlock
osc staging rebuild [STAGING...]
osc staging repair REQUEST... osc staging repair REQUEST...
""" """
if opts.version: if opts.version:
@ -252,6 +256,8 @@ def do_staging(self, subcmd, opts, *args):
min_args, max_args = 0, 0 min_args, max_args = 0, 0
elif cmd == 'unlock': elif cmd == 'unlock':
min_args, max_args = 0, 0 min_args, max_args = 0, 0
elif cmd == 'rebuild':
min_args, max_args = 0, None
else: else:
raise oscerr.WrongArgs('Unknown command: %s' % cmd) raise oscerr.WrongArgs('Unknown command: %s' % cmd)
if len(args) - 1 < min_args: 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) ListCommand(api).perform(args[1:], supersede=opts.supersede)
elif cmd == 'adi': elif cmd == 'adi':
AdiCommand(api).perform(args[1:], move=opts.move, by_dp=opts.by_develproject, split=opts.split) 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': elif cmd == 'repair':
RepairCommand(api).perform(args[1:]) RepairCommand(api).perform(args[1:])

17
osclib/rebuild_command.py Normal file
View File

@ -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))

View File

@ -35,6 +35,7 @@ from osc.core import makeurl
from osc.core import http_GET from osc.core import http_GET
from osc.core import http_POST from osc.core import http_POST
from osc.core import http_PUT from osc.core import http_PUT
from osc.core import rebuild
from osclib.cache import Cache from osclib.cache import Cache
from osclib.comments import CommentAPI from osclib.comments import CommentAPI
@ -735,6 +736,22 @@ class StagingAPI(object):
return False 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): def project_status(self, project):
short = self.extract_staging_short(project) short = self.extract_staging_short(project)
query = {'format': 'json'} query = {'format': 'json'}