Esempio n. 1
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()
Esempio n. 2
0
    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 PROTOCOL 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 PROTOCOL module
        qd_manager.update("org.apache.qpid.dispatch.log", {"enable": "trace+"}, name="log/PROTOCOL")
        blocking_connection = BlockingConnection(self.address)

        self.create_sender_receiver(TEST_ADDR, hello_world_5,
                                    blocking_connection)
        # 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 'PROTOCOL' 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/PROTOCOL")

        self.create_sender_receiver(TEST_ADDR, hello_world_6, blocking_connection)

        # Count the number of attaches for address TEST_ADDR, there should be 0
        num_attaches = 0
        logs = qd_manager.get_log()
        for log in logs:
            if 'PROTOCOL' 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 'PROTOCOL' in log[0]:
                if "@attach" in log[2] and TEST_ADDR in log[2]:
                    num_attaches += 1

        self.assertTrue(num_attaches == 0)
Esempio n. 3
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)
Esempio 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)
    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)
Esempio n. 6
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)
Esempio n. 7
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()