Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Turris
Foris Controller
foris-controller-testtools
Commits
ebb3033b
Verified
Commit
ebb3033b
authored
Jan 17, 2019
by
Štěpán Henek
🐻
Browse files
add controller_id into messages
parent
5612c4df
Changes
1
Hide whitespace changes
Inline
Side-by-side
foris_controller_testtools/infrastructure.py
View file @
ebb3033b
...
...
@@ -49,6 +49,7 @@ NOTIFICATIONS_OUTPUT_PATH = "/tmp/foris-controller-notifications-test.json"
MQTT_HOST
=
"localhost"
MQTT_PORT
=
11883
MQTT_ID
=
os
.
environ
.
get
(
"TEST_CLIENT_ID"
,
"%012x"
%
uuid
.
getnode
())
CONTROLLER_ID
=
"%012x"
%
uuid
.
getnode
()
notifications_lock
=
Lock
()
...
...
@@ -242,6 +243,9 @@ class Infrastructure(object):
self
.
connected
=
True
def
process_message
(
self
,
data
):
if
'controller_id'
not
in
data
:
data
[
'controller_id'
]
=
CONTROLLER_ID
if
self
.
name
==
"unix-socket"
:
while
not
os
.
path
.
exists
(
self
.
sock_path
):
time
.
sleep
(
1
)
...
...
@@ -258,7 +262,9 @@ class Infrastructure(object):
received
+=
sock
.
recv
(
length
)
recv_len
=
len
(
received
)
return
json
.
loads
(
received
.
decode
(
"utf8"
))
res
=
json
.
loads
(
received
.
decode
(
"utf8"
))
del
res
[
"controller_id"
]
return
res
elif
self
.
name
==
"ubus"
:
import
ubus
...
...
@@ -275,39 +281,42 @@ class Infrastructure(object):
ubus
.
call
(
module
,
function
,
{
"payload"
:
{
"multipart_data"
:
data_part
},
"final"
:
False
,
"multipart"
:
True
,
"request_id"
:
request_id
,
'controller_id'
:
data
[
"controller_id"
],
})
res
=
ubus
.
call
(
module
,
function
,
{
"payload"
:
{
"multipart_data"
:
""
},
"final"
:
True
,
"multipart"
:
True
,
"request_id"
:
request_id
,
'controller_id'
:
data
[
"controller_id"
],
})
else
:
res
=
ubus
.
call
(
module
,
function
,
{
"payload"
:
{
"data"
:
inner_data
}
if
inner_data
is
not
None
else
{},
"final"
:
True
,
"multipart"
:
False
,
"request_id"
:
request_id
,
'controller_id'
:
data
[
"controller_id"
],
})
ubus
.
disconnect
()
resp
=
json
.
loads
(
""
.
join
([
e
[
"data"
]
for
e
in
res
]))
if
"errors"
in
resp
:
return
{
u
"module"
:
data
[
"module"
],
u
"action"
:
data
[
"action"
],
u
"kind"
:
u
"reply"
,
u
"errors"
:
resp
[
"errors"
]
,
"module"
:
data
[
"module"
],
"action"
:
data
[
"action"
],
"kind"
:
u
"reply"
,
"errors"
:
resp
[
"errors"
]
}
if
"data"
in
resp
:
return
{
u
"module"
:
data
[
"module"
],
u
"action"
:
data
[
"action"
],
u
"kind"
:
u
"reply"
,
u
"data"
:
resp
[
"data"
]
,
"module"
:
data
[
"module"
],
"action"
:
data
[
"action"
],
"kind"
:
u
"reply"
,
"data"
:
resp
[
"data"
]
}
return
{
u
"module"
:
data
[
"module"
],
u
"action"
:
data
[
"action"
],
u
"kind"
:
u
"reply"
,
"module"
:
data
[
"module"
],
"action"
:
data
[
"action"
],
"kind"
:
u
"reply"
,
}
elif
self
.
name
==
"mqtt"
:
...
...
@@ -345,6 +354,8 @@ class Infrastructure(object):
client
.
connect
(
MQTT_HOST
,
MQTT_PORT
,
30
)
client
.
loop_start
()
client
.
_thread
.
join
(
30
)
del
output
[
"controller_id"
]
return
output
else
:
...
...
@@ -352,6 +363,10 @@ class Infrastructure(object):
def
process_message_ubus_raw
(
self
,
data
,
request_id
,
final
,
multipart
,
multipart_data
):
import
ubus
if
'controller_id'
not
in
data
:
data
[
'controller_id'
]
=
CONTROLLER_ID
if
not
ubus
.
get_connected
():
ubus
.
connect
(
self
.
sock_path
)
module
=
"foris-controller-%s"
%
data
.
get
(
"module"
,
"?"
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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