[ovs-dev] [PATCH] ovs-bugtool: Added --ovs option to get only ovs related information

Arun Sharma arun.sharma at calsoftinc.com
Tue Jul 10 19:07:24 UTC 2012


New option --ovs is added for ovs-bugtool command to collect only openvswitch
relevant information. To perform filtering on plugins, a new xml attribute
"filters=ovs" (optional) in element of openvswitch.xml will be required.
Value of 'filters' attribute will be compared with filtering option like --ovs
to get all relevant operation to collect information. If no "--option" is
passed then it will behave as earlier.

Plus, trailing whitespaces are fixed.

Signed-off-by: Arun Sharma <arun.sharma at calsoftinc.com>
---
 utilities/bugtool/ovs-bugtool.in                   |   83 ++++++++++++++------
 .../bugtool/plugins/network-status/openvswitch.xml |   16 ++--
 .../plugins/system-configuration/openvswitch.xml   |    2 +-
 .../bugtool/plugins/system-logs/openvswitch.xml    |    2 +-
 4 files changed, 68 insertions(+), 35 deletions(-)

diff --git a/utilities/bugtool/ovs-bugtool.in b/utilities/bugtool/ovs-bugtool.in
index 3bafa13..af2bb6e 100755
--- a/utilities/bugtool/ovs-bugtool.in
+++ b/utilities/bugtool/ovs-bugtool.in
@@ -404,6 +404,10 @@ def main(argv = None):
     global ANSWER_YES_TO_ALL, SILENT_MODE
     global entries, data, dbg, unlimited_data
 
+    # Filter flags
+    only_ovs_info = False
+    filter_data = False
+
     # we need access to privileged files, exit if we are not running as root
     if os.getuid() != 0:
         print >>sys.stderr, "Error: ovs-bugtool must be run as root"
@@ -420,7 +424,7 @@ def main(argv = None):
         (options, params) = getopt.gnu_getopt(
             argv, 'sy', ['capabilities', 'silent', 'yestoall', 'entries=',
                          'output=', 'outfd=', 'outfile=', 'all', 'unlimited',
-                         'debug'])
+                         'debug', 'ovs'])
     except getopt.GetoptError, opterr:
         print >>sys.stderr, opterr
         return 2
@@ -478,6 +482,9 @@ def main(argv = None):
             dbg = True
             ProcOutput.debug = True
 
+        if k == '--ovs':
+            only_ovs_info = True
+
     if len(params) != 1:
         print >>sys.stderr, "Invalid additional arguments", str(params)
         return 2
@@ -493,6 +500,9 @@ def main(argv = None):
     if ANSWER_YES_TO_ALL:
         output("Warning: '--yestoall' argument provided, will not prompt for individual files.")
 
+    if only_ovs_info:
+        filter_data = True
+
     output('''
 This application will collate dmesg output, details of the
 hardware configuration of your machine, information about the build of
@@ -547,7 +557,7 @@ exclude those logs from the archive.
     for d in disk_list():
         cmd_output(CAP_HDPARM_T, [HDPARM, '-tT', '/dev/%s' % d])
 
-    file_output(CAP_KERNEL_INFO, [PROC_VERSION, PROC_MODULES, PROC_DEVICES, 
+    file_output(CAP_KERNEL_INFO, [PROC_VERSION, PROC_MODULES, PROC_DEVICES,
                                   PROC_FILESYSTEMS, PROC_CMDLINE])
     cmd_output(CAP_KERNEL_INFO, [ZCAT, PROC_CONFIG], label='config')
     cmd_output(CAP_KERNEL_INFO, [SYSCTL, '-A'])
@@ -561,7 +571,7 @@ exclude those logs from the archive.
     cmd_output(CAP_MULTIPATH, [DMSETUP, 'table'])
     func_output(CAP_MULTIPATH, 'multipathd_topology', multipathd_topology)
     cmd_output(CAP_MULTIPATH, [MPPUTIL, '-a'])
-    if CAP_MULTIPATH in entries:
+    if CAP_MULTIPATH in entries and not filter_data:
         dump_rdac_groups(CAP_MULTIPATH)
 
     tree_output(CAP_NETWORK_CONFIG, SYSCONFIG_NETWORK_SCRIPTS, IFCFG_RE)
@@ -609,10 +619,12 @@ exclude those logs from the archive.
             vspidfile = open(OPENVSWITCH_VSWITCHD_PID)
             vspid = int(vspidfile.readline().strip())
             vspidfile.close()
-            for b in bond_list(vspid):
-                cmd_output(CAP_NETWORK_STATUS,
-                           [OVS_APPCTL, '-t', '@RUNDIR@/ovs-vswitchd.%s.ctl' % vspid, '-e' 'bond/show %s' % b],
-                           'ovs-appctl-bond-show-%s.out' % b)
+            if not filter_data or only_ovs_info:
+                for b in bond_list(vspid):
+                    cmd_output(CAP_NETWORK_STATUS,
+                               [OVS_APPCTL, '-t',
+                                '@RUNDIR@/ovs-vswitchd.%s.ctl' % vspid, '-e' 'bond/show %s' % b],
+                               'ovs-appctl-bond-show-%s.out' % b)
         except e:
             pass
 
@@ -650,15 +662,30 @@ exclude those logs from the archive.
     tree_output(CAP_YUM, APT_SOURCES_LIST_D)
     cmd_output(CAP_YUM, [DPKG_QUERY, '-W', '-f=${Package} ${Version} ${Status}\n'], 'dpkg-packages')
 
-    try:
-        load_plugins()
-    except:
-        pass
-    
+    # Filter out ovs related information if --ovs option passed
+    if only_ovs_info:
+        ovs_info_caps = [CAP_NETWORK_STATUS, CAP_SYSTEM_LOGS,
+                         CAP_NETWORK_CONFIG]
+        ovs_info_list = ['process-tree']
+        for (k, v) in data.items():
+            cap = v['cap']
+            ovs_info = k[0] if v.has_key('filename') else k
+            if ovs_info not in ovs_info_list and cap not in ovs_info_caps:
+                del data[k]
+
+        load_plugins(False, 'ovs')
+    else:
+       try:
+           load_plugins()
+       except:
+           pass
+
     # permit the user to filter out data
-    for k in sorted(data.keys()):
-        if not ANSWER_YES_TO_ALL and not yes("Include '%s'? [Y/n]: " % k):
-            del data[k]
+    for (k, v) in sorted(data.items()):
+       cap = v['cap']
+       key = k[0] if v.has_key('filename') else k
+       if not ANSWER_YES_TO_ALL and not yes("Include '%s'? [Y/n]: " % key):
+           del data[k]
 
     # collect selected data now
     output_ts('Running commands to collect data')
@@ -773,7 +800,7 @@ def module_info(cap):
 
 
 def multipathd_topology(cap):
-    pipe = Popen([MULTIPATHD, '-k'], bufsize=1, stdin=PIPE, 
+    pipe = Popen([MULTIPATHD, '-k'], bufsize=1, stdin=PIPE,
                      stdout=PIPE, stderr=dev_null)
     stdout, stderr = pipe.communicate('show topology')
 
@@ -837,7 +864,7 @@ def dump_rdac_groups(cap):
                 group, _ = line.split(None, 1)
                 cmd_output(cap, [MPPUTIL, '-g', group])
 
-def load_plugins(just_capabilities = False):
+def load_plugins(just_capabilities = False, filter = None):
     def getText(nodelist):
         rc = ""
         for node in nodelist:
@@ -851,7 +878,7 @@ def load_plugins(just_capabilities = False):
         if val in ['true', 'false', 'yes', 'no']:
             ret = val in ['true', 'yes']
         return ret
-        
+
     for dir in [d for d in os.listdir(PLUGIN_DIR) if os.path.isdir(os.path.join(PLUGIN_DIR, d))]:
         if not caps.has_key(dir):
             if not os.path.exists("%s/%s.xml" % (PLUGIN_DIR, dir)):
@@ -881,28 +908,34 @@ def load_plugins(just_capabilities = False):
 
         if just_capabilities:
             continue
-                    
+
         plugdir = os.path.join(PLUGIN_DIR, dir)
         for file in [f for f in os.listdir(plugdir) if f.endswith('.xml')]:
             xmldoc = parse(os.path.join(plugdir, file))
             assert xmldoc.documentElement.tagName == "collect"
 
             for el in xmldoc.documentElement.getElementsByTagName("*"):
+                filters_tmp = el.getAttribute("filters")
+                filters = [] if filters_tmp == '' else filters_tmp.split(',')
                 if el.tagName == "files":
                     newest_first = getBoolAttr(el, 'newest_first')
-                    file_output(dir, getText(el.childNodes).split(),
-                                newest_first=newest_first)
+                    if filter == None or filter in filters:
+                        file_output(dir, getText(el.childNodes).split(),
+                                    newest_first=newest_first)
                 elif el.tagName == "directory":
                     pattern = el.getAttribute("pattern")
                     if pattern == '': pattern = None
                     negate = getBoolAttr(el, 'negate')
                     newest_first = getBoolAttr(el, 'newest_first')
-                    tree_output(dir, getText(el.childNodes), pattern and re.compile(pattern) or None,
-                                negate=negate, newest_first=newest_first)
+                    if filter == None or filter in filters:
+                        tree_output(dir, getText(el.childNodes),
+                                    pattern and re.compile(pattern) or None,
+                                    negate=negate, newest_first=newest_first)
                 elif el.tagName == "command":
                     label = el.getAttribute("label")
                     if label == '': label = None
-                    cmd_output(dir, getText(el.childNodes), label)
+                    if filter == None or filter in filters:
+                        cmd_output(dir, getText(el.childNodes), label)
 
 def make_tar(subdir, suffix, output_fd, output_file):
     global SILENT_MODE, data
@@ -982,7 +1015,7 @@ def make_zip(subdir, output_file):
                 pass
     finally:
         zf.close()
-    
+
     output ('Writing archive %s successful.' % filename)
     if SILENT_MODE:
         print filename
diff --git a/utilities/bugtool/plugins/network-status/openvswitch.xml b/utilities/bugtool/plugins/network-status/openvswitch.xml
index 1316071..9539f7c 100644
--- a/utilities/bugtool/plugins/network-status/openvswitch.xml
+++ b/utilities/bugtool/plugins/network-status/openvswitch.xml
@@ -17,12 +17,12 @@
 -->
 
 <collect>
-  <command label="tc-class-show">/usr/share/openvswitch/scripts/ovs-bugtool-tc-class-show</command>
-  <command label="ovs-vsctl-show">/usr/share/openvswitch/scripts/ovs-bugtool-vsctl-show</command>
-  <command label="dump-ovsdb">/usr/share/openvswitch/scripts/ovs-bugtool-ovsdb-dump</command>
-  <command label="ovs-appctl-lacp-show">/usr/share/openvswitch/scripts/ovs-bugtool-lacp-show</command>
-  <command label="ovs-appctl-cfm-show">/usr/share/openvswitch/scripts/ovs-bugtool-cfm-show</command>
-  <command label="ovs-appctl-coverage-show">/usr/share/openvswitch/scripts/ovs-bugtool-coverage-show</command>
-  <command label="ovs-appctl-bond-show">/usr/share/openvswitch/scripts/ovs-bugtool-bond-show</command>
-  <command label="ovs-appctl-memory-show">/usr/share/openvswitch/scripts/ovs-bugtool-memory-show</command>
+  <command label="tc-class-show" filters="ovs">/usr/share/openvswitch/scripts/ovs-bugtool-tc-class-show</command>
+  <command label="ovs-vsctl-show" filters="ovs">/usr/share/openvswitch/scripts/ovs-bugtool-vsctl-show</command>
+  <command label="dump-ovsdb" filters="ovs">/usr/share/openvswitch/scripts/ovs-bugtool-ovsdb-dump</command>
+  <command label="ovs-appctl-lacp-show" filters="ovs">/usr/share/openvswitch/scripts/ovs-bugtool-lacp-show</command>
+  <command label="ovs-appctl-cfm-show" filters="ovs">/usr/share/openvswitch/scripts/ovs-bugtool-cfm-show</command>
+  <command label="ovs-appctl-coverage-show" filters="ovs">/usr/share/openvswitch/scripts/ovs-bugtool-coverage-show</command>
+  <command label="ovs-appctl-bond-show" filters="ovs">/usr/share/openvswitch/scripts/ovs-bugtool-bond-show</command>
+  <command label="ovs-appctl-memory-show" filters="ovs">/usr/share/openvswitch/scripts/ovs-bugtool-memory-show</command>
 </collect>
diff --git a/utilities/bugtool/plugins/system-configuration/openvswitch.xml b/utilities/bugtool/plugins/system-configuration/openvswitch.xml
index ea6f32e..d1d5a1a 100644
--- a/utilities/bugtool/plugins/system-configuration/openvswitch.xml
+++ b/utilities/bugtool/plugins/system-configuration/openvswitch.xml
@@ -18,5 +18,5 @@
 
 <collect>
     <command label="timezone">date --rfc-3339=seconds</command>
-    <command label="ovs-daemons-ver">/usr/share/openvswitch/scripts/ovs-bugtool-daemons-ver</command>
+    <command label="ovs-daemons-ver" filters="ovs">/usr/share/openvswitch/scripts/ovs-bugtool-daemons-ver</command>
 </collect>
diff --git a/utilities/bugtool/plugins/system-logs/openvswitch.xml b/utilities/bugtool/plugins/system-logs/openvswitch.xml
index f735113..8493361 100644
--- a/utilities/bugtool/plugins/system-logs/openvswitch.xml
+++ b/utilities/bugtool/plugins/system-logs/openvswitch.xml
@@ -17,5 +17,5 @@
 -->
 
 <collect>
-  <directory label="ovsdb-backups" pattern=".*/conf.db.backup[0-9][^/]*$">/etc/openvswitch</directory>
+  <directory label="ovsdb-backups" filters="ovs" pattern=".*/conf.db.backup[0-9][^/]*$">/etc/openvswitch</directory>
 </collect>
-- 
1.7.2.5




More information about the dev mailing list