Exemple #1
0
    def run(self):
        ctx = self.ctx
        master = self.master
        actual_edges = self.actual_edges
        lock = self.lock
        n = self.n

        try:
            socket.setdefaulttimeout(3.0)
            node_api = rosnode.get_api_uri(master, n)
            if not node_api:
                ctx.errors.append(WtfError("Master does not have lookup information for node [%s]"%n))
                return
                
            node = xmlrpclib.ServerProxy(node_api)
            start = time.time()
            socket.setdefaulttimeout(3.0)            
            code, msg, bus_info = node.getBusInfo('/roswtf')
            end = time.time()
            with lock:
                if (end-start) > 1.:
                    ctx.warnings.append(WtfWarning("Communication with node [%s] is very slow"%n))
                if code != 1:
                    ctx.warnings.append(WtfWarning("Node [%s] would not return bus info"%n))
                elif not bus_info:
                    if not n in ctx.service_providers:
                        ctx.warnings.append(WtfWarning("Node [%s] is not connected to anything"%n))
                else:
                    edges = _businfo(ctx, n, bus_info)
                    actual_edges.extend(edges)
        except socket.error, e:
            pass #ignore as we have rules to catch this
Exemple #2
0
def _compute_system_state(ctx):
    socket.setdefaulttimeout(3.0)
    master = roslib.scriptutil.get_master()

    # store system state
    code, msg, val = master.getSystemState('/roswtf')
    if code != 1:
        return
    ctx.system_state = val

    pubs, subs, srvs = val
    
    # compute list of topics and services
    topics = []
    for t, _ in itertools.chain(pubs, subs):
        topics.append(t)
    services = []
    service_providers = []
    for s, l in srvs:
        services.append(s)
        service_providers.extend(l)
    ctx.topics = topics
    ctx.services = services
    ctx.service_providers = service_providers

    # compute list of nodes
    nodes = []
    for s in val:
        for t, l in s:
            nodes.extend(l)
    ctx.nodes = list(set(nodes)) #uniq

    # - compute reverse mapping of URI->nodename
    count = 0
    start = time.time()
    for n in ctx.nodes:
        count += 1
        try:
            code, msg, val = master.lookupNode('/roswtf', n)
        except socket.error:
            ctx.errors.append(WtfError("cannot contact ROS Master at %s"%roslib.rosenv.get_master_uri()))
            raise WtfException("roswtf lost connection to the ROS Master at %s"%roslib.rosenv.get_master_uri())
        if code == 1:
            ctx.uri_node_map[val] = n
        else:
            ctx.warnings.append(WtfWarning("Inconsistent state on master for node [%s]"%n))
    end = time.time()
    # - time thresholds currently very arbitrary
    if count:
        if ((end - start) / count) > 1.:
            ctx.warnings.append(WtfError("Communication with master is very slow (>1s average)"))        
        elif (end - start) / count > .5:
            ctx.warnings.append(WtfWarning("Communication with master is very slow (>0.5s average)")) 
Exemple #3
0
def probe_all_services(ctx):
    master = roslib.scriptutil.get_master()
    errors = []
    for service_name in ctx.services:
        code, msg, service_uri = master.lookupService('/rosservice', service_name)
        if code != 1:
            ctx.warnings.append(WtfWarning("Unable to lookup service [%s]"%service_name))
        else:
            try:
                headers = rosservice.get_service_headers(service_name, service_uri)
                if not headers:
                    errors.append("service [%s] did not return service headers"%service_name)
            except roslib.network.ROSHandshakeException, e:
                errors.append("service [%s] appears to be malfunctioning"%service_name)
            except Exception, e:
                errors.append("service [%s] appears to be malfunctioning: %s"%(service_name, e))
Exemple #4
0
def probe_all_services(ctx):
    master = roslib.scriptutil.get_master()
    errors = []
    for service_name in ctx.services:
        try:
            code, msg, service_uri = master.lookupService('/rosservice', service_name)
        except:
            ctx.errors.append(WtfError("cannot contact ROS Master at %s"%roslib.rosenv.get_master_uri()))
            raise WtfException("roswtf lost connection to the ROS Master at %s"%roslib.rosenv.get_master_uri())
        
        if code != 1:
            ctx.warnings.append(WtfWarning("Unable to lookup service [%s]"%service_name))
        else:
            try:
                headers = rosservice.get_service_headers(service_name, service_uri)
                if not headers:
                    errors.append("service [%s] did not return service headers"%service_name)
            except roslib.network.ROSHandshakeException, e:
                errors.append("service [%s] appears to be malfunctioning"%service_name)
            except Exception, e:
                errors.append("service [%s] appears to be malfunctioning: %s"%(service_name, e))