Commit f9b518cd authored by Federico Sismondi's avatar Federico Sismondi
Browse files

Merge branch 'lock_fix' into 'master'

Lock fix

See merge request !25
parents 68728043 4a7e5695
......@@ -27,7 +27,7 @@ Usage:
>>> from messages import * # doctest: +SKIP
>>> m = MsgTestCaseSkip()
>>> m
MsgTestCaseSkip(_api_version = 0.1.36, _type = testcoordination.testcase.skip, testcase_id = TD_COAP_CORE_02_v01, )
MsgTestCaseSkip(_api_version = 0.1.38, _type = testcoordination.testcase.skip, testcase_id = TD_COAP_CORE_02_v01, )
>>> m.routing_key
'control.testcoordination'
>>> m.message_id # doctest: +SKIP
......@@ -38,18 +38,18 @@ MsgTestCaseSkip(_api_version = 0.1.36, _type = testcoordination.testcase.skip, t
# also we can modify some of the fields (rewrite the default ones)
>>> m = MsgTestCaseSkip(testcase_id = 'TD_COAP_CORE_03_v01')
>>> m
MsgTestCaseSkip(_api_version = 0.1.36, _type = testcoordination.testcase.skip, testcase_id = TD_COAP_CORE_03_v01, )
MsgTestCaseSkip(_api_version = 0.1.38, _type = testcoordination.testcase.skip, testcase_id = TD_COAP_CORE_03_v01, )
>>> m.testcase_id
'TD_COAP_CORE_03_v01'
# and even export the message in json format (for example for sending the message though the amqp event bus)
>>> m.to_json()
'{"_api_version": "0.1.36", "_type": "testcoordination.testcase.skip", "testcase_id": "TD_COAP_CORE_03_v01"}'
'{"_api_version": "0.1.38", "_type": "testcoordination.testcase.skip", "testcase_id": "TD_COAP_CORE_03_v01"}'
# We can use the Message class to import json into Message objects:
>>> m=MsgTestSuiteStart()
>>> m.to_json()
'{"_api_version": "0.1.36", "_type": "testcoordination.testsuite.start"}'
'{"_api_version": "0.1.38", "_type": "testcoordination.testsuite.start"}'
>>> json_message = m.to_json()
>>> obj=Message.from_json(json_message)
>>> type(obj)
......@@ -62,7 +62,7 @@ MsgTestCaseSkip(_api_version = 0.1.36, _type = testcoordination.testcase.skip, t
# the error reply (note that we pass the message of the request to build the reply):
>>> err = MsgErrorReply(m)
>>> err
MsgErrorReply(_api_version = 0.1.36, _type = sniffing.start, error_code = Some error code TBD, error_message = Some
MsgErrorReply(_api_version = 0.1.38, _type = sniffing.start, error_code = Some error code TBD, error_message = Some
error message TBD, ok = False, )
>>> m.reply_to
'control.sniffing.service.reply'
......@@ -81,7 +81,7 @@ import time
import json
import uuid
API_VERSION = '0.1.36'
API_VERSION = '0.1.38'
# TODO use metaclasses instead?
......@@ -284,17 +284,37 @@ class MsgAgentTunStart(Message):
}
class MsgAgentSerialStarted(Message):
"""
Description: Message for indicating that agent serial interface has been started
Type: Event
Pub/Sub: Testing Tool -> Agent
Description: TBD
"""
routing_key = "control.serial.from.tbd"
_msg_data_template = {
"_type": "serial.started",
"name": "tbd",
"port": "tbd",
"boudrate": "tbd",
}
class MsgAgentTunStarted(Message):
"""
Description: Message for indicating that agent tun has been started
Type: Event
Pub/Sub: Testing Tool -> Agent
Pub/Sub: Agent -> Testing Tool
Description: TBD
"""
routing_key = "control.tun.from.agent_TT"
routing_key = "control.tun.from.tbd"
_msg_data_template = {
"_type": "tun.started",
......@@ -322,7 +342,6 @@ class MsgPacketInjectRaw(Message):
_msg_data_template = {
"_type": "packet.inject.raw",
"timestamp": "1488586183.45",
"interface_name": "tun0",
"data": [96, 0, 0, 0, 0, 36, 0, 1, 254, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 255, 2, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 22, 58, 0, 5, 2, 0, 0, 1, 0, 143, 0, 112, 7, 0, 0, 0, 1, 4, 0, 0, 0, 255, 2, 0, 0,
......@@ -343,7 +362,6 @@ class MsgPacketSniffedRaw(Message):
_msg_data_template = {
"_type": "packet.sniffed.raw",
"timestamp": "1488586183.45",
"interface_name": "tun0",
"data": [96, 0, 0, 0, 0, 36, 0, 1, 254, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 255, 2, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 22, 58, 0, 5, 2, 0, 0, 1, 0, 143, 0, 112, 7, 0, 0, 0, 1, 4, 0, 0, 0, 255, 2, 0, 0,
......@@ -407,6 +425,45 @@ class MsgTestingToolComponentReady(Message):
}
class MsgSessionChat(Message):
"""
Requirements: GUI should implement
Type: Event
Pub/Sub: UI 1 (2) -> UI 2 (1)
Description: Generic descriptor of chat messages
"""
routing_key = "log.warning.the_drummer"
_msg_data_template = {
"_type": "chat",
"user_name": "Ringo",
"iut_node": "tbd",
"description": "I've got blisters on my fingers!"
}
class MsgSessionLog(Message):
"""
Requirements: Testing Tool SHOULD implement
Type: Event
Pub/Sub: Any Testing tool's component -> user/devs interfaces
Description: Generic descriptor of log messages
"""
routing_key = "log.warning.the_drummer"
_msg_data_template = {
"_type": "log",
"component": "the_drummer",
"description": "I've got blisters on my fingers!"
}
# TODO delete "Interop" to generalize
class MsgInteropSessionConfiguration(Message):
......@@ -1792,9 +1849,12 @@ class MsgPerformanceStats(Message):
message_types_dict = {
"log": MsgSessionLog, # Any -> Any
"chat": MsgSessionChat, # GUI_x -> GUI_y
"agent.configured": MsgAgentConfigured, # TestingTool -> GUI
"tun.start": MsgAgentTunStart, # TestingTool -> Agent
"tun.started": MsgAgentTunStarted, # Agent -> TestingTool
"serial.started": MsgAgentSerialStarted, # Agent -> TestingTool
"packet.sniffed.raw": MsgPacketSniffedRaw, # Agent -> TestingTool
"packet.inject.raw": MsgPacketInjectRaw, # TestingTool -> Agent
"session.interop.configuration": MsgInteropSessionConfiguration, # Orchestrator -> TestingTool
......
......@@ -4,7 +4,7 @@ import json
import serial
import logging
import sys
from utils import messages
from kombu import Exchange
from collections import OrderedDict
from utils import arrow_down, arrow_up, finterop_banner
......@@ -43,15 +43,41 @@ class SerialListener(object):
self.frame_slip = ''
log.info("opening serial reader..")
self.ser = serial.Serial(port=self.dev,
baudrate=int(self.br),
timeout=0.001
)
self.ser.flushInput()
try:
self.ser = serial.Serial(port=self.dev,
baudrate=int(self.br),
timeout=0.001
)
except serial.serialutil.SerialException as e:
log.error(e)
log.error('Does dev %s exist?' % serial_port)
sys.exit(1)
try:
self.ser.open()
except Exception as e:
log.error(e)
try:
self.ser.flushInput()
except Exception as e:
log.error(e)
self.mrkey = "data.serial.fromAgent.%s" % self.agent_name
self.data_plane_mrkey = "data.serial.fromAgent.%s" % self.agent_name
self.control_plane_mrkey = "control.serial.fromAgent.%s" % self.agent_name
self.message_read_count = 0
# notify interface is opened
m = messages.MsgAgentSerialStarted(
name=self.agent_name,
port=self.dev,
boudrate=self.br
)
self.producer.publish(m.to_dict(),
exchange=self.exchange,
routing_key=self.control_plane_mrkey)
def close(self):
self._stop = True
......@@ -64,6 +90,8 @@ class SerialListener(object):
self.start_frame = 0
self.frame = ''
self.frame_slip = ''
else:
log.debug("Rubbish message dropped..")
def state_esc(self, data):
if data.encode('hex') != SLIP_ESC_END and data.encode('hex') != SLIP_ESC_ESC:
......@@ -120,21 +148,22 @@ class SerialListener(object):
return ia
def send_amqp(self, data, data_slip):
body = OrderedDict()
body['_type'] = 'packet.sniffed.raw'
body['interface_name'] = 'serial'
body['data'] = self.convert_bytearray_to_intarray(bytearray.fromhex(data))
body['data_slip'] = self.convert_bytearray_to_intarray(bytearray.fromhex(data_slip))
m = messages.MsgPacketSniffedRaw(
interface_name='serial',
data=self.convert_bytearray_to_intarray(bytearray.fromhex(data)),
data_slip=self.convert_bytearray_to_intarray(bytearray.fromhex(data_slip)),
)
self.frame_slip = ''
self.producer.publish(body,
self.producer.publish(m.to_dict(),
exchange=self.exchange,
routing_key=self.mrkey)
routing_key=self.data_plane_mrkey)
print(arrow_up)
log.info('\n # # # # # # # # # # # # SERIAL INTERFACE # # # # # # # # # # # # ' +
'\n data packet Serial -> EventBus' +
'\n' + json.dumps(body) +
'\n' + m.to_json() +
'\n # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # '
)
......
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