Commit 329ca8b3 authored by Xavier Thompson's avatar Xavier Thompson

software/theia: Add embedded-instance-parameters option

See merge request nexedi/slapos!987
parents 24463a79 ebec62b3
......@@ -15,11 +15,11 @@
[instance-theia]
_update_hash_filename_ = instance-theia.cfg.jinja.in
md5sum = 65c66a4cc4eb1d074dcafddf945a34d4
md5sum = a4211295ecd3919b61abbcd51085971f
[instance]
_update_hash_filename_ = instance.cfg.in
md5sum = 43923e3e1f27c43696ecbca9ee147bdb
md5sum = 9a5d6ac099c460481af7c1bdfd8de770
[yarn.lock]
_update_hash_filename_ = yarn.lock
......
......@@ -24,6 +24,11 @@
"description": "Type of the optional embedded software",
"type": "string"
},
"embedded-instance-parameters": {
"title": "Embedded Instance Parameters",
"description": "Parameters for the embedded instance, as a JSON dict",
"type": "string"
},
"frontend-guid": {
"title": "Frontend Instance ID",
"description": "Unique identifier of the frontend instance, like \"SOFTINST-11031\".",
......
{% set additional_frontend = slapconfiguration_section['configuration.additional-frontend-guid'] %}
{% set parameter_dict = dict(default_parameter_dict, **parameter_dict) %}
{% set additional_frontend = parameter_dict['additional-frontend-guid'] %}
[buildout]
extends =
......@@ -26,12 +27,6 @@ develop-eggs-directory = ${buildout:develop-eggs-directory}
offline = true
[instance-parameter]
{% for k, v in slapconfiguration_section.items() -%}
{{ k }} = {{ v }}
{% endfor -%}
[publish-connection-parameter]
<= monitor-publish
recipe = slapos.cookbook:publish
......@@ -142,18 +137,18 @@ return = domain secure_access
[remote-frontend]
<= remote-frontend-base
name = $${instance-parameter:configuration.frontend-name}
software-url = $${instance-parameter:configuration.frontend-sr}
software-type = $${instance-parameter:configuration.frontend-sr-type}
sla-instance_guid = $${instance-parameter:configuration.frontend-guid}
name = {{ parameter_dict['frontend-name'] }}
software-url = {{ parameter_dict['frontend-sr'] }}
software-type = {{ parameter_dict['frontend-sr-type'] }}
sla-instance_guid = {{ parameter_dict['frontend-guid'] }}
{% if additional_frontend %}
[remote-additional-frontend]
<= remote-frontend-base
name = $${instance-parameter:configuration.additional-frontend-name}
software-url = $${instance-parameter:configuration.additional-frontend-sr}
software-type = $${instance-parameter:configuration.additional-frontend-sr-type}
sla-instance_guid = $${instance-parameter:configuration.additional-frontend-guid}
name = {{ parameter_dict['additional-frontend-name'] }}
software-url = {{ parameter_dict['additional-frontend-sr'] }}
software-type = {{ parameter_dict['additional-frontend-sr-type'] }}
sla-instance_guid = {{ parameter_dict['additional-frontend-guid'] }}
{% endif %}
......@@ -169,7 +164,7 @@ bytes = 12
recipe = slapos.cookbook:free_port
minimum = 3000
maximum = 3100
ip = $${instance-parameter:ipv6-random}
ip = {{ ipv6_random }}
[frontend-instance-certificate]
recipe = plone.recipe.command
......@@ -325,7 +320,7 @@ template =
recipe = slapos.cookbook:free_port
minimum = 3500
maximum = 3600
ip = $${instance-parameter:ipv4-random}
ip = {{ ipv4_random }}
[theia-service]
recipe = slapos.recipe.template:jinja2
......@@ -360,7 +355,7 @@ command-line = $${theia-service:rendered} --hostname=$${:hostname} --port=$${:p
hash-existing-files =
${yarn.lock:output}
${theia-wrapper:rendered}
ip = $${instance-parameter:ipv4-random}
ip = {{ ipv4_random }}
hostname = $${:ip}
port = $${theia-service:port}
base-url = $${theia-service:base-url}
......@@ -416,11 +411,11 @@ command =
recipe = slapos.cookbook:free_port
minimum = 4000
maximum = 4100
ip = $${instance-parameter:ipv4-random}
ip = {{ ipv4_random }}
[slapos-standalone-config]
ipv4 = $${instance-parameter:ipv4-random}
ipv6 = $${instance-parameter:ipv6-random}
ipv4 = {{ ipv4_random }}
ipv6 = {{ ipv6_random }}
port = $${slapos-standalone-port:port}
slapos-configuration = $${directory:runner}/etc/slapos.cfg
computer-id = slaprunner
......@@ -451,8 +446,11 @@ template =
$${slapos-standalone-config:ipv6} \
$${slapos-standalone-config:port} \
$${slapos-standalone-config:computer-id} \
--sr='$${instance-parameter:configuration.embedded-sr}' \
--srtype='$${instance-parameter:configuration.embedded-sr-type}' \
{% if parameter_dict.get('embedded-sr') %} \
--sr='{{ parameter_dict['embedded-sr'] }}' \
--srtype='{{ parameter_dict['embedded-sr-type'] }}' \
--srparams='$${embedded-instance-parameters:rendered}' \
{% endif %} \
$${slap-connection:server-url} \
$${slap-connection:computer-id} \
$${slap-connection:partition-id} \
......@@ -482,7 +480,7 @@ command =
update-command = $${:command}
service-name = slapos-node-auto
supervisor-conf = $${directory:runner}/etc/supervisord.conf
autorun = $${instance-parameter:configuration.autorun}
autorun = {{ parameter_dict['autorun'] }}
# Theia Local Environment Setup
......@@ -579,6 +577,14 @@ recipe = slapos.cookbook:symbolic.link
target-directory = $${directory:project}
link-binary = $${directory:runner}
{% if parameter_dict.get('embedded-sr') -%}
[embedded-instance-parameters]
recipe = slapos.recipe.template:jinja2
rendered = $${directory:etc}/$${:_buildout_section_name_}.json
template =
inline:{{ parameter_dict['embedded-instance-parameters'] | indent(2) }}
{%- endif %}
[request-script-template]
recipe = slapos.recipe.template:jinja2
rendered = $${directory:project}/$${:_buildout_section_name_}.sh
......
......@@ -12,20 +12,6 @@ partition = $${slap-connection:partition-id}
url = $${slap-connection:server-url}
key = $${slap-connection:key-file}
cert = $${slap-connection:cert-file}
;Theia default configuration
configuration.autorun = running
configuration.embedded-sr =
configuration.embedded-sr-type =
;Frontend default configuration
configuration.frontend-name = Theia Frontend
configuration.frontend-sr = http://git.erp5.org/gitweb/slapos.git/blob_plain/HEAD:/software/apache-frontend/software.cfg
configuration.frontend-sr-type = RootSoftwareInstance
configuration.frontend-guid =
;Additional frontend default configuration
configuration.additional-frontend-name = Theia Additional Frontend
configuration.additional-frontend-sr = http://git.erp5.org/gitweb/slapos.git/blob_plain/HEAD:/software/apache-frontend/software.cfg
configuration.additional-frontend-sr-type = RootSoftwareInstance
configuration.additional-frontend-guid =
[switch-softwaretype]
recipe = slapos.cookbook:switch-softwaretype
......@@ -39,4 +25,23 @@ template = ${instance-theia:output}
rendered = $${buildout:directory}/instance-theia.cfg
mode = 0644
context =
section slapconfiguration_section slap-configuration
jsonkey default_parameter_dict :default-parameters
key parameter_dict slap-configuration:configuration
key ipv6_random slap-configuration:ipv6-random
key ipv4_random slap-configuration:ipv4-random
default-parameters =
{
"autorun": "running",
"embedded-sr": null,
"embedded-sr-type": null,
"embedded-instance-parameters": "null",
"frontend-name": "Theia Frontend",
"frontend-sr": "$${:frontend-sr}",
"frontend-sr-type": "RootSoftwareInstance",
"frontend-guid": null,
"additional-frontend-name":"Theia Additional Frontend",
"additional-frontend-sr": "$${:frontend-sr}",
"additional-frontend-sr-type": "RootSoftwareInstance",
"additional-frontend-guid": null
}
frontend-sr = http://git.erp5.org/gitweb/slapos.git/blob_plain/HEAD:/software/apache-frontend/software.cfg
......@@ -53,6 +53,7 @@ entry-points =
initialization =
import argparse
import glob
import json
import os.path
import sys
import signal
......@@ -68,6 +69,7 @@ initialization =
parser.add_argument('computer_id')
parser.add_argument('--sr')
parser.add_argument('--srtype')
parser.add_argument('--srparams')
forwarded_arguments = parser.add_argument_group('forwarded')
forwarded_arguments.add_argument('master_url')
forwarded_arguments.add_argument('computer')
......@@ -118,9 +120,24 @@ initialization =
print("Error instanciating: {}".format(e))
if args.sr:
print("Supplying and Requesting Embedded Software {}".format(args.sr))
try:
with open(args.srparams) as f:
params = json.load(f)
except Exception:
params = None
if not isinstance(params, dict):
params = None
print("Supplying and Requesting Embedded Software {sr} with type {srtype}".format(
sr=args.sr, srtype=args.srtype))
print("With parameters {param_dict} parsed from '{srparams}'".format(
param_dict=params, srparams=args.srparams))
standalone.supply(args.sr)
standalone.request(args.sr, "Embedded Instance", args.srtype or None)
standalone.request(
args.sr,
"Embedded Instance",
args.srtype or None,
partition_parameter_kw=params,
)
quit_requested = []
def signal_handler(signum, frame):
......
......@@ -232,12 +232,14 @@ class TestTheiaEmbeddedSlapOSShutdown(TheiaTestCase):
class TestTheiaWithSR(TheiaTestCase):
sr_url = 'bogus/software.cfg'
sr_type = 'bogus_type'
instance_parameters = '{\n"bogus_param": "bogus_value"\n}'
@classmethod
def getInstanceParameterDict(cls):
return {
'embedded-sr': cls.sr_url,
'embedded-sr-type': cls.sr_type,
'embedded-instance-parameters': cls.instance_parameters
}
def test(self):
......@@ -248,6 +250,9 @@ class TestTheiaWithSR(TheiaTestCase):
self.assertIsNotNone(re.search(r"%s\s+slaprunner\s+available" % (self.sr_url,), info), info)
self.assertIsNotNone(re.search(r"%s\s+%s\s+%s" % (self.sr_url, self.sr_type, instance_name), info), info)
service_info = subprocess.check_output((slapos, 'service', 'info', instance_name), universal_newlines=True)
self.assertIn("{'bogus_param': 'bogus_value'}", service_info)
class TestTheiaFrontend(TheiaTestCase):
@classmethod
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment