Пример #1
0
 def verify_switch(self, retries=30, log=None, port=None):
     """ Verify the switch is THRIFT reachable """
     if not log:
         log = self.log
     port = port or self.port
     """ Verfiy that both userver and agent are reachable """
     # check if userver is reachable, tests can bring down userver
     # Example: T33276019
     if not is_host_ping_reachable(self.switch.name, log):
         return False
     """ Verify the switch is THRIFT reachable """
     for retry in range(retries):  # don't use @retry, this is OSS
         try:
             with FbossAgentClient(self.switch.name, port) as client:
                 client.keepalive(
                 )  # simple check, will pass if agent is up
                 # this actually checks that agent is in a ready state
                 client.getAllPortInfo()  # will throw FbossBaseError
                 return True
         except (FbossBaseError, TTransportException,
                 TServiceRouterException) as e:
             log.warning("Switch failed to thrift verify (try #%d): %s" %
                         (retry, str(e)))
             time.sleep(1)
     return False
Пример #2
0
 def _get_fboss_agent_client(self, hostname: str) -> FbossAgentClient:
     client = FbossAgentClient(hostname,
                               port=DEFAULT_AGENT_REMOTE_PORT,
                               timeout=DEFAULT_THRIFT_TIMEOUT)
     self.assertTrue(
         client,
         msg="Invalid FbossAgentClient",
     )
     return client
Пример #3
0
    def convert(self, value, param, ctx):
        try:
            if self.port_info_map is None:
                with FbossAgentClient(ctx.obj.hostname) as client:
                    self.port_info_map = client.getAllPortInfo()
            if value.isdigit():
                port = self.port_info_map[int(value)]
                return port.portId
            for port_id, port_info in self.port_info_map.items():
                if port_info.name == value:
                    return port_id
            raise ValueError("No port found with that name")

        except (ValueError, KeyError):
            self.fail("%s is not a valid Port" % value, param, ctx)
Пример #4
0
 def _get_fboss_agent_client(self, hostname: str) -> FbossAgentClient:
     client = FbossAgentClient(hostname,
                               port=DEFAULT_AGENT_REMOTE_PORT,
                               timeout=DEFAULT_THRIFT_TIMEOUT)
     return client
Пример #5
0
 def switch_thrift(self, port=None):
     port = port or self.port
     return FbossAgentClient(self.switch.name, port=port)