Package roswtf
[frames] | no frames]

Source Code for Package roswtf

  1  # Software License Agreement (BSD License) 
  2  # 
  3  # Copyright (c) 2009, Willow Garage, Inc. 
  4  # All rights reserved. 
  5  # 
  6  # Redistribution and use in source and binary forms, with or without 
  7  # modification, are permitted provided that the following conditions 
  8  # are met: 
  9  # 
 10  #  * Redistributions of source code must retain the above copyright 
 11  #    notice, this list of conditions and the following disclaimer. 
 12  #  * Redistributions in binary form must reproduce the above 
 13  #    copyright notice, this list of conditions and the following 
 14  #    disclaimer in the documentation and/or other materials provided 
 15  #    with the distribution. 
 16  #  * Neither the name of Willow Garage, Inc. nor the names of its 
 17  #    contributors may be used to endorse or promote products derived 
 18  #    from this software without specific prior written permission. 
 19  # 
 20  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 21  # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 22  # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
 23  # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
 24  # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
 25  # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
 26  # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 27  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 28  # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
 29  # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
 30  # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  # POSSIBILITY OF SUCH DAMAGE. 
 32  # 
 33  # Revision $Id$ 
 34   
 35  """ 
 36  roswtf command-line tool. 
 37  """ 
 38   
 39  from __future__ import print_function 
 40   
 41  import os 
 42  import socket 
 43  import sys 
 44  import traceback 
 45   
 46  import rospkg 
 47  import rosgraph.names 
 48       
49 -def yaml_results(ctx):
50 cd = ctx.as_dictionary() 51 d = {} 52 d['warnings'] = {} 53 d['errors'] = {} 54 wd = d['warnings'] 55 for warn in ctx.warnings: 56 wd[warn.format_msg%cd] = warn.return_val 57 ed = d['warnings'] 58 for err in ctx.warnings: 59 ed[err.format_msg%cd] = err.return_val 60 import yaml 61 print(yaml.dump(d))
62 77 #print("ERROR:", e.msg 78
79 -def roswtf_main():
80 try: 81 import std_msgs.msg 82 import rosgraph_msgs.msg 83 except ImportError: 84 print("ERROR: The core ROS message libraries (std_msgs and rosgraph_msgs) have not been built.") 85 sys.exit(1) 86 87 from roswtf.context import WtfException 88 try: 89 _roswtf_main() 90 except WtfException as e: 91 print(str(e), file=sys.stderr)
92
93 -def _roswtf_main():
94 launch_files = names = None 95 # performance optimization 96 rospack = rospkg.RosPack() 97 all_pkgs = rospack.list() 98 99 import optparse 100 parser = optparse.OptionParser(usage="usage: roswtf [launch file]", description="roswtf is a tool for verifying a ROS installation and running system. Checks provided launchfile if provided, else current stack or package.") 101 # #2268 102 parser.add_option("--all", 103 dest="all_packages", default=False, 104 action="store_true", 105 help="run roswtf against all packages") 106 # #2270 107 parser.add_option("--no-plugins", 108 dest="disable_plugins", default=False, 109 action="store_true", 110 help="disable roswtf plugins") 111 112 parser.add_option("--offline", 113 dest="offline", default=False, 114 action="store_true", 115 help="only run offline tests") 116 117 #TODO: --all-pkgs option 118 options, args = parser.parse_args() 119 if args: 120 launch_files = args 121 if 0: 122 # disable names for now as don't have any rules yet 123 launch_files = [a for a in args if os.path.isfile(a)] 124 names = [a for a in args if not a in launch_files] 125 names = [rosgraph.names.script_resolve_name('/roswtf', n) for n in names] 126 127 from roswtf.context import WtfContext 128 from roswtf.environment import wtf_check_environment, invalid_url, ros_root_check 129 from roswtf.graph import wtf_check_graph 130 import roswtf.rosdep_db 131 import roswtf.py_pip_deb_checks 132 import roswtf.network 133 import roswtf.packages 134 import roswtf.roslaunchwtf 135 import roswtf.stacks 136 import roswtf.plugins 137 if not options.disable_plugins: 138 static_plugins, online_plugins = roswtf.plugins.load_plugins() 139 else: 140 static_plugins, online_plugins = [], [] 141 142 # - do a ros_root check first and abort if it fails as rest of tests are useless after that 143 error = ros_root_check(None, ros_root=os.environ['ROS_ROOT']) 144 if error: 145 print("ROS_ROOT is invalid: "+str(error)) 146 sys.exit(1) 147 148 all_warnings = [] 149 all_errors = [] 150 151 if launch_files: 152 ctx = WtfContext.from_roslaunch(launch_files) 153 #TODO: allow specifying multiple roslaunch files 154 else: 155 curr_package = rospkg.get_package_name('.') 156 if curr_package: 157 print("Package:", curr_package) 158 ctx = WtfContext.from_package(curr_package) 159 #TODO: load all .launch files in package 160 elif os.path.isfile('stack.xml'): 161 curr_stack = os.path.basename(os.path.abspath('.')) 162 print("Stack:", curr_stack) 163 ctx = WtfContext.from_stack(curr_stack) 164 else: 165 print("No package or stack in context") 166 ctx = WtfContext.from_env() 167 if options.all_packages: 168 print("roswtf will run against all packages") 169 ctx.pkgs = all_pkgs 170 171 # static checks 172 wtf_check_environment(ctx) 173 roswtf.rosdep_db.wtf_check(ctx) 174 roswtf.py_pip_deb_checks.wtf_check(ctx) 175 roswtf.network.wtf_check(ctx) 176 roswtf.packages.wtf_check(ctx) 177 roswtf.stacks.wtf_check(ctx) 178 roswtf.roslaunchwtf.wtf_check_static(ctx) 179 for p in static_plugins: 180 p(ctx) 181 182 print("="*80) 183 print("Static checks summary:\n") 184 print_results(ctx) 185 186 # Save static results and start afresh for online checks 187 all_warnings.extend(ctx.warnings) 188 all_errors.extend(ctx.errors) 189 del ctx.warnings[:] 190 del ctx.errors[:] 191 192 # test online 193 print("="*80) 194 195 try: 196 197 if options.offline or not ctx.ros_master_uri or invalid_url(ctx.ros_master_uri) or not rosgraph.is_master_online(): 198 online_checks = False 199 else: 200 online_checks = True 201 if online_checks: 202 online_checks = True 203 print("Beginning tests of your ROS graph. These may take awhile...") 204 205 # online checks 206 wtf_check_graph(ctx, names=names) 207 elif names: 208 # TODO: need to rework this logic 209 print("\nCannot communicate with master, unable to diagnose [%s]"%(', '.join(names))) 210 return 211 else: 212 print("\nROS Master does not appear to be running.\nOnline graph checks will not be run.\nROS_MASTER_URI is [%s]"%(ctx.ros_master_uri)) 213 return 214 215 # spin up a roswtf node so we can subscribe to messages 216 import rospy 217 rospy.init_node('roswtf', anonymous=True) 218 219 online_checks = True 220 roswtf.roslaunchwtf.wtf_check_online(ctx) 221 222 for p in online_plugins: 223 online_checks = True 224 p(ctx) 225 226 if online_checks: 227 # done 228 print("\nOnline checks summary:\n") 229 print_results(ctx) 230 231 except roswtf.context.WtfException as e: 232 print(str(e), file=sys.stderr) 233 print("\nAborting checks, partial results summary:\n") 234 print_results(ctx) 235 except Exception as e: 236 traceback.print_exc() 237 print(str(e), file=sys.stderr) 238 print("\nAborting checks, partial results summary:\n") 239 print_results(ctx)
240 241 #TODO: print results in YAML if run remotely 242 #yaml_results(ctx) 243