This commit is contained in:
Filip Valder
2017-08-07 14:02:12 +02:00
parent e3a002f0ff
commit 77dc96ce7b

View File

@@ -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",