Merge pull request #834 from jberry-suse/supersede-command

supersede: separate command, feedback, and force supersede post source project check
This commit is contained in:
Jimmy Berry 2017-04-20 14:10:08 -05:00 committed by GitHub
commit 52d356db29
4 changed files with 46 additions and 22 deletions

View File

@ -47,6 +47,7 @@ from osclib.unselect_command import UnselectCommand
from osclib.repair_command import RepairCommand
from osclib.rebuild_command import RebuildCommand
from osclib.request_splitter import RequestSplitter
from osclib.supersede_command import SupersedeCommand
from osclib.prio_command import PrioCommand
OSC_STAGING_VERSION = '0.0.1'
@ -149,8 +150,6 @@ def do_staging(self, subcmd, opts, *args):
changed from state new or review more than 3 days ago will be removed.
"list" will list/supersede requests for ring packages or all if no rings.
The package list is used to limit what requests are superseded when
called with the --supersede option.
"repair" will attempt to repair the state of a request that has been
corrupted.
@ -238,6 +237,9 @@ def do_staging(self, subcmd, opts, *args):
If the force option is included the rebuild checks will be ignored and
all packages failing to build will be triggered.
"supersede" will supersede requests were applicable.
A request list can be used to limit what is superseded.
Usage:
osc staging accept [--force] [--no-cleanup] [LETTER...]
osc staging acheck
@ -248,7 +250,7 @@ def do_staging(self, subcmd, opts, *args):
osc staging frozenage [STAGING...]
osc staging ignore [-m MESSAGE] REQUEST...
osc staging unignore [--cleanup] [REQUEST...|all]
osc staging list [--supersede] [PACKAGE...]
osc staging list [--supersede]
osc staging select [--no-freeze] [--move [--from STAGING]]
[--add PACKAGE]
STAGING REQUEST...
@ -261,6 +263,7 @@ def do_staging(self, subcmd, opts, *args):
osc staging rebuild [--force] [STAGING...]
osc staging repair [--cleanup] [REQUEST...]
osc staging setprio [STAGING...]
osc staging supersede [REQUEST...]
"""
if opts.version:
self._print_version()
@ -297,6 +300,8 @@ def do_staging(self, subcmd, opts, *args):
min_args, max_args = 0, 0
elif cmd == 'rebuild':
min_args, max_args = 0, None
elif cmd == 'supersede':
min_args, max_args = 0, None
else:
raise oscerr.WrongArgs('Unknown command: %s' % cmd)
if len(args) - 1 < min_args:
@ -515,7 +520,7 @@ def do_staging(self, subcmd, opts, *args):
elif cmd == 'unignore':
UnignoreCommand(api).perform(args[1:], opts.cleanup)
elif cmd == 'list':
ListCommand(api).perform(args[1:], supersede=opts.supersede)
ListCommand(api).perform(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':
@ -524,3 +529,5 @@ def do_staging(self, subcmd, opts, *args):
RepairCommand(api).perform(args[1:], opts.cleanup)
elif cmd == 'setprio':
PrioCommand(api).perform(args[1:])
elif cmd == 'supersede':
SupersedeCommand(api).perform(args[1:])

View File

@ -1,5 +1,6 @@
from osc import oscerr
from osclib.request_splitter import RequestSplitter
from osclib.supersede_command import SupersedeCommand
class ListCommand:
@ -14,13 +15,13 @@ class ListCommand:
def __init__(self, api):
self.api = api
def perform(self, packages=None, supersede=False):
def perform(self, supersede=False):
"""
Perform the list command
"""
if supersede:
self.api.dispatch_open_requests(packages)
SupersedeCommand(self.api).perform()
requests = self.api.get_open_requests()
requests_ignored = self.api.get_ignored_requests()

View File

@ -451,15 +451,15 @@ class StagingAPI(object):
source.get('package'),
source.get('rev'))
def superseded_request(self, request, target_pkgs=None):
def superseded_request(self, request, target_requests=None):
"""
Returns a staging info for a request or None
:param request - a Request instance
:return dict with 'prj' and 'rq_id' of the old request
"""
if not target_pkgs:
target_pkgs = []
if not target_requests:
target_requests = []
# Consolidate all data from request
request_id = int(request.get('id'))
@ -478,9 +478,11 @@ class StagingAPI(object):
msg = msg.format(request_id, action)
logging.info(msg)
# Only consider if submit or delete and in target_pkgs if provided.
# Only consider if submit or delete and in target_requests if provided.
is_targeted = (target_package in target_requests or
str(request_id) in target_requests)
if action.get('type') in ['submit', 'delete'] and (
not(target_pkgs) or target_package in target_pkgs):
not(target_requests) or is_targeted):
stage_info = self.packages_staged.get(target_package)
# Ensure a request for same package is already staged.
@ -490,7 +492,8 @@ class StagingAPI(object):
# If both are submits from different source projects then check
# the source info and proceed accordingly, otherwise supersede.
if not(
# A targeted package overrides this condition.
if is_targeted or not(
request_new.find('action').get('type') == 'submit' and
request_old.find('action').get('type') == 'submit' and
request_new.find('action/source').get('project') !=
@ -514,16 +517,16 @@ class StagingAPI(object):
return None
def update_superseded_request(self, request, target_pkgs=None):
def update_superseded_request(self, request, target_requests=None):
"""
Replace superseded requests that are already in some
staging prj
:param request: request we are checking if it is fine
"""
if not target_pkgs:
target_pkgs = []
if not target_requests:
target_requests = []
stage_info = self.superseded_request(request, target_pkgs)
stage_info = self.superseded_request(request, target_requests)
request_id = int(request.get('id'))
if stage_info:
@ -535,7 +538,7 @@ class StagingAPI(object):
# Add the new one that should be replacing it
self.rq_to_prj(request_id, stage_info['prj'])
self._invalidate_get_open_requests()
return True
return stage_info
return False
@memoize(session=True)
@ -578,15 +581,15 @@ class StagingAPI(object):
requests.append(rq)
return requests
def dispatch_open_requests(self, packages=None):
def dispatch_open_requests(self, target_requests=None):
"""
Verify all requests and dispatch them to staging projects or
approve them
"""
if not packages:
packages = []
if not target_requests:
target_requests = []
# get all current pending requests
requests = self.get_open_requests()
@ -594,11 +597,13 @@ class StagingAPI(object):
# check if we can reduce it down by accepting some
for rq in requests:
request_id = int(rq.get('id'))
if request_id in requests_ignored:
if not len(target_requests) and request_id in requests_ignored:
continue
# if self.crings:
# self.accept_non_ring_request(rq)
self.update_superseded_request(rq, packages)
stage_info = self.update_superseded_request(rq, target_requests)
if stage_info:
yield (stage_info, rq)
def get_prj_meta(self, project):
url = make_meta_url('prj', project, self.apiurl)

View File

@ -0,0 +1,11 @@
class SupersedeCommand(object):
def __init__(self, api):
self.api = api
def perform(self, requests=None):
for stage_info, request in self.api.dispatch_open_requests(requests):
action = request.find('action')
target_package = action.find('target').get('package')
print('request {} for {} superseded {} in {}'.format(
request.get('id'), target_package, stage_info['rq_id'], stage_info['prj']))