Exemplo n.º 1
0
 def test_000_stats(self):
     # Run curl 127.0.0.1:port --http2-prior-knowledge
     address = self.router_qdra.http_addresses[0]
     self.run_curl(address=address)
     address = self.router_qdra.http_addresses[0] + "/myinfo"
     out = self.run_curl(
         args=['-d', 'fname=Mickey&lname=Mouse', '-X', 'POST'],
         address=address)
     self.assertIn('Success! Your first name is Mickey, last name is Mouse',
                   out)
     qd_manager = QdManager(self, address=self.router_qdra.addresses[0])
     stats = qd_manager.query('org.apache.qpid.dispatch.httpRequestInfo')
     self.assertEqual(len(stats), 2)
     for s in stats:
         self.assertEqual(s.get('requests'), 2)
         self.assertEqual(s.get('details').get('GET:200'), 1)
         self.assertEqual(s.get('details').get('POST:200'), 1)
     if stats[0].get('direction') == 'out':
         self.assertEqual(stats[1].get('direction'), 'in')
         self.assertEqual(stats[0].get('bytesOut'), 24)
         self.assertEqual(stats[0].get('bytesIn'), 3944)
         self.assertEqual(stats[1].get('bytesOut'), 3944)
         self.assertEqual(stats[1].get('bytesIn'), 24)
     else:
         self.assertEqual(stats[0].get('direction'), 'in')
         self.assertEqual(stats[1].get('direction'), 'out')
         self.assertEqual(stats[0].get('bytesOut'), 3944)
         self.assertEqual(stats[0].get('bytesIn'), 24)
         self.assertEqual(stats[1].get('bytesOut'), 24)
         self.assertEqual(stats[1].get('bytesIn'), 3944)
    def test_000_stats(self):
        client = HTTPConnection("127.0.0.1:%s" % self.http_listener11_port,
                                timeout=TIMEOUT)
        self._do_request(client, self.TESTS_11["GET"])
        self._do_request(client, self.TESTS_11["POST"])
        client.close()
        qd_manager = QdManager(self, address=self.INT_A.listener)
        stats = qd_manager.query('org.apache.qpid.dispatch.httpRequestInfo')
        self.assertEqual(len(stats), 2)
        for s in stats:
            self.assertEqual(s.get('requests'), 10)
            self.assertEqual(s.get('details').get('GET:400'), 1)
            self.assertEqual(s.get('details').get('GET:200'), 6)
            self.assertEqual(s.get('details').get('GET:204'), 1)
            self.assertEqual(s.get('details').get('POST:200'), 2)

        def assert_approximately_equal(a, b):
            self.assertTrue((abs(a - b) / a) < 0.1)

        if stats[0].get('direction') == 'out':
            self.assertEqual(stats[1].get('direction'), 'in')
            assert_approximately_equal(stats[0].get('bytesOut'), 1059)
            assert_approximately_equal(stats[0].get('bytesIn'), 8849)
            assert_approximately_equal(stats[1].get('bytesOut'), 8830)
            assert_approximately_equal(stats[1].get('bytesIn'), 1059)
        else:
            self.assertEqual(stats[0].get('direction'), 'in')
            self.assertEqual(stats[1].get('direction'), 'out')
            assert_approximately_equal(stats[0].get('bytesOut'), 8849)
            assert_approximately_equal(stats[0].get('bytesIn'), 1059)
            assert_approximately_equal(stats[1].get('bytesOut'), 1059)
            assert_approximately_equal(stats[1].get('bytesIn'), 8830)
Exemplo n.º 3
0
    def test_enable_protocol_trace_on_non_existent_connection(self):
        qd_manager = QdManager(self, self.address)

        bad_request = False

        try:
            # Turn on trace logging for connection with invalid or non-existent identity
            outs = qd_manager.update("org.apache.qpid.dispatch.connection", {"enableProtocolTrace": "true"}, identity='G10000')
        except Exception as e:
            if "BadRequestStatus" in str(e):
                bad_request = True

        self.assertTrue(bad_request)
Exemplo n.º 4
0
    def test_router_core_logger(self):
        blocking_connection = BlockingConnection(self.address)

        TEST_ADDRESS = "test_multiple_log_file"

        blocking_receiver = blocking_connection.create_receiver(
            address=TEST_ADDRESS)
        blocking_sender = blocking_connection.create_sender(
            address=TEST_ADDRESS, options=apply_options)

        TEST_MSG_BODY = "LOGTEST"
        msg = Message(body=TEST_MSG_BODY)
        blocking_sender.send(msg)
        received_message = blocking_receiver.receive()
        self.assertEqual(TEST_MSG_BODY, received_message.body)
        qd_manager = QdManager(self, self.address)
        logs = qd_manager.get_log()

        router_core_found = False
        for log in logs:
            if 'ROUTER_CORE' in log[0]:
                router_core_found = True
                break

        self.assertTrue(router_core_found)

        core_log_file_found = True
        all_lines_router_core = True
        try:
            # Before the fix to DISPATCH-1575, this file will not be
            # created because the router core module was logging to the ROUTER
            # module instead of the ROUTER_CORE module.
            with open(self.router.outdir + '/test-router-core.log',
                      'r') as core_log:
                for line in core_log:
                    # Every line in the file must log to the router core module.
                    if "ROUTER_CORE" not in line:
                        all_lines_router_core = False
                        break
        except:
            core_log_file_found = False

        self.assertTrue(core_log_file_found)
        self.assertTrue(all_lines_router_core)
Exemplo n.º 5
0
    def test_000_stats(self):
        # Run curl 127.0.0.1:port --http2-prior-knowledge
        address = self.router_qdra.http_addresses[0]
        qd_manager = QdManager(self, address=self.router_qdra.addresses[0])

        # First request
        out = self.run_curl(address)

        # Second request
        address = self.router_qdra.http_addresses[0] + "/myinfo"
        out = self.run_curl(address, args=['-d', 'fname=Mickey&lname=Mouse', '-X', 'POST'])
        self.assertIn('Success! Your first name is Mickey, last name is Mouse', out)

        stats = qd_manager.query('org.apache.qpid.dispatch.httpRequestInfo')
        self.assertEqual(len(stats), 2)

        # Give time for the core thread to augment the stats.
        i = 0
        while i < 3:
            if not stats or stats[0].get('requests') < 2:
                i += 1
                sleep(1)
                stats = qd_manager.query('org.apache.qpid.dispatch.httpRequestInfo')
            else:
                break

        for s in stats:
            self.assertEqual(s.get('requests'), 2)
            self.assertEqual(s.get('details').get('GET:200'), 1)
            self.assertEqual(s.get('details').get('POST:200'), 1)
        if stats[0].get('direction') == 'out':
            self.assertEqual(stats[1].get('direction'), 'in')
            self.assertEqual(stats[0].get('bytesOut'), 24)
            self.assertEqual(stats[0].get('bytesIn'), 3944)
            self.assertEqual(stats[1].get('bytesOut'), 3944)
            self.assertEqual(stats[1].get('bytesIn'), 24)
        else:
            self.assertEqual(stats[0].get('direction'), 'in')
            self.assertEqual(stats[1].get('direction'), 'out')
            self.assertEqual(stats[0].get('bytesOut'), 3944)
            self.assertEqual(stats[0].get('bytesIn'), 24)
            self.assertEqual(stats[1].get('bytesOut'), 24)
            self.assertEqual(stats[1].get('bytesIn'), 3944)
Exemplo n.º 6
0
    def test_000_stats(self):
        # Run curl 127.0.0.1:port --http2-prior-knowledge
        address = self.router_qdra.http_addresses[0]
        self.run_curl(address=address)
        address = self.router_qdra.http_addresses[0] + "/myinfo"
        out = self.run_curl(
            args=['-d', 'fname=Mickey&lname=Mouse', '-X', 'POST'],
            address=address)
        self.assertIn('Success! Your first name is Mickey, last name is Mouse',
                      out)
        qd_manager_a = QdManager(self, address=self.router_qdra.addresses[0])
        stats_a = qd_manager_a.query(
            'org.apache.qpid.dispatch.httpRequestInfo')

        # Give time for the core thread to augment the stats.
        i = 0
        while i < 3:
            s = stats_a[0]
            i += 1
            if s.get('requests') < 2:
                sleep(1)
                stats_a = qd_manager_a.query(
                    'org.apache.qpid.dispatch.httpRequestInfo')
            else:
                break

        self.assertEqual(len(stats_a), 1)
        self.assertEqual(stats_a[0].get('requests'), 2)
        self.assertEqual(stats_a[0].get('direction'), 'in')
        self.assertEqual(stats_a[0].get('bytesOut'), 3944)
        self.assertEqual(stats_a[0].get('bytesIn'), 24)
        qd_manager_b = QdManager(self, address=self.router_qdrb.addresses[0])
        stats_b = qd_manager_b.query(
            'org.apache.qpid.dispatch.httpRequestInfo')
        self.assertEqual(len(stats_b), 1)

        i = 0
        while i < 3:
            s = stats_b[0]
            i += 1
            if s.get('requests') < 2:
                sleep(1)
                stats_b = qd_manager_b.query(
                    'org.apache.qpid.dispatch.httpRequestInfo')
            else:
                break

        self.assertEqual(stats_b[0].get('requests'), 2)
        self.assertEqual(stats_b[0].get('direction'), 'out')
        self.assertEqual(stats_b[0].get('bytesOut'), 24)
        self.assertEqual(stats_b[0].get('bytesIn'), 3944)
Exemplo n.º 7
0
    def test_inter_router_sasl_fail(self):
        passed = False
        long_type = 'org.apache.qpid.dispatch.connection'
        qd_manager = QdManager(self, address=self.routers[1].addresses[0])
        connections = qd_manager.query(long_type)
        for connection in connections:
            if connection['role'] == 'inter-router':
                passed = True
                break

        # There was no inter-router connection established.
        self.assertFalse(passed)

        qd_manager = QdManager(self, address=self.routers[1].addresses[0])
        logs = qd_manager.get_log()

        sasl_failed = False
        file_open_failed = False
        for log in logs:
            if log[0] == 'SERVER' and log[
                    1] == "info" and "amqp:unauthorized-access Authentication failed [mech=PLAIN]" in log[
                        2]:
                sasl_failed = True
            if log[0] == "CONN_MGR" and log[
                    1] == "error" and "Unable to open password file" in log[
                        2] and "error: No such file or directory" in log[2]:
                file_open_failed = True

        self.assertTrue(sasl_failed)
        self.assertTrue(file_open_failed)
Exemplo n.º 8
0
    def test_http_listener_delete(self):
        name = 'delete_listener'
        name_1 = 'delete_listener_1'
        normal_listen_port = self.get_port()
        #
        # Open listeners on two HTTP enabled ports. Delete one of the
        # HTTP listeners and make sure that it is really gone and also
        # make sure that the other HTTP listener is still working.
        #
        http_delete_listen_port_1 = self.get_port()
        http_delete_listen_port_2 = self.get_port()
        config = Qdrouterd.Config([
            ('router', {'mode': 'standalone', 'id': 'A'}),
            ('listener', {'port': normal_listen_port}),
            ('listener', {'httpRootDir': os.path.dirname(__file__), 'name': name, 'port': http_delete_listen_port_1, 'http': True}),
            ('listener', {'httpRootDir': os.path.dirname(__file__), 'name': name_1, 'port': http_delete_listen_port_2, 'http': True})])
        router = self.qdrouterd(name="expect_fail_1", config=config, wait=True)

        def address():
            return router.addresses[0]

        # Perform a GET request on the http_delete_listen_port_1 just to make
        # sure that it is up and running.
        url_1 = "%s/system_tests_http.txt" % "http://localhost:%d" % http_delete_listen_port_1
        out = self.get(url_1, use_ca=False)

        # Perform a GET request on the http_delete_listen_port_2 just to make
        # sure that it is up and running.
        url_2 = "%s/system_tests_http.txt" % "http://localhost:%d" % http_delete_listen_port_2
        out = self.get(url_2, use_ca=False)

        # Now both http_delete_listen_port_1 and http_delete_listen_port_2
        # are working.

        # Delete the listener on port http_delete_listen_port_1
        long_type = 'org.apache.qpid.dispatch.listener'
        mgmt = QdManager(self, address=address())

        if self.skip_delete_http_listener_test:
            # You are not allowed to delete a http:yes listener
            # Try deleting it and make sure you get an exception.
            try:
                mgmt.delete(long_type, name=name)
            except Exception as e:
                if "BadRequestStatus: HTTP listeners cannot be deleted" in str(e):
                    exception_raised = True
            self.assertTrue(exception_raised)
        else:
            mgmt.delete(long_type, name=name)

            # Once again try to perform a GET request. Now since the listener
            # is gone, the GET will fail.
            ret_val = retry(lambda: self.is_get_request_failing(url_1, use_ca=False), timeout=10, delay=2)
            self.assertTrue(ret_val)

            # HTTP listener on port http_delete_listen_port_1 has been
            # deleted successfully. Make sure that the listener on port
            # http_delete_listen_port_2 is still working.
            out = self.get(url_2, use_ca=False)
Exemplo n.º 9
0
    def test_inter_router_protocol_trace(self):
        qd_manager = QdManager(self, self.address)

        # The router already has trace logging turned on for all connections.
        # Get the connection id of the inter-router connection
        results = qd_manager.query("org.apache.qpid.dispatch.connection")
        conn_id = None
        for result in results:
            if result['role'] == 'inter-router':
                conn_id = result['identity']

        # Turn off trace logging for the inter-router connection. This update command is run async by the router
        # so we need to sleep a bit before the operation is actually completed.
        qd_manager.update("org.apache.qpid.dispatch.connection",
                          {"enableProtocolTrace": "false"},
                          identity=conn_id)
        time.sleep(1)

        num_transfers = self._get_transfer_frame_count(conn_id)

        # Create a receiver. This will send an MAU update to the other router but we should not see any of that
        # in the log since the trace logging for the inter-router connection has been turned off.
        TEST_ADDR_1 = "EnableConnectionLevelProtocolTraceTest1"
        conn_2 = BlockingConnection(self.address)
        conn_2.create_receiver(address=TEST_ADDR_1)
        # Give some time for the MAU to go over the inter-router connection.
        time.sleep(2)
        num_transfers_after_update = self._get_transfer_frame_count(conn_id)

        # Since there will be no transfer frames printed in the log, there should be no more new transfers in the
        # log file.
        self.assertEqual(num_transfers_after_update, num_transfers)

        # Turn on trace logging for the inter-router connection
        qd_manager.update("org.apache.qpid.dispatch.connection",
                          {"enableProtocolTrace": "yes"},
                          identity=conn_id)

        # Create a receiver and make sure the MAU update is NOT seen on the inter-router connection log
        TEST_ADDR_2 = "EnableConnectionLevelProtocolTraceTest2"
        conn_1 = BlockingConnection(self.address)
        conn_1.create_receiver(address=TEST_ADDR_2)

        # Give time for the MAU to be generated.
        time.sleep(2)

        num_transfers_after_update = self._get_transfer_frame_count(conn_id)

        # Since we have now turned on trace logging for the inter-router connection, we should see
        # additional transfer frames in the log and we check that here.
        self.assertGreater(num_transfers_after_update, num_transfers)
        conn_1.close()
        conn_2.close()
    def test_01_toggle_default_trace_logging(self):
        hello_world_1 = "Hello World_1!"
        hello_world_2 = "Hello World_2!"
        hello_world_3 = "Hello World_3!"
        hello_world_4 = "Hello World_4!"
        qd_manager = QdManager(self, self.address)

        blocking_connection = BlockingConnection(self.address)
        TEST_ADDR = "apachetest1"
        self.create_sender_receiver(TEST_ADDR, hello_world_1,
                                    blocking_connection)

        # STEP 1: Make sure that proton trace logging is turned on already.
        # Search for attach frames in the log for address TEST_ADDR. There should be 4 attaches
        num_attaches = 0
        logs = qd_manager.get_log()
        for log in logs:
            if u'SERVER' in log[0]:
                if "@attach" in log[2] and TEST_ADDR in log[2]:
                    num_attaches += 1
        # num_attaches for address TEST_ADDR must be 4, two attaches to/from sender and receiver
        self.assertTrue(num_attaches == 4)

        # STEP 2: Turn off trace logging using qdmanage
        qd_manager.update("org.apache.qpid.dispatch.log", {"enable": "info+"},
                          name="log/DEFAULT")

        # Step 3: Now, router trace logging is turned off (has been set to info+)
        # Create the sender and receiver again on a different address and make
        # sure that the attaches are NOT showing in the log for that address.

        TEST_ADDR = "apachetest2"
        self.create_sender_receiver(TEST_ADDR, hello_world_2,
                                    blocking_connection)

        # STEP 3: Count the nimber of attaches for address TEST_ADDR, there should be none
        num_attaches = 0
        logs = qd_manager.get_log()
        for log in logs:
            if u'SERVER' in log[0]:
                if "@attach" in log[2] and TEST_ADDR in log[2]:
                    num_attaches += 1
        # There should be no attach frames with address TEST_ADDR
        # because we turned of trace logging.
        self.assertTrue(num_attaches == 0)

        # STEP 4: Tuen trace logging back on again and make sure num_attaches = 4
        TEST_ADDR = "apachetest3"
        qd_manager.update("org.apache.qpid.dispatch.log", {"enable": "trace+"},
                          name="log/DEFAULT")
        self.create_sender_receiver(TEST_ADDR, hello_world_3,
                                    blocking_connection)

        # STEP 3: Count the number of attaches for address TEST_ADDR, there should be 4
        num_attaches = 0
        logs = qd_manager.get_log()
        for log in logs:
            if u'SERVER' in log[0]:
                if "@attach" in log[2] and TEST_ADDR in log[2]:
                    num_attaches += 1
        # There should be 4 attach frames with address TEST_ADDR
        # because we turned on trace logging.
        self.assertTrue(num_attaches == 4)

        # Create a brand new blocking connection  and make sure that connection
        # is logging at trace level as well.
        num_attaches = 0
        TEST_ADDR = "apachetest4"
        self.create_sender_receiver(TEST_ADDR, hello_world_4)
        num_attaches = 0
        logs = qd_manager.get_log()
        for log in logs:
            if u'SERVER' in log[0]:
                if "@attach" in log[2] and TEST_ADDR in log[2]:
                    num_attaches += 1

        self.assertTrue(num_attaches == 4)
    def test_02_toggle_server_trace_logging(self):
        """
        This test is similar to test_01_toggle_default_trace_logging but it tests the
        SERVER log level.
        """
        hello_world_5 = "Hello World_5!"
        hello_world_6 = "Hello World_6!"
        hello_world_7 = "Hello World_7!"
        TEST_ADDR = "apachetest5"

        # Step 1. Turn off trace logging for module DEFAULT and enable trace logging
        #         for the SERVER module and make sure it works.
        qd_manager = QdManager(self, self.address)
        # Set log level to info+ on the DEFAULT module
        qd_manager.update("org.apache.qpid.dispatch.log", {"enable": "info+"},
                          name="log/DEFAULT")
        # Set log level to trace+ on the SERVER module
        qd_manager.update("org.apache.qpid.dispatch.log", {"enable": "trace+"},
                          name="log/SERVER")
        blocking_connection = BlockingConnection(self.address)

        self.create_sender_receiver(TEST_ADDR, hello_world_5,
                                    blocking_connection)
        # Count the nimber of attaches for address TEST_ADDR, there should be 4
        num_attaches = 0
        logs = qd_manager.get_log()
        for log in logs:
            if u'SERVER' in log[0]:
                if "@attach" in log[2] and TEST_ADDR in log[2]:
                    num_attaches += 1
        # There should be 4 attach frames with address TEST_ADDR
        # because we turned on trace logging.
        self.assertTrue(num_attaches == 4)

        TEST_ADDR = "apachetest6"
        qd_manager.update("org.apache.qpid.dispatch.log", {"enable": "info+"},
                          name="log/SERVER")

        self.create_sender_receiver(TEST_ADDR, hello_world_6,
                                    blocking_connection)

        # Count the nimber of attaches for address TEST_ADDR, there should be 0
        num_attaches = 0
        logs = qd_manager.get_log()
        for log in logs:
            if u'SERVER' in log[0]:
                if "@attach" in log[2] and TEST_ADDR in log[2]:
                    num_attaches += 1
        self.assertTrue(num_attaches == 0)

        # Create a brand new blocking connection  and make sure that connection
        # is logging at info level as well.
        TEST_ADDR = "apachetest7"
        self.create_sender_receiver(TEST_ADDR, hello_world_7)
        num_attaches = 0
        logs = qd_manager.get_log()
        for log in logs:
            if u'SERVER' in log[0]:
                if "@attach" in log[2] and TEST_ADDR in log[2]:
                    num_attaches += 1

        self.assertTrue(num_attaches == 0)
 def test_call_timeout(self):
     qm = QdManager(self, self.router.addresses[0])
     ts = TestCallTimeout(self.router.addresses[0], qm)
     ts.run()
     self.assertEqual("TIMED OUT!", ts.error)
Exemplo n.º 13
0
    def test_turn_on_protocol_trace(self):
        hello_world_0 = "Hello World_0!"
        qd_manager = QdManager(self, self.address)
        blocking_connection = BlockingConnection(self.address)

        TEST_ADDR = "moduletest0"
        self.create_sender_receiver(TEST_ADDR, hello_world_0,
                                    blocking_connection)

        num_attaches = 0
        logs = qd_manager.get_log()
        for log in logs:
            if u'PROTOCOL' in log[0]:
                if "@attach" in log[2] and TEST_ADDR in log[2]:
                    num_attaches += 1

        # num_attaches for address TEST_ADDR must be 4, two attaches to/from sender and receiver
        self.assertTrue(num_attaches == 4)

        # Turn off trace logging using qdmanage
        qd_manager.update("org.apache.qpid.dispatch.log", {"enable": "info+"},
                          name="log/DEFAULT")

        # Turn on trace (not trace+) level logging for the PROTOCOL module. After doing
        # this we will create a sender and a receiver and make sure that the PROTOCOL module
        # is emitting proton frame trace messages.

        # Before DISPATCH-1558, the only way to turn on proton frame trace logging was to set
        # enable to trace on the SERVER or the DEFAULT module. Turning on trace for the SERVER
        # module would also spit out dispatch trace level messages from the SERVER module.
        # DISPATCH-1558 adds the new PROTOCOL module which moves all protocol traces into
        # that module.
        qd_manager.update("org.apache.qpid.dispatch.log", {"enable": "trace+"},
                          name="log/PROTOCOL")

        TEST_ADDR = "moduletest1"
        hello_world_1 = "Hello World_1!"
        self.create_sender_receiver(TEST_ADDR, hello_world_1,
                                    blocking_connection)

        num_attaches = 0
        logs = qd_manager.get_log()
        for log in logs:
            if u'PROTOCOL' in log[0]:
                if "@attach" in log[2] and TEST_ADDR in log[2]:
                    num_attaches += 1

        # num_attaches for address TEST_ADDR must be 4, two attaches to/from sender and receiver
        self.assertTrue(num_attaches == 4)

        # Now turn off trace logging for the PROTOCOL module and make sure
        # that there is no more proton frame trace messages appearing in the log
        qd_manager.update("org.apache.qpid.dispatch.log", {"enable": "info+"},
                          name="log/PROTOCOL")

        TEST_ADDR = "moduletest2"
        hello_world_2 = "Hello World_2!"
        self.create_sender_receiver(TEST_ADDR, hello_world_2,
                                    blocking_connection)

        num_attaches = 0
        logs = qd_manager.get_log()
        for log in logs:
            if u'PROTOCOL' in log[0]:
                if "@attach" in log[2] and TEST_ADDR in log[2]:
                    num_attaches += 1

        # num_attaches for address TEST_ADDR must be 4, two attaches to/from sender and receiver
        self.assertTrue(num_attaches == 0)
Exemplo n.º 14
0
    def test_single_connection_protocol_trace(self):
        qd_manager = QdManager(self, self.address)

        # Turn off trace logging on all connections.
        qd_manager.update("org.apache.qpid.dispatch.log", {"enable": "info+"},
                          name="log/DEFAULT")

        TEST_ADDR_1 = "EnableConnectionLevelProtocolTraceTest1"
        MSG_BODY = "EnableConnectionLevelProtocolTraceTestMessage1"
        CONTAINER_ID_1 = "CONTAINERID_1"
        container_1 = Container()
        container_1.container_id = CONTAINER_ID_1
        conn_1 = BlockingConnection(self.address, container=container_1)

        TEST_ADDR_2 = "EnableConnectionLevelProtocolTraceTest1"
        CONTAINER_ID_2 = "CONTAINERID_2"
        container_2 = Container()
        container_2.container_id = CONTAINER_ID_2
        conn_2 = BlockingConnection(self.address, container=container_2)

        results = qd_manager.query("org.apache.qpid.dispatch.connection")
        conn_id = None
        for result in results:
            if result[u'container'] == CONTAINER_ID_1:
                conn_id = result[u'identity']

        # Turn on trace logging for connection with identity conn_id
        qd_manager.update("org.apache.qpid.dispatch.connection",
                          {"enableProtocolTrace": "true"},
                          identity=conn_id)

        blocking_receiver_1 = conn_1.create_receiver(address=TEST_ADDR_1)
        blocking_sender_1 = conn_1.create_sender(address=TEST_ADDR_1,
                                                 options=apply_options)

        blocking_receiver_2 = conn_2.create_receiver(address=TEST_ADDR_2)
        blocking_sender_2 = conn_2.create_sender(address=TEST_ADDR_2,
                                                 options=apply_options)

        num_attaches_1 = 0
        num_attaches_2 = 0
        logs = qd_manager.get_log()
        for log in logs:
            if u'PROTOCOL' in log[0]:
                if "@attach" in log[2] and TEST_ADDR_1 in log[2]:
                    num_attaches_1 += 1
                elif "@attach" in log[2] and TEST_ADDR_2 in log[2]:
                    num_attaches_2 += 1

        # num_attaches_1 for address TEST_ADDR_1 must be 4, two attaches to/from sender and receiver
        self.assertTrue(num_attaches_1 == 4)

        # num_attaches_2 for address TEST_ADDR_2 must be 0 since trace was not
        # turned on for that connection
        self.assertTrue(num_attaches_2 == 0)

        # Now turn off the connection tracing on that connection
        qd_manager.update("org.apache.qpid.dispatch.connection",
                          {"enableProtocolTrace": "off"},
                          identity=conn_id)
        blocking_receiver_1.close()
        blocking_sender_1.close()

        # Since tracing was turned off, there should be no detaches
        logs = qd_manager.get_log()
        num_detaches = 0
        for log in logs:
            if u'PROTOCOL' in log[0]:
                if "@detach" in log[2]:
                    num_detaches += 1
        self.assertTrue(num_detaches == 0)
        blocking_receiver_2.close()
        blocking_sender_2.close()
        conn_1.close()
        conn_2.close()
Exemplo n.º 15
0
    def test_inter_router_protocol_trace(self):
        qd_manager = QdManager(self, self.address)
        # Turn off trace logging on all connections for Router B.
        qd_manager.update("org.apache.qpid.dispatch.log", {"enable": "info+"},
                          name="log/DEFAULT")

        # Get the connection id of the inter-router connection
        results = qd_manager.query("org.apache.qpid.dispatch.connection")
        conn_id = None
        for result in results:
            if result[u'role'] == u'inter-router':
                conn_id = result[u'identity']

        # Turn on trace logging for the inter-router connection
        qd_manager.update("org.apache.qpid.dispatch.connection",
                          {"enableProtocolTrace": "true"},
                          identity=conn_id)

        # Create a receiver and make sure the MAU update is seen on the inter-router connection log
        TEST_ADDR_1 = "EnableConnectionLevelProtocolTraceTest1"
        conn_2 = BlockingConnection(self.address)
        blocking_receiver_1 = conn_2.create_receiver(address=TEST_ADDR_1)

        # Give some time for the MAU to go over the inter-router link
        time.sleep(2)
        logs = qd_manager.get_log()
        mau_found = False
        for log in logs:
            if u'PROTOCOL' in log[0]:
                if "@transfer" in log[2] and TEST_ADDR_1 in log[
                        2] and "MAU" in log[2]:
                    mau_found = True
                    break

        self.assertTrue(mau_found)

        # Turn off trace logging for the inter-router connection
        qd_manager.update("org.apache.qpid.dispatch.connection",
                          {"enableProtocolTrace": "no"},
                          identity=conn_id)

        # Create a receiver and make sure the MAU update is NOT seen on the inter-router connection log
        TEST_ADDR_2 = "EnableConnectionLevelProtocolTraceTest2"
        conn_1 = BlockingConnection(self.address)
        blocking_receiver_2 = conn_1.create_receiver(address=TEST_ADDR_2)

        time.sleep(1)

        logs = qd_manager.get_log()
        mau_found = False
        for log in logs:
            if u'PROTOCOL' in log[0]:
                if "@transfer" in log[2] and TEST_ADDR_2 in log[
                        2] and "MAU" in log[2]:
                    mau_found = True
                    break

        self.assertFalse(mau_found)
        conn_1.close()
        conn_2.close()
Exemplo n.º 16
0
    def check_connector_delete(self, client_addr, server_addr):
        # Run curl 127.0.0.1:port --http2-prior-knowledge
        # We are first making sure that the http request goes thru successfully.
        out = self.run_curl(client_addr)

        # Run a qdmanage query on connections to see how many qdr_connections are
        # there on the egress router
        qd_manager = QdManager(self, address=server_addr)

        connections = qd_manager.query('org.apache.qpid.dispatch.connection')

        self.assertGreaterEqual(len(connections), 2)

        server_conn_found = False
        for conn in connections:
            if os.environ['SERVER_LISTEN_PORT'] in conn['name']:
                server_conn_found = True
                break
        self.assertTrue(server_conn_found)

        # Run a qdmanage DELETE on the httpConnector
        http_connectors  = qd_manager.query('org.apache.qpid.dispatch.httpConnector')
        self.assertEqual(len(http_connectors), 1)

        # Delete the httpConnector
        qd_manager.delete("org.apache.qpid.dispatch.httpConnector", name=self.connector_name)

        # Make sure the connector is gone
        http_connectors  = qd_manager.query('org.apache.qpid.dispatch.httpConnector')
        self.assertEqual(len(http_connectors), 0)

        # Deleting the connector must have taken out the connection to the server.
        connections = qd_manager.query('org.apache.qpid.dispatch.connection')
        http_server_conn_found = False
        for conn in connections:
            if os.environ['SERVER_LISTEN_PORT'] in conn['name']:
                server_conn_found = True
                break
        self.assertFalse(http_server_conn_found)

        sleep(2)

        # Now, run a curl client GET request with a timeout
        request_timed_out = False
        try:
            out = self.run_curl(client_addr, timeout=5)
            print(out)
        except Exception as e:
            request_timed_out = True

        self.assertTrue(request_timed_out)

        # Add back the httpConnector
        # qdmanage CREATE type=httpConnector address=examples.com host=127.0.0.1 port=80 protocolVersion=HTTP2
        create_result = qd_manager.create("org.apache.qpid.dispatch.httpConnector", self.connector_props)
        num_tries = 2
        tries = 0
        conn_present = False
        while tries < num_tries:
            connections = qd_manager.query('org.apache.qpid.dispatch.connection')
            tries += 1
            if (len(connections) < 2):
                sleep(2)
            else:
                conn_present = True
        self.assertTrue(conn_present)

        out = self.run_curl(client_addr)
        ret_string = ""
        i = 0
        while (i < 1000):
            ret_string += str(i) + ","
            i += 1
        self.assertIn(ret_string, out)
Exemplo n.º 17
0
    def test_name_collision(self):
        args = {"name": "autoLink", "address": "autoLink1", "connection": "broker", "dir": "in"}
        # Add autoLink with the same name as the one already present.
        al_long_type = 'org.apache.qpid.dispatch.router.config.autoLink'
        addr_long_type = 'org.apache.qpid.dispatch.router.config.address'
        lr_long_type = 'org.apache.qpid.dispatch.router.config.linkRoute'
        mgmt = QdManager(self, address=self.router.addresses[0])
        test_pass = False
        try:
            mgmt.create(al_long_type, args)
        except Exception as e:
            if "BadRequestStatus: Name conflicts with an existing entity" in str(e):
                test_pass = True
        self.assertTrue(test_pass)

        # Try to add duplicate linkRoute and make sure it fails
        args = {"name": "linkRoute", "prefix": "linkRoute",
                "connection": "broker", "dir": "in"}

        mgmt = QdManager(self, address=self.router.addresses[0])
        test_pass = False
        try:
            mgmt.create(lr_long_type, args)
        except Exception as e:
            if "BadRequestStatus: Name conflicts with an existing entity" in str(e):
                test_pass = True
        self.assertTrue(test_pass)

        args = {"name": "address", "prefix": "address.1",
                "waypoint": "yes"}
        mgmt = QdManager(self, address=self.router.addresses[0])
        test_pass = False
        try:
            mgmt.create(addr_long_type, args)
        except Exception as e:
            if "BadRequestStatus: Name conflicts with an existing entity" in str(e):
                test_pass = True
        self.assertTrue(test_pass)

        # The linkRoutes, autoLinks and addrConfigs share the same hashtable
        # but with a prefix.
        # The following tests make sure that same names used on
        # different entities are allowed.

        # insert a linkRoute with the name of an existing autoLink and make
        # sure that is ok
        args = {"name": "autoLink", "prefix": "linkRoute",
                "connection": "broker", "dir": "in"}
        mgmt = QdManager(self, address=self.router.addresses[0])
        mgmt.create(lr_long_type, args)

        # insert a linkRoute with the name of an existing addr config and make
        # sure that is ok
        args = {"name": "address", "prefix": "linkRoute",
                "connection": "broker", "dir": "in"}
        mgmt = QdManager(self, address=self.router.addresses[0])
        mgmt.create(lr_long_type, args)

        # insert an autoLink with the name of an existing linkRoute and make
        # sure that is ok
        args = {"name": "linkRoute", "address": "autoLink1", "connection": "broker", "dir": "in"}
        mgmt = QdManager(self, address=self.router.addresses[0])
        mgmt.create(al_long_type, args)

        # insert an autoLink with the name of an existing address and make
        # sure that is ok
        args = {"name": "address", "address": "autoLink1", "connection": "broker", "dir": "in"}
        al_long_type = 'org.apache.qpid.dispatch.router.config.autoLink'
        mgmt = QdManager(self, address=self.router.addresses[0])
        mgmt.create(al_long_type, args)

        # insert an address with the name of an existing autoLink and make
        # sure that is ok
        args = {"name": "autoLink", "prefix": "address.2",
                "waypoint": "yes"}
        mgmt = QdManager(self, address=self.router.addresses[0])
        mgmt.create(addr_long_type, args)

        # insert an autoLink with the name of an existing linkRoute and make
        # sure that is ok
        args = {"name": "linkRoute", "prefix": "address.3",
                "waypoint": "yes"}
        mgmt = QdManager(self, address=self.router.addresses[0])
        mgmt.create(addr_long_type, args)
    def _valid_properties_check(self, client_class):
        """
        Test a few different valid property maps
        """

        valid_properties = [
            {
                # empty
            },
            {
                "simple": "string",
                "int": -3,
                "bool": True,
                "Null": None,
                "list": [1, 2, "a", None, False, "done"],
                "map": {
                    "key": "value"
                },
            },
            # compound + nested
            {
                "string":
                "string value",
                "integer":
                999,
                "map": {
                    "map-bool": False,
                    "map-list": [1, "A", None],
                    "map-map": {
                        "key1": "string",
                        "key2": 1,
                        "key3": True,
                        "key4": False,
                        "key5": None,
                        "key6": ["x", False, "z", None]
                    },
                },
                "None":
                None,
                "True":
                True,
                "False":
                False,
                "list":
                [1, 2, {
                    "a": 1,
                    "b": None,
                    "c": True,
                    "d": "end"
                }, "text", 3]
            }
        ]

        i = 0
        for op in valid_properties:
            name = "Router%d" % i
            i += 1
            config = [('router', {
                'id': name
            }), ('listener', {
                'port': self.tester.get_port()
            })]

            router = self.tester.qdrouterd(name,
                                           Qdrouterd.Config(config),
                                           wait=True)
            new_port = self.tester.get_port()
            input = json.dumps({
                'port': new_port,
                'name': "%s%d" % (client_class.entity, i),
                'openProperties': op
            })

            cmd = "CREATE --type=org.apache.qpid.dispatch.%s --stdin" % client_class.entity
            output = QdManager(tester=self)(cmd=cmd,
                                            address=router.addresses[0],
                                            input=input,
                                            timeout=TIMEOUT)
            rc = json.loads(output)
            self.assertIn("openProperties", rc)
            self.assertEqual(op, rc["openProperties"])

            client = client_class(router)
            client.run(host=rc.get("host"),
                       port=new_port,
                       pf=rc.get("protocolFamily", "IPv4"))
            router.teardown()
Exemplo n.º 19
0
    def test_https_get(self):
        def http_listener(**kwargs):
            args = dict(kwargs)
            args.update({'port': self.get_port(), 'http': 'yes', 'httpRootDir': os.path.dirname(__file__)})
            return ('listener', args)

        def listener(**kwargs):
            args = dict(kwargs)
            args.update({'port': self.get_port()})
            return ('listener', args)

        name = 'delete-me'
        config = Qdrouterd.Config([
            ('router', {'id': 'QDR.HTTPS'}),
            ('sslProfile', {'name': 'simple-ssl',
                            'caCertFile': self.ssl_file('ca-certificate.pem'),
                            'certFile': self.ssl_file('server-certificate.pem'),
                            'privateKeyFile': self.ssl_file('server-private-key.pem'),
                            'ciphers': 'ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS',
                            'password': '******'
                            }),
            http_listener(sslProfile='simple-ssl', requireSsl=False, authenticatePeer=False),
            http_listener(sslProfile='simple-ssl', requireSsl=True, authenticatePeer=False),
            http_listener(sslProfile='simple-ssl', requireSsl=True, authenticatePeer=True),
            http_listener(name=name, sslProfile='simple-ssl', requireSsl=True, authenticatePeer=True),
            listener(name='mgmt_listener', authenticatePeer=False)])
        # saslMechanisms='EXTERNAL'

        r = self.qdrouterd('https-test-router', config)
        r.wait_ready()

        def address():
            return r.addresses[4]

        self.assert_get("https://localhost:%s" % r.ports[0])
        # requireSsl=false Allows simple-ssl HTTP

        # DISPATCH-1513: libwebsockets versions 3.2.0 introduces a new flag called
        # LWS_SERVER_OPTION_ALLOW_HTTP_ON_HTTPS_LISTENER
        # The new flag allows (as the flag says) HTTP over HTTPS listeners.
        # Since this flag is not available before lws 3.2.0 we need
        # to selectively disable this check
        if qpid_dispatch_site.LIBWEBSOCKETS_VERSION >= (3, 2, 0):
            self.assert_get("http://localhost:%s" % r.ports[0])

        self.assert_get("https://localhost:%s" % r.ports[1])
        # requireSsl=True does not allow simple-ssl HTTP
        self.assertRaises(Exception, self.assert_get, "http://localhost:%s" % r.ports[1])

        # authenticatePeer=True requires a client cert
        self.assertRaises((URLError, ssl.SSLError), self.assert_get, "https://localhost:%s" % r.ports[2])

        # Provide client cert
        self.assert_get_cert("https://localhost:%d" % r.ports[2])

        # Try a get on the HTTP listener we are going to delete
        self.assert_get_cert("https://localhost:%d" % r.ports[3])

        if not self.skip_delete_http_listener_test:
            # Delete the listener with name 'delete-me'
            long_type = 'org.apache.qpid.dispatch.listener'
            mgmt = QdManager(self, address=address())
            mgmt.delete(long_type, name=name)

            # Make sure that the listener got deleted.
            ret_val = retry(lambda: self.is_get_request_failing("https://localhost:%s/system_tests_http.txt" % r.ports[3], use_get_cert=True), timeout=10, delay=2)
            self.assertTrue(ret_val)

            # Make sure other ports are working normally after the above delete.
            self.assert_get_cert("https://localhost:%d" % r.ports[2])
 def test_worker_threads(self):
     long_type = 'org.apache.qpid.dispatch.router'
     qd_manager = QdManager(self, address=self.address())
     output = qd_manager.query('org.apache.qpid.dispatch.router')
     self.assertEqual(output[0]['workerThreads'], 4)