From d93f98caba12ffa0aa1a0b6a1bbd9ca39c2d2569 Mon Sep 17 00:00:00 2001 From: Filip Valder Date: Mon, 7 Aug 2017 13:58:33 +0200 Subject: [PATCH 1/4] Fix #618: mbs-build prints json instead of message --- contrib/mbs-build | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/contrib/mbs-build b/contrib/mbs-build index 14e55c3f..e06a8021 100755 --- a/contrib/mbs-build +++ b/contrib/mbs-build @@ -249,7 +249,7 @@ def submit_module_build(scm_url, branch, server, id_provider, pyrpkg, verify=Tru scm_url = get_scm_url(scm_url, pyrpkg) branch = get_scm_branch(branch) if not scm_url or not branch: - return -2 + return -2, None logging.info("Submitting module build %s", scm_url) @@ -261,9 +261,11 @@ def submit_module_build(scm_url, branch, server, id_provider, pyrpkg, verify=Tru logging.info(resp.text) data = resp.json() - if 'id' in data: - return data['id'] - return -3 + if 'error' in data: + return -4, "%s %s: %s" % (data['status'], data['error'], data['message']) + elif 'id' in data: + return data['id'], None + return -3, None def do_local_build(scm_url, branch, skiptests, log_flag=None): """ @@ -464,9 +466,11 @@ def main(): if args.cmd_name == "submit": # Submit the module build. - build_id = submit_module_build(args.scm_url, args.branch, args.server, - args.idprovider, args.pyrpkg_client, args.verify, args.optional) + build_id, errmsg = submit_module_build(args.scm_url, args.branch, args.server, + args.idprovider, args.pyrpkg_client, args.verify, args.optional) if build_id < 0: + if errmsg: + logging.critical(errmsg) sys.exit(build_id) if args.watch: From e3a002f0ff69688c7a27fb51a0e2f0326b9fec54 Mon Sep 17 00:00:00 2001 From: Filip Valder Date: Mon, 7 Aug 2017 13:59:56 +0200 Subject: [PATCH 2/4] use print rather than logging.info (similarly to watch_build) --- contrib/mbs-build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/mbs-build b/contrib/mbs-build index e06a8021..33cc341d 100755 --- a/contrib/mbs-build +++ b/contrib/mbs-build @@ -476,7 +476,7 @@ def main(): if args.watch: watch_build(args.server, build_id) else: - logging.info("Submitted module build %r" % build_id) + print("Submitted module build %r" % build_id) elif args.cmd_name == "local": sys.exit(do_local_build(args.scm_url, args.branch, args.skiptests, log_flag)) From 77dc96ce7b4636f5cd3423603b8f9369912b54df Mon Sep 17 00:00:00 2001 From: Filip Valder Date: Mon, 7 Aug 2017 14:02:12 +0200 Subject: [PATCH 3/4] fix PEP8 --- contrib/mbs-build | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/contrib/mbs-build b/contrib/mbs-build index 33cc341d..69584f71 100755 --- a/contrib/mbs-build +++ b/contrib/mbs-build @@ -119,6 +119,7 @@ def watch_build(server, build_id): if not done: time.sleep(30) + # Ideally we would use oidc.send_request here, but it doesn't support # custom HTTP verbs/methods like "PATCH". It sends just "POST"... # TODO: Remove this method once python-openidc-client with verb support @@ -168,6 +169,7 @@ def _send_oidc_request(oidc, verb, *args, **kwargs): else: return resp + def send_authorized_request(verb, server, id_provider, url, body, **kwargs): """ Sends authorized request to server. @@ -193,6 +195,7 @@ def send_authorized_request(verb, server, id_provider, url, body, **kwargs): scopes=scopes, **kwargs) return resp + def get_scm_url(scm_url, pyrpkg, local=False): """ If `scm_url` it not set, returns the scm_url based on git repository @@ -203,7 +206,7 @@ def get_scm_url(scm_url, pyrpkg, local=False): return scm_url logging.info("You have not provided SCM URL or branch. Trying to get " - "it from current working directory") + "it from current working directory") if local: # Just get the local URL from the current working directory. @@ -212,16 +215,17 @@ def get_scm_url(scm_url, pyrpkg, local=False): else: # Get the url using pyrpkg implementation. process = subprocess.Popen([pyrpkg, 'giturl'], stdout=subprocess.PIPE, - stderr=subprocess.PIPE) + stderr=subprocess.PIPE) out, err = process.communicate() if process.returncode != 0 and len(err) != 0: logging.error("Cannot get the giturl from current " - "working directory using the %s", pyrpkg) + "working directory using the %s", pyrpkg) logging.error(err) return None - scm_url = out[:-1] # remove new-line + scm_url = out[:-1] # remove new-line return scm_url + def get_scm_branch(branch): """ If `branch` it not set, returns the branch name based on git repository @@ -231,16 +235,17 @@ def get_scm_branch(branch): return branch process = subprocess.Popen(['git', 'rev-parse', '--abbrev-ref', 'HEAD'], - stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = process.communicate() if process.returncode != 0 and len(err) != 0: logging.error("Cannot get the branch name from current " - "working directory.") + "working directory.") logging.error(err) return None - branch = out[:-1] # remove new-line + branch = out[:-1] # remove new-line return branch + def submit_module_build(scm_url, branch, server, id_provider, pyrpkg, verify=True, optional=None): """ Submits the module defined by `scm_url` to MBS instance defined @@ -251,7 +256,6 @@ def submit_module_build(scm_url, branch, server, id_provider, pyrpkg, verify=Tru if not scm_url or not branch: return -2, None - logging.info("Submitting module build %s", scm_url) body = {'scmurl': scm_url, 'branch': branch} body.update({x.split("=")[0]: x.split("=")[1] for x in optional}) @@ -267,6 +271,7 @@ def submit_module_build(scm_url, branch, server, id_provider, pyrpkg, verify=Tru return data['id'], None return -3, None + def do_local_build(scm_url, branch, skiptests, log_flag=None): """ Starts the local build using the 'mbs-manager build_module_locally' @@ -278,7 +283,6 @@ def do_local_build(scm_url, branch, skiptests, log_flag=None): if not scm_url or not branch: return None - logging.info("Starting local build of %s, branch %s", scm_url, branch) command = ['mbs-manager'] if log_flag: @@ -293,6 +297,7 @@ def do_local_build(scm_url, branch, skiptests, log_flag=None): process.communicate() return process.returncode + def cancel_module_build(server, id_provider, build_id, verify=True): """ Cancels the module build. @@ -304,6 +309,7 @@ def cancel_module_build(server, id_provider, build_id, verify=True): {'state': 'failed'}, verify=verify) logging.info(resp.text) + def show_overview(server, finished, limit=30): if not server: server = DEFAULT_MBS_SERVER @@ -373,6 +379,7 @@ def show_overview(server, finished, limit=30): print(tabulate(table, headers=headers)) + def main(): # Parse command line arguments parser = argparse.ArgumentParser(description="Submits and manages module builds.") @@ -435,7 +442,7 @@ def main(): parser_local.add_argument("scm_url", nargs='?') parser_local.add_argument("branch", nargs='?') parser_local.add_argument('--skiptests', dest='skiptests', action='store_true', - help="add macro for skipping check section/phase") + help="add macro for skipping check section/phase") parser_overview = subparsers.add_parser( 'overview', help="show overview of module builds", From 13bcb05d9826f5745e2882f0ddd355cab3881b40 Mon Sep 17 00:00:00 2001 From: Filip Valder Date: Mon, 7 Aug 2017 14:07:03 +0200 Subject: [PATCH 4/4] Fix #617: mbs-build shows python error --- contrib/mbs-build | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/contrib/mbs-build b/contrib/mbs-build index 69584f71..bffecf44 100755 --- a/contrib/mbs-build +++ b/contrib/mbs-build @@ -249,7 +249,7 @@ def get_scm_branch(branch): def submit_module_build(scm_url, branch, server, id_provider, pyrpkg, verify=True, optional=None): """ Submits the module defined by `scm_url` to MBS instance defined - by `server`. Returns build_id or negative error code. + by `server`. Returns tuple: build_id or negative error code, error message. """ scm_url = get_scm_url(scm_url, pyrpkg) branch = get_scm_branch(branch) @@ -258,7 +258,11 @@ def submit_module_build(scm_url, branch, server, id_provider, pyrpkg, verify=Tru logging.info("Submitting module build %s", scm_url) body = {'scmurl': scm_url, 'branch': branch} - body.update({x.split("=")[0]: x.split("=")[1] for x in optional}) + try: + optional_dict = {y[0]: y[1] for y in [x.split("=", 1) for x in optional]} + except IndexError: + return -5, "Optional arguments are not in a proper arg=value format." + body.update(optional_dict) resp = send_authorized_request( "POST", server, id_provider, "/module-build-service/1/module-builds/", body, verify=verify)