Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
slapos
Commits
3766503c
Commit
3766503c
authored
Jun 04, 2023
by
Léo-Paul Géneau
👾
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos/software: run quickjs as a service
parent
b8965e75
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
53 deletions
+22
-53
software/js-drone/buildout.hash.cfg
software/js-drone/buildout.hash.cfg
+2
-2
software/js-drone/instance-peer.cfg.jinja.in
software/js-drone/instance-peer.cfg.jinja.in
+12
-10
software/js-drone/instance.cfg.in
software/js-drone/instance.cfg.in
+0
-7
software/js-drone/test/test.py
software/js-drone/test/test.py
+8
-34
No files found.
software/js-drone/buildout.hash.cfg
View file @
3766503c
...
...
@@ -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
...
...
software/js-drone/instance-peer.cfg.jinja.in
View file @
3766503c
[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
...
...
software/js-drone/instance.cfg.in
View file @
3766503c
...
...
@@ -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
...
...
software/js-drone/test/test.py
View file @
3766503c
...
...
@@ -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
(
'
JSDrone
TestCase-2'
).
getInstanceParameterDict
()[
'_'
]),
json
.
loads
(
self
.
get_partition
(
'
Subscriber
TestCase-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
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment