def test_topology_not_changed(self, router_interior):
        """
        Query all interior routers one more time and expect last topology change variable
        to return the same value and that the number of nodes in the network remains the same.
        :param router_interior:
        :return:
        """

        query = RouterQuery(router_interior.node.get_ip(),
                            router_interior.port, router_interior)

        # Retrieving router info
        router_info = query.router()[0]

        # Must be set to False after loop is processed
        topology_changed = True
        nodes = query.node()

        for node in nodes:
            if node.nextHop != '(self)':
                continue

            topology_changed = self.last_topology_change[
                router_info.name] != node.lastTopoChange
            logging.debug(
                "Last topology change for: %s = %s [before: %s]" %
                (router_info.name, self.last_topology_change[router_info.name],
                 node.lastTopoChange))

            break

        assert not topology_changed
        assert len(nodes) == len(self.last_topology_change.keys())
    def test_nodes_in_topology(self, router):
        """
        Validates that edge routers do not show any node when queried, and
        interior routers are showing other nodes.
        It also stores last topology change from each interior router and it
        will be used later, after edge routers are restarted.
        :param router:
        :return:
        """
        query = RouterQuery(router.node.get_ip(), router.port, router)

        # Get router mode
        router_info = query.router()[0]
        mode = router_info.mode

        # Query nodes in network
        nodes = query.node()

        # If edge, expect no nodes returned
        if mode == 'edge':
            assert not nodes
            return

        # Following applies just to interior
        assert nodes
        assert len(nodes) > 1

        # Loop through nodes and store lastTopoChange for current instance
        for node in nodes:
            if node.nextHop == '(self)':
                self.last_topology_change[
                    router_info.name] = node.lastTopoChange
                logging.debug("Last topology change for: %s = %s" %
                              (router_info.name, node.lastTopoChange))
def validate_mesh_size(router, new_size):
    """
    Asserts that router topology size matches "new_size" value.
    :param router:
    :param new_size:
    :return:
    """
    for attempt in range(ATTEMPTS):
        # Wait before querying nodes
        logger.debug('Attempt %d/%d' % (attempt+1, ATTEMPTS))
        logger.debug('Waiting %s seconds for router mesh to be formed' % WAIT_ROUTER_MESH_SECS)
        time.sleep(WAIT_ROUTER_MESH_SECS)
    
        # Query nodes in topology
        try:
            query = RouterQuery(host=router.node.ip, port=router.port, router=router)
            node_list = query.node()
        except ConnectionException as ex:
            logging.error("Unable to connect with router: %s" % ex)
            continue

        logging.debug("List of nodes: %s" % node_list)

        # If expected number of nodes found, break
        if len(node_list) == new_size:
            break

    # Assertions
    assert node_list
    assert len(node_list) == new_size
示例#4
0
def validate_mesh_size(router: Dispatch, new_size: int):
    """
    Asserts that router topology size matches "new_size" value.
    :param router:
    :param new_size:
    :return:
    """
    time.sleep(90)
    query = RouterQuery(host=router.node.ip, port=router.port, router=router)
    node_list = query.node()
    assert len(node_list) == new_size
示例#5
0
def query_connections(router: Router):
    """
    Queries management API using given Router instance
    for existing connections.
    :param router:
    :return:
    """
    print("  -> List of connections on %s:" % router.node.hostname)
    query = RouterQuery(host=router.node.get_ip())

    # The query below returns a namedtuple representing a Connection entity
    for conn in query.connection():
        print("     - %s" % conn.name)
 def _get_router_query(router: Dispatch) -> RouterQuery:
     """
     Creates a RouterQuery based on provided Router instance
     :param router:
     :return:
     """
     query = RouterQuery(host=router.node.get_ip(),
                         port=router.port,
                         router=router)
     return query
示例#7
0
    def test_network(self, iqa: IQAInstance):
        assert iqa

        # Expected router from inventory is available
        router_i1: Dispatch = iqa.get_routers(
            "one_interior_router.Router.I1")[0]
        assert router_i1

        # Querying router network
        query = RouterQuery(router_i1.node.get_ip(), router_i1.port)
        nodes = []
        for attempt in range(MAX_ATTEMPTS):
            try:
                nodes = query.node()
                break
            except ConnectionException:
                time.sleep(DELAY_SECS)
                pass

        # Assert only one node in the network (from $management)
        assert len(nodes) == 1