debug_snapshot.py
Go to the documentation of this file.
00001 """
00002 The snapshot command creates a zip file of relevant robot debug info.
00003 
00004 Copyright 2016 Fetch Robotics Inc.
00005 Author: Aaron Blasdel
00006 """
00007 
00008 import shutil
00009 import os
00010 import tempfile
00011 import subprocess
00012 import datetime
00013 
00014 from ..util import ssh, add_robot
00015 
00016 name = "debug-snapshot"
00017 help_text = "Take a debug snapshot of a running robot"
00018 
00019 snapshot_version = "0.0.1"
00020 
00021 fileroot = "debug_snapshot"
00022 fileroot = '_' + fileroot + '_'
00023 
00024 bagname = 'robot.bag'
00025 
00026 # all ros command must source setup.bash
00027 rosbash = 'source /opt/ros/indigo/setup.bash;'
00028 devnull = open(os.devnull, 'w+')
00029 
00030 topics = ["/robot_state",
00031           "/diagnostics",
00032           "/diagnostics_agg",
00033           "/battery_state"]
00034 
00035 # All commands requiring sudo must be added in main
00036 commands = {"dpkg_fetch":"COLUMNS=200 dpkg -l ros-indigo-fetch-*",
00037             "dpkg_all":"COLUMNS=200 dpkg -l",
00038             "lsusb":"lsusb -v",
00039             "lspci":"lspci -vv",
00040             "roswtf":rosbash + "roswtf",
00041             "rosnode_list":rosbash + "rosnode list",
00042             "rostopic_list":rosbash + "rostopic list",
00043             "rossrv_list":rosbash + "rosservice list",
00044             "rosparam_list":rosbash + "rosparam list",
00045             "rosparam_dump":rosbash + "rosparam get /",
00046             "dmesg":"dmesg",
00047             "date":"date",
00048             "meminfo":"cat /proc/meminfo",
00049             "ip_route":"ip route",
00050             "ifconfig":"ifconfig -a",
00051             "iwconfig":"iwconfig",
00052             "network_interfaces":"cat /etc/network/interfaces",
00053             "hosts":"cat /etc/hosts",
00054             "env":"env",
00055             "roscore.conf":"cat /etc/init/roscore.conf",
00056             "robot.conf":"cat /etc/init/robot.conf",
00057             "sixad.conf":"cat /etc/init/sixad.conf",
00058             "soundplay.conf":"cat /etc/init/soundplay.conf",
00059             "joystick_monitor.conf":"cat /etc/init/joystick_monitor.conf",
00060             "read_board_charger": rosbash + "rosrun fetch_drivers read_board 0x3f",
00061             "read_board_mainboard": rosbash + "rosrun fetch_drivers read_board 0x00",
00062             "read_board_wheel_left": rosbash + "rosrun fetch_drivers read_board 0x11",
00063             "read_board_wheel_right": rosbash + "rosrun fetch_drivers read_board 0x12",
00064             "top": "top -n 1 -b",
00065            }
00066 
00067 
00068 def main(args):
00069     # all commands requiring sudo must prepend this
00070     sudostr = "echo %s | sudo -S " % args.fetch_password[-1]
00071 
00072     commands.update({"robot_log":sudostr + "cat /var/log/upstart/robot.log"})
00073 
00074     print 'Running debug snapshot tool.'
00075     dirpath = tempfile.mkdtemp()
00076 
00077     # Start bag recording
00078     bag_process = ['rosbag', 'record', '-q', '--duration=10', '-j',
00079                    '-O', bagname] + topics
00080     bag = subprocess.Popen(bag_process, cwd=dirpath, stdout=devnull)
00081 
00082     # Record version file
00083     with open(dirpath + '/version.txt', 'w') as version_file:
00084         version_file.write(snapshot_version)
00085 
00086     # Execute remote commands on robot
00087     for key, value in commands.iteritems():
00088         print "Creating '%s.txt'." % key
00089         ssh('fetch', args.robot, value, fname=dirpath + '/' + key,
00090             password=args.fetch_password[-1])
00091 
00092     print 'Waiting for data gathering to complete'
00093 
00094     # Wait for the rosbag record parent process to exit cleanly
00095     bag.wait()
00096 
00097     # Zip directory
00098     timestr = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
00099     filename = args.robot + fileroot + timestr + '.zip'
00100 
00101     print 'Data gathering complete creating %s' % filename
00102     proc = subprocess.Popen(["zip", "-r", filename, dirpath],
00103                             stdout=devnull,
00104                             stderr=devnull)
00105     proc.wait()
00106 
00107     # remove temp directory
00108     shutil.rmtree(dirpath)
00109 
00110     if proc.returncode == 0:
00111         print "Created %s" % filename
00112     else:
00113         print "ERROR: failed to zip directory: %s" % dirpath
00114 
00115 def add_arguments(parser):
00116     parser.add_argument(
00117         "--fetch-password", nargs="?", action="append", default=["robotics"],
00118         help="Password for the fetch account (or blank to prompt)"
00119     )
00120     add_robot(parser)


fetch_tools
Author(s): Alex Henning
autogenerated on Thu Jun 6 2019 21:10:20