Commit c61e5df3 authored by Xavier Thompson's avatar Xavier Thompson

software/theia: Add 'embedded-sr' option

See merge request nexedi/slapos!913
parent 71644ca4
......@@ -15,7 +15,7 @@
[instance]
filename = instance.cfg.in
md5sum = 524c0b40d6ee49841fdbb2cf26fd1833
md5sum = 9a3142d6c43616b69217ea4979f25847
[yarn.lock]
filename = yarn.lock
......
......@@ -13,6 +13,16 @@
"disabled"
],
"default": "running"
},
"embedded-sr": {
"title": "Embedded Software URL",
"description": "Optional URL of a software to be embedded",
"type": "string"
},
"embedded-sr-type": {
"title": "Embedded Software Type",
"description": "Type of the optional embedded software",
"type": "string"
}
}
}
......@@ -316,6 +316,8 @@ 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}' \
$${slap-connection:server-url} \
$${slap-connection:computer-id} \
$${slap-connection:partition-id} \
......@@ -404,6 +406,8 @@ url = $${slap-connection:server-url}
key = $${slap-connection:key-file}
cert = $${slap-connection:cert-file}
configuration.autorun = running
configuration.embedded-sr =
configuration.embedded-sr-type =
[slapos-autorun]
recipe = plone.recipe.command
......
......@@ -71,6 +71,8 @@ initialization =
parser.add_argument('ipv6')
parser.add_argument('server_port', type=int)
parser.add_argument('computer_id')
parser.add_argument('--sr')
parser.add_argument('--srtype')
forwarded_arguments = parser.add_argument_group('forwarded')
forwarded_arguments.add_argument('master_url')
forwarded_arguments.add_argument('computer')
......@@ -119,6 +121,11 @@ initialization =
except slapos.slap.standalone.SlapOSNodeCommandError as e:
print("Error instanciating: {}".format(e))
if args.sr:
print("Supplying and Requesting Embedded Software {}".format(args.sr))
standalone.supply(args.sr)
standalone.request(args.sr, "Embedded Instance", args.srtype or None)
quit_requested = []
def signal_handler(signum, frame):
print("Signal {signum} received".format(signum=signum))
......
......@@ -38,6 +38,7 @@ from six.moves.urllib.parse import urlparse, urljoin
import pexpect
import psutil
import requests
import sqlite3
from slapos.testing.testcase import makeModuleSetUpAndTestCaseClass
from slapos.grid.svcbackend import getSupervisorRPC
......@@ -184,3 +185,59 @@ class TestTheiaEmbeddedSlapOSShutdown(SlapOSInstanceTestCase):
# the supervisor controlling instances is also stopped
self.assertFalse(embedded_slapos_process.is_running())
class SQLiteDB(object):
def __init__(self, sqlitedb_file):
self.sqlitedb_file = sqlitedb_file
def select(self, fields, table, where={}):
connection = sqlite3.connect(self.sqlitedb_file)
def dict_factory(cursor, row):
d = {}
for idx, col in enumerate(cursor.description):
d[col[0]] = row[idx]
return d
connection.row_factory = dict_factory
cursor = connection.cursor()
condition = " AND ".join("%s='%s'" % (k, v) for k, v in where.items())
cursor.execute(
"SELECT %s FROM %s%s"
% (
", ".join(fields),
table,
" WHERE %s" % condition if where else "",
)
)
return cursor.fetchall()
class TestTheiaWithSR(SlapOSInstanceTestCase):
__partition_reference__ = 'T' # for sockets in included slapos
srurl = 'bogus/software.cfg'
srtype = 'bogus'
@classmethod
def getInstanceParameterDict(cls):
return {
'embedded-sr': cls.srurl,
'embedded-sr-type': cls.srtype,
}
def test(self):
db = SQLiteDB(os.path.join(self.computer_partition_root_path, 'srv', 'runner', 'var', 'proxy.db'))
supplied = db.select(
fields=["*"],
table = "software14",
where={'url': self.srurl}
)
self.assertEqual(len(supplied), 1)
requested = db.select(
fields=["*"],
table = "partition14",
where={'software_release': self.srurl, 'software_type': self.srtype}
)
self.assertEqual(len(requested), 1)
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