summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkshithijiyer <kshithij.ki@gmail.com>2020-07-10 18:21:36 +0530
committerBala Konda Reddy M <bala12352@gmail.com>2020-07-15 10:04:10 +0000
commit2b2bd0ab3fe94bd835a997f8b2bdabe1c66c42b9 (patch)
treec478b232882049c1ba7162f2296c0a134249ea90
parenta9532ef6f4ddeeeae27d12eb3d5fd122dad2b4d7 (diff)
[Tool] Add tool to split log to tc wise logs
Adding tool to split glusto-tests logs into tc wise logs. usage: log_splitter [-h] -f LOG_FILE [-d DESTINATION_DIR] Tool to split glusto logs to individual testcase logs. optional arguments: -h, --help show this help message and exit -f LOG_FILE, --log_file LOG_FILE Glusto test log file -d DESTINATION_DIR, --dist-dir DESTINATION_DIR Path were individual test logs are to be stored. Change-Id: I776a1455f9f70c13ae6ad9d11f23a4b5366c5f6f Signed-off-by: kshithijiyer <kshithij.ki@gmail.com>
-rw-r--r--tools/log_splitter/README.md37
-rw-r--r--tools/log_splitter/log_splitter.py100
-rw-r--r--tools/log_splitter/setup.py33
3 files changed, 170 insertions, 0 deletions
diff --git a/tools/log_splitter/README.md b/tools/log_splitter/README.md
new file mode 100644
index 0000000..e44aaec
--- /dev/null
+++ b/tools/log_splitter/README.md
@@ -0,0 +1,37 @@
+# log_splitter
+Tool to split glusto logs to individual testcase logs.
+
+## Prerequisites
+Python 3.x
+
+## Installation
+1. Change directory to the project directory.
+
+```
+# cd tools/log_splitter
+```
+
+2. Now run the installation script.
+
+```
+# python3 setup.py install
+```
+
+3. To check run:
+
+```
+# log_splitter --help
+```
+
+## Usage
+Just pass glusto_test.log file to the script as shown below:
+
+```
+# log_splitter -f glusto_test.log
+```
+
+**Note**:
+The default destination directory is `.` (present dir) `-d` or `--dist-dir` option.
+
+## Licence
+[GPLv3](https://github.com/gluster/glusto-tests/blob/master/LICENSE)
diff --git a/tools/log_splitter/log_splitter.py b/tools/log_splitter/log_splitter.py
new file mode 100644
index 0000000..e433b3e
--- /dev/null
+++ b/tools/log_splitter/log_splitter.py
@@ -0,0 +1,100 @@
+# Copyright (C) 2020 Red Hat, Inc. <http://www.redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY :or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+# Imports needed by the script.
+import argparse
+import os
+import sys
+
+
+def check_and_create_dir_if_not_present(directory):
+ """
+ A function to check and create directory if not present
+
+ Args:
+ directory(str): Directory to be created if not present
+
+ Retuns:
+ bool: True if successful else False
+ """
+ if not os.path.isdir(directory):
+ cmd = "mkdir -p {}".format(directory)
+ ret = os.system(cmd)
+ if ret:
+ return False
+ print("[INFO]: Dir created successfully")
+ else:
+ print("[INFO]: The dir already exists")
+ return True
+
+
+def main():
+ """
+ Main function of the tool.
+ """
+ # Setting up command line arguments.
+ parser = argparse.ArgumentParser(
+ description="Tool to split glusto logs to individual testcase logs."
+ )
+ parser.add_argument(
+ '-f', '--log_file', type=str, dest='log_file', required=True,
+ help="Glusto test log file")
+ parser.add_argument(
+ '-d', '--dist-dir', type=str, default=".", dest="destination_dir",
+ help="Path were individual test logs are to be stored.")
+ args = parser.parse_args()
+
+ # Fetching the values from command line.
+ log_file = args.log_file
+ destination_dir = args.destination_dir
+
+ # Check and create dir if not present
+ if not check_and_create_dir_if_not_present(destination_dir):
+ sys.exit("[ERROR]: Unable to create dir")
+
+ with open(log_file, 'r', encoding="ISO-8859-1") as log_file_fd:
+
+ # Read lines and set flag to check if
+ # file is open
+ file_open_flag = False
+ while True:
+ line = log_file_fd.readline()
+ if not line:
+ break
+
+ # Check if line is starting line.
+ if '(setUp) Starting Test : ' in line:
+ if file_open_flag:
+ file_open_flag = False
+
+ # Open new fd for individual test
+ # file
+ filename = line.split(' ')[7]
+ if destination_dir != '.':
+ filename = os.path.join(destination_dir,
+ filename)
+ file_open_flag = True
+
+ # Write lines to individual test file
+ if file_open_flag:
+ with open(filename, 'w') as test_file:
+ test_file.write(line)
+
+ print("[INFO]: Log file split completed")
+
+
+if __name__ == "__main__":
+ main()
diff --git a/tools/log_splitter/setup.py b/tools/log_splitter/setup.py
new file mode 100644
index 0000000..2d922f3
--- /dev/null
+++ b/tools/log_splitter/setup.py
@@ -0,0 +1,33 @@
+# Copyright (C) 2020 Red Hat, Inc. <http://www.redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY :or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+from setuptools import setup
+
+setup(
+ name='log_splitter',
+ version="1.0",
+ author='Red Hat, Inc.',
+ author_email='gluster-devel@gluster.org',
+ url='http://www.gluster.org',
+ licens="GPLv3+",
+ description=("Tool to split glusto logs to "
+ "individual testcase logs."),
+ py_modules=['log_splitter'],
+ entry_points="""
+ [console_scripts]
+ log_splitter = log_splitter:main
+ """
+)