Commit 43cf3899 authored by Federico Sismondi's avatar Federico Sismondi

fix error in perf message, added agent.configured, fixed doc

parent bc674a0e
This diff is collapsed.
"""
Module for building automatically the doc of the API messages in markdown format.
"""
import inspect
from messages import *
import inspect
gitlab_url = 'https://gitlab.f-interop.eu/f-interop-contributors/utils/blob/master/messages.py'
doc_parser = 'https://gitlab.f-interop.eu/f-interop-contributors/utils/blob/master/messages_doc.py'
header = """Messages format
This section describes the format of the messages used by the testing tool.
This section of the documentation is autogenerated by
[tool](https://gitlab.f-interop.eu/f-interop-contributors/utils/blob/master/messages_doc.py)
[tool](%s)
Check out the messages library
[tool](%s)
Version %s
""" %API_VERSION
""" % (doc_parser, gitlab_url, API_VERSION)
services = []
events = []
def message_amqp_section(file, message_instance):
file.write("\n\n```amqp")
file.write("\n %s" % message_instance)
file.write("\n ```")
return
def message_json_section(file, message_instance):
file.write("\n\n```json")
file.write("\n %s" % json.dumps(message_instance.to_dict(),indent=4,))
file.write("\n %s" % json.dumps(message_instance.to_dict(), indent=4, ))
file.write("\n ```")
return
def print_doc_tables(services, events):
"""
......@@ -42,8 +49,10 @@ def print_doc_tables(services, events):
|SERVICES | DESCRIPTION|
|---| ---|
|[*testcoordination.testsuite.getstatus*](#testcoordination-testsuite-getstatus) | Message for debugging purposes. The coordination component returns the status of the execution |
|[*testcoordination.testsuite.gettestcases*](#testcoordination-testsuite-gettestcases) | Message for requesting the list of test cases included in the test suite.|
|[*testcoordination.testsuite.getstatus*](#testcoordination-testsuite-getstatus) | Message for debugging
purposes. The coordination component returns the status of the execution |
|[*testcoordination.testsuite.gettestcases*](#testcoordination-testsuite-gettestcases) | Message for requesting
the list of test cases included in the test suite.|
### API events
......@@ -51,16 +60,20 @@ def print_doc_tables(services, events):
|MESSAGES CONSUMED | DESCRIPTION|
|---| ---|
|[*testcoordination.testsuite.start*](#testcoordination-testsuite-start) | Message for triggering start of test suite. The command is given by one of the users of the session.|
|[*testcoordination.testsuite.abort*](#testcoordination-testsuite-abort)| Message for aborting the ongoing test session.|
|[*testcoordination.testcase.skip*](#testcoordination-testcase-skip) | Message for skipping a test case. Coordinator passes to the next test case if there is any left.|
|[*testcoordination.testsuite.start*](#testcoordination-testsuite-start) | Message for triggering start of test
suite. The command is given by one of the users of the session.|
|[*testcoordination.testsuite.abort*](#testcoordination-testsuite-abort)| Message for aborting the ongoing test
session.|
|[*testcoordination.testcase.skip*](#testcoordination-testcase-skip) | Message for skipping a test case.
Coordinator passes to the next test case if there is any left.|
Coordinator generates and publishes the following messages:
|MESSAGES PUBLISHED | DESCRIPTION|
|---| ---|
|[*testcoordination.testcase.next*](#testcoordination-testcase-next) | Indicates next testcase to be executed |
|[*testcoordination.testsuite.finished*](#testcoordination-testsuite-finished) | Indicates there's no more test cases to execute |
|[*testcoordination.testsuite.finished*](#testcoordination-testsuite-finished) | Indicates there's no more test
cases to execute |
|[*testcoordination.error*](#testcoordination-error) | Message used to indicate errors on coordiation component |
......@@ -86,12 +99,12 @@ TBD listens and consumes the following messages from the bus:
|---| ---|"""
def table_row(event_type):
s=""
s+="|[*%s*](#%s) | Some description that needs to be writen manually |"\
%(
event_type,
event_type.replace('.','-')
)
s = ""
s += "|[*%s*](#%s) | Some description that needs to be writen manually |" \
% (
event_type,
event_type.replace('.', '-')
)
return s
print(head_1)
......@@ -111,7 +124,6 @@ TBD listens and consumes the following messages from the bus:
print(table_row(e._type))
if __name__ == '__main__':
with open('_messages.md', "w+") as f:
......@@ -122,27 +134,68 @@ if __name__ == '__main__':
for msg_type, msg_class in sorted(message_types_dict.items()):
# Message Type
f.write('\n\n\n## %s' %(msg_type))
f.write('\n\n\n## %s' % (msg_type))
# Message docstring
f.write('\n\n### Description:\n%s' % (msg_class.__doc__))
# Header
f.write('\n\n### Description:\n\n')
# Message code source:
line_number = (inspect.findsource(msg_class)[1])
url = gitlab_url + "#L%s" %line_number
f.write('\n\n### Source code: \n[%s](%s)\n' %(msg_class.__name__,url))
# markdown table header
f.write("\n| []() | |\n| --- | --- |\n")
md_bullet_list = ''
unknown = ''
# Message class docstring to table
for line in msg_class.__doc__.splitlines():
if line and not line.isspace():
# Message's fields table
# TODO do we need this?
if "description:" in str(line).lower():
sp_line = line.split(':')
if len(sp_line) > 1:
f.write("|Description:|{0}|\n".format(sp_line[1].strip()))
elif len(sp_line) == 1:
f.write("|Description:||\n")
else:
raise NotImplementedError()
elif '- ' in line:
md_bullet_list += "||{0}|\n".format(line.strip())
elif "Type:" in line:
sp_line = line.split(':')
f.write('|{0}|{1}|\n'.format(sp_line[0].strip(), sp_line[1].strip()))
elif "Requirements:" in line:
sp_line = line.split(':')
f.write('|{0}|{1}|\n'.format(sp_line[0].strip(), sp_line[1].strip()))
elif "Pub/Sub:" in line:
sp_line = line.split(':')
f.write('|{0}|{1}|\n'.format(sp_line[0].strip(), sp_line[1].strip()))
else:
if md_bullet_list is not '':
md_bullet_list += '||{0}|\n'.format(line)
else:
unknown += '||{0}|\n'.format(line)
f.write(md_bullet_list)
f.write(unknown)
# Message code source:
line_number = (inspect.findsource(msg_class)[1])
url = gitlab_url + "#L%s" % line_number
f.write('\n\n### Source code: \n[%s](%s)\n' % (msg_class.__name__, url))
msg_instance = None
# Messages's example AMQP + JSON
if 'reply' not in msg_class.__name__.lower(): # Message is not a reply
if 'reply' not in msg_class.__name__.lower(): # Message is not a reply
msg_instance = msg_class()
else: # Message is a reply -> we need to generate it using a request
else: # Message is a reply -> we need to generate it using a request
reply_class_name = msg_class.__name__
request_class_name = ''
......@@ -151,13 +204,13 @@ if __name__ == '__main__':
elif 'Reply' in msg_class.__name__:
request_class_name = reply_class_name.replace("Reply", '')
else:
raise Exception('cannot process message event: %s' %msg_type)
raise Exception('cannot process message event: %s' % msg_type)
request_instance = globals()[request_class_name]()
msg_instance = msg_class(request_message = request_instance)
msg_instance = msg_class(request_message=request_instance)
# add the amqo + json section
message_amqp_section(f,msg_instance)
message_amqp_section(f, msg_instance)
message_json_section(f, msg_instance)
if 'service' in msg_instance.routing_key:
......@@ -166,4 +219,3 @@ if __name__ == '__main__':
events.append(msg_instance)
print_doc_tables(services, events)
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