diff options
| author | Mark Stapp <mjs@voltanet.io> | 2021-02-04 11:13:01 -0500 |
|---|---|---|
| committer | Mark Stapp <mjs@voltanet.io> | 2021-02-15 08:13:06 -0500 |
| commit | 70b99f2fffe5751655e5e410fbe77c5d546c6e2b (patch) | |
| tree | d2788688785518d30bb6548303c05e33105de9df /tools/generate_support_bundle.py | |
| parent | d887c7bf04f08b37ec122587f11cd2079cb22bd7 (diff) | |
tests: make generate support bundle python3 only
Make the generate-support-bundle script and interactions more
python3-friendly, and use python3 explicitly.
Signed-off-by: Mark Stapp <mjs@voltanet.io>
Diffstat (limited to 'tools/generate_support_bundle.py')
| -rwxr-xr-x | tools/generate_support_bundle.py | 46 |
1 files changed, 22 insertions, 24 deletions
diff --git a/tools/generate_support_bundle.py b/tools/generate_support_bundle.py index ae258bddfe..38fdbd46df 100755 --- a/tools/generate_support_bundle.py +++ b/tools/generate_support_bundle.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 ######################################################## ### Python Script to generate the FRR support bundle ### @@ -7,7 +7,6 @@ import os import subprocess import datetime -TOOLS_DIR = "tools/" ETC_DIR = "/etc/frr/" LOG_DIR = "/var/log/frr/" SUCCESS = 1 @@ -15,16 +14,6 @@ FAIL = 0 inputFile = ETC_DIR + "support_bundle_commands.conf" -# Open support bundle configuration file -def openConfFile(i_file): - try: - with open(i_file) as supportBundleConfFile: - lines = filter(None, (line.rstrip() for line in supportBundleConfFile)) - return lines - except IOError: - return [] - - # Create the output file name def createOutputFile(procName): fileName = procName + "_support_bundle.log" @@ -50,9 +39,9 @@ def openOutputFile(fileName): # Close the output file for this process -def closeOutputFile(file): +def closeOutputFile(f): try: - file.close() + f.close() return SUCCESS except IOError: return FAIL @@ -67,13 +56,13 @@ def executeCommand(cmd, outputFile): try: dateTime = datetime.datetime.now() outputFile.write(">>[" + str(dateTime) + "]" + cmd + "\n") - outputFile.write(cmd_output) + outputFile.write(str(cmd_output)) outputFile.write( "########################################################\n" ) outputFile.write("\n") - except: - print("Writing to ouptut file Failed") + except Exception as e: + print("Writing to output file Failed: ", e) except subprocess.CalledProcessError as e: dateTime = datetime.datetime.now() outputFile.write(">>[" + str(dateTime) + "]" + cmd + "\n") @@ -85,10 +74,23 @@ def executeCommand(cmd, outputFile): # Process the support bundle configuration file # and call appropriate functions -def processConfFile(lines): +def processConfFile(): + + lines = list() + outputFile = None + + try: + with open(inputFile, "r") as supportBundleConfFile: + for l in supportBundleConfFile: + lines.append(l.rstrip()) + except IOError: + print("conf file {} not present".format(inputFile)) + return + for line in lines: - if line[0][0] == "#": + if len(line) == 0 or line[0] == "#": continue + cmd_line = line.split(":") if cmd_line[0] == "PROC_NAME": outputFileName = createOutputFile(cmd_line[1]) @@ -112,8 +114,4 @@ def processConfFile(lines): # Main Function -lines = openConfFile(inputFile) -if not lines: - print("File support_bundle_commands.conf not present in /etc/frr/ directory") -else: - processConfFile(lines) +processConfFile() |
