Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
f-interop-contributors
utils
Commits
f97f8c02
Commit
f97f8c02
authored
Oct 19, 2017
by
Federico Sismondi
Browse files
updated libs and CLI
parent
7f84bc34
Changes
3
Hide whitespace changes
Inline
Side-by-side
interop_cli.py
View file @
f97f8c02
...
...
@@ -54,7 +54,6 @@ MESSAGE_TYPES_NOT_ECHOED = [
TEMP_DIR
=
'tmp'
session_profile
=
OrderedDict
(
{
'user_name'
:
"Walter White"
,
...
...
@@ -345,22 +344,62 @@ def _handle_testcase_select():
def
_handle_get_testcase_list
():
# requires testing tool to implement GetTestCases feature see MsgTestSuiteGetTestCases
# requires testing tool to implement GetTestCases feature
,
see MsgTestSuiteGetTestCases
if
_connection_ok
():
temp_channel
=
state
[
'connection'
].
channel
()
request_message
=
MsgTestSuiteGetTestCases
()
testcases_list_reponse
=
amqp_request
(
temp_channel
,
request_message
,
COMPONENT_ID
)
try
:
testcases_list_reponse
=
amqp_request
(
temp_channel
,
request_message
,
COMPONENT_ID
)
except
Exception
as
e
:
_echo_error
(
'Is testing tool up?'
)
_echo_error
(
e
)
return
try
:
state
[
'tc_list'
]
=
testcases_list_reponse
.
tc_list
except
Exception
as
e
:
_echo_error
(
e
)
return
_echo_list_of_dicts_as_table
(
state
[
'tc_list'
])
else
:
_echo_error
(
'No connection established'
)
def
_handle_get_testsuite_status
():
# requires testing tool to implement GetStatus feature, see MsgTestSuiteGetStatus
if
_connection_ok
():
temp_channel
=
state
[
'connection'
].
channel
()
request_message
=
MsgTestSuiteGetStatus
()
try
:
status_resp
=
amqp_request
(
temp_channel
,
request_message
,
COMPONENT_ID
)
except
Exception
as
e
:
_echo_error
(
'Is testing tool up?'
)
_echo_error
(
e
)
return
resp
=
status_resp
.
to_dict
()
tc_states
=
resp
[
'tc_list'
]
del
resp
[
'tc_list'
]
# print general states
_echo_dict_as_table
(
resp
)
list
=
[]
list
.
append
((
'testcase id'
,
'testcase ref'
,
'testcase status'
))
for
tc
in
tc_states
:
if
tc
:
val1
,
val2
,
val3
,
_
,
_
,
_
=
tc
.
values
()
list
.
append
((
val1
,
val2
,
val3
))
# print tc states
_echo_list_as_table
(
list
,
first_row_is_header
=
True
)
else
:
_echo_error
(
'No connection established'
)
def
_handle_action_testsuite_start
():
if
click
.
confirm
(
'Do you want START test suite?'
):
msg
=
MsgTestSuiteStart
()
...
...
@@ -425,6 +464,7 @@ def _handle_action_verify():
message_handles_options
=
{
'ts_start'
:
_handle_action_testsuite_start
,
'ts_status'
:
_handle_get_testsuite_status
,
'ts_abort'
:
_handle_action_testsuite_abort
,
'tc_start'
:
_handle_action_testcase_start
,
'tc_restart'
:
_handle_action_testcase_restart
,
...
...
@@ -555,6 +595,7 @@ def _set_up_connection():
# conn for repl publisher
try
:
state
[
'connection'
]
=
pika
.
BlockingConnection
(
pika
.
URLParameters
(
session_profile
[
'amqp_url'
]))
state
[
'channel'
]
=
state
[
'connection'
].
channel
()
except
pika
.
exceptions
.
ProbableAccessDeniedError
:
...
...
@@ -660,9 +701,16 @@ def _exit():
def
_echo_welcome_message
():
m
=
"""
Welcome to F-Interop platform!
the Test assistant will help you go through the interoperability session (messages in cyan).
If you experience any problems, or have any suggestions or feedback don't hesitate to drop me an email at:
federico.sismondi@inria.fr
The Test assistant will help you go through the interoperability session (messages in cyan).
"""
_echo_session_helper
(
m
)
m
=
"""
*********************************************************************************
* If you experience any problems, or you have any suggestions or feedback *
* don't hesitate to drop me an email at: federico.sismondi@inria.fr *
*********************************************************************************
"""
_echo_session_helper
(
m
)
...
...
@@ -752,19 +800,32 @@ def _echo_testcase_partial_verdicts_as_table(pvs):
click
.
echo
(
click
.
style
(
tabulate
(
table
,
headers
=
"firstrow"
),
fg
=
COLOR_TEST_SESSION_HELPER_MESSAGE
))
def
_echo_list_of_dicts_as_table
(
l
):
try
:
assert
type
(
l
)
is
list
for
d
in
l
:
#for each dict obj in the list
_echo_dict_as_table
(
d
)
table
=
[]
first
=
True
for
d
in
l
:
# for each dict obj in the list
if
d
:
if
first
:
# adds table header , we assume all dicts have same keys
first
=
False
table
.
append
(
tuple
(
d
.
keys
()))
table
.
append
(
tuple
(
d
.
values
()))
_echo_list_as_table
(
table
,
first_row_is_header
=
True
)
except
Exception
as
e
:
_echo_error
(
'wrong frame format passed?'
)
if
l
:
_echo_error
(
l
)
_echo_error
(
e
)
_echo_error
(
traceback
.
format_exc
())
def
_echo_report_as_table
(
report_dict
):
try
:
...
...
@@ -774,21 +835,24 @@ def _echo_report_as_table(report_dict):
for
tc_name
,
tc_report
in
testcases
:
table
=
[]
table
.
append
((
"Testcase ID"
,
'Final verdict'
,
'Description'
))
table
.
append
((
tc_name
,
tc_report
[
'verdict'
],
tc_report
[
'description'
]))
# testcase report
click
.
echo
()
click
.
echo
(
click
.
style
(
tabulate
(
table
,
headers
=
"firstrow"
),
fg
=
COLOR_TEST_SESSION_HELPER_MESSAGE
))
click
.
echo
()
_echo_testcase_partial_verdicts_as_table
(
tc_report
[
'partial_verdicts'
])
click
.
echo
()
if
tc_report
:
table
.
append
((
"Testcase ID"
,
'Final verdict'
,
'Description'
))
table
.
append
((
tc_name
,
tc_report
[
'verdict'
],
tc_report
[
'description'
]))
# testcase report
click
.
echo
()
click
.
echo
(
click
.
style
(
tabulate
(
table
,
headers
=
"firstrow"
),
fg
=
COLOR_TEST_SESSION_HELPER_MESSAGE
))
click
.
echo
()
_echo_testcase_partial_verdicts_as_table
(
tc_report
[
'partial_verdicts'
])
click
.
echo
()
else
:
_echo_error
(
'No report for testcase %s '
%
tc_name
)
except
Exception
as
e
:
_echo_error
(
'wrong frame format passed?'
)
_echo_error
(
e
)
_echo_error
(
traceback
.
format_exc
())
_echo_error
(
json
.
dumps
(
report_dict
))
def
_echo_frames_as_table
(
frames
:
list
):
...
...
@@ -817,15 +881,25 @@ def _echo_frames_as_table(frames: list):
click
.
echo
()
# new line
except
Exception
as
e
:
_echo_error
(
'wrong frame format passed?'
)
_echo_error
(
e
)
_echo_error
(
traceback
.
format_exc
())
def
_echo_list_as_table
(
ls
:
list
):
click
.
echo
(
click
.
style
(
tabulate
(
ls
),
fg
=
COLOR_TEST_SESSION_HELPER_MESSAGE
))
def
_echo_list_as_table
(
ls
:
list
,
first_row_is_header
=
False
):
list_flat_items
=
[]
assert
type
(
ls
)
is
list
for
row
in
ls
:
assert
type
(
row
)
is
not
str
list_flat_items
.
append
(
tuple
(
list_to_str
(
item
)
for
item
in
row
))
if
first_row_is_header
:
click
.
echo
(
click
.
style
(
tabulate
(
list_flat_items
,
headers
=
"firstrow"
),
fg
=
COLOR_TEST_SESSION_HELPER_MESSAGE
))
else
:
click
.
echo
(
click
.
style
(
tabulate
(
list_flat_items
),
fg
=
COLOR_TEST_SESSION_HELPER_MESSAGE
))
click
.
echo
()
# new line
...
...
@@ -891,6 +965,9 @@ def list_to_str(ls):
ret
=
''
if
ls
is
None
:
return
'None'
if
type
(
ls
)
is
str
:
return
ls
...
...
@@ -915,7 +992,12 @@ if __name__ == "__main__":
pass
# use default
try
:
session_profile
.
update
({
'amqp_url'
:
str
(
os
.
environ
[
'AMQP_URL'
])})
url
=
'%s?%s&%s'
%
(
str
(
os
.
environ
[
'AMQP_URL'
]),
"heartbeat_interval=600"
,
"blocked_connection_timeout=300"
)
session_profile
.
update
({
'amqp_url'
:
url
})
except
KeyError
as
e
:
pass
# use default
...
...
messages.py
View file @
f97f8c02
...
...
@@ -27,7 +27,7 @@ Usage:
>>> from messages import * # doctest: +SKIP
>>> m = MsgTestCaseSkip(testcase_id = 'some_testcase_id')
>>> m
MsgTestCaseSkip(_api_version = 0.1.4
5
, _type = testcoordination.testcase.skip, description = Skip testcase, node = someNode, testcase_id = some_testcase_id, )
MsgTestCaseSkip(_api_version = 0.1.4
7
, _type = testcoordination.testcase.skip, description = Skip testcase, node = someNode, testcase_id = some_testcase_id, )
>>> m.routing_key
'control.testcoordination'
>>> m.message_id # doctest: +SKIP
...
...
@@ -38,18 +38,18 @@ MsgTestCaseSkip(_api_version = 0.1.45, _type = testcoordination.testcase.skip, d
# also we can modify some of the fields (rewrite the default ones)
>>> m = MsgTestCaseSkip(testcase_id = 'TD_COAP_CORE_03')
>>> m
MsgTestCaseSkip(_api_version = 0.1.4
5
, _type = testcoordination.testcase.skip, description = Skip testcase, node = someNode, testcase_id = TD_COAP_CORE_03, )
MsgTestCaseSkip(_api_version = 0.1.4
7
, _type = testcoordination.testcase.skip, description = Skip testcase, node = someNode, testcase_id = TD_COAP_CORE_03, )
>>> m.testcase_id
'TD_COAP_CORE_03'
# 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.4
5
", "_type": "testcoordination.testcase.skip", "description": "Skip testcase", "node": "someNode", "testcase_id": "TD_COAP_CORE_03"}'
'{"_api_version": "0.1.4
7
", "_type": "testcoordination.testcase.skip", "description": "Skip testcase", "node": "someNode", "testcase_id": "TD_COAP_CORE_03"}'
# We can use the Message class to import json into Message objects:
>>> m=MsgTestSuiteStart()
>>> m.to_json()
'{"_api_version": "0.1.4
5
", "_type": "testcoordination.testsuite.start", "description": "Event test suite START"}'
'{"_api_version": "0.1.4
7
", "_type": "testcoordination.testsuite.start", "description": "Event test suite START"}'
>>> json_message = m.to_json()
>>> obj=Message.from_json(json_message)
>>> type(obj)
...
...
@@ -62,7 +62,7 @@ MsgTestCaseSkip(_api_version = 0.1.45, _type = testcoordination.testcase.skip, d
# 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.4
5
, _type = sniffing.start, error_code = Some error code TBD, error_message = Some error message TBD, ok = False, )
MsgErrorReply(_api_version = 0.1.4
7
, _type = sniffing.start, error_code = Some error code TBD, error_message = Some error message TBD, ok = False, )
>>> m.reply_to
'control.sniffing.service.reply'
>>> err.routing_key
...
...
@@ -80,7 +80,7 @@ import time
import
json
import
uuid
API_VERSION
=
'0.1.4
5
'
API_VERSION
=
'0.1.4
7
'
# TODO use metaclasses instead?
...
...
@@ -622,6 +622,23 @@ class MsgTestSuiteStart(Message):
"description"
:
"Event test suite START"
}
class
MsgTestSuiteStarted
(
Message
):
"""
Requirements: Testing Tool SHOULD publish to event
Type: Event
Pub/Sub: Testing Tool -> GUI
Description: tbd
"""
routing_key
=
"control.testcoordination"
_msg_data_template
=
{
"_type"
:
"testcoordination.testsuite.started"
,
"description"
:
"Event test suite STARTED"
}
class
MsgTestSuiteFinish
(
Message
):
"""
...
...
@@ -1131,6 +1148,24 @@ class MsgTestSuiteAbort(Message):
}
class
MsgTestCaseAbort
(
Message
):
"""
Requirements: Testing Tool SHOULD listen to event
Type: Event
Pub/Sub: GUI (or automated-IUT)-> Testing Tool
Description: Event for current test case ABORT
"""
routing_key
=
"control.testcoordination"
_msg_data_template
=
{
"_type"
:
"testcoordination.testcase.abort"
,
"description"
:
"Event ABORT current testcase"
}
class
MsgTestSuiteGetStatus
(
Message
):
"""
Requirements: Testing Tool SHOULD implement (other components should not subscribe to event)
...
...
@@ -1946,9 +1981,10 @@ message_types_dict = {
"testingtool.configured"
:
MsgTestingToolConfigured
,
# TestingTool -> Orchestrator, GUI
"testingtool.component.ready"
:
MsgTestingToolComponentReady
,
# Testing Tool internal
"testingtool.component.shutdown"
:
MsgTestingToolComponentShutdown
,
# Testing Tool internal
"testingtool.ready"
:
MsgTestingToolReady
,
#
GUI
Testing Tool -> GUI
"testingtool.ready"
:
MsgTestingToolReady
,
# Testing Tool -> GUI
"testingtool.terminate"
:
MsgTestingToolTerminate
,
# orchestrator -> TestingTool
"testcoordination.testsuite.start"
:
MsgTestSuiteStart
,
# GUI -> TestingTool
"testcoordination.testsuite.started"
:
MsgTestSuiteStarted
,
# Testing Tool -> GUI
"testcoordination.testsuite.finish"
:
MsgTestSuiteFinish
,
# GUI -> TestingTool
"testcoordination.testcase.ready"
:
MsgTestCaseReady
,
# TestingTool -> GUI
"testcoordination.testcase.start"
:
MsgTestCaseStart
,
# GUI -> TestingTool
...
...
@@ -1966,6 +2002,7 @@ message_types_dict = {
"testcoordination.testcase.restart"
:
MsgTestCaseRestart
,
# GUI -> TestingTool
"testcoordination.testcase.skip"
:
MsgTestCaseSkip
,
# GUI -> TestingTool
"testcoordination.testcase.select"
:
MsgTestCaseSelect
,
# GUI -> TestingTool
"testcoordination.testcase.abort"
:
MsgTestCaseAbort
,
# GUI -> TestingTool
# "testcoordination.testcase.finish": MsgTestCaseFinish, # GUI -> TestingTool
"testcoordination.testcase.finished"
:
MsgTestCaseFinished
,
# TestingTool -> GUI
"testcoordination.testcase.verdict"
:
MsgTestCaseVerdict
,
# TestingTool -> GUI
...
...
rmq_handler.py
View file @
f97f8c02
...
...
@@ -39,7 +39,7 @@ try:
except
ImportError
:
pass
VERSION
=
'0.0.
6
'
VERSION
=
'0.0.
7
'
# defaults vars
AMQP_URL
=
'amqp://guest:guest@localhost'
...
...
@@ -172,7 +172,7 @@ class JsonFormatter(logging.Formatter):
try
:
log_record
=
OrderedDict
()
log_record
[
'_type'
]
=
'log'
log_record
[
'component'
]
=
record
.
modul
e
log_record
[
'component'
]
=
record
.
nam
e
except
NameError
:
log_record
=
{}
...
...
@@ -216,7 +216,7 @@ class RabbitMQHandler(logging.Handler):
except
pika
.
exceptions
.
ConnectionClosed
:
print
(
"Log han
l
der connection closed. Reconnecting.."
)
print
(
"Log hand
l
er connection closed. Reconnecting.."
)
self
.
connection
=
pika
.
BlockingConnection
(
pika
.
URLParameters
(
self
.
url
))
self
.
channel
=
self
.
connection
.
channel
()
...
...
@@ -234,17 +234,19 @@ class RabbitMQHandler(logging.Handler):
finally
:
self
.
release
()
def
close
(
self
):
self
.
acquire
()
try
:
if
self
.
channel
:
self
.
channel
.
close
()
self
.
channel
.
close
()
except
AttributeError
:
pass
if
self
.
connection
:
self
.
connection
.
close
()
try
:
self
.
connection
.
close
()
except
AttributeError
:
pass
finally
:
self
.
release
()
...
...
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