go.ligato.io/vpp-agent/v3@v3.5.0/tests/robot/libraries/bridge_domain/bridge_utils.py (about)

     1  import vpp_api
     2  
     3  from robot.api import logger
     4  
     5  
     6  def bridge_domain_dump(host, username, password, node):
     7      """Execute API command bridge_domain_dump on the specified host/node and return the API reply.
     8  
     9      :param host: docker host name or ip
    10      :param username: username for the docker host
    11      :param password: password for the docker host
    12      :param node: VPP node name in docker
    13      :type host: str
    14      :type username: str
    15      :type password: str
    16      :type node: str
    17      :returns: API reply data
    18      :rtype: list
    19      """
    20  
    21      # Use max uint32 value to dump all ACLs
    22      int_max = 4294967295
    23  
    24      data = vpp_api.vpp_api.execute_api(
    25          host, username, password, node, "bridge_domain_dump", bd_id=int_max)
    26  
    27      bridges = []
    28      for item in data[0]["api_reply"]:
    29          bridges.append(process_bridge_domain_dump(item))
    30  
    31      return bridges
    32  
    33  
    34  def process_bridge_domain_dump(data):
    35      """Process API reply bridge_domain_dump and return dictionary of usable values.
    36  
    37      :param data: API reply from bridge_domain_dump call,
    38      :type data: dict
    39      :return: Values ready for comparison with Agent or ETCD values.
    40      :rtype: dict
    41      :raises RuntimeError: If the data is in an unexpceted format,
    42      """
    43  
    44      if len(data) > 1:
    45          logger.debug(len(data))
    46          logger.trace(data)
    47          raise RuntimeError("Data contains more than one API reply.")
    48  
    49      data = data["bridge_domain_details"]
    50  
    51      return data
    52  
    53  
    54  def filter_bridge_domain_dump_by_id(data, bd_id):
    55      """Find bridge domain entry in provided dump by the specified bridge domain index.
    56  
    57      :param data: API reply from vridge_domain_dump
    58      :param bd_id: Bridge domain index.
    59      :type data: list
    60      :type bd_id: int
    61      :returns: Single bridge domain entry.
    62      :rtype: dict
    63      :raises RuntimeError: If the bridge domain is not present in API dump."""
    64  
    65      for item in data:
    66          if str(item["bd_id"]) == str(bd_id):
    67              return item
    68      else:
    69          raise RuntimeError("Bridge domain not found by id {id}.".format(id=bd_id))