Commit 3766503c authored by Léo-Paul Géneau's avatar Léo-Paul Géneau 👾

slapos/software: run quickjs as a service

parent b8965e75
......@@ -18,7 +18,7 @@ md5sum = ed0356dab0213a99fcd56e8a48e1c4d2
[instance-profile]
filename = instance.cfg.in
md5sum = c7f9de7830c1a6a57ae8683a1d329977
md5sum = 43e19ec3145928d79803528796eee8e0
[instance-default]
filename = instance-default.cfg.jinja
......@@ -26,7 +26,7 @@ md5sum = 0ed9aac3b3a61c41b8a7b61ab8067c77
[instance-peer]
filename = instance-peer.cfg.jinja.in
md5sum = 8615afba84028f1a61ca922cb1c0dcc5
md5sum = 7d063b33dbdd7548e2a23bc4d8a66a43
[main]
_update_hash_filename_ = drone-scripts/main.js.jinja
......
[buildout]
parts =
main
symlink-quickjs-binary
qjs-launcher
publish-connection-information
[directory]
......@@ -15,6 +14,7 @@ var = $${:home}/var
log = $${:var}/log
public = $${:srv}/public
run = $${:etc}/run
service = $${:etc}/service
[js-dynamic-template]
......@@ -44,14 +44,16 @@ template = ${pubsub:target}
template = ${worker:target}
<= js-dynamic-template
[symlink-quickjs-binary]
recipe = slapos.recipe.build
binary-path = ${quickjs:location}/bin/qjs
target = $${directory:bin}/qjs
init =
import os
if not os.path.exists(options['target']):
os.symlink(options['binary-path'], options['target'])
[user]
recipe = slapos.recipe.build:download
url = {{ parameter_dict['flightScript'] }}
destination = $${directory:etc}/user.js
offline = false
[qjs-launcher]
recipe = slapos.cookbook:wrapper
wrapper-path = $${directory:run}/qjs-launcher
command-line = ${quickjs:location}/bin/qjs $${main:rendered} $${user:target} &> $${directory:log}/qjs-launcher.log
[script-js]
recipe = slapos.recipe.template:jinja2
......
......@@ -50,12 +50,6 @@ recipe = slapos.cookbook:mkdirectory
home = $${buildout:directory}
etc = $${:home}/etc
[user]
recipe = slapos.recipe.build:download
url = $${slap-configuration:configuration.flightScript}
destination = $${directory:etc}/user.js
offline = false
[gwsocket-port]
recipe = slapos.cookbook:free_port
minimum = 6789
......@@ -79,7 +73,6 @@ inline =
[instance-peer]
<= dynamic-template-base
url = ${instance-peer:output}
depends = $${user:recipe}
extra-context =
key configuration peer-configuration:output
key ipv6 slap-configuration:ipv6-random
......
......@@ -30,13 +30,11 @@ import json
import os
import socket
import struct
import subprocess
import time
import websocket
from slapos.testing.testcase import makeModuleSetUpAndTestCaseClass
MAIN_SCRIPT_NAME = 'main.js'
'''
0. positionArray
0.1 latitude
......@@ -53,7 +51,6 @@ MONITORED_ITEM_NB = 3
OPC_UA_PORT = 4840
OPC_UA_NET_IF = 'lo'
MCAST_GRP = 'ff15::1111'
USER_SCRIPT_NAME = 'user.js'
# OPC UA Pub/Sub related constants
VERSION = 1
......@@ -114,8 +111,7 @@ setUpModule, SlapOSInstanceTestCase = makeModuleSetUpAndTestCaseClass(
os.path.join(os.path.dirname(__file__), '..', 'software.cfg')))
class JSDroneTestCase(SlapOSInstanceTestCase):
class SubscriberTestCase(SlapOSInstanceTestCase):
@classmethod
def getInstanceParameterDict(cls):
return {
......@@ -135,37 +131,11 @@ class JSDroneTestCase(SlapOSInstanceTestCase):
def setUp(self):
super().setUp()
subscriber_partition = self.get_partition('JSDroneTestCase-2')
instance_path = json.loads(
subscriber_partition.getConnectionParameterDict()['_'])['instance-path']
quickjs_bin = os.path.join(instance_path, 'bin', 'qjs')
script_dir = os.path.join(instance_path, 'etc')
self.qjs_process = subprocess.Popen(
[
quickjs_bin,
os.path.join(script_dir, MAIN_SCRIPT_NAME),
os.path.join(script_dir, USER_SCRIPT_NAME),
]
)
subscriber_partition = self.get_partition('SubscriberTestCase-2')
self.websocket_server_address = json.loads(
subscriber_partition.getConnectionParameterDict()['_'])['websocket-url']
time.sleep(0.5)
def tearDown(self):
ws = websocket.WebSocket()
ws.connect(self.websocket_server_address, timeout=5)
try:
ws.send("quit")
except websocket.WebSocketTimeoutException:
pass
finally:
ws.close()
time.sleep(0.1)
if self.qjs_process.returncode == None:
self.qjs_process.kill()
self.qjs_process.communicate()
super().tearDown()
def ua_networkMessage_encodeHeader(self):
ua_byte1 = int(VERSION)
ua_byte1 |= int(PUBLISHER_ID_ENABLED) << 4
......@@ -255,7 +225,10 @@ class JSDroneTestCase(SlapOSInstanceTestCase):
s.sendto(ua_message, ('::1', OPC_UA_PORT))
def test_process(self):
expected_process_name_list = ['http-server-on-watch']
expected_process_name_list = [
'qjs-launcher',
'http-server-on-watch',
]
with self.slap.instance_supervisor_rpc as supervisor:
process_names = [process['name']
for process in supervisor.getAllProcessInfo()]
......@@ -272,7 +245,7 @@ class JSDroneTestCase(SlapOSInstanceTestCase):
def test_subscriber_instance_parameter_dict(self):
self.assertEqual(
json.loads(self.get_partition('JSDroneTestCase-2').getInstanceParameterDict()['_']),
json.loads(self.get_partition('SubscriberTestCase-2').getInstanceParameterDict()['_']),
{
'autopilotIp': '192.168.27.1',
'autopilotPort': 7909,
......@@ -371,3 +344,4 @@ class JSDroneTestCase(SlapOSInstanceTestCase):
b'\\u001b[32minfo/client\\u001b[0m\\tReceived speed of drone 0: %.2f ? %.2f m/s %.2f m/s\\n"}' % SPEED_ARRAY_VALUES,
ws.recv_frame().data,
)
ws.close()
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