def test_remote_node(self):
     """Test that we can access management info of remote nodes using get_mgmt_nodes addresses"""
     nodes = [self.cleanup(Node.connect(Url(r.addresses[0]))) for r in self.routers]
     remotes = sum([n.get_mgmt_nodes() for n in nodes], [])
     self.assertEqual([u'amqp:/_topo/0/router2/$management', u'amqp:/_topo/0/router1/$management'], remotes)
     # Query router2 indirectly via router1
     remote_url = Url(self.routers[0].addresses[0], path=Url(remotes[0]).path)
     remote = self.cleanup(Node.connect(remote_url))
     self.assertEqual(["router2"], [r.id for r in remote.query(type=ROUTER).get_entities()])
 def test_remote_node(self):
     """Test that we can access management info of remote nodes using get_mgmt_nodes addresses"""
     nodes = [self.cleanup(Node.connect(Url(r.addresses[0]))) for r in self.routers]
     remotes = sum([n.get_mgmt_nodes() for n in nodes], [])
     self.assertEqual(set([u'amqp:/_topo/0/router%s/$management' % i for i in [0, 1, 2]]),
                      set(remotes))
     self.assertEqual(9, len(remotes))
     # Query router2 indirectly via router1
     remote_url = Url(self.routers[0].addresses[0], path=Url(remotes[0]).path)
     remote = self.cleanup(Node.connect(remote_url))
     router_id = remotes[0].split("/")[3]
     assert router_id in ['router0', 'router1', 'router2']
     self.assertEqual([router_id], [r.id for r in remote.query(type=ROUTER).get_entities()])
    def test_router_node(self):
        """Test node entity in a trio of linked routers"""
        nodes = [
            self.cleanup(Node.connect(Url(r.addresses[0])))
            for r in self.routers
        ]
        rnode_lists = [n.query(type=NODE).get_dicts() for n in nodes]

        def check(attrs):
            name = attrs['id']
            self.assertEqual(attrs['identity'], 'router.node/%s' % name)
            self.assertEqual(attrs['name'], 'router.node/%s' % name)
            self.assertEqual(attrs['type'],
                             'org.apache.qpid.dispatch.router.node')
            self.assertEqual(attrs['address'], 'amqp:/_topo/0/%s' % name)
            return name

        self.assertEqual({"router0", "router1", "router2"},
                         {check(n)
                          for n in rnode_lists[0]})
        self.assertEqual({"router0", "router1", "router2"},
                         {check(n)
                          for n in rnode_lists[1]})
        self.assertEqual({"router0", "router1", "router2"},
                         {check(n)
                          for n in rnode_lists[2]})
    def test_create_listener(self):
        """Create a new listener on a running router"""

        port = self.get_port()
        # Note qdrouter schema defines port as string not int, since it can be a service name.
        attributes = {
            'name': 'foo',
            'port': str(port),
            'role': 'normal',
            'saslMechanisms': 'ANONYMOUS',
            'authenticatePeer': False
        }
        entity = self.assert_create_ok(LISTENER, 'foo', attributes)
        self.assertEqual(entity['name'], 'foo')
        self.assertEqual(entity['host'], '')

        # Connect via the new listener
        node3 = self.cleanup(Node.connect(Url(port=port)))
        router = node3.query(type=ROUTER).get_entities()
        self.assertEqual(self.router.name, router[0]['id'])

        # Delete the listener
        entity.delete()
        response = self.node.query(type=LISTENER, attribute_names=['name'])
        for l in response.get_dicts():
            self.assertTrue(l['name'] != 'foo')
 def test_entity_names(self):
     nodes = [self.cleanup(Node.connect(Url(r.addresses[0]))) for r in self.routers]
     # Test that all entities have a consitent identity format: type/name
     entities = list(chain(
         *[n.query(attribute_names=['type', 'identity', 'name']).iter_entities() for n in nodes]))
     for e in entities:
         if e.type == MANAGEMENT:
             self.assertEqual(e.identity, "self")
         else:
             if e.type == 'org.apache.qpid.dispatch.connection':
                 # This will make sure that the identity of the connection object is always numeric
                 self.assertRegexpMatches(str(e.identity), "[1-9]+", e)
             else:
                 self.assertRegexpMatches(e.identity, "^%s/" % short_name(e.type), e)
 def test_entity_names(self):
     nodes = [
         self.cleanup(Node.connect(Url(r.addresses[0])))
         for r in self.routers
     ]
     # Test that all entities have a consitent identity format: type/name
     entities = list(
         chain(*[
             n.query(attribute_names=['type', 'identity', 'name'
                                      ]).iter_entities() for n in nodes
         ]))
     for e in entities:
         if e.type == MANAGEMENT:
             self.assertEqual(e.identity, "self")
         else:
             self.assertRegexpMatches(e.identity,
                                      "^%s/" % short_name(e.type), e)
    def test_create_listener(self):
        """Create a new listener on a running router"""

        port = self.get_port()
        # Note qdrouter schema defines port as string not int, since it can be a service name.
        attributes = {
            'name': 'foo',
            'port': str(port),
            'role': 'normal',
            'saslMechanisms': 'ANONYMOUS',
            'authenticatePeer': False
        }
        entity = self.assert_create_ok(LISTENER, 'foo', attributes)
        self.assertEqual(entity['name'], 'foo')
        self.assertEqual(entity['addr'], '127.0.0.1')

        # Connect via the new listener
        node3 = self.cleanup(Node.connect(Url(port=port)))
        router = node3.query(type=ROUTER).get_entities()
        self.assertEqual(self.router.name, router[0]['routerId'])