Files
8ab8f1ca455df315677cff66c3de6c2279ce90ee
devstack /tools /worlddump.py

202 lines
5.3 KiB
Python
Raw Normal View History

#
# Copyright 2014 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Dump the state of the world for post mortem."""
import argparse
import datetime
import os.path
def get_options():
parser = argparse.ArgumentParser(
description='Dump world state for debugging')
parser.add_argument('-d', '--dir',
default='.',
help='Output directory for worlddump')
default='',
help='Additional name to tag into file')
if name:
fmt += "-" + name
fmt += ".txt"
return os.path.join(dirname, now.strftime(fmt))
def warn(msg):
print "WARN: %s" % msg
print cmd
print "-" * len(cmd)
print
subprocess.check_call(cmd, shell=True)
print "*** Failed to run '%(cmd)s': %(err)s" % {'cmd': cmd, 'err': e}
if not spawn.find_executable(cmd):
print "*** %s not found: skipping" % cmd
return False
return True
print
print name
print "=" * len(name)
print
# the df output
df = [s.split() for s in dfraw.splitlines()]
for fs in df:
try:
if int(fs[4][:-1]) > 95:
warn("Device %s (%s) is %s full, might be an issue" % (
fs[0], fs[5], fs[4]))
except ValueError:
# if it doesn't look like an int, that's fine
pass
print dfraw
return
_dump_cmd("sudo ebtables -t %s -L" % table)
tables = ['filter', 'nat', 'mangle']
process = subprocess.Popen(['ip', 'netns'], stdout=subprocess.PIPE)
stdout, _ = process.communicate()
return stdout.split()
_header("Network Dump")
_dump_cmd("brctl show")
_dump_cmd("arp -n")
for cmd in ip_cmds + ['netns']:
_dump_cmd("ip %s" % cmd)
for netns_ in _netns_list():
for cmd in ip_cmds:
args = {'netns': netns_, 'cmd': cmd}
_dump_cmd('sudo ip netns exec %(netns)s ip %(cmd)s' % args)
_header("Open vSwitch Dump")
# will not be present so
if not _find_cmd('ovs-vsctl'):
return
# NOTE(ihrachys): worlddump is used outside of devstack context (f.e. in
# grenade), so there is no single place to determine the bridge names from.
# Hardcode for now.
bridges = ('br-int', 'br-tun', 'br-ex')
_dump_cmd("sudo ovs-vsctl show")
for bridge in bridges:
_dump_cmd("sudo ovs-ofctl show %s" % bridge)
for bridge in bridges:
_dump_cmd("sudo ovs-ofctl dump-flows %s" % bridge)
_dump_cmd("ps axo "
"user,ppid,pid,pcpu,pmem,vsz,rss,tty,stat,start,time,args")
_header("Compute consoles")
for root, dirnames, filenames in os.walk('/opt/stack'):
for filename in fnmatch.filter(filenames, 'console.log'):
fullpath = os.path.join(root, filename)
_dump_cmd("sudo cat %s" % fullpath)
_header("nova-compute Guru Meditation Report")
try:
subprocess.check_call(["pgrep","nova-compute"])
except subprocess.CalledProcessError:
print "Skipping as nova-compute does not appear to be running"
return
opts = get_options()
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
with open(fname, 'w') as f:
os.dup2(f.fileno(), sys.stdout.fileno())
disk_space()
process_list()
if __name__ == '__main__':
try:
sys.exit(main())
except KeyboardInterrupt:
sys.exit(1)