Beispiel #1
0
    def relaunch_nodes(self):
        succeeded = []
        failed = []
        api = self.getapi()
        if self.nodes_xml is not None:
            try:
                _logger.debug("sending [%s] XML [\n%s\n]" %
                              (self.uri, self.nodes_xml))
                code, msg, val = api.launch(self.nodes_xml)
                if code == 1:
                    c_succ, c_fail = val
                    succeeded.extend(c_succ)
                    failed.extend(c_fail)
                else:
                    printerrlog('error launching on [%s, uri %s]: %s' %
                                (self.name, self.uri, msg))
            except socket.error as e:
                errno, msg = e
                printerrlog('error launching on [%s, uri %s]: %s' %
                            (self.name, self.uri, str(msg)))
            except socket.gaierror as e:
                errno, msg = e
                # usually errno == -2. See #815.
                child_host, _ = network.parse_http_host_and_port(self.uri)
                printerrlog(
                    "Unable to contact remote roslaunch at [%s]. This is most likely due to a network misconfiguration with host lookups. Please make sure that you can contact '%s' from this machine"
                    % (child.uri, child_host))

            except Exception as e:
                printerrlog('error launching on [%s, uri %s]: %s' %
                            (self.name, self.uri, str(e)))
        else:
            _logger.error("xml provided is not defined")
Beispiel #2
0
    def __init__(self, run_id, name, server_uri, pm, sigint_timeout=DEFAULT_TIMEOUT_SIGINT, sigterm_timeout=DEFAULT_TIMEOUT_SIGTERM):
        """
        @param server_uri: XML-RPC URI of server
        @type  server_uri: str
        @param pm: process monitor to use
        @type  pm: L{ProcessMonitor}
        @param sigint_timeout: The SIGINT timeout used when killing nodes (in seconds).
        @type  sigint_timeout: float
        @param sigterm_timeout: The SIGTERM timeout used when killing nodes if SIGINT does not stop the node (
                                in seconds).
        @type  sigterm_timeout: float
        @raise RLException: If parameters are invalid
        """            
        super(ROSLaunchChildHandler, self).__init__(pm)        
        if server_uri is None:
            raise RLException("server_uri is not initialized")
        self.run_id = run_id
        
        # parse the URI to make sure it's valid
        _, urlport = network.parse_http_host_and_port(server_uri)
        if urlport <= 0:
            raise RLException("ERROR: roslaunch server URI is not a valid XML-RPC URI. Value is [%s]"%m.uri)

        self.name = name
        self.pm = pm
        self.server_uri = server_uri
        self.sigint_timeout = sigint_timeout
        self.sigterm_timeout = sigterm_timeout
        self.server = ServerProxy(server_uri)
Beispiel #3
0
    def launch_remote_nodes(self):
        """
        Contact each child to launch remote nodes
        """
        succeeded = []
        failed = []
        
        # initialize remote_nodes. we use the machine config key as
        # the key for the dictionary so that we can bin the nodes.
        self.remote_nodes = {}
        for m in self.machine_list:
            self.remote_nodes[m.config_key()] = []
            
        # build list of nodes that will be launched by machine
        nodes = [x for x in self.rosconfig.nodes if not is_machine_local(x.machine)]
        for n in nodes:
            self.remote_nodes[n.machine.config_key()].append(n)
            
        for child in self.remote_processes:
            nodes = self.remote_nodes[child.machine.config_key()]
            body = '\n'.join([n.to_remote_xml() for n in nodes])
            # #3799: force utf-8 encoding 
            xml = '<?xml version="1.0" encoding="utf-8"?>\n<launch>\n%s</launch>'%body 
                
            api = child.getapi()
            # TODO: timeouts
            try:
                self.logger.debug("sending [%s] XML [\n%s\n]"%(child.uri, xml))
                code, msg, val = api.launch(xml)
                if code == 1:
                    c_succ, c_fail = val
                    succeeded.extend(c_succ)
                    failed.extend(c_fail)
                else:
                    printerrlog('error launching on [%s, uri %s]: %s'%(child.name, child.uri, msg))
                    self._assume_failed(nodes, failed)
            except socket.error as e:
                errno, msg = e
                printerrlog('error launching on [%s, uri %s]: %s'%(child.name, child.uri, str(msg)))
                self._assume_failed(nodes, failed)

            except socket.gaierror as e:
                errno, msg = e
                # usually errno == -2. See #815. 
                child_host, _ = network.parse_http_host_and_port(child.uri)
                printerrlog("Unable to contact remote roslaunch at [%s]. This is most likely due to a network misconfiguration with host lookups. Please make sure that you can contact '%s' from this machine"%(child.uri, child_host))
                self._assume_failed(nodes, failed)

            except Exception as e:
                printerrlog('error launching on [%s, uri %s]: %s'%(child.name, child.uri, str(e)))
                self._assume_failed(nodes, failed)

        return succeeded, failed
 def test_parse_http_host_and_port(self):
     from rosgraph.network import parse_http_host_and_port
     invalid = ['', 'http://', 'http://localhost:bar', None]
     for t in invalid:
         try:
             parse_http_host_and_port(t)
             assert False, "should have failed: %s"%t
         except ValueError:
             pass
 
     assert ('localhost', 80) == parse_http_host_and_port('http://localhost')
     assert ('localhost', 1234) == parse_http_host_and_port('http://localhost:1234')
     assert ('localhost', 1) == parse_http_host_and_port('http://localhost:1')
     assert ('willowgarage.com', 1) == parse_http_host_and_port('http://willowgarage.com:1')
Beispiel #5
0
    def __init__(self, run_id, name, server_uri, pm):
        """
        @param server_uri: XML-RPC URI of server
        @type  server_uri: str
        @param pm: process monitor to use
        @type  pm: L{ProcessMonitor}
        @raise RLException: If parameters are invalid
        """            
        super(ROSLaunchChildHandler, self).__init__(pm)        
        if server_uri is None:
            raise RLException("server_uri is not initialized")
        self.run_id = run_id
        
        # parse the URI to make sure it's valid
        _, urlport = network.parse_http_host_and_port(server_uri)
        if urlport <= 0:
            raise RLException("ERROR: roslaunch server URI is not a valid XML-RPC URI. Value is [%s]"%m.uri)

        self.name = name
        self.pm = pm
        self.server_uri = server_uri
        self.server = ServerProxy(server_uri)
Beispiel #6
0
    def __init__(self, run_id, name, server_uri, pm):
        """
        @param server_uri: XML-RPC URI of server
        @type  server_uri: str
        @param pm: process monitor to use
        @type  pm: L{ProcessMonitor}
        @raise RLException: If parameters are invalid
        """            
        super(ROSLaunchChildHandler, self).__init__(pm)        
        if server_uri is None:
            raise RLException("server_uri is not initialized")
        self.run_id = run_id
        
        # parse the URI to make sure it's valid
        _, urlport = network.parse_http_host_and_port(server_uri)
        if urlport <= 0:
            raise RLException("ERROR: roslaunch server URI is not a valid XML-RPC URI. Value is [%s]"%m.uri)

        self.name = name
        self.pm = pm
        self.server_uri = server_uri
        self.server = ServerProxy(server_uri)
Beispiel #7
0
    def test_parse_http_host_and_port(self):
        from rosgraph.network import parse_http_host_and_port
        invalid = ['', 'http://', 'http://localhost:bar', None]
        for t in invalid:
            try:
                parse_http_host_and_port(t)
                assert False, "should have failed: %s" % t
            except ValueError:
                pass

        assert ('localhost',
                80) == parse_http_host_and_port('http://localhost')
        assert ('localhost',
                1234) == parse_http_host_and_port('http://localhost:1234')
        assert ('localhost',
                1) == parse_http_host_and_port('http://localhost:1')
        assert ('willowgarage.com',
                1) == parse_http_host_and_port('http://willowgarage.com:1')
        assert ('FEDC:BA98:7654:3210:FEDC:BA98:7654:3210'.lower(),
                81) == parse_http_host_and_port(
                    'http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:81')
Beispiel #8
0
    def launch_remote_nodes(self):
        """
        Contact each child to launch remote nodes
        """
        succeeded = []
        failed = []

        # initialize remote_nodes. we use the machine config key as
        # the key for the dictionary so that we can bin the nodes.
        self.remote_nodes = {}
        for m in self.machine_list:
            self.remote_nodes[m.config_key()] = []

        # build list of nodes that will be launched by machine
        nodes = [
            x for x in self.rosconfig.nodes if not is_machine_local(x.machine)
        ]
        for n in nodes:
            self.remote_nodes[n.machine.config_key()].append(n)

        for child in self.remote_processes:
            nodes = self.remote_nodes[child.machine.config_key()]
            body = '\n'.join([n.to_remote_xml() for n in nodes])
            # #3799: force utf-8 encoding
            xml = '<?xml version="1.0" encoding="utf-8"?>\n<launch>\n%s</launch>' % body

            api = child.getapi()
            # TODO: timeouts
            try:
                self.logger.debug("sending [%s] XML [\n%s\n]" %
                                  (child.uri, xml))
                code, msg, val = api.launch(xml)
                if code == 1:
                    c_succ, c_fail = val
                    succeeded.extend(c_succ)
                    failed.extend(c_fail)
                else:
                    printerrlog('error launching on [%s, uri %s]: %s' %
                                (child.name, child.uri, msg))
                    self._assume_failed(nodes, failed)
            except socket.error as e:
                errno, msg = e
                printerrlog('error launching on [%s, uri %s]: %s' %
                            (child.name, child.uri, str(msg)))
                self._assume_failed(nodes, failed)

            except socket.gaierror as e:
                errno, msg = e
                # usually errno == -2. See #815.
                child_host, _ = network.parse_http_host_and_port(child.uri)
                printerrlog(
                    "Unable to contact remote roslaunch at [%s]. This is most likely due to a network misconfiguration with host lookups. Please make sure that you can contact '%s' from this machine"
                    % (child.uri, child_host))
                self._assume_failed(nodes, failed)

            except Exception as e:
                printerrlog('error launching on [%s, uri %s]: %s' %
                            (child.name, child.uri, str(e)))
                self._assume_failed(nodes, failed)

        return succeeded, failed
Beispiel #9
0
 def test_create_local_xmlrpc_uri(self):
     from rosgraph.network import parse_http_host_and_port, create_local_xmlrpc_uri
     os.environ['ROS_HOSTNAME'] = 'localhost'
     assert ('localhost', 1234) == parse_http_host_and_port(
         create_local_xmlrpc_uri(1234))
 def test_create_local_xmlrpc_uri(self):
     from rosgraph.network import parse_http_host_and_port, create_local_xmlrpc_uri
     os.environ['ROS_HOSTNAME'] = 'localhost'    
     assert ('localhost', 1234) == parse_http_host_and_port(create_local_xmlrpc_uri(1234))