]> git.puffer.fish Git - mirror/frr.git/commitdiff
tests: make generate support bundle python3 only 8015/head
authorMark Stapp <mjs@voltanet.io>
Thu, 4 Feb 2021 16:13:01 +0000 (11:13 -0500)
committerMark Stapp <mjs@voltanet.io>
Mon, 15 Feb 2021 13:13:06 +0000 (08:13 -0500)
Make the generate-support-bundle script and interactions more
python3-friendly, and use python3 explicitly.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
tests/topotests/lib/common_config.py
tools/generate_support_bundle.py

index 3f360ef40ab5866142d38fa451e6740761ea8dd3..a1ef2f5f28ccdb32d0a593216c80d83ed5747ab4 100644 (file)
@@ -677,7 +677,10 @@ def generate_support_bundle():
     for rname, rnode in router_list.items():
         logger.info("Generating support bundle for {}".format(rname))
         rnode.run("mkdir -p /var/log/frr")
-        bundle_log = rnode.run("python2 /usr/lib/frr/generate_support_bundle.py")
+
+        # Support only python3 going forward
+        bundle_log = rnode.run("env python3 /usr/lib/frr/generate_support_bundle.py")
+
         logger.info(bundle_log)
 
         dst_bundle = "{}/{}/support_bundles/{}".format(TMPDIR, rname, test_name)
index ae258bddfe39915db33e653df25e2d5cf08168f9..38fdbd46df4b2070d285be7e1353b9e262742906 100755 (executable)
@@ -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()