def __init__(self, first_host, second_host, first_address, second_address,
                 dynamic, lookup_host, routers):
        super(LinkRouteTest, self).__init__(prefetch=0)
        self.logger = Logger(title="LinkRouteTest")
        self.first_host = first_host
        self.second_host = second_host
        self.first_address = first_address
        self.second_address = second_address
        self.dynamic = dynamic
        self.lookup_host = lookup_host
        self.routers = routers
        self.reactor = None

        self.first_conn = None
        self.second_conn = None
        self.error = None
        self.first_sender = None
        self.first_receiver = None
        self.second_sender = None
        self.second_receiver = None
        self.poll_timer = None

        self.count = 10
        self.n_sent = 0
        self.n_rcvd = 0
        self.n_settled = 0
예제 #2
0
    def __init__(self, first_host, second_host, first_address, second_address, container_id="ALC"):
        super(WaypointTest, self).__init__()
        self.first_host     = first_host
        self.second_host    = second_host
        self.first_address  = first_address
        self.second_address = second_address
        self.container_id   = container_id
        self.logger = Logger(title="WaypointTest")

        self.first_conn        = None
        self.second_conn       = None
        self.error             = None
        self.first_sender      = None
        self.first_sender_created = False
        self.first_sender_link_opened = False
        self.first_receiver    = None
        self.first_receiver_created    = False
        self.waypoint_sender   = None
        self.waypoint_receiver = None
        self.waypoint_queue    = []
        self.waypoint_sender_opened = False
        self.waypoint_receiver_opened = False
        self.firsts_created = False

        self.count  = 10
        self.n_sent = 0
        self.n_rcvd = 0
        self.n_waypoint_rcvd = 0
        self.n_thru = 0
        self.outs = None
예제 #3
0
    def __init__(self, sender_host, receiver_host, test_address,
                 message_size=100000, count=10, expect_block=True, print_to_console=False):
        super(OversizeMessageTransferTest, self).__init__()
        self.sender_host = sender_host
        self.receiver_host = receiver_host
        self.test_address = test_address
        self.msg_size = message_size
        self.count = count
        self.expect_block = expect_block

        self.sender_conn = None
        self.receiver_conn = None
        self.error = None
        self.sender = None
        self.receiver = None
        self.proxy = None

        self.n_sent = 0
        self.n_rcvd = 0
        self.n_accepted = 0
        self.n_rejected = 0
        self.n_aborted = 0
        self.n_connection_error = 0
        self.shut_down = False

        self.logger = Logger(title=("OversizeMessageTransferTest - %s" % (self.test_address)), print_to_console=print_to_console)
        self.log_unhandled = False
예제 #4
0
    def setUpClass(cls):
        super(TcpAdaptorManagementTest, cls).setUpClass()

        if DISABLE_SELECTOR_TESTS:
            return

        cls.tcp_server_port = cls.tester.get_port()
        cls.tcp_listener_port = cls.tester.get_port()
        cls.test_name = 'TCPMgmtTest'

        # Here we have a simple barebones standalone router config.
        config = [
            ('router', {'mode': 'standalone',
                        'id': cls.test_name}),
            ('listener', {'role': 'normal',
                          'port': cls.tester.get_port()}),
        ]
        config = Qdrouterd.Config(config)
        cls.router = cls.tester.qdrouterd(cls.test_name, config, wait=True)

        # Start the echo server. This is the server that the tcpConnector
        # will be connecting to.
        server_prefix = "ECHO_SERVER ES_%s" % cls.test_name
        cls.logger = Logger(title="TcpAdaptor",
                            print_to_console=True,
                            save_for_dump=False,
                            ofilename="../setUpClass/TcpAdaptor_echo_server.log")
        cls.echo_server = TcpEchoServer(prefix=server_prefix,
                                        port=cls.tcp_server_port,
                                        logger=cls.logger)
        # The router and the echo server are running at this point.
        assert cls.echo_server.is_running
    def __init__(self,
                 test_class,
                 sender_host,
                 routers,
                 test_address,
                 expect_receives,
                 blocked_by_ingress,
                 blocked_by_interior,
                 message_size=100000,
                 count=10,
                 print_to_console=False):
        """
        Construct an instance of the multicast test
        :param test_class:    test class - has wait-connection function
        :param sender_host:         router for the sender connection
        :param routers:             a list of all the routers for receiver connections
        :param test_address:        sender/receiver AMQP address
        :param expect_receives:     array of expected receive counts
        :param blocked_by_ingress:  true if ingress router blocks
        :param blocked_by_interior: true if edge router messages also blocked by interior
        :param message_size:        in bytes
        :param count:               how many messages to send
        :param print_to_console:    print logs as they happen
        """
        super(OversizeMulticastTransferTest, self).__init__()
        self.test_class = test_class
        self.sender_host = sender_host
        self.routers = routers
        self.test_address = test_address
        self.msg_size = message_size
        self.count = count
        self.expect_receives = expect_receives  # router array
        self.blocked_by_ingress = blocked_by_ingress
        self.blocked_by_interior = blocked_by_interior
        self.messages = []

        self.sender_conn = None
        self.receiver_conns = [None, None, None, None]  # router array
        self.error = None
        self.sender = None
        self.receivers = [None, None, None, None]  # router array
        self.proxy = None

        self.network_stable = False
        self.n_sent = 0
        self.n_rcvds = [0, 0, 0, 0]  # router array
        self.n_accepted = 0
        self.n_rejected = 0
        self.n_modified = 0
        self.n_released = 0
        self.n_send_settled = 0
        self.n_aborteds = [0, 0, 0, 0]  # router array
        self.n_connection_error = 0
        self.shut_down = False

        self.logger = Logger(title=("OversizeMulticastTransferTest - %s" %
                                    (self.test_address)),
                             print_to_console=print_to_console)
        self.log_unhandled = False  # verbose diagnostics of proton callbacks
예제 #6
0
 def __init__(self, server_port, client_port, tests, handler_cls=None):
     self._logger = Logger(title="TestServer", print_to_console=False)
     self._client_port = client_port
     self._server_addr = ("", server_port)
     self._server = MyHTTPServer(self._server_addr,
                                 handler_cls or RequestHandler,
                                 tests)
     self._server.allow_reuse_address = True
     self._thread = Thread(target=self._run)
     self._thread.daemon = True
     self._thread.start()
    def __init__(self,
                 test_class,
                 sender_host,
                 receiver_host,
                 test_address,
                 message_size=100000,
                 count=10,
                 blocked_by_both=False,
                 print_to_console=False):
        """
        Construct an instance of the unicast test
        :param test_class:    test class - has wait-connection function
        :param sender_host:   router for sender connection
        :param receiver_host: router for receiver connection
        :param test_address:  sender/receiver AMQP address
        :param message_size:  in bytes
        :param count:         how many messages to send
        :param blocked_by_both:  true if edge router messages are also blocked by interior
        :param print_to_console: print logs as they happen
        """
        super(OversizeMessageTransferTest, self).__init__()
        self.test_class = test_class
        self.sender_host = sender_host
        self.receiver_host = receiver_host
        self.test_address = test_address
        self.msg_size = message_size
        self.count = count
        self.blocked_by_both = blocked_by_both
        self.expect_block = True
        self.messages = []

        self.sender_conn = None
        self.receiver_conn = None
        self.error = None
        self.sender = None
        self.receiver = None
        self.proxy = None

        self.network_stable = False
        self.n_sent = 0
        self.n_rcvd = 0
        self.n_accepted = 0
        self.n_rejected = 0
        self.n_modified = 0
        self.n_released = 0
        self.n_send_settled = 0
        self.n_aborted = 0
        self.n_connection_error = 0
        self.shut_down = False

        self.logger = Logger(title=("OversizeMessageTransferTest - %s" %
                                    (self.test_address)),
                             print_to_console=print_to_console)
        self.log_unhandled = False  # verbose diagnostics of proton callbacks
예제 #8
0
    def __init__(self, test_name, client_n, logger, client, server, size,
                 count,
                 print_client_logs=True,
                 timeout=TIMEOUT,
                 port_override=None):
        """
        Launch an echo client upon construction.

        :param test_name: Unique name for log file prefix
        :param client_n: Client number for differentiating otherwise identical clients
        :param logger: parent logger for logging test activity vs. client activity
        :param client: router name to which the client connects
        :param server: name whose address the client is targeting
        :param size: length of messages in bytes
        :param count: number of messages to be sent/verified
        :param print_client_logs: verbosity switch
        :return Null if success else string describing error
        """
        self.test_name = test_name
        self.client_n = str(client_n)
        self.logger = logger
        self.client = client
        self.server = server
        self.size = size
        self.count = count
        self.timeout = timeout
        self.print_client_logs = print_client_logs
        self.client_final = False

        # Each router has a listener for the echo server attached to every router
        self.listener_port = TcpAdaptor.tcp_client_listener_ports[self.client][self.server] if port_override is None else port_override

        self.name = "%s_%s_%s_%s" % \
                    (self.test_name, self.client_n, self.size, self.count)
        self.client_prefix = "ECHO_CLIENT %s" % self.name
        self.client_logger = Logger(title=self.client_prefix,
                                    print_to_console=self.print_client_logs,
                                    save_for_dump=False,
                                    ofilename="../setUpClass/TcpAdaptor_echo_client_%s.log" % self.name)

        try:
            self.e_client = TcpEchoClient(prefix=self.client_prefix,
                                          host='localhost',
                                          port=self.listener_port,
                                          size=self.size,
                                          count=self.count,
                                          timeout=self.timeout,
                                          logger=self.client_logger)

        except Exception as exc:
            self.e_client.error = "TCP_TEST TcpAdaptor_runner_%s failed. Exception: %s" % \
                                  (self.name, traceback.format_exc())
            self.logger.log(self.e_client.error)
            raise Exception(self.e_client.error)
예제 #9
0
 def __init__(self, tests, port, repeat=1):
     self._id = uuid.uuid4().hex
     self._conn_addr = ("127.0.0.1:%s" % port)
     self._tests = tests
     self._repeat = repeat
     self._logger = Logger(title="TestClient: %s" % self._id,
                           print_to_console=False)
     self._thread = Thread(target=self._run)
     self._thread.daemon = True
     self.error = None
     self.count = 0
     self._thread.start()
예제 #10
0
 def __init__(self, url, container_id=None, **handler_kwargs):
     super(FakeBroker, self).__init__(**handler_kwargs)
     self.url = url
     self.queues = {}
     self.acceptor = None
     self.in_count = 0
     self.out_count = 0
     self.link_errors = 0
     self._connections = []
     self._error = None
     self._container = Container(self)
     self._container.container_id = container_id or 'FakeBroker'
     self._logger = Logger(title=self._container.container_id)
     self._thread = Thread(target=self._main)
     self._thread.daemon = True
     self._stop_thread = False
     self._thread.start()
    def __init__(self, sender_host, receiver_host, address):
        super(MessageRouteAbortTest, self).__init__()
        self.sender_host      = sender_host
        self.receiver_host    = receiver_host
        self.address          = address

        self.sender_conn   = None
        self.receiver_conn = None
        self.error         = None
        self.sender1       = None
        self.receiver      = None
        self.delivery      = None
        self.logger        = Logger(title="MessageRouteAbortTest")

        self.program       = [('D', 10), ('D', 20), ('A', 30), ('A', 40), ('D', 50), ('D', 60),
                              ('A', 100), ('D', 110),
                              ('A', 1000), ('A', 1010), ('A', 1020), ('A', 1030), ('A', 1040), ('D', 1050),
                              ('A', 10000), ('A', 10010), ('A', 10020), ('A', 10030), ('A', 10040), ('D', 10050),
                              ('A', 100000), ('A', 100010), ('A', 100020), ('A', 100030), ('A', 100040), ('D', 100050), ('F', 10)]
        self.result        = []
        self.expected_result = [10, 20, 50, 60, 110, 1050, 10050, 100050]
    def __init__(self, sender_host, primary_host, fallback_host, addr):
        super(SwitchoverTest, self).__init__()
        self.sender_host = sender_host[0]
        self.primary_host = primary_host[0]
        self.fallback_host = fallback_host[0]
        self.sender_name = sender_host[1]
        self.primary_name = primary_host[1]
        self.fallback_name = fallback_host[1]
        self.addr = addr
        self.count = 300

        # DISPATCH-2213 back off on logging.
        self.log_sends = 100  # every 100th send
        self.log_recvs = 100  # every 100th receive
        self.log_released = 100  # every 100th sender released

        self.sender_conn = None
        self.primary_conn = None
        self.fallback_conn = None
        self.primary_open = False
        self.fallback_open = False
        self.error = None
        self.n_tx = 0
        self.n_rx = 0
        self.n_rel = 0
        self.phase = 0
        self.tx_seq = 0
        self.local_rel = 0

        self.log_prefix = "FALLBACK_TEST %s" % self.addr
        self.logger = Logger("SwitchoverTest_%s" % addr,
                             print_to_console=False)
        # Prepend a convenience SERVER line for scraper tool.
        # Then the logs from this test can be merged with the router logs in scraper.
        self.logger.log("SERVER (info) Container Name: %s" % self.addr)
        self.logger.log("%s SwitchoverTest sender:%s primary:%s fallback:%s" %
                        (self.log_prefix, self.sender_name, self.primary_name,
                         self.fallback_name))
    def test_yy_query_many_links(self):
        # This test will fail without the fix for DISPATCH-974
        c = BlockingConnection(self.address())
        self.logger = Logger(title="test_yy_query_many_links")
        count = 0
        COUNT = 5000

        ADDRESS_SENDER = "examples-sender"
        ADDRESS_RECEIVER = "examples-receiver"

        # This loop creates 5000 consumer and 5000 producer links with
        # different addresses
        while count < COUNT:
            r = c.create_receiver(ADDRESS_RECEIVER + str(count))
            s = c.create_sender(ADDRESS_SENDER + str(count))
            count += 1

        # Try fetching all 10,000 addresses
        # This qdmanage query command would fail without the fix
        # for DISPATCH-974
        query_command = 'QUERY --type=org.apache.qpid.dispatch.router.address'
        outs = json.loads(self.run_qdmanage(query_command))

        sender_addresses = 0
        receiver_addresses = 0

        for out in outs:
            if ADDRESS_SENDER in out['name']:
                sender_addresses += 1
            if ADDRESS_RECEIVER in out['name']:
                receiver_addresses += 1

        self.assertEqual(sender_addresses, COUNT)
        self.assertEqual(receiver_addresses, COUNT)

        query_command = 'QUERY --type=link'
        outs = json.loads(self.run_qdmanage(query_command))

        out_links = 0
        in_links = 0
        success = False

        i = 0
        while i < 3:
            i += 1
            for out in outs:
                if out.get('owningAddr'):
                    if ADDRESS_SENDER in out['owningAddr']:
                        in_links += 1
                    if ADDRESS_RECEIVER in out['owningAddr']:
                        out_links += 1

            # If the link count is less than COUNT, try again in 2 seconds
            # Try after 2 more seconds for a total of 6 seconds.
            # If the link count is still less than expected count, there
            # is something wrong, the test has failed.
            if out_links < COUNT or in_links < COUNT:
                self.logger.log("out_links=%s, in_links=%s" %
                                (str(out_links), str(in_links)))
                sleep(2)
                outs = json.loads(self.run_qdmanage(query_command))
            else:
                self.logger.log("Test success!")
                success = True
                break

        if not success:
            self.logger.dump()

        self.assertEqual(out_links, COUNT)
        self.assertEqual(in_links, COUNT)
예제 #14
0
def main(argv):
    retval = 0
    logger = None
    # parse args
    p = argparse.ArgumentParser()
    p.add_argument('--port', '-p', help='Required listening port number')
    p.add_argument('--name', help='Optional logger prefix')
    p.add_argument(
        '--echo',
        '-e',
        type=int,
        default=0,
        const=1,
        nargs="?",
        help=
        'Exit after echoing this many bytes. Default value "0" disables exiting on byte count.'
    )
    p.add_argument(
        '--timeout',
        '-t',
        type=float,
        default=0.0,
        const=1,
        nargs="?",
        help='Timeout in seconds. Default value "0" disables timeouts')
    p.add_argument('--log',
                   '-l',
                   action='store_true',
                   help='Write activity log to console')
    del argv[0]
    args = p.parse_args(argv)

    # port
    if args.port is None:
        raise Exception("User must specify a port number")
    port = args.port

    # name / prefix
    prefix = args.name if args.name is not None else "ECHO_SERVER (%s)" % (
        str(port))

    # echo
    if args.echo < 0:
        raise Exception("Echo count must be greater than zero")

    # timeout
    if args.timeout < 0.0:
        raise Exception("Timeout must be greater than or equal to zero")

    signaller = GracefulExitSignaler()
    server = None

    try:
        # logging
        logger = Logger(title="%s port %s" % (prefix, port),
                        print_to_console=args.log,
                        save_for_dump=False)

        server = TcpEchoServer(prefix, port, args.echo, args.timeout, logger)

        keep_running = True
        while keep_running:
            time.sleep(0.1)
            if server.error is not None:
                logger.log("%s Server stopped with error: %s" %
                           (prefix, server.error))
                keep_running = False
                retval = 1
            if server.exit_status is not None:
                logger.log("%s Server stopped with status: %s" %
                           (prefix, server.exit_status))
                keep_running = False
            if signaller.kill_now:
                logger.log("%s Process killed with signal" % prefix)
                keep_running = False
            if keep_running and not server.is_running:
                logger.log("%s Server stopped with no error or status" %
                           prefix)
                keep_running = False

    except Exception:
        if logger is not None:
            logger.log("%s Exception: %s" % (prefix, traceback.format_exc()))
        retval = 1

    if server is not None and server.sock is not None:
        server.sock.close()

    return retval
    def setUpClass(cls):
        """Start a router"""
        super(TcpAdaptor, cls).setUpClass()

        if DISABLE_SELECTOR_TESTS:
            return

        def router(name, mode, connection, extra=None):
            """
            Launch a router through the system_test framework.
            For each router:
             * normal listener first
             #* http listener for console connections
             * tcp listener for 'nodest', which will never exist
             * tcp connector to echo server whose address is the same as this router's name
             * six tcp listeners, one for each server on each router on the network
            :param name: router name
            :param mode: router mode: interior or edge
            :param connection: list of router-level connection/listener tuples
            :param extra: yet more configuation tuples. unused for now
            :return:
            """
            config = [
                ('router', {
                    'mode': mode,
                    'id': name
                }),
                ('listener', {
                    'port': cls.amqp_listener_ports[name]
                }),
                # ('listener', {'port': cls.http_listener_ports[name], 'http': 'yes'}),
                ('tcpListener', {
                    'host': "0.0.0.0",
                    'port': cls.nodest_listener_ports[name],
                    'address': 'nodest',
                    'siteId': cls.site
                }),
                ('tcpConnector', {
                    'host': "127.0.0.1",
                    'port': cls.tcp_server_listener_ports[name],
                    'address': 'ES_' + name,
                    'siteId': cls.site
                })
            ]
            if connection:
                config.extend(connection)
            listeners = []
            for rtr in cls.router_order:
                listener = {
                    'host': "0.0.0.0",
                    'port': cls.tcp_client_listener_ports[name][rtr],
                    'address': 'ES_' + rtr,
                    'siteId': cls.site
                }
                tup = [(('tcpListener', listener))]
                listeners.extend(tup)
            config.extend(listeners)

            if extra:
                config.extend(extra)

            config = Qdrouterd.Config(config)
            cls.routers.append(cls.tester.qdrouterd(name, config, wait=True))

        cls.routers = []

        # define logging levels
        cls.print_logs_server = False
        cls.print_logs_client = True
        cls.logger = Logger(title="TcpAdaptor-testClass",
                            print_to_console=True,
                            save_for_dump=False,
                            ofilename='../setUpClass/TcpAdaptor.log')
        # Write a dummy log line for scraper.
        cls.logger.log("SERVER (info) Container Name: TCP_TEST")

        # Allocate echo server ports first
        for rtr in cls.router_order:
            cls.tcp_server_listener_ports[rtr] = cls.tester.get_port()

        # start echo servers immediately after the echo server
        # ports are assigned.
        for rtr in cls.router_order:
            test_name = "TcpAdaptor"
            server_prefix = "ECHO_SERVER %s ES_%s" % (test_name, rtr)
            server_logger = Logger(
                title=test_name,
                print_to_console=cls.print_logs_server,
                save_for_dump=False,
                ofilename="../setUpClass/TcpAdaptor_echo_server_%s.log" % rtr)
            cls.logger.log("TCP_TEST Launching echo server '%s'" %
                           server_prefix)
            server = TcpEchoServer(prefix=server_prefix,
                                   port=cls.tcp_server_listener_ports[rtr],
                                   logger=server_logger)
            assert server.is_running
            cls.echo_servers[rtr] = server

        cls.EC2_conn_stall_connector_port = cls.tester.get_port()
        # start special naughty servers that misbehave on purpose
        server_prefix = "ECHO_SERVER TcpAdaptor NS_EC2_CONN_STALL"
        server_logger = Logger(
            title="TcpAdaptor",
            print_to_console=cls.print_logs_server,
            save_for_dump=False,
            ofilename="../setUpClass/TcpAdaptor_echo_server_NS_CONN_STALL.log")
        cls.logger.log("TCP_TEST Launching echo server '%s'" % server_prefix)
        server = TcpEchoServer(prefix=server_prefix,
                               port=cls.EC2_conn_stall_connector_port,
                               logger=server_logger,
                               conn_stall=Q2_DELAY_SECONDS)
        assert server.is_running
        cls.echo_server_NS_CONN_STALL = server

        # Allocate a sea of router ports
        for rtr in cls.router_order:
            cls.amqp_listener_ports[rtr] = cls.tester.get_port()
            tl_ports = {}
            for tcp_listener in cls.router_order:
                tl_ports[tcp_listener] = cls.tester.get_port()
            cls.tcp_client_listener_ports[rtr] = tl_ports
            cls.nodest_listener_ports[rtr] = cls.tester.get_port()

        inter_router_port_AB = cls.tester.get_port()
        cls.INTA_edge_port = cls.tester.get_port()
        cls.INTA_conn_stall_listener_port = cls.tester.get_port()

        # Launch the routers using the sea of router ports
        router('INTA', 'interior',
               [('listener', {
                   'role': 'inter-router',
                   'port': inter_router_port_AB
               }),
                ('listener', {
                    'name': 'uplink',
                    'role': 'edge',
                    'port': cls.INTA_edge_port
                }),
                ('tcpListener', {
                    'host': "0.0.0.0",
                    'port': cls.INTA_conn_stall_listener_port,
                    'address': 'NS_EC2_CONN_STALL',
                    'siteId': cls.site
                })])
        inter_router_port_BC = cls.tester.get_port()
        cls.INTB_edge_port = cls.tester.get_port()
        router('INTB', 'interior', [('connector', {
            'role': 'inter-router',
            'port': inter_router_port_AB
        }), ('listener', {
            'role': 'inter-router',
            'port': inter_router_port_BC
        }),
                                    ('listener', {
                                        'name': 'uplink',
                                        'role': 'edge',
                                        'port': cls.INTB_edge_port
                                    })])

        cls.INTC_edge_port = cls.tester.get_port()
        router('INTC', 'interior', [('connector', {
            'role': 'inter-router',
            'port': inter_router_port_BC
        }),
                                    ('listener', {
                                        'name': 'uplink',
                                        'role': 'edge',
                                        'port': cls.INTC_edge_port
                                    })])

        router('EA1', 'edge', [('connector', {
            'name': 'uplink',
            'role': 'edge',
            'port': cls.INTA_edge_port
        })])
        router('EA2', 'edge', [('connector', {
            'name': 'uplink',
            'role': 'edge',
            'port': cls.INTA_edge_port
        })])
        router('EB1', 'edge', [('connector', {
            'name': 'uplink',
            'role': 'edge',
            'port': cls.INTB_edge_port
        })])
        router('EB2', 'edge', [('connector', {
            'name': 'uplink',
            'role': 'edge',
            'port': cls.INTB_edge_port
        })])
        router('EC1', 'edge', [('connector', {
            'name': 'uplink',
            'role': 'edge',
            'port': cls.INTC_edge_port
        })])
        cls.EC2_conn_stall_listener_port = cls.tester.get_port()
        router('EC2', 'edge', [('connector', {
            'name': 'uplink',
            'role': 'edge',
            'port': cls.INTC_edge_port
        }),
                               ('tcpConnector', {
                                   'host': "127.0.0.1",
                                   'port': cls.EC2_conn_stall_connector_port,
                                   'address': 'NS_EC2_CONN_STALL',
                                   'siteId': cls.site
                               }),
                               ('tcpListener', {
                                   'host': "0.0.0.0",
                                   'port': cls.EC2_conn_stall_listener_port,
                                   'address': 'NS_EC2_CONN_STALL',
                                   'siteId': cls.site
                               })])

        cls.INTA = cls.routers[0]
        cls.INTB = cls.routers[1]
        cls.INTC = cls.routers[2]
        cls.EA1 = cls.routers[3]
        cls.EA2 = cls.routers[4]
        cls.EB1 = cls.routers[5]
        cls.EB2 = cls.routers[6]
        cls.EC1 = cls.routers[7]
        cls.EC2 = cls.routers[8]

        cls.router_dict = {}
        cls.router_dict['INTA'] = cls.INTA
        cls.router_dict['INTB'] = cls.INTB
        cls.router_dict['INTC'] = cls.INTC
        cls.router_dict['EA1'] = cls.EA1
        cls.router_dict['EA2'] = cls.EA2
        cls.router_dict['EB1'] = cls.EB1
        cls.router_dict['EB2'] = cls.EB2
        cls.router_dict['EC1'] = cls.EC1
        cls.router_dict['EC2'] = cls.EC2

        cls.logger.log("TCP_TEST INTA waiting for connection to INTB")
        cls.INTA.wait_router_connected('INTB')
        cls.logger.log("TCP_TEST INTB waiting for connection to INTA")
        cls.INTB.wait_router_connected('INTA')
        cls.logger.log("TCP_TEST INTB waiting for connection to INTC")
        cls.INTB.wait_router_connected('INTC')
        cls.logger.log("TCP_TEST INTC waiting for connection to INTB")
        cls.INTC.wait_router_connected('INTB')

        # Create a scoreboard for the ports
        p_out = []
        for rtr in cls.router_order:
            p_out.append("%s_amqp=%d" % (rtr, cls.amqp_listener_ports[rtr]))
            p_out.append("%s_echo_server=%d" %
                         (rtr, cls.tcp_server_listener_ports[rtr]))
            for tcp_listener in cls.router_order:
                p_out.append(
                    "%s_echo_listener_for_%s=%d" %
                    (rtr, tcp_listener,
                     cls.tcp_client_listener_ports[rtr][tcp_listener]))
            p_out.append("%s_nodest_listener=%d" %
                         (rtr, cls.nodest_listener_ports[rtr]))
            # p_out.append("%s_http_listener=%d" %
            #             (rtr, cls.http_listener_ports[rtr]))
        p_out.append("inter_router_port_AB=%d" % inter_router_port_AB)
        p_out.append("inter_router_port_BC=%d" % inter_router_port_BC)
        p_out.append("INTA_edge_port=%d" % cls.INTA_edge_port)
        p_out.append("INTB_edge_port=%d" % cls.INTB_edge_port)
        p_out.append("INTC_edge_port=%d" % cls.INTC_edge_port)
        p_out.append("EC2_conn_stall_connector_port%d" %
                     cls.EC2_conn_stall_connector_port)
        p_out.append("INTA_conn_stall_listener_port%d" %
                     cls.INTA_conn_stall_listener_port)
        p_out.append("EC2_conn_stall_listener_port%d" %
                     cls.EC2_conn_stall_listener_port)

        # write to log
        for line in p_out:
            cls.logger.log("TCP_TEST %s" % line)

        # write to shell script
        with open("../setUpClass/TcpAdaptor-ports.sh", 'w') as o_file:
            for line in p_out:
                o_file.write("set %s\n" % line)

        # Write a script to run scraper on this test's log files
        scraper_abspath = os.path.join(os.environ.get('BUILD_DIR'), 'tests',
                                       'scraper', 'scraper.py')
        logs_dir = os.path.abspath("../setUpClass")
        main_log = "TcpAdaptor.log"
        echo_logs = "TcpAdaptor_echo*"
        big_test_log = "TcpAdaptor_all.log"
        int_logs = "I*.log"
        edge_logs = "E*.log"
        log_modules_spec = "--log-modules TCP_ADAPTOR,TCP_TEST,ECHO_SERVER,ECHO_CLIENT"
        html_output = "TcpAdaptor.html"

        with open("../setUpClass/TcpAdaptor-run-scraper.sh", 'w') as o_file:
            o_file.write("#!/bin/bash\n\n")
            o_file.write(
                "# Script to run scraper on test class TcpAdaptor test result\n"
            )
            o_file.write("# cd into logs directory\n")
            o_file.write("cd %s\n\n" % logs_dir)
            o_file.write("# Concatenate test class logs into single file\n")
            o_file.write("cat %s %s > %s\n\n" %
                         (main_log, echo_logs, big_test_log))
            o_file.write("# run scraper\n")
            o_file.write("python %s %s -f %s %s %s > %s\n\n" %
                         (scraper_abspath, log_modules_spec, int_logs,
                          edge_logs, big_test_log, html_output))
            o_file.write("echo View the results by opening the html file\n")
            o_file.write("echo     firefox %s" %
                         (os.path.join(logs_dir, html_output)))

        # wait for server addresses (mobile ES_<rtr>) to propagate to all interior routers
        interior_rtrs = [
            rtr for rtr in cls.router_order if rtr.startswith('I')
        ]
        found_all = False
        while not found_all:
            found_all = True
            cls.logger.log(
                "TCP_TEST Poll wait for echo server addresses to propagate")
            for rtr in interior_rtrs:
                # query each interior for addresses
                p = Process([
                    'qdstat', '-b',
                    str(cls.router_dict[rtr].addresses[0]), '-a'
                ],
                            name='qdstat-snap1',
                            stdout=PIPE,
                            expect=None,
                            universal_newlines=True)
                out = p.communicate()[0]
                # examine what this router can see; signal poll loop to continue or not
                lines = out.split("\n")
                server_lines = [
                    line for line in lines
                    if "mobile" in line and "ES_" in line
                ]
                if not len(server_lines) == len(cls.router_order):
                    found_all = False
                    seen = []
                    for line in server_lines:
                        flds = line.split()
                        seen.extend(
                            [fld for fld in flds if fld.startswith("ES_")])
                    unseen = [
                        srv for srv in cls.router_order
                        if "ES_" + srv not in seen
                    ]
                    cls.logger.log(
                        "TCP_TEST Router %s sees only %d of %d addresses. Waiting for %s"
                        % (rtr, len(server_lines), len(
                            cls.router_order), unseen))
        cls.logger.log("TCP_TEST Done poll wait")
예제 #16
0
def main(argv):
    retval = 0
    # parse args
    p = argparse.ArgumentParser()
    p.add_argument('--host', '-b', help='Required target host')
    p.add_argument('--port',
                   '-p',
                   type=int,
                   help='Required target port number')
    p.add_argument(
        '--size',
        '-s',
        type=int,
        default=100,
        const=1,
        nargs='?',
        help=
        'Size of payload in bytes must be >= 0. Size of zero connects and disconnects with no data traffic.'
    )
    p.add_argument(
        '--count',
        '-c',
        type=int,
        default=1,
        const=1,
        nargs='?',
        help=
        'Number of payloads to process must be >= 0. Count of zero connects and disconnects with no data traffic.'
    )
    p.add_argument('--name', help='Optional logger prefix')
    p.add_argument(
        '--timeout',
        '-t',
        type=float,
        default=0.0,
        const=1,
        nargs="?",
        help='Timeout in seconds. Default value "0" disables timeouts')
    p.add_argument('--log',
                   '-l',
                   action='store_true',
                   help='Write activity log to console')
    del argv[0]
    args = p.parse_args(argv)

    # host
    if args.host is None:
        raise Exception("User must specify a host")
    host = args.host

    # port
    if args.port is None:
        raise Exception("User must specify a port number")
    port = args.port

    # size
    if args.size < 0:
        raise Exception("Size must be greater than or equal to zero")
    size = args.size

    # count
    if args.count < 0:
        raise Exception("Count must be greater than or equal to zero")
    count = args.count

    # name / prefix
    prefix = args.name if args.name is not None else "ECHO_CLIENT (%d_%d_%d)" % \
                                                     (port, size, count)

    # timeout
    if args.timeout < 0.0:
        raise Exception("Timeout must be greater than or equal to zero")

    signaller = GracefulExitSignaler()
    logger = None

    try:
        # logging
        logger = Logger(title="%s host:%s port %d size:%d count:%d" %
                        (prefix, host, port, size, count),
                        print_to_console=args.log,
                        save_for_dump=False)

        client = TcpEchoClient(prefix, host, port, size, count, args.timeout,
                               logger)

        keep_running = True
        while keep_running:
            time.sleep(0.1)
            if client.error is not None:
                logger.log("%s Client stopped with error: %s" %
                           (prefix, client.error))
                keep_running = False
                retval = 1
            if client.exit_status is not None:
                logger.log("%s Client stopped with status: %s" %
                           (prefix, client.exit_status))
                keep_running = False
            if signaller.kill_now:
                logger.log("%s Process killed with signal" % prefix)
                keep_running = False
            if keep_running and not client.is_running:
                logger.log("%s Client stopped with no error or status" %
                           prefix)
                keep_running = False

    except Exception:
        client.error = "ERROR: exception : '%s'" % traceback.format_exc()
        if logger is not None:
            logger.log("%s Exception: %s" % (prefix, traceback.format_exc()))
        retval = 1

    if client.error is not None:
        # write client errors to stderr
        def eprint(*args, **kwargs):
            print(*args, file=sys.stderr, **kwargs)

        elines = client.error.split("\n")
        for line in elines:
            eprint("ERROR:", prefix, line)

    return retval
예제 #17
0
def main(argv):
    retval = 0
    logger = None
    # parse args
    p = argparse.ArgumentParser()
    p.add_argument('--port', '-p', help='Required listening port number')
    p.add_argument('--name', help='Optional logger prefix')
    p.add_argument(
        '--echo',
        '-e',
        type=int,
        default=0,
        const=1,
        nargs="?",
        help=
        'Exit after echoing this many bytes. Default value "0" disables exiting on byte count.'
    )
    p.add_argument(
        '--timeout',
        '-t',
        type=float,
        default=0.0,
        const=1,
        nargs="?",
        help='Timeout in seconds. Default value "0.0" disables timeouts')
    p.add_argument('--log',
                   '-l',
                   action='store_true',
                   help='Write activity log to console')
    # Add controlled server misbehavior for testing conditions seen in the field
    # Stall required to trigger Q2 testing for DISPATCH-1947 and improving test DISPATCH-1981
    p.add_argument(
        '--connect-stall',
        type=float,
        default=0.0,
        const=1,
        nargs="?",
        help=
        'Accept connections but wait this many seconds before reading from socket. Default value "0.0" disables stall'
    )
    # Close on connect - exercises control paths scrutinized under DISPATCH-1968
    p.add_argument(
        '--close-on-connect',
        action='store_true',
        help=
        'Close client connection without reading from socket when listener connects. If stall is specified then stall before closing.'
    )
    # Close on data - exercises control paths scrutinized under DISPATCH-1968
    p.add_argument('--close-on-data',
                   action='store_true',
                   help='Close client connection as soon as data arrives.')
    del argv[0]
    args = p.parse_args(argv)

    # port
    if args.port is None:
        raise Exception("User must specify a port number")
    port = args.port

    # name / prefix
    prefix = args.name if args.name is not None else "ECHO_SERVER (%s)" % (
        str(port))

    # echo
    if args.echo < 0:
        raise Exception("Echo count must be greater than zero")

    # timeout
    if args.timeout < 0.0:
        raise Exception("Timeout must be greater than or equal to zero")

    # timeout
    if args.connect_stall < 0.0:
        raise Exception("Connect-stall must be greater than or equal to zero")

    signaller = GracefulExitSignaler()
    server = None

    try:
        # logging
        logger = Logger(title="%s port %s" % (prefix, port),
                        print_to_console=args.log,
                        save_for_dump=False)

        server = TcpEchoServer(prefix, port, args.echo, args.timeout, logger,
                               args.connect_stall, args.close_on_connect,
                               args.close_on_data)

        keep_running = True
        while keep_running:
            time.sleep(0.1)
            if server.error is not None:
                logger.log("%s Server stopped with error: %s" %
                           (prefix, server.error))
                keep_running = False
                retval = 1
            if server.exit_status is not None:
                logger.log("%s Server stopped with status: %s" %
                           (prefix, server.exit_status))
                keep_running = False
            if signaller.kill_now:
                logger.log("%s Process killed with signal" % prefix)
                keep_running = False
            if keep_running and not server.is_running:
                logger.log("%s Server stopped with no error or status" %
                           prefix)
                keep_running = False

    except Exception:
        if logger is not None:
            logger.log("%s Exception: %s" % (prefix, traceback.format_exc()))
        retval = 1

    if server is not None and server.sock is not None:
        server.sock.close()

    return retval