Example #1
0
    def test_Master(self):
        from roslaunch.core import Master
        old_env = os.environ.get('ROS_MASTER_URI', None)
        try:
            os.environ['ROS_MASTER_URI'] = 'http://foo:789'
            m = Master()
            self.assertEquals(m.type, Master.ROSMASTER)
            self.assertEquals(m.uri, 'http://foo:789')
            self.assertEquals(m, m)
            self.assertEquals(m, Master())
            
            m = Master(Master.ROSMASTER, 'http://foo:1234')
            self.assertEquals(m.type, Master.ROSMASTER)
            self.assertEquals(m.uri, 'http://foo:1234')
            self.assertEquals(m, m)
            self.assertEquals(m, Master(Master.ROSMASTER, 'http://foo:1234'))

            import xmlrpclib
            self.assert_(isinstance(m.get(), xmlrpclib.ServerProxy))
            m.uri = 'http://foo:567'
            self.assertEquals(567, m.get_port())
            self.failIf(m.is_running())

        finally:
            if old_env is None:
                del os.environ['ROS_MASTER_URI']
            else:
                os.environ['ROS_MASTER_URI'] = old_env
Example #2
0
    def test_validate_master_launch(self):
        import roslaunch.launch
        from roslaunch.core import Master
        from roslaunch.launch import validate_master_launch
        roslaunch.launch.printerrlog = self.my_printerrlog

        # Good configurations
        os.environ['ROS_MASTER_URI'] = 'http://localhost:11311'
        m = Master(uri='http://localhost:11311')
        validate_master_launch(m, True)
        self.assertEquals(None, self.printerrlog_msg)
        validate_master_launch(m, False)
        self.assertEquals(None, self.printerrlog_msg)

        # roscore with mismatched port in environment
        os.environ['ROS_MASTER_URI'] = 'http://localhost:11312'
        validate_master_launch(m, True)
        self.assert_('port' in self.printerrlog_msg)
        self.printerrlog_msg = None

        # roscore with mismatched hostname in environment
        os.environ['ROS_MASTER_URI'] = 'http://fake:11311'
        validate_master_launch(m, True)
        self.assert_('host' in self.printerrlog_msg)
        self.printerrlog_msg = None

        # roslaunch with remote master that cannot be contacted
        os.environ['ROS_MASTER_URI'] = 'http://fake:11311'
        self.assertEquals(None, self.printerrlog_msg)

        # environment doesn't matter for remaining tests
        os.environ['ROS_MASTER_URI'] = 'http://localhost:11311'
        m = Master(uri="http://fake:11311")

        # roscore with hostname that points elsewhere, warn user. This
        # generally could only happen if the user has a bad local host
        # config.
        validate_master_launch(m, True)
        self.assert_("WARNING" in self.printerrlog_msg)
        self.printerrlog_msg = None

        # roscore with host that is not ours
        m = Master(uri="http://willowgarage.com:11311")
        validate_master_launch(m, True)
        self.assert_("WARNING" in self.printerrlog_msg)
        self.printerrlog_msg = None

        # roslaunch with remote master that is out of contact, fail
        try:
            validate_master_launch(m, False)
            self.fail("should not pass if remote master cannot be contacted")
        except roslaunch.RLException:
            pass
Example #3
0
def test_Master():
    from roslaunch.core import Master
    # can't verify value of is_running for actual master
    m = Master(uri='http://localhost:11311')
    assert m.type == Master.ROSMASTER
    m.get_host() == 'localhost'
    m.get_port() == 11311
    assert m.is_running() in [True, False]
    assert isinstance(m.get(), ServerProxy)
    assert isinstance(m.get_multi(), MultiCall)

    m = Master(uri='http://badhostname:11312')
    m.get_host() == 'badhostname'
    m.get_port() == 11312
    assert m.is_running() == False
Example #4
0
    def __init__(self):
        """
        Initialize an empty config object. Master defaults to the environment's master.
        """
        self.master = Master()
        self.nodes_core = []
        self.nodes = []  #nodes are unnamed

        # list of resolved node names. This is so that we can check for naming collisions
        self.resolved_node_names = []

        self.tests = []
        self.machines = {}  #key is name
        self.params = {}  #key is name
        self.clear_params = []
        self.executables = []

        # for tools like roswtf
        self.config_errors = []

        m = local_machine()  #for local exec
        self.machines[m.name] = m
        self._assign_machines_complete = False
        self._remote_nodes_present = None

        self.logger = logging.getLogger('roslaunch')
Example #5
0
    def create_master(self, type_, uri, auto_str):
        """
        @param type_: type attribute or None if type attribute not provided
        @type  type_: str
        @param uri: URI attribute or None if not specified
        @type  uri: str
        @param auto_str: auto attribute or None if not provided
        @type  auto_str: str
        @raise ValueError: if parameters cannot be processed into valid Master
        """
        if type_ is not None and type_.strip() == '':
            raise ValueError("'type' must be non-empty")

        try:  # auto attribute
            auto_str = (auto_str or 'no').lower().strip()
            auto = _master_auto[auto_str]
        except KeyError:
            raise ValueError("invalid <master> 'auto' value: %s" % auto_str)

        # TODO: URI validation
        return Master(type_=type_, uri=uri, auto=auto)
Example #6
0
    def test_Master(self):
        from roslaunch.core import Master
        old_env = os.environ.get('ROS_MASTER_URI', None)
        try:
            os.environ['ROS_MASTER_URI'] = 'http://foo:789'
            m = Master()
            self.assertEquals(m.type, Master.ROSMASTER)
            self.assertEquals(m.uri, 'http://foo:789')
            self.assertEquals(m.auto, Master.AUTO_NO)
            self.assertEquals(m.log_output, False)
            self.assertEquals(m, m)
            self.assertEquals(m, Master())

            m = Master(Master.ROSMASTER, 'http://foo:1234', Master.AUTO_START)
            self.assertEquals(m.type, Master.ROSMASTER)
            self.assertEquals(m.uri, 'http://foo:1234')
            self.assertEquals(m.auto, Master.AUTO_START)
            self.assertEquals(m.log_output, False)
            self.assertEquals(m, m)
            self.assertEquals(
                m,
                Master(Master.ROSMASTER, 'http://foo:1234', Master.AUTO_START))

            import xmlrpclib
            self.assert_(isinstance(m.get(), xmlrpclib.ServerProxy))
            m.set_port(567)
            self.assertEquals(m.uri, 'http://foo:567/')
            self.failIf(m.is_running())

            try:
                m = Master(Master.ROSMASTER, 'http://foo:1234', False)
                self.fail("should have failed on invalid auto value")
            except:
                pass
            try:
                m = Master(Master.ROSMASTER, 'http://foo:1234', 123)
                self.fail("should have failed on invalid auto value")
            except:
                pass

        finally:
            if old_env is None:
                del os.environ['ROS_MASTER_URI']
            else:
                os.environ['ROS_MASTER_URI'] = old_env