From 220f842c5dd53cd2b227b997d1b6d525caedeb72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Chv=C3=A1tal?= Date: Tue, 4 Mar 2014 12:58:04 +0100 Subject: [PATCH 1/8] Add switch wether to commit to Factory or not during accept. --- osc-staging.py | 6 ++++-- osclib/accept_command.py | 9 +++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/osc-staging.py b/osc-staging.py index 6cba4ada..1d7b0c81 100644 --- a/osc-staging.py +++ b/osc-staging.py @@ -127,6 +127,8 @@ def _staging_submit_devel(self, project, opts): return +@cmdln.option('-c', '--commit', action='store_true', + help='accept the request completely and commit the changes to the openSUSE:Factory') @cmdln.option('-e', '--everything', action='store_true', help='during check do not stop on first first issue and show them all') @cmdln.option('-p', '--parent', metavar='TARGETPROJECT', @@ -171,7 +173,7 @@ def do_staging(self, subcmd, opts, *args): osc staging list osc staging select [--move [-from PROJECT]] LETTER REQUEST... osc staging unselect LETTER REQUEST... - osc staging accept LETTER + osc staging accept [--commit] LETTER osc staging cleanup_rings """ if opts.version: @@ -254,7 +256,7 @@ def do_staging(self, subcmd, opts, *args): for prj in args[1:]: osclib.freeze_command.FreezeCommand(api).perform(api. prj_from_letter(prj)) elif cmd == 'accept': - return AcceptCommand(api).perform(api. prj_from_letter(args[1])) + return AcceptCommand(api).perform(api. prj_from_letter(args[1]), opts.commit) elif cmd == 'unselect': tprj = api.prj_from_letter(args[1]) # see issue 1784 for rq, rq_prj in RequestFinder.find_sr(args[2:], opts.apiurl).items(): diff --git a/osclib/accept_command.py b/osclib/accept_command.py index 5ec3d67d..a032f1ac 100644 --- a/osclib/accept_command.py +++ b/osclib/accept_command.py @@ -5,11 +5,12 @@ class AcceptCommand: def __init__(self, api): self.api = api - def perform(self, project): + def perform(self, project, commit): """ Accept the staging LETTER for review and submit to factory Then disable the build to disabled :param project: staging project we are working with + :param commit: switch wether to commit the pkgs to factory right away or not """ status = self.api.check_project_status(project) @@ -25,6 +26,10 @@ class AcceptCommand: requests.append(req['id']) for req in requests: - change_request_state(self.api.apiurl, str(req), 'accepted', message='Accept to factory') + # If we are not doing direct commit print out commands needed to accept it + if commit: + change_request_state(self.api.apiurl, str(req), 'accepted', message='Accept to factory') + else: + print('osc rq accept -m "Accept to factory" {}'.format(req)) self.api.build_switch_prj(project, 'disable') From 69644939f9447fc6750fbf8b2b10f698ecd6f476 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Chv=C3=A1tal?= Date: Tue, 4 Mar 2014 14:16:24 +0100 Subject: [PATCH 2/8] Add wine to the staged packages so we won't ignore testresults in test. --- tests/fixtures/ring-1-project.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/fixtures/ring-1-project.xml b/tests/fixtures/ring-1-project.xml index fe4d2883..3b349221 100644 --- a/tests/fixtures/ring-1-project.xml +++ b/tests/fixtures/ring-1-project.xml @@ -1,3 +1,4 @@ + From cdee7e8e9fff75b228acaae87e1d3d98b5f08381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Chv=C3=A1tal?= Date: Tue, 4 Mar 2014 14:17:53 +0100 Subject: [PATCH 3/8] Whitespace. Remove unused mock function. --- tests/obs.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/tests/obs.py b/tests/obs.py index d8718b77..a9e49769 100644 --- a/tests/obs.py +++ b/tests/obs.py @@ -30,15 +30,6 @@ if PY3: else: string_types = basestring, -# Here place all mockable functions -@contextlib.contextmanager -def mock_generate_ring_packages(): - with mock.patch('oscs.StagingAPI._generate_ring_packages', return_value={ - 'elem-ring-0': 'openSUSE:Factory:Rings:0-Bootstrap', - 'elem-ring-1': 'openSUSE:Factory:Rings:1-MinimalX'}): - yield - - class OBS: """ Class trying to simulate a simple OBS @@ -166,7 +157,7 @@ class OBS: if len(path) > 1: ret = self._pretty_callback(request, 'https://localhost' + posixpath.dirname(path), headers, False) if exception: - raise BaseException("No tests/obs.pyresponse for {0} on {1} provided".format(request.method,uri)) + raise BaseException("No tests/obs.pyresponse for {0} on {1} provided".format(request.method, uri)) else: return None From 25ccbe03705fcabb650b6bb22b9873413776a920 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Chv=C3=A1tal?= Date: Tue, 4 Mar 2014 14:21:23 +0100 Subject: [PATCH 4/8] Fix ring-packages test. --- tests/api_tests.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/api_tests.py b/tests/api_tests.py index ee020af8..89e934f8 100644 --- a/tests/api_tests.py +++ b/tests/api_tests.py @@ -44,6 +44,7 @@ class TestApiCalls(unittest.TestCase): ring_packages = { 'elem-ring-0': 'openSUSE:Factory:Rings:0-Bootstrap', 'elem-ring-1': 'openSUSE:Factory:Rings:1-MinimalX', + 'wine': 'openSUSE:Factory:Rings:1-MinimalX', } # Register OBS From 72c5d06af3982932be2cd61efd8f476cf98e4899 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Chv=C3=A1tal?= Date: Tue, 4 Mar 2014 14:32:57 +0100 Subject: [PATCH 5/8] Remove wrong fixme. --- osclib/stagingapi.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/osclib/stagingapi.py b/osclib/stagingapi.py index 114432c9..48c0540e 100644 --- a/osclib/stagingapi.py +++ b/osclib/stagingapi.py @@ -221,7 +221,6 @@ class StagingAPI(object): # check if we can reduce it down by accepting some for rq in requests: self.accept_non_ring_request(rq) - # FIXME: dispatch to various staging projects automatically def get_prj_pseudometa(self, project): """ @@ -291,7 +290,6 @@ class StagingAPI(object): if append: data['requests'].append({'id': request_id, 'package': package}) self.set_prj_pseudometa(project, data) - # FIXME Add sr to group request as well def get_request_id_for_package(self, project, package): """ From 41f197f53ebc54de8978e32e465dd7d772dd2656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Chv=C3=A1tal?= Date: Tue, 4 Mar 2014 15:20:05 +0100 Subject: [PATCH 6/8] Implement skipping build/openqa skip if we check only non-ring packages. --- osclib/stagingapi.py | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/osclib/stagingapi.py b/osclib/stagingapi.py index 48c0540e..b23eed09 100644 --- a/osclib/stagingapi.py +++ b/osclib/stagingapi.py @@ -325,7 +325,6 @@ class StagingAPI(object): data = self.get_prj_pseudometa(project) data['requests'] = filter(lambda x: x['package'] != package, data['requests']) self.set_prj_pseudometa(project, data) - # FIXME Add sr to group request as well def rm_from_prj(self, project, package=None, request_id=None, msg=None, review='accepted'): @@ -410,6 +409,22 @@ class StagingAPI(object): state = 'missing reviews: ' + ', '.join(failing_groups) return '{}: {}'.format(package, state) + def check_ring_packages(self, project, requests): + """ + Checks if packages from requests are in some ring or not + :param project: project to check + :param requests: list of requests to verify + :return True (has ring packages) / False (has no ring packages) + """ + + for request in requests: + pkg = self.get_package_for_request_id(project, request) + if pkg in self.ring_packages: + return True + + return False + + def check_project_status(self, project, verbose=False): """ Checks a staging project for acceptance. Checks all open @@ -435,11 +450,11 @@ class StagingAPI(object): open_requests.remove(req) if req not in requests: requests.append(req) - if len(open_requests) != 0: + if open_requests: return ['Request(s) {} are not tracked but are open for the prj'.format(','.join(open_requests))] # If we find no requests in staging then it is empty so we ignore it - if len(requests) == 0: + if not requests: return False # Check if the requests are acceptable and bail out on @@ -451,16 +466,17 @@ class StagingAPI(object): if not verbose: break - # Check the buildstatus - buildstatus = self.gather_build_status(project) - if buildstatus: - # here no append as we are adding list to list - report += self.generate_build_status_details(buildstatus, verbose) - - # Check the openqa state - ret = self.find_openqa_state(project) - if ret: - report.append(ret) + # Check the build/openQA only if we have some ring packages + if self.check_ring_packages(project, requests): + # Check the buildstatus + buildstatus = self.gather_build_status(project) + if buildstatus: + # here no append as we are adding list to list + report += self.generate_build_status_details(buildstatus, verbose) + # Check the openqa state + ret = self.find_openqa_state(project) + if ret: + report.append(ret) if report: return report From e1cd88908a989ab489fb0d3cc7080509f424df39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Chv=C3=A1tal?= Date: Tue, 4 Mar 2014 15:35:52 +0100 Subject: [PATCH 7/8] Do not overabuse len. --- osclib/stagingapi.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/osclib/stagingapi.py b/osclib/stagingapi.py index b23eed09..36391505 100644 --- a/osclib/stagingapi.py +++ b/osclib/stagingapi.py @@ -581,7 +581,7 @@ class StagingAPI(object): }) # Print the results - if len(working) == 0 and len(broken) == 0: + if not working and not broken: return None else: return [project, working, broken] @@ -598,13 +598,13 @@ class StagingAPI(object): return retval project, working, broken = details - if len(working) != 0: + if working: retval.append('At least following repositories is still building:') for i in working: retval.append(' {}: {}'.format(i['path'], i['state'])) if not verbose: break - if len(broken) != 0: + if broken: retval.append('Following packages are broken:') for i in broken: retval.append(' {} ({}): {}'.format(i['pkg'], i['path'], @@ -746,7 +746,7 @@ class StagingAPI(object): query['by_group'] = by_group if not msg: msg = 'Being evaluated by group "{}"'.format(by_group) - if len(query) == 0: + if not query: raise oscerr.WrongArgs('We need a group or a project') query['cmd'] = 'addreview' url = self.makeurl(['request', str(request_id)], query) From 6426d92b6a0c8e48b7b07d2847e914334a4f8b24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Chv=C3=A1tal?= Date: Tue, 4 Mar 2014 15:45:59 +0100 Subject: [PATCH 8/8] Fix whitespace. --- tests/api_tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/api_tests.py b/tests/api_tests.py index 89e934f8..370c571b 100644 --- a/tests/api_tests.py +++ b/tests/api_tests.py @@ -44,7 +44,7 @@ class TestApiCalls(unittest.TestCase): ring_packages = { 'elem-ring-0': 'openSUSE:Factory:Rings:0-Bootstrap', 'elem-ring-1': 'openSUSE:Factory:Rings:1-MinimalX', - 'wine': 'openSUSE:Factory:Rings:1-MinimalX', + 'wine': 'openSUSE:Factory:Rings:1-MinimalX', } # Register OBS