def test_topology_not_changed(self, router_interior: RouterType) -> None:
        """
        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 = 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: bool = True
        nodes: list = query.node()

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

            topology_changed: bool = 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: RouterType) -> None:
        """
        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 = 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: list = 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 _get_router_query(router: Dispatch) -> RouterQuery:
     """
     Creates a RouterQuery based on provided Router instance
     :param router:
     :return:
     """
     query: RouterQuery = RouterQuery(host=router.node.get_ip(),
                                      port=router.port,
                                      router=router)
     return query
Esempio n. 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 = RouterQuery(host=router.node.ip, port=router.port, router=router)
    node_list: list = query.node()
    assert len(node_list) == new_size
Esempio n. 5
0
def query_connections(router: Dispatch) -> None:
    """
    Queries management API using given Router instance
    for existing connections.
    :param router:
    :return:
    """
    print("  -> List of connections on %s:" % router.node.hostname)
    query: RouterQuery = 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)
Esempio n. 6
0
def validate_mesh_size(router: RouterType, new_size: int) -> None:
    """
    Asserts that router topology size matches "new_size" value.
    :param router:
    :param new_size:
    :return:
    """
    # Wait before querying nodes
    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
    query: RouterQuery = RouterQuery(host=router.node.host,
                                     port=router.port,
                                     router=router)
    node_list: list = query.node()
    logging.debug("List of nodes: %s" % node_list)

    # Assertions
    assert node_list
    assert len(node_list) == new_size