Initial commit for log helper tool
Some changes are made according to comments

Related-prod: PRODX-19555

Change-Id: I35df871919a464b8782d70a498e48b21fffcb0b3
diff --git a/log_helper/README.md b/log_helper/README.md
new file mode 100644
index 0000000..8957b7f
--- /dev/null
+++ b/log_helper/README.md
@@ -0,0 +1,30 @@
+CLI helper tool
+======================
+
+This CLI helper tool gathers all log lines related to resource | req-id from particular folder with logs.
+All related resources and their IDs used in Tempest tests are stored in machine-readable YAML file with the following format:
+
+<test identifier>:
+  status: PASSED|FAILED
+  resources:
+    <openstack-service name (nova|neutron|glance|keystone)>:
+       <resource-name (port|server|security-group|router)>:
+       <request-id (req-xxxx) >:
+         name: <resource name (test-port-mytest|test-vm-)>
+         id/uuid: <resource id>
+         request: <exact request>
+        http:
+           error: <if exists>
+           status_code: <>
+
+How to use
+----------
+
+- Extract/save all openstack pod logs to folder (ex. pod-logs)
+
+- Generate tempest report using report_parcer tool
+
+- Run log_helper tool with folder name and tempest report YAML file as input parameters:
+
+``python3 log_helper.py <folder-with-logs> <tempest-report-yaml>``
+
diff --git a/log_helper/__init__.py b/log_helper/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/log_helper/__init__.py
diff --git a/log_helper/log_helper.py b/log_helper/log_helper.py
new file mode 100644
index 0000000..076de3f
--- /dev/null
+++ b/log_helper/log_helper.py
@@ -0,0 +1,39 @@
+import subprocess
+import sys
+import os
+import yaml
+
+
+def log_gather(resource_id, sub_resource):
+    """ Get all log lines related to req-id
+       :param resource_id: ID of Request
+       :param: name of sub_resource log file, e.g subnet.log for neutron resource
+       """
+    try:
+        directory = os.walk(sys.argv[1])
+    except IndexError:
+        print('Argument <folder-with-logs> is not provided')
+        raise ValueError('Argument <folder-with-logs> is not provided')
+
+    for dirs in directory:
+        run_cmd = f"grep {resource_id} {dirs[0]}/* >> {sub_resource}"
+        subprocess.run(run_cmd, shell=True)
+
+
+with open(sys.argv[2]) as f:
+    test_resources = yaml.safe_load(f)
+
+for test in test_resources.items():
+    # Find all the failed tempest test from YAML file and gather logs for
+    # related resources in corresponded folders
+    if test[1]['status'] == 'failure':
+        print('Collecting logs for ' + test[0])
+        os.makedirs(test[0], exist_ok=True)
+        for resource in test[1]['resources']:
+            os.makedirs(os.path.join(test[0], resource), exist_ok=True)
+            for sub_resource in test[1]['resources'][resource]:
+                log_gather(list(test[1]['resources'][resource][sub_resource])[0],
+                           os.path.join(test[0], resource, sub_resource + '.' + 'log'))
+
+print('The logger is finished')
+