aboutsummaryrefslogtreecommitdiffstats
path: root/test/csit/scripts/multicloud-ocata/generic_sim/log_parser.py
diff options
context:
space:
mode:
authorShashank Kumar Shankar <shashank.kumar.shankar@intel.com>2018-04-20 11:22:55 -0700
committerVictor Morales <victor.morales@intel.com>2018-05-10 12:27:13 -0700
commitf8aab84d0665344ac865baa24ee3e10335d63b5e (patch)
treec7f3d681d59463c05ded36276ef8b59e36354eb7 /test/csit/scripts/multicloud-ocata/generic_sim/log_parser.py
parent006629d1a712bf256c2d50cb8ea8d1fb94612977 (diff)
CSIT for Multicloud-Ocata HPA
Adds CSIT tests for multicloud ocata HPA. Change-Id: I89c51f8bd9056fd8c2afd871ab9ab8b0cc567bb9 Issue-ID: MULTICLOUD-214 Depends-On: Idc7b0b709caf79e03c2f66774ef780223b913946 Signed-off-by: Shashank Kumar Shankar <shashank.kumar.shankar@intel.com> Signed-off-by: Victor Morales <victor.morales@intel.com>
Diffstat (limited to 'test/csit/scripts/multicloud-ocata/generic_sim/log_parser.py')
-rw-r--r--test/csit/scripts/multicloud-ocata/generic_sim/log_parser.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/test/csit/scripts/multicloud-ocata/generic_sim/log_parser.py b/test/csit/scripts/multicloud-ocata/generic_sim/log_parser.py
new file mode 100644
index 000000000..1334e608c
--- /dev/null
+++ b/test/csit/scripts/multicloud-ocata/generic_sim/log_parser.py
@@ -0,0 +1,61 @@
+import argparse
+
+import yaml
+
+
+def _find_aai_response_content(inp):
+ return inp.split("||||")[1].split("with response content = ")[1]
+
+def _find_openstack_url(inp):
+ return inp.split("||||")[1].split("making request with URI:")[1]
+
+def _find_openstack_response_content(inp):
+ return inp.split("||||")[1].split("with content:")[1].replace("u'", "'")
+
+def _add_response(all_responses, url, http_verb, body, status_code=200, content_type="application/json"):
+ if url not in all_responses.keys():
+ all_responses[url] = {
+ http_verb: {
+ "status_code": status_code,
+ "content_type": content_type,
+ "body": body
+ }
+ }
+ elif http_verb not in all_responses[url].keys():
+ all_responses[url][http_verb] = {
+ "status_code": status_code,
+ "content_type": content_type,
+ "body": body
+ }
+
+def parse_lines(content, aai_ip):
+ aai_pattern = "https://%s:30233/" % aai_ip
+ openstack_pattern = "making request with URI:"
+
+ openstack_responses = {}
+ aai_responses = {}
+ for i, line in enumerate(content):
+ current_line = line.strip()
+ if aai_pattern in current_line and "DEBUG" not in current_line:
+ url = current_line.split(" ")[8][:-1].replace(aai_pattern, "")
+ _add_response(aai_responses, url, current_line.split(" ")[9][:-1],
+ _find_aai_response_content(content[i + 3]))
+ elif openstack_pattern in current_line:
+ _add_response(openstack_responses,
+ _find_openstack_url(current_line), "get",
+ _find_openstack_response_content(content[i + 2]))
+
+ return [
+ { "file": "nova.yml", "responses": openstack_responses },
+ { "file": "aai.yml", "responses": aai_responses }
+ ]
+
+if __name__ == "__main__":
+ parser = argparse.ArgumentParser(description='Convert logs to responses YAML tree file.')
+ parser.add_argument('--log-file', type=argparse.FileType('r'), help="Log file to be parsed", required=True)
+ parser.add_argument('--aai-ip', help="A&AI IP Address", required=True)
+ args = parser.parse_args()
+
+ for mock_responses in parse_lines(args.log_file.readlines(), args.aai_ip):
+ with open(mock_responses["file"], 'w') as yaml_file:
+ yaml.dump(mock_responses["responses"], yaml_file, default_flow_style=False)