summaryrefslogtreecommitdiffstats
path: root/utils/agljobtemplate.py
diff options
context:
space:
mode:
authorLoys Ollivier <lollivier@baylibre.com>2017-09-08 09:57:39 +0200
committerKevin Hilman <khilman@baylibre.com>2017-09-08 09:04:47 -0700
commit0535413a98ace7cbf301bba18dd95254302d584f (patch)
treefd991f9e6a6e3055f92de665a63c6f03cde057bf /utils/agljobtemplate.py
parentb516553ebf08c2aec03b840d618fafd548656706 (diff)
Add callback option to command line
The callback option takes one argument. It is the name of the file located in ./templates/callback/ that contains all the "secret" information such as the callback FQDN, lab name and token. A readme is provided: ./templates/callback/callback_readme.txt Change-Id: Id457d90eba0d1312e43246ca607289ad829fd55f Signed-off-by: Loys Ollivier <lollivier@baylibre.com> Signed-off-by: Kevin Hilman <khilman@baylibre.com>
Diffstat (limited to 'utils/agljobtemplate.py')
-rw-r--r--utils/agljobtemplate.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/utils/agljobtemplate.py b/utils/agljobtemplate.py
index 2b80127..29f101e 100644
--- a/utils/agljobtemplate.py
+++ b/utils/agljobtemplate.py
@@ -2,17 +2,31 @@
# -*- coding: utf-8 -*-
import os
-import sys
import jinja2
+import ConfigParser
def get_extension(path):
return path.split('.')[-1]
+def parse_callback_file(template_path, callback_file, job):
+ callback_file_path = template_path + '/callback/' + callback_file + '.cfg'
+ try:
+ with open(callback_file_path):
+ cfg = ConfigParser.ConfigParser()
+ cfg.read(callback_file_path)
+ job['backend_fqdn'] = cfg.get('default', 'backend_fqdn')
+ job['lab_name'] = cfg.get('default', 'lab_name')
+ job['lab_token'] = cfg.get('default', 'lab_token')
+ except IOError:
+ raise IOError, "Unable to read from file {}".format(callback_file_path)
+
+
class Agljobtemplate(object):
DEFAULT_PATH = "templates"
+ CALLBACK_DIR = "callback"
MACHINES_DIR = "machines"
TESTS_DIR = "tests"
RFS_TYPE = ['nfs', 'nbd', 'ramdisk']
@@ -45,7 +59,8 @@ class Agljobtemplate(object):
def rfs_types(self):
return self.RFS_TYPE
- def render_job(self, url, machine, job_name="AGL-short-smoke", priority="medium", tests=[], rfs_type=None):
+ def render_job(self, url, machine, job_name="AGL-short-smoke", priority="medium", tests=[], rfs_type=None,
+ kci_callback=None):
test_templates = []
if machine not in self.machines:
@@ -68,6 +83,13 @@ class Agljobtemplate(object):
if rfs_type is not None:
job['rootfs_type'] = rfs_type
+ if kci_callback:
+ if test_templates:
+ job['callback_name'] = 'lava/test'
+ else:
+ job['callback_name'] = 'lava/boot'
+ parse_callback_file(self._template_path, kci_callback, job)
+
env = jinja2.Environment(loader=jinja2.FileSystemLoader(self._template_path))
env.filters['get_extension'] = get_extension
template = env.get_template(os.path.join(self.MACHINES_DIR, machine + ".jinja2"))