aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Copeland <ben.copeland@linaro.org>2019-03-21 14:28:49 +0000
committerBenjamin Copeland <ben.copeland@linaro.org>2019-03-22 13:03:09 +0000
commit7209152fe80fce9ea444da2566ef3fa5b65983da (patch)
treebf310b0fee09ab217c49969b65ec42615d9bde61
parent273a22c32147a94c817fae3e375c85e05402fecb (diff)
Local support: Add local support to ci-yadp-builder.
This feature allows us to run the python script with --local, which will create the groovy template file in /tmp/ location. This is useful for debugging efforts and not having to need a jenkins server running. Furthermore the last changes of dryrun support weren't properly merged between the two versions of python (so python3 dryrun wasn't working) and we were calling a template file that no longer exists. Change-Id: I5fd219fa6e55616de6b6f01ac031e6259e4d0be6 Reviewed-on: https://review.linaro.org/c/30874 Reviewed-by: Fathi Boudra <fathi.boudra@linaro.org> Reviewed-by: Kelley Spoon <kelley.spoon@linaro.org> Reviewed-by: Benjamin Copeland <ben.copeland@linaro.org>
-rwxr-xr-xyadp_builder.py25
-rwxr-xr-xyadp_builder_v2.py32
2 files changed, 40 insertions, 17 deletions
diff --git a/yadp_builder.py b/yadp_builder.py
index a8e50dc..e2094e0 100755
--- a/yadp_builder.py
+++ b/yadp_builder.py
@@ -58,11 +58,11 @@ class Loader(yaml.Loader, metaclass=LoaderMeta):
return yaml.load(f, Loader)
-def jinja2_from_template(directory, template_name, data):
+def jinja2_from_template(directory, template_name, data, dryrun=False):
loader = FileSystemLoader(directory)
env = Environment(loader=loader)
template = env.get_template(template_name)
- return template.render(hosts=data)
+ return template.render(hosts=data, dryrun=dryrun)
def get_parser():
@@ -82,6 +82,8 @@ def get_parser():
help="Setting logging level, default: %(default)s")
parser.add_argument('--dryrun', action='store_true',
help='Do not publish to Jenkins')
+ parser.add_argument('--local', action='store_true',
+ help='Create tmp file only, to be used with dryrun.')
return parser
@@ -95,20 +97,25 @@ if __name__ == '__main__':
template_output = jinja2_from_template(
'./templates',
'configure-yadocker-cloud.groovy.j2', data)
- server = jenkins.Jenkins(args.server, username=args.username,
+
+ if not args.local:
+ server = jenkins.Jenkins(args.server, username=args.username,
password=args.password)
if args.dryrun:
with open('/tmp/configure-yadocker-cloud.groovy', 'w') as fw:
fw.write(template_output)
template_output = jinja2_from_template(
'./templates',
- 'configure-yadocker-cloud.groovy-dryrun.j2', data)
-
- publishdry = server.run_script(template_output)
- if 'error' in publishdry:
+ 'configure-yadocker-cloud.groovy.j2', data, args.dryrun)
+ if not args.local:
+ publishdry = server.run_script(template_output)
+ if 'error' in publishdry:
+ logging.info(publishdry)
+ exit(1)
logging.info(publishdry)
- exit(1)
- logging.info(publishdry)
+ else:
+ logging.info('Template file created at \
+ /tmp/configure-yadocker-cloud.groovy')
else:
publish = server.run_script(template_output)
logging.info(publish)
diff --git a/yadp_builder_v2.py b/yadp_builder_v2.py
index 56309d5..cb4ac86 100755
--- a/yadp_builder_v2.py
+++ b/yadp_builder_v2.py
@@ -43,7 +43,7 @@ class Loader(yaml.Loader):
return yaml.load(f, Loader)
-def jinja2_from_template(directory, template_name, data, dryrun):
+def jinja2_from_template(directory, template_name, data, dryrun=False):
loader = FileSystemLoader(directory)
env = Environment(loader=loader)
template = env.get_template(template_name)
@@ -67,6 +67,8 @@ def get_parser():
help="Setting logging level, default: %(default)s")
parser.add_argument('--dryrun', action='store_true',
help='Do not publish to Jenkins')
+ parser.add_argument('--local', action='store_true',
+ help='Create tmp file only')
return parser
@@ -79,13 +81,27 @@ if __name__ == '__main__':
logging.debug(data)
template_output = jinja2_from_template(
'./templates',
- 'configure-yadocker-cloud.groovy.j2', data, args.dryrun)
+ 'configure-yadocker-cloud.groovy.j2', data)
- if args.loglevel == "DEBUG":
+ if not args.local:
+ server = jenkins.Jenkins(args.server, username=args.username,
+ password=args.password)
+ if args.dryrun:
with open('/tmp/configure-yadocker-cloud.groovy', 'w') as fw:
fw.write(template_output)
-
- server = jenkins.Jenkins(args.server, username=args.username,
- password=args.password)
- publish = server.run_script(template_output)
- logging.info(publish)
+ template_output = jinja2_from_template(
+ './templates',
+ 'configure-yadocker-cloud.groovy.j2', data, args.dryrun)
+ if not args.local:
+ publishdry = server.run_script(template_output)
+ if 'error' in publishdry:
+ logging.info(publishdry)
+ exit(1)
+ logging.info(publishdry)
+ else:
+ logging.info('Template file created at \
+ /tmp/configure-yadocker-cloud.groovy')
+ logging.debug(template_output)
+ else:
+ publish = server.run_script(template_output)
+ logging.info(publish)