~james-page/ubuntu/saucy/openvswitch/1.12-snapshot

« back to all changes in this revision

Viewing changes to utilities/bugtool/ovs-bugtool.in

  • Committer: James Page
  • Date: 2013-08-21 10:16:57 UTC
  • mfrom: (1.1.20)
  • Revision ID: james.page@canonical.com-20130821101657-3o0z0qeiv5zkwlzi
New upstream snapshot

Show diffs side-by-side

added added

removed removed

Lines of Context:
76
76
PROC_MOUNTS = '/proc/mounts'
77
77
ISCSI_CONF = '/etc/iscsi/iscsid.conf'
78
78
ISCSI_INITIATOR = '/etc/iscsi/initiatorname.iscsi'
79
 
LVM_CACHE = '/etc/lvm/cache/.cache'
80
 
LVM_CONFIG = '/etc/lvm/lvm.conf'
81
79
PROC_CPUINFO = '/proc/cpuinfo'
82
80
PROC_MEMINFO = '/proc/meminfo'
83
81
PROC_IOPORTS = '/proc/ioports'
90
88
PROC_CMDLINE = '/proc/cmdline'
91
89
PROC_CONFIG = '/proc/config.gz'
92
90
PROC_USB_DEV = '/proc/bus/usb/devices'
93
 
PROC_XEN_BALLOON = '/proc/xen/balloon'
94
91
PROC_NET_BONDING_DIR = '/proc/net/bonding'
95
92
IFCFG_RE = re.compile(r'^.*/ifcfg-.*')
96
93
ROUTE_RE = re.compile(r'^.*/route-.*')
117
114
OPENVSWITCH_DEFAULT_CONTROLLER = '/etc/default/openvswitch-controller'
118
115
OPENVSWITCH_CONF_DB = '@DBDIR@/conf.db'
119
116
OPENVSWITCH_VSWITCHD_PID = '@RUNDIR@/ovs-vswitchd.pid'
120
 
COLLECTD_LOGS_DIR = '/var/lib/collectd/rrd'
121
117
VAR_LOG_DIR = '/var/log/'
122
118
VAR_LOG_CORE_DIR = '/var/log/core'
123
 
X11_LOGS_DIR = VAR_LOG_DIR
124
 
X11_LOGS_RE = re.compile(r'.*/Xorg\..*$')
125
 
X11_AUTH_DIR = '/root/'
126
 
X11_AUTH_RE = re.compile(r'.*/\.((Xauthority)|(serverauth\.[0-9]*))$')
127
119
YUM_LOG = '/var/log/yum.log'
128
120
YUM_REPOS_DIR = '/etc/yum.repos.d'
129
 
PAM_DIR = '/etc/pam.d'
130
 
KRB5_CONF = '/etc/krb5.conf'
131
121
 
132
122
#
133
123
# External programs
145
135
ETHTOOL = 'ethtool'
146
136
FDISK = 'fdisk'
147
137
FIND = 'find'
148
 
HDPARM = 'hdparm'
149
138
IFCONFIG = 'ifconfig'
150
139
IPTABLES = 'iptables'
151
140
ISCSIADM = 'iscsiadm'
152
141
LOSETUP = 'losetup'
153
142
LS = 'ls'
154
143
LSPCI = 'lspci'
155
 
LVDISPLAY = 'lvdisplay'
156
 
LVS = 'lvs'
157
144
MD5SUM = 'md5sum'
158
145
MODINFO = 'modinfo'
159
146
MPPUTIL = 'mppUtil'
164
151
OVS_VSCTL = 'ovs-vsctl'
165
152
OVS_APPCTL = 'ovs-appctl'
166
153
PS = 'ps'
167
 
PVS = 'pvs'
168
154
ROUTE = 'route'
169
155
RPM = 'rpm'
170
156
SG_MAP = 'sg_map'
171
157
SYSCTL = 'sysctl'
172
158
TC = 'tc'
173
159
UPTIME = 'uptime'
174
 
VGS = 'vgs'
175
 
VGSCAN = 'vgscan'
176
160
ZCAT = 'zcat'
177
161
 
178
162
#
214
198
CAP_XML_ELEMENT = 'capability'
215
199
 
216
200
 
217
 
CAP_BLOBS                = 'blobs'
218
201
CAP_BOOT_LOADER          = 'boot-loader'
219
 
CAP_COLLECTD_LOGS        = 'collectd-logs'
220
202
CAP_DISK_INFO            = 'disk-info'
221
 
CAP_FIRSTBOOT            = 'firstboot'
222
203
CAP_HARDWARE_INFO        = 'hardware-info'
223
 
CAP_HDPARM_T             = 'hdparm-t'
224
 
CAP_HIGH_AVAILABILITY    = 'high-availability'
225
204
CAP_KERNEL_INFO          = 'kernel-info'
226
205
CAP_LOSETUP_A            = 'loopback-devices'
227
206
CAP_MULTIPATH            = 'multipath'
228
207
CAP_NETWORK_CONFIG       = 'network-config'
229
208
CAP_NETWORK_STATUS       = 'network-status'
230
 
CAP_OEM                  = 'oem'
231
 
CAP_PAM                  = 'pam'
 
209
CAP_OPENVSWITCH_LOGS     = 'ovs-system-logs'
232
210
CAP_PROCESS_LIST         = 'process-list'
233
 
CAP_PERSISTENT_STATS     = 'persistent-stats'
234
211
CAP_SYSTEM_LOGS          = 'system-logs'
235
212
CAP_SYSTEM_SERVICES      = 'system-services'
236
 
CAP_VNCTERM              = 'vncterm'
237
 
CAP_WLB                  = 'wlb'
238
 
CAP_X11_LOGS             = 'X11'
239
 
CAP_X11_AUTH             = 'X11-auth'
240
213
CAP_YUM                  = 'yum'
241
214
 
242
215
KB = 1024
246
219
cap_sizes = {}
247
220
unlimited_data = False
248
221
dbg = False
 
222
# Default value for the number of rotated logs.
 
223
log_days = 20
249
224
 
250
225
def cap(key, pii=PII_MAYBE, min_size=-1, max_size=-1, min_time=-1,
251
226
        max_time=-1, mime=MIME_TEXT, checked=True, hidden=False):
254
229
    cap_sizes[key] = 0
255
230
 
256
231
 
257
 
cap(CAP_BLOBS,               PII_NO,                    max_size=5*MB)
258
232
cap(CAP_BOOT_LOADER,         PII_NO,                    max_size=3*KB,
259
233
    max_time=5)
260
 
cap(CAP_COLLECTD_LOGS,       PII_MAYBE,                 max_size=50*MB,
261
 
    max_time=5)
262
234
cap(CAP_DISK_INFO,           PII_MAYBE,                 max_size=50*KB,
263
235
    max_time=20)
264
 
cap(CAP_FIRSTBOOT,           PII_YES,   min_size=60*KB, max_size=80*KB)
265
236
cap(CAP_HARDWARE_INFO,       PII_MAYBE,                 max_size=30*KB,
266
237
    max_time=20)
267
 
cap(CAP_HDPARM_T,            PII_NO,    min_size=0,     max_size=5*KB,
268
 
    min_time=20, max_time=90, checked=False, hidden=True)
269
 
cap(CAP_HIGH_AVAILABILITY,   PII_MAYBE,                 max_size=5*MB)
270
238
cap(CAP_KERNEL_INFO,         PII_MAYBE,                 max_size=120*KB,
271
239
    max_time=5)
272
240
cap(CAP_LOSETUP_A,           PII_MAYBE,                 max_size=KB, max_time=5)
274
242
    max_time=10)
275
243
cap(CAP_NETWORK_CONFIG,      PII_IF_CUSTOMIZED,
276
244
                                        min_size=0,     max_size=40*KB)
277
 
cap(CAP_NETWORK_STATUS,      PII_YES,                   max_size=50*KB,
 
245
cap(CAP_NETWORK_STATUS,      PII_YES,                   max_size=50*MB,
278
246
    max_time=30)
279
 
cap(CAP_PAM,                 PII_NO,                    max_size=50*KB)
280
 
cap(CAP_PERSISTENT_STATS,    PII_MAYBE,                 max_size=50*MB,
281
 
    max_time=60)
 
247
cap(CAP_OPENVSWITCH_LOGS,    PII_MAYBE,                 max_size=-1,
 
248
    max_time=5)
282
249
cap(CAP_PROCESS_LIST,        PII_YES,                   max_size=30*KB,
283
250
    max_time=20)
284
 
cap(CAP_SYSTEM_LOGS,         PII_MAYBE,                 max_size=50*MB,
 
251
cap(CAP_SYSTEM_LOGS,         PII_MAYBE,                 max_size=200*MB,
285
252
    max_time=5)
286
253
cap(CAP_SYSTEM_SERVICES,     PII_NO,                    max_size=5*KB,
287
254
    max_time=20)
288
 
cap(CAP_VNCTERM,             PII_MAYBE, checked = False)
289
 
cap(CAP_WLB,                 PII_NO,                    max_size=3*MB,
290
 
    max_time=20)
291
 
cap(CAP_X11_LOGS,            PII_NO,                    max_size=100*KB)
292
 
cap(CAP_X11_AUTH,            PII_NO,                    max_size=100*KB)
293
255
cap(CAP_YUM,                 PII_IF_CUSTOMIZED,         max_size=10*KB,
294
256
    max_time=30)
295
257
 
361
323
        t = str(func).split()
362
324
        data[label] = {'cap': cap, 'func': func}
363
325
 
 
326
def log_output(cap, logs, newest_first=False):
 
327
    global log_days
 
328
    file_output(cap, logs)
 
329
    file_output(cap,
 
330
        ['%s.%d' % (f, n) for n in range(1, log_days+1) for f in logs], \
 
331
        newest_first=newest_first)
 
332
    file_output(cap,
 
333
        ['%s.%d.gz' % (f, n) for n in range(1, log_days+1) for f in logs], \
 
334
        newest_first=newest_first)
 
335
 
364
336
def collect_data():
365
337
    process_lists = {}
366
338
 
404
376
 
405
377
def main(argv=None):
406
378
    global ANSWER_YES_TO_ALL, SILENT_MODE
407
 
    global entries, data, dbg, unlimited_data
 
379
    global entries, data, dbg, unlimited_data, log_days
408
380
 
409
381
    # Filter flags
410
382
    only_ovs_info = False
416
388
        return 1
417
389
 
418
390
    output_file = None
419
 
    output_type = 'tar.bz2'
 
391
    output_type = 'tar.gz'
420
392
    output_fd = -1
421
393
 
422
394
    if argv is None:
426
398
        (options, params) = getopt.gnu_getopt(
427
399
            argv, 'sy', ['capabilities', 'silent', 'yestoall', 'entries=',
428
400
                         'output=', 'outfd=', 'outfile=', 'all', 'unlimited',
429
 
                         'debug', 'ovs'])
 
401
                         'debug', 'ovs', 'log-days='])
430
402
    except getopt.GetoptError, opterr:
431
403
        print >>sys.stderr, opterr
432
404
        return 2
488
460
            only_ovs_info = True
489
461
            collect_all_info = False
490
462
 
 
463
        if k == '--log-days':
 
464
            log_days = int(v)
 
465
 
491
466
    if len(params) != 1:
492
467
        print >>sys.stderr, "Invalid additional arguments", str(params)
493
468
        return 2
523
498
    cmd_output(CAP_BOOT_LOADER, [LS, '-lR', '/boot'])
524
499
    cmd_output(CAP_BOOT_LOADER, [MD5SUM, BOOT_KERNEL, BOOT_INITRD], label='vmlinuz-initrd.md5sum')
525
500
 
526
 
    tree_output(CAP_COLLECTD_LOGS, COLLECTD_LOGS_DIR)
527
501
    cmd_output(CAP_DISK_INFO, [FDISK, '-l'])
528
502
    file_output(CAP_DISK_INFO, [PROC_PARTITIONS, PROC_MOUNTS])
529
503
    file_output(CAP_DISK_INFO, [FSTAB, ISCSI_CONF, ISCSI_INITIATOR])
530
504
    cmd_output(CAP_DISK_INFO, [DF, '-alT'])
531
505
    cmd_output(CAP_DISK_INFO, [DF, '-alTi'])
532
 
    for d in disk_list():
533
 
        cmd_output(CAP_DISK_INFO, [HDPARM, '-I', '/dev/%s' % d])
534
506
    if len(pidof('iscsid')) != 0:
535
507
        cmd_output(CAP_DISK_INFO, [ISCSIADM, '-m', 'node'])
536
 
    cmd_output(CAP_DISK_INFO, [VGSCAN])
537
 
    cmd_output(CAP_DISK_INFO, [PVS])
538
 
    cmd_output(CAP_DISK_INFO, [VGS])
539
 
    cmd_output(CAP_DISK_INFO, [LVS])
540
 
    file_output(CAP_DISK_INFO, [LVM_CACHE, LVM_CONFIG])
541
508
    cmd_output(CAP_DISK_INFO, [LS, '-R', '/sys/class/scsi_host'])
542
509
    cmd_output(CAP_DISK_INFO, [LS, '-R', '/sys/class/scsi_disk'])
543
510
    cmd_output(CAP_DISK_INFO, [LS, '-R', '/sys/class/fc_transport'])
544
511
    cmd_output(CAP_DISK_INFO, [SG_MAP, '-x'])
545
512
    func_output(CAP_DISK_INFO, 'scsi-hosts', dump_scsi_hosts)
546
 
    cmd_output(CAP_DISK_INFO, [LVDISPLAY, '--map'])
547
513
 
548
514
    file_output(CAP_HARDWARE_INFO, [PROC_CPUINFO, PROC_MEMINFO, PROC_IOPORTS, PROC_INTERRUPTS])
549
515
    cmd_output(CAP_HARDWARE_INFO, [DMIDECODE])
552
518
    file_output(CAP_HARDWARE_INFO, [PROC_USB_DEV, PROC_SCSI])
553
519
    file_output(CAP_HARDWARE_INFO, [SYSCONFIG_HWCONF])
554
520
    cmd_output(CAP_HARDWARE_INFO, [LS, '-lR', '/dev'])
555
 
    # FIXME IDE?
556
521
 
557
 
    for d in disk_list():
558
 
        cmd_output(CAP_HDPARM_T, [HDPARM, '-tT', '/dev/%s' % d])
559
522
 
560
523
    file_output(CAP_KERNEL_INFO, [PROC_VERSION, PROC_MODULES, PROC_DEVICES,
561
524
                                  PROC_FILESYSTEMS, PROC_CMDLINE])
595
558
            f.close()
596
559
            if os.path.islink('/sys/class/net/%s/device' % p) and int(t) == 1:
597
560
                # ARPHRD_ETHER
598
 
                cmd_output(CAP_NETWORK_STATUS, [ETHTOOL, p])
599
561
                cmd_output(CAP_NETWORK_STATUS, [ETHTOOL, '-S', p])
600
 
                cmd_output(CAP_NETWORK_STATUS, [ETHTOOL, '-k', p])
601
 
                cmd_output(CAP_NETWORK_STATUS, [ETHTOOL, '-i', p])
602
 
                cmd_output(CAP_NETWORK_STATUS, [ETHTOOL, '-c', p])
 
562
                if not p.startswith('vif') and not p.startswith('tap'):
 
563
                    cmd_output(CAP_NETWORK_STATUS, [ETHTOOL, p])
 
564
                    cmd_output(CAP_NETWORK_STATUS, [ETHTOOL, '-k', p])
 
565
                    cmd_output(CAP_NETWORK_STATUS, [ETHTOOL, '-i', p])
 
566
                    cmd_output(CAP_NETWORK_STATUS, [ETHTOOL, '-c', p])
603
567
            if int(t) == 1:
604
568
                cmd_output(CAP_NETWORK_STATUS,
605
569
                           [TC, '-s', '-d', 'class', 'show', 'dev', p])
624
588
        except e:
625
589
            pass
626
590
 
627
 
    tree_output(CAP_PAM, PAM_DIR)
628
 
    file_output(CAP_PAM, [KRB5_CONF])
629
 
 
630
591
    cmd_output(CAP_PROCESS_LIST, [PS, 'wwwaxf', '-eo', 'pid,tty,stat,time,nice,psr,pcpu,pmem,nwchan,wchan:25,args'], label='process-tree')
631
592
    func_output(CAP_PROCESS_LIST, 'fd_usage', fd_usage)
632
593
 
633
 
    logs = ([ VAR_LOG_DIR + x for x in
634
 
             [ 'crit.log', 'kern.log', 'daemon.log', 'user.log',
635
 
             'syslog', 'messages', 'secure', 'debug', 'dmesg', 'boot' ]]
636
 
            + [ OPENVSWITCH_LOG_DIR + x for x in
637
 
                [ 'ovs-vswitchd.log', 'ovsdb-server.log',
638
 
                  'ovs-xapi-sync.log', 'ovs-monitor-ipsec.log', 'ovs-ctl.log' ]])
639
 
    file_output(CAP_SYSTEM_LOGS, logs)
640
 
    file_output(CAP_SYSTEM_LOGS,
641
 
                [ '%s.%d' % (f, n) for n in range(20) for f in logs ])
642
 
    file_output(CAP_SYSTEM_LOGS,
643
 
                [ '%s.%d.gz' % (f, n) for n in range(20) for f in logs ])
 
594
    system_logs = ([ VAR_LOG_DIR + x for x in
 
595
        ['crit.log', 'kern.log', 'daemon.log', 'user.log',
 
596
        'syslog', 'messages', 'secure', 'debug', 'dmesg', 'boot']])
 
597
    ovs_logs = ([ OPENVSWITCH_LOG_DIR + x for x in
 
598
        ['ovs-vswitchd.log', 'ovsdb-server.log',
 
599
        'ovs-xapi-sync.log', 'ovs-monitor-ipsec.log', 'ovs-ctl.log']])
 
600
    log_output(CAP_SYSTEM_LOGS, system_logs)
 
601
    log_output(CAP_OPENVSWITCH_LOGS, ovs_logs)
644
602
 
645
603
    if not os.path.exists('/var/log/dmesg') and not os.path.exists('/var/log/boot'):
646
604
        cmd_output(CAP_SYSTEM_LOGS, [DMESG])
647
605
 
648
606
    cmd_output(CAP_SYSTEM_SERVICES, [CHKCONFIG, '--list'])
649
607
 
650
 
    tree_output(CAP_X11_LOGS, X11_LOGS_DIR, X11_LOGS_RE)
651
 
    tree_output(CAP_X11_AUTH, X11_AUTH_DIR, X11_AUTH_RE)
652
608
    tree_output(CAP_SYSTEM_LOGS, VAR_LOG_CORE_DIR)
653
609
 
654
610
    file_output(CAP_YUM, [YUM_LOG])
726
682
    else:
727
683
        make_zip(subdir, output_file)
728
684
 
729
 
    clean_tapdisk_logs()
730
 
 
731
685
    if dbg:
732
686
        print >>sys.stderr, "Category sizes (max, actual):\n"
733
687
        for c in caps.keys():
735
689
                                                     cap_sizes[c])
736
690
    return 0
737
691
 
738
 
def find_tapdisk_logs():
739
 
    return glob.glob('/var/log/blktap/*.log*')
740
 
 
741
 
def generate_tapdisk_logs():
742
 
    for pid in pidof('tapdisk'):
743
 
        try:
744
 
            os.kill(pid, SIGUSR1)
745
 
            output_ts("Including logs for tapdisk process %d" % pid)
746
 
        except :
747
 
            pass
748
 
    # give processes a second to write their logs
749
 
    time.sleep(1)
750
 
 
751
 
def clean_tapdisk_logs():
752
 
    for filename in find_tapdisk_logs():
753
 
        try:
754
 
            os.remove(filename)
755
 
        except :
756
 
            pass
757
 
 
758
 
def filter_db_pii(str, state):
759
 
    if 'in_secret_table' not in state:
760
 
        state['in_secret_table'] = False
761
 
 
762
 
    if str.startswith('<table ') and 'name="secret"' in str:
763
 
        state['in_secret_table'] = True
764
 
    elif str.startswith('</table>'):
765
 
        state['in_secret_table'] = False
766
 
 
767
 
    if state['in_secret_table'] and str.startswith("<row"): # match only on DB rows
768
 
        str = re.sub(r'(value=")[^"]+(")', r'\1REMOVED\2', str)
769
 
    return str
770
 
 
771
692
def dump_scsi_hosts(cap):
772
693
    output = ''
773
694
    l = os.listdir('/sys/class/scsi_host')
934
855
                    continue
935
856
                if el.tagName == "files":
936
857
                    newest_first = getBoolAttr(el, 'newest_first')
937
 
                    file_output(dir, getText(el.childNodes).split(),
938
 
                                newest_first=newest_first)
 
858
                    if el.getAttribute("type") == "logs":
 
859
                        log_output(dir, getText(el.childNodes).split(),
 
860
                                    newest_first=newest_first)
 
861
                    else:
 
862
                        file_output(dir, getText(el.childNodes).split(),
 
863
                                    newest_first=newest_first)
939
864
                elif el.tagName == "directory":
940
865
                    pattern = el.getAttribute("pattern")
941
866
                    if pattern == '': pattern = None