Ejemplo n.º 1
0
def probe_all_services(ctx):
    master = rosgraph.Master('/roswtf')
    errors = []
    for service_name in ctx.services:
        try:
            service_uri = master.lookupService(service_name)
        except:
            ctx.errors.append(
                WtfError("cannot contact ROS Master at %s" %
                         rosgraph.rosenv.get_master_uri()))
            raise WtfException(
                "roswtf lost connection to the ROS Master at %s" %
                rosgraph.rosenv.get_master_uri())

        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 rosgraph.network.ROSHandshakeException as e:
            errors.append("service [%s] appears to be malfunctioning" %
                          service_name)
        except Exception as e:
            errors.append("service [%s] appears to be malfunctioning: %s" %
                          (service_name, e))
    return errors
Ejemplo n.º 2
0
    def test_get_service_headers(self):
        import rosservice
        orig_uri = os.environ['ROS_MASTER_URI']
        os.environ['ROS_MASTER_URI'] = 'http://fake_host:12356'
        try:
            c = 'rosservice'

            # test error conditions, integration tests cover success cases
            try:
                rosservice.get_service_headers('/add_two_ints', 'fake://localhost:1234')
                self.fail("should have raised")
            except rosservice.ROSServiceException: pass
            try:
                rosservice.get_service_headers('/add_two_ints', 'rosrpc://fake_host:1234')
                self.fail("should have raised IO exc")
            except rosservice.ROSServiceIOException: pass
            
        
        finally:
            os.environ['ROS_MASTER_URI'] = orig_uri
    def test_get_service_headers(self):
        import rosservice
        orig_uri = os.environ['ROS_MASTER_URI']
        os.environ['ROS_MASTER_URI'] = 'http://fake_host:12356'
        try:
            c = 'rosservice'

            # test error conditions, integration tests cover success cases
            try:
                rosservice.get_service_headers('/add_two_ints', 'fake://localhost:1234')
                self.fail("should have raised")
            except rosservice.ROSServiceException: pass
            try:
                rosservice.get_service_headers('/add_two_ints', 'rosrpc://fake_host:1234')
                self.fail("should have raised IO exc")
            except rosservice.ROSServiceIOException: pass
            
        
        finally:
            os.environ['ROS_MASTER_URI'] = orig_uri
Ejemplo n.º 4
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))
Ejemplo n.º 5
0
def generateReportSrviceCalls(service,serviceArguments, serviceArgumentsValues,serviceReturns,serviceReturnsValues, client):
    x = rosservice.get_service_headers(service,rosservice.get_service_uri(service))
    toReturn = {'srv':str(x['type']), 'client':client, 'server':str(rosservice.get_service_node(service)), 'service_name': service}

    reqSubReport = []
    respSubReport = {}
    for x in range (0,len(serviceArguments)):
        reqSubReport.append(str(serviceArgumentsValues[x]))
    # for x in range (0, len(serviceReturns)):
    #     if service in serviceExpeptions:
    #         respSubReport['ExtendedReport'] = 'ExtendedReport'
    #         break
    #     respSubReport[str(serviceReturns[x])] = str(serviceReturnsValues[x])
    toReturn['req'] = ','.join(reqSubReport)
    #toReturn['resp'] = respSubReport
    return toReturn
Ejemplo n.º 6
0
def generateReportSrviceCalls(service,serviceArguments, serviceArgumentsValues,serviceReturns,serviceReturnsValues, client):
    x = rosservice.get_service_headers(service,rosservice.get_service_uri(service))
    toReturn = {'srv':str(x['type']), 'client':client, 'server':str(rosservice.get_service_node(service)), 'service_name': service}

    reqSubReport = []
    respSubReport = {}
    for x in range (0,len(serviceArguments)):
        reqSubReport.append(str(serviceArgumentsValues[x]))
    # for x in range (0, len(serviceReturns)):
    #     if service in serviceExpeptions:
    #         respSubReport['ExtendedReport'] = 'ExtendedReport'
    #         break
    #     respSubReport[str(serviceReturns[x])] = str(serviceReturnsValues[x])
    toReturn['req'] = ','.join(reqSubReport)
    #toReturn['resp'] = respSubReport
    return toReturn
Ejemplo n.º 7
0
def probe_all_services(ctx):
    master = rosgraph.Master('/roswtf')
    errors = []
    for service_name in ctx.services:
        try:
            service_uri = master.lookupService(service_name)
        except:
            ctx.errors.append(WtfError("cannot contact ROS Master at %s"%rosgraph.rosenv.get_master_uri()))
            raise WtfException("roswtf lost connection to the ROS Master at %s"%rosgraph.rosenv.get_master_uri())
        
        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 rosgraph.network.ROSHandshakeException as e:
            errors.append("service [%s] appears to be malfunctioning"%service_name)
        except Exception as e:
            errors.append("service [%s] appears to be malfunctioning: %s"%(service_name, e))
    return errors
Ejemplo n.º 8
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))
Ejemplo n.º 9
0
def find_service(service_type,
                 timeout=rospy.rostime.Duration(5.0),
                 unique=False):
    '''
    Do a lookup to find services of the type
    specified. This will raise exceptions if it times out or returns
    multiple values. It can apply the additional logic of whether this should
    return a single unique result, or a list. Under the hood this calls out to the ros master for a list
    of registered services and it parses that to determine the result. If nothing
    is found, it loops around internally on a 10Hz loop until the result is
    found or the specified timeout is reached.

    Usage:

    .. code-block:: python

        from rocon_python_comms import find_service

        try:
            service_name = rocon_python_comms.find_service('rocon_interaction_msgs/SetInteractions',
                                                           timeout=rospy.rostime.Duration(15.0),
                                                           unique=True)
        except rocon_python_comms.NotFoundException as e:
            rospy.logwarn("failed to find the set_interactions service.")

    :param str service_type: service type specification, e.g. concert_msgs/GetInteractions
    :param rospy.Duration timeout: raise an exception if nothing is found before this timeout occurs.
    :param bool unique: flag to select the lookup behaviour (single/multiple results)

    :returns: the fully resolved name of the service (unique) or list of names (non-unique)
    :rtype: str

    :raises: :exc:`.NotFoundException`
    '''
    # we could use rosservice_find here, but that throws exceptions and aborts if it comes
    # across any rosservice on the system which is no longer valid. To be robust against this
    # I've just pulled the internals of rosservice_find (ugh its fugly) and replicated it here
    # with the only difference in that I continue over that exception.
    unique_service_name = None
    service_names = []
    timeout_time = time.time() + timeout.to_sec()
    master = rosgraph.Master(rospy.get_name())
    while not rospy.is_shutdown(
    ) and time.time() < timeout_time and not service_names:
        services_information = []
        try:
            _, _, services = master.getSystemState()
            for service_name, unused_node_name in services:
                service_uri = master.lookupService(service_name)
                services_information.append((service_name, service_uri))
        except (rosgraph.masterapi.Error, rosgraph.masterapi.Failure,
                socket.error) as e:
            raise NotFoundException(
                "unable to communicate with the master [%s]" % str(e))
        for (service_name, service_uri) in services_information:
            try:
                next_service_type = get_service_headers(
                    service_name, service_uri).get('type', None)
            except ROSServiceIOException:  # should also catch socket.error?
                # ignore this - it is usually a sign of a bad service that could be thrown
                # up by somebody else and not what we're trying to find. If we can skip past it
                # here we can be robust to other people's problems.
                continue
            if next_service_type == service_type:
                service_names.append(service_name)
        if unique:
            if len(service_names) > 1:
                raise NotFoundException("multiple services found %s." %
                                        service_names)
            elif len(service_names) == 1:
                unique_service_name = service_names[0]
        if not service_names:
            rospy.rostime.wallsleep(0.1)
    if not service_names:
        raise NotFoundException("timed out")

    return unique_service_name if unique_service_name else service_names
Ejemplo n.º 10
0
def find_service(service_type, timeout=rospy.rostime.Duration(5.0), unique=False):
    '''
    Do a lookup to find services of the type
    specified. This will raise exceptions if it times out or returns
    multiple values. It can apply the additional logic of whether this should
    return a single unique result, or a list. Under the hood this calls out to the ros master for a list
    of registered services and it parses that to determine the result. If nothing
    is found, it loops around internally on a 10Hz loop until the result is
    found or the specified timeout is reached.

    Usage:

    .. code-block:: python

        from rocon_python_comms import find_service

        try:
            service_name = rocon_python_comms.find_service('rocon_interaction_msgs/SetInteractions',
                                                           timeout=rospy.rostime.Duration(15.0),
                                                           unique=True)
        except rocon_python_comms.NotFoundException as e:
            rospy.logwarn("failed to find the set_interactions service.")

    :param str service_type: service type specification, e.g. concert_msgs/GetInteractions
    :param rospy.Duration timeout: raise an exception if nothing is found before this timeout occurs.
    :param bool unique: flag to select the lookup behaviour (single/multiple results)

    :returns: the fully resolved name of the service (unique) or list of names (non-unique)
    :rtype: str

    :raises: :exc:`.NotFoundException`
    '''
    # we could use rosservice_find here, but that throws exceptions and aborts if it comes
    # across any rosservice on the system which is no longer valid. To be robust against this
    # I've just pulled the internals of rosservice_find (ugh its fugly) and replicated it here
    # with the only difference in that I continue over that exception.
    unique_service_name = None
    service_names = []
    timeout_time = time.time() + timeout.to_sec()
    master = rosgraph.Master(rospy.get_name())
    while not rospy.is_shutdown() and time.time() < timeout_time and not service_names:
        services_information = []
        try:
            _, _, services = master.getSystemState()
            for service_name, unused_node_name in services:
                service_uri = master.lookupService(service_name)
                services_information.append((service_name, service_uri))
        except (rosgraph.masterapi.Error, rosgraph.masterapi.Failure, socket.error) as e:
            raise NotFoundException("unable to communicate with the master [%s]" % str(e))
        for (service_name, service_uri) in services_information:
            try:
                next_service_type = get_service_headers(service_name, service_uri).get('type', None)
            except ROSServiceIOException:  # should also catch socket.error?
                # ignore this - it is usually a sign of a bad service that could be thrown
                # up by somebody else and not what we're trying to find. If we can skip past it
                # here we can be robust to other people's problems.
                continue
            if next_service_type == service_type:
                service_names.append(service_name)
        if unique:
            if len(service_names) > 1:
                raise NotFoundException("multiple services found %s." % service_names)
            elif len(service_names) == 1:
                unique_service_name = service_names[0]
        if not service_names:
            rospy.rostime.wallsleep(0.1)
    if not service_names:
        raise NotFoundException("timed out")

    return unique_service_name if unique_service_name else service_names