Example #1
0
    def test_create_master_process2(self):
        # accidentally wrote two versions of this, need to merge
        from roslaunch.core import Master, RLException
        import roslib.rosenv
        from roslaunch.nodeprocess import create_master_process

        ros_root = roslib.rosenv.get_ros_root()

        # test failures
        failed = False
        try:
            create_master_process('runid-unittest',
                                  Master.ROSMASTER,
                                  roslib.rosenv.get_ros_root(),
                                  0,
                                  log_output=True)
            failed = True
        except RLException:
            pass
        self.failIf(failed, "invalid port should have triggered error")

        # test success with ROSMASTER
        m1 = create_master_process('runid-unittest',
                                   Master.ROSMASTER,
                                   ros_root,
                                   1234,
                                   log_output=True)
        self.assertEquals('runid-unittest', m1.run_id)
        self.assertEquals(True, m1.log_output)
        self.failIf(m1.started)
        self.failIf(m1.stopped)
        self.assertEquals(None, m1.cwd)
        self.assertEquals('master', m1.name)
        master_p = os.path.join(ros_root, 'bin', 'rosmaster')
        self.assert_(master_p in m1.args)
        # - it should have the default environment
        self.assertEquals(os.environ, m1.env)
        #  - check args
        self.assert_('--core' in m1.args)
        # - make sure port arguent is correct
        idx = m1.args.index('-p')
        self.assertEquals('1234', m1.args[idx + 1])

        # test port argument
        m2 = create_master_process('runid-unittest',
                                   Master.ROSMASTER,
                                   ros_root,
                                   1234,
                                   log_output=False)
        self.assertEquals('runid-unittest', m2.run_id)
        self.assertEquals(False, m2.log_output)

        # test ros_root argument as well as log_output default
        m3 = create_master_process('runid-unittest', Master.ROSMASTER,
                                   ros_root, 1234)
        self.assertEquals('runid-unittest', m3.run_id)
        self.assertEquals(False, m3.log_output)
        master_p = os.path.join(ros_root, 'bin', 'rosmaster')
        self.assert_(master_p in m3.args)
Example #2
0
    def test_create_master_process(self):
        from roslaunch.core import Node, Machine, Master, RLException
        from roslaunch.nodeprocess import create_master_process, LocalProcess
        
        ros_root = '/ros/root'
        port = 1234
        type = Master.ROSMASTER
        run_id = 'foo'

        # test invalid params
        try:
            create_master_process(run_id, type, ros_root, -1)
            self.fail("shoud have thrown RLException")
        except RLException: pass
        try:
            create_master_process(run_id, type, ros_root, 10000000)
            self.fail("shoud have thrown RLException")
        except RLException: pass
        try:
            create_master_process(run_id, 'foo', ros_root, port)
            self.fail("shoud have thrown RLException")
        except RLException: pass

        # test valid params
        p = create_master_process(run_id, type, ros_root, port)
        self.assert_(isinstance(p, LocalProcess))
        self.assertEquals(p.args[0], 'rosmaster')
        idx = p.args.index('-p')
        self.failIf(idx < 1)
        self.assertEquals(p.args[idx+1], str(port))
        self.assert_('--core' in p.args)

        self.assertEquals(p.package, 'rosmaster')
        p = create_master_process(run_id, type, ros_root, port)
Example #3
0
    def _launch_master(self):
        """
        Launches master if requested. 
        @return: True if a master was launched, False if a master was
        already running.
        @rtype: bool
        @raise RLException: if master launch fails
        """
        m = self.config.master
        is_running = m.is_running()

        if self.is_core and is_running:
            raise RLException(
                "roscore cannot run as another roscore/master is already running. \nPlease kill other roscore/master processes before relaunching.\nThe ROS_MASTER_URI is %s"
                % (m.uri))

        if not is_running:
            validate_master_launch(m, self.is_core, self.is_rostest)

            printlog("auto-starting new master")
            p = create_master_process(self.run_id, m.type, get_ros_root(),
                                      m.get_port(), self.num_workers,
                                      self.timeout)
            self.pm.register_core_proc(p)
            success = p.start()
            if not success:
                raise RLException("ERROR: unable to auto-start master process")
            timeout_t = time.time() + _TIMEOUT_MASTER_START
            while not m.is_running() and time.time() < timeout_t:
                time.sleep(0.1)

        if not m.is_running():
            raise RLException("ERROR: could not contact master [%s]" % m.uri)

        printlog_bold("ROS_MASTER_URI=%s" % m.uri)
        # TODO: although this dependency doesn't cause anything bad,
        # it's still odd for launch to know about console stuff. This
        # really should be an event.
        update_terminal_name(m.uri)

        # Param Server config params
        param_server = m.get()

        # #773: unique run ID
        self._check_and_set_run_id(param_server, self.run_id)

        if self.server_uri:
            # store parent XML-RPC URI on param server
            # - param name is the /roslaunch/hostname:port so that multiple roslaunches can store at once
            hostname, port = rosgraph.network.parse_http_host_and_port(
                self.server_uri)
            hostname = _hostname_to_rosname(hostname)
            self.logger.info("setting /roslaunch/uris/%s__%s' to %s" %
                             (hostname, port, self.server_uri))
            param_server.setParam(_ID,
                                  '/roslaunch/uris/%s__%s' % (hostname, port),
                                  self.server_uri)

        return not is_running
Example #4
0
    def test_create_master_process2(self):
        # accidentally wrote two versions of this, need to merge
        from roslaunch.core import Master, RLException
        import rospkg
        from roslaunch.nodeprocess import create_master_process

        ros_root = rospkg.get_ros_root()
        
        # test failures
        failed = False
        try:
            create_master_process('runid-unittest', Master.ROSMASTER, rospkg.get_ros_root(), 0)
            failed = True
        except RLException: pass
        self.failIf(failed, "invalid port should have triggered error")

        # test success with ROSMASTER
        m1 = create_master_process('runid-unittest', Master.ROSMASTER, ros_root, 1234)
        self.assertEquals('runid-unittest', m1.run_id)
        self.failIf(m1.started)
        self.failIf(m1.stopped)
        self.assertEquals(None, m1.cwd)
        self.assertEquals('master', m1.name)
        master_p = 'rosmaster'
        self.assert_(master_p in m1.args)
        # - it should have the default environment
        self.assertEquals(os.environ, m1.env)
        #  - check args
        self.assert_('--core' in m1.args)
        # - make sure port arguent is correct
        idx = m1.args.index('-p')
        self.assertEquals('1234', m1.args[idx+1])

        # test port argument
        m2 = create_master_process('runid-unittest', Master.ROSMASTER, ros_root, 1234)
        self.assertEquals('runid-unittest', m2.run_id)

        # test ros_root argument 
        m3 = create_master_process('runid-unittest', Master.ROSMASTER, ros_root, 1234)
        self.assertEquals('runid-unittest', m3.run_id)
        master_p = 'rosmaster'
        self.assert_(master_p in m3.args)
Example #5
0
    def _launch_master(self):
        """
        Launches master if requested. 
        @return: True if a master was launched, False if a master was
        already running.
        @rtype: bool
        @raise RLException: if master launch fails
        """
        m = self.config.master
        is_running = m.is_running()

        if self.is_core and is_running:
            raise RLException("roscore cannot run as another roscore/master is already running. \nPlease kill other roscore/master processes before relaunching.\nThe ROS_MASTER_URI is %s"%(m.uri))

        if not is_running:
            validate_master_launch(m, self.is_core, self.is_rostest)

            printlog("auto-starting new master")
            p = create_master_process(self.run_id, m.type, get_ros_root(), m.get_port(), self.num_workers, self.timeout)
            self.pm.register_core_proc(p)
            success = p.start()
            if not success:
                raise RLException("ERROR: unable to auto-start master process")
            timeout_t = time.time() + _TIMEOUT_MASTER_START
            while not m.is_running() and time.time() < timeout_t:
                time.sleep(0.1)

        if not m.is_running():
            raise RLException("ERROR: could not contact master [%s]"%m.uri)
        
        printlog_bold("ROS_MASTER_URI=%s"%m.uri)
        # TODO: although this dependency doesn't cause anything bad,
        # it's still odd for launch to know about console stuff. This
        # really should be an event.
        update_terminal_name(m.uri)

        # Param Server config params
        param_server = m.get()
        
        # #773: unique run ID
        self._check_and_set_run_id(param_server, self.run_id)

        if self.server_uri:
            # store parent XML-RPC URI on param server
            # - param name is the /roslaunch/hostname:port so that multiple roslaunches can store at once
            hostname, port = rosgraph.network.parse_http_host_and_port(self.server_uri)
            hostname = _hostname_to_rosname(hostname)
            self.logger.info("setting /roslaunch/uris/%s__%s' to %s"%(hostname, port, self.server_uri))
            param_server.setParam(_ID, '/roslaunch/uris/%s__%s'%(hostname, port),self.server_uri)

        return not is_running
Example #6
0
    def test_create_master_process(self):
        from roslaunch.core import Node, Machine, Master, RLException
        from roslaunch.nodeprocess import create_master_process, LocalProcess

        ros_root = '/ros/root'
        port = 1234
        type = Master.ROSMASTER
        run_id = 'foo'

        # test invalid params
        try:
            create_master_process(run_id, type, ros_root, -1)
            self.fail("shoud have thrown RLException")
        except RLException:
            pass
        try:
            create_master_process(run_id, type, ros_root, 10000000)
            self.fail("shoud have thrown RLException")
        except RLException:
            pass
        try:
            create_master_process(run_id, 'foo', ros_root, port)
            self.fail("shoud have thrown RLException")
        except RLException:
            pass

        # test valid params
        p = create_master_process(run_id, type, ros_root, port)
        self.assert_(isinstance(p, LocalProcess))
        self.assertEquals(p.args[0], os.path.join(ros_root, 'bin',
                                                  'rosmaster'))
        idx = p.args.index('-p')
        self.failIf(idx < 1)
        self.assertEquals(p.args[idx + 1], str(port))
        self.assert_('--core' in p.args)

        self.assertEquals(p.package, 'rosmaster')
        self.failIf(p.log_output)

        p = create_master_process(run_id,
                                  type,
                                  ros_root,
                                  port,
                                  log_output=True)
        self.assert_(p.log_output)
Example #7
0
    def test_create_master_process(self):
        from roslaunch.core import Node, Machine, Master, RLException
        from roslaunch.nodeprocess import create_master_process, LocalProcess

        ros_root = '/ros/root'
        port = 1234
        type = Master.ROSMASTER
        run_id = 'foo'

        # test invalid params
        try:
            create_master_process(run_id, type, ros_root, -1)
            self.fail("shoud have thrown RLException")
        except RLException:
            pass
        try:
            create_master_process(run_id, type, ros_root, 10000000)
            self.fail("shoud have thrown RLException")
        except RLException:
            pass
        try:
            create_master_process(run_id, 'foo', ros_root, port)
            self.fail("shoud have thrown RLException")
        except RLException:
            pass

        # test valid params
        p = create_master_process(run_id, type, ros_root, port)
        self.assert_(isinstance(p, LocalProcess))
        self.assertEquals(p.args[0], 'rosmaster')
        idx = p.args.index('-p')
        self.failIf(idx < 1)
        self.assertEquals(p.args[idx + 1], str(port))
        self.assert_('--core' in p.args)

        self.assertEquals(p.package, 'rosmaster')
        p = create_master_process(run_id, type, ros_root, port)

        self.assertEquals(
            create_master_process(run_id,
                                  type,
                                  ros_root,
                                  port,
                                  sigint_timeout=3).sigint_timeout, 3)
        self.assertEquals(
            create_master_process(run_id,
                                  type,
                                  ros_root,
                                  port,
                                  sigint_timeout=1).sigint_timeout, 1)
        self.assertRaises(RLException,
                          create_master_process,
                          run_id,
                          type,
                          ros_root,
                          port,
                          sigint_timeout=0)

        self.assertEquals(
            create_master_process(run_id,
                                  type,
                                  ros_root,
                                  port,
                                  sigterm_timeout=3).sigterm_timeout, 3)
        self.assertEquals(
            create_master_process(run_id,
                                  type,
                                  ros_root,
                                  port,
                                  sigterm_timeout=1).sigterm_timeout, 1)
        self.assertRaises(RLException,
                          create_master_process,
                          run_id,
                          type,
                          ros_root,
                          port,
                          sigterm_timeout=0)
Example #8
0
    def _launch_master(self):
        """
        Launches master if requested. Must be run after L{_setup_master()}.
        @raise RLException: if master launch fails
        """
        m = self.config.master
        auto = m.auto
        is_running = m.is_running()

        if self.is_core and is_running:
            raise RLException(
                "roscore cannot run as another roscore/master is already running. \nPlease kill other roscore/master processes before relaunching.\nThe ROS_MASTER_URI is %s"
                % (m.uri))

        self.logger.debug("launch_master [%s]", auto)
        if auto in [m.AUTO_START, m.AUTO_RESTART] and not is_running:
            if auto == m.AUTO_START:
                printlog(
                    "starting new master (master configured for auto start)")
            elif auto == m.AUTO_RESTART:
                printlog(
                    "starting new master (master configured for auto restart)")

            _, urlport = roslib.network.parse_http_host_and_port(m.uri)
            if urlport <= 0:
                raise RLException(
                    "ERROR: master URI is not a valid XML-RPC URI. Value is [%s]"
                    % m.uri)

            p = create_master_process(self.run_id, m.type, get_ros_root(),
                                      urlport, m.log_output)
            self.pm.register_core_proc(p)
            success = p.start()
            if not success:
                raise RLException("ERROR: unable to auto-start master process")
            timeout_t = time.time() + _TIMEOUT_MASTER_START
            while not m.is_running() and time.time() < timeout_t:
                time.sleep(0.1)

        if not m.is_running():
            raise RLException("ERROR: could not contact master [%s]" % m.uri)

        printlog_bold("ROS_MASTER_URI=%s" % m.uri)
        # TODO: although this dependency doesn't cause anything bad,
        # it's still odd for launch to know about console stuff. This
        # really should be an event.
        update_terminal_name(m.uri)

        # Param Server config params
        param_server = m.get()

        # #773: unique run ID
        self._check_and_set_run_id(param_server, self.run_id)

        if self.server_uri:
            # store parent XML-RPC URI on param server
            # - param name is the /roslaunch/hostname:port so that multiple roslaunches can store at once
            hostname, port = roslib.network.parse_http_host_and_port(
                self.server_uri)
            hostname = _hostname_to_rosname(hostname)
            self.logger.info("setting /roslaunch/uris/%s__%s' to %s" %
                             (hostname, port, self.server_uri))
            param_server.setParam(_ID,
                                  '/roslaunch/uris/%s__%s' % (hostname, port),
                                  self.server_uri)