Commit ebec62b3 authored by Xavier Thompson's avatar Xavier Thompson

software/theia: Add embedded-instance-parameters

This option takes a string representing a valid JSON object and
forwards the corresponding python dict to the embedded instance.
parent 7918c2b2
......@@ -15,11 +15,11 @@
[instance-theia]
_update_hash_filename_ = instance-theia.cfg.jinja.in
md5sum = 740998d9735b0c12a16ddc62a2aa9c98
md5sum = a4211295ecd3919b61abbcd51085971f
[instance]
_update_hash_filename_ = instance.cfg.in
md5sum = b1c6fc005340bd60fa8a53eda4781771
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\".",
......
......@@ -446,8 +446,11 @@ template =
$${slapos-standalone-config:ipv6} \
$${slapos-standalone-config:port} \
$${slapos-standalone-config:computer-id} \
{% 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} \
......@@ -574,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
......
......@@ -34,6 +34,7 @@ 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",
......
......@@ -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