From 98383e9cd73135e61bf4e2417a5b53ff0d2598c7 Mon Sep 17 00:00:00 2001
From: Nicolas Wavrant <nicolas.wavrant@nexedi.com>
Date: Mon, 14 Nov 2016 12:22:48 +0100
Subject: [PATCH] slaprunner: adapt the instanciation to correctly extend the
 resilient stack. Also, the instance-runner-export template becomes a Jinja
 template

---
 software/slaprunner/common.cfg                |  8 ++--
 .../slaprunner/instance-runner-export.cfg.in  | 40 +++++++++----------
 software/slaprunner/instance.cfg              | 19 ++++++---
 3 files changed, 37 insertions(+), 30 deletions(-)

diff --git a/software/slaprunner/common.cfg b/software/slaprunner/common.cfg
index 958b78867..67f70ecee 100644
--- a/software/slaprunner/common.cfg
+++ b/software/slaprunner/common.cfg
@@ -53,7 +53,7 @@ parts =
 recipe = slapos.recipe.template
 url = ${:_profile_base_location_}/instance.cfg
 output = ${buildout:directory}/template.cfg
-md5sum = 62c2ad4b0e2fe3edad27bdb885dee626
+md5sum = 06107f93ebe78905c957a4c4fc4edf16
 mode = 0644
 
 [template-runner]
@@ -89,10 +89,10 @@ filename = runner-export.sh.jinja2
 mode = 0644
 
 [instance-runner-export]
-recipe = slapos.recipe.template
+recipe = slapos.recipe.build:download
 url = ${:_profile_base_location_}/instance-runner-export.cfg.in
-output = ${buildout:directory}/instance-runner-export.cfg
-md5sum = fb0974c51380eef28d4839318e0ef6e2
+filename = instance-runner-export.cfg.in
+md5sum = 852a2ed99af566d27e5e4403334a3376
 mode = 0644
 
 [template-resilient]
diff --git a/software/slaprunner/instance-runner-export.cfg.in b/software/slaprunner/instance-runner-export.cfg.in
index 026ae15e3..9eaf31ee1 100644
--- a/software/slaprunner/instance-runner-export.cfg.in
+++ b/software/slaprunner/instance-runner-export.cfg.in
@@ -1,6 +1,6 @@
 [buildout]
-extends = template-runner.cfg
-          pbsready-exporter.cfg
+extends = {{ template_runner_path }}
+          {{ pbsready_export_template_path }}
 
 parts +=
   nginx_conf
@@ -41,51 +41,51 @@ parts +=
 recipe = slapos.cookbook:free_port
 minimum = 49980
 maximum = 49989
-ip = $${slap-network-information:local-ipv4}
+ip = ${slap-network-information:local-ipv4}
 
 [runner-free-port]
 recipe = slapos.cookbook:free_port
 minimum = 50005
 maximum = 50014
-ip = $${slap-network-information:global-ipv6}
+ip = ${slap-network-information:global-ipv6}
 
 [slaprunner]
-proxy_port = $${proxy-free-port:port}
-runner_port = $${runner-free-port:port}
+proxy_port = ${proxy-free-port:port}
+runner_port = ${runner-free-port:port}
 
 [supervisord-free-port]
 recipe = slapos.cookbook:free_port
 minimum = 39986
 maximum = 39995
-ip = $${slaprunner:ipv4}
+ip = ${slaprunner:ipv4}
 
 [supervisord]
-port = $${supervisord-free-port:port}
+port = ${supervisord-free-port:port}
 
 [exporter]
 recipe = slapos.recipe.template:jinja2
-template = ${template-runner-export-script:location}/${template-runner-export-script:filename}
-rendered = $${directory:bin}/$${slap-parameter:namebase}-exporter
+template = {{ exporter_script_path }}
+rendered = ${directory:bin}/${slap-parameter:namebase}-exporter
 # backward compatibility for resilient stack
-wrapper = $${:rendered}
+wrapper = ${:rendered}
 mode = 700
 context =
   section directory directory
-  raw  output_log_file $${directory:log}/resilient.log
-  raw  shell_binary ${bash:location}/bin/bash
-  raw  rsync_binary ${rsync:location}/bin/rsync
+  raw  output_log_file ${directory:log}/resilient.log
+  raw  shell_binary {{ bash_executable_location }}
+  raw  rsync_binary {{ rsync_executable_location }}
 
 [monitor-httpd-free-port]
 recipe = slapos.cookbook:free_port
 minimum = 8437
 maximum = 8446
-ip = $${slap-network-information:global-ipv6}
+ip = ${slap-network-information:global-ipv6}
 
 [monitor-instance-parameter]
-monitor-httpd-port = $${monitor-httpd-free-port:port}
+monitor-httpd-port = ${monitor-httpd-free-port:port}
 # Pass some parameter to dispay in monitoring interface
 instance-configuration =
-  httpdcors cors-domain $${slaprunner-httpd-cors:location} $${httpd-graceful-wrapper:output}
+  httpdcors cors-domain ${slaprunner-httpd-cors:location} ${httpd-graceful-wrapper:output}
 
 # Extends publish section with resilient parameters
 [publish-connection-information]
@@ -93,11 +93,11 @@ instance-configuration =
 
 [monitor-check-resilient-feed-file]
 recipe = slapos.recipe.template:jinja2
-template = ${template-monitor-check-resilient-feed:location}/${template-monitor-check-resilient-feed:filename}
-rendered = $${monitor-directory:reports}/check-create-resilient-feed-files
+template = {{ monitor_check_resilient_feed_template_path }}
+rendered = ${monitor-directory:reports}/check-create-resilient-feed-files
 mode = 700
 context =
   key input_feed_directory directory:notifier-feeds
   key monitor_feed_directory monitor-directory:public
-  raw base_url http://[$${notifier:host}]:$${notifier:port}/get/
+  raw base_url http://[${notifier:host}]:${notifier:port}/get/
   raw python_executable ${buildout:executable}
diff --git a/software/slaprunner/instance.cfg b/software/slaprunner/instance.cfg
index ddcf5a196..27f38b07f 100644
--- a/software/slaprunner/instance.cfg
+++ b/software/slaprunner/instance.cfg
@@ -1,11 +1,12 @@
 [buildout]
 parts =
-  template-pbsready-export
   switch_softwaretype
 
 eggs-directory = ${buildout:eggs-directory}
 develop-eggs-directory = ${buildout:develop-eggs-directory}
 
+extends = ${template-resilient-templates:output}
+
 [switch_softwaretype]
 recipe = slapos.cookbook:softwaretype
 default = $${instance-base-runner:rendered}
@@ -13,7 +14,7 @@ resilient = $${instance-resilient:rendered}
 test = $${instance-resilient-test:rendered}
 runner = $${instance-base-runner:rendered}
 runner-import = ${instance-runner-import:output}
-runner-export = ${instance-runner-export:output}
+runner-export = $${template-runner-export:rendered}
 
 frozen = ${instance-frozen:output}
 pull-backup = ${template-pull-backup:output}
@@ -59,13 +60,19 @@ context =
     key slapparameter_dict slap-configuration:configuration
 mode = 0644
 
-[template-pbsready-export]
+[template-runner-export]
 recipe = slapos.recipe.template:jinja2
-template = ${pbsready-export:output}
-rendered = $${buildout:directory}/pbsready-exporter.cfg
+template = ${instance-runner-export:target}
+rendered = $${buildout:directory}/instance-runner-export.cfg
 mode = 640
 context =
-  key slapparameter_dict slap-configuration:configuration
+  key pbsready_export_template_path template-pbsready-export:rendered
+  key template_runner_path instance-base-runner:rendered
+  raw exporter_script_path ${template-runner-export-script:location}/${template-runner-export-script:filename}
+  raw monitor_check_resilient_feed_template_path ${template-monitor-check-resilient-feed:location}/${template-monitor-check-resilient-feed:filename}
+  raw buildout_executable_location ${buildout:executable}
+  raw bash_executable_location ${bash:location}/bin/bash
+  raw rsync_executable_location ${rsync:location}/bin/rsync
 
 [slap-configuration]
 recipe = slapos.cookbook:slapconfiguration
-- 
2.30.9