示例#1
0
    def remove_interface(self, ifName):
        if ifName not in self.added_interfaces:
            raise FbossBaseError(
                "User attempted to remove an interface they did not add. Ignoring.")

        command = "ip link del dev {}".format(ifName)
        try:
            self.check_output(command)
        except Exception as e:
            raise FbossBaseError("Error deleting interface: {}".format(str(e)))
        self.added_interfaces.remove(ifName)
        return True
示例#2
0
 def getPktCapture(self, interface_name, ms_timeout, maxPackets):
     """ All documentation for this call is in thrift definition """
     if interface_name not in self.pcap_captures:
         raise FbossBaseError("No startPktCapture() for Interface " +
                              interface_name)
     reader = self.pcap_captures[interface_name]
     start = time.time()
     intf = interface_name  # horrible hack to fit in 80 chars below
     self.log.debug("getPktCapture(%s,ms_timeout=%d,maxPackets=%d)" %
                   (interface_name, ms_timeout, maxPackets))
     while time.time() < (start + (ms_timeout / 1000)):
         # this reader is set to not block, so this will busy wait until
         # packets show up or the timeout occurs.  Given the note
         # about the readtimeout param in open_live() not being widely
         # supported, this is the best we can do
         try:
             reader.dispatch(
                 maxPackets,
                 lambda phdr, pdata: self._pkt_callback(intf, phdr, pdata))
         except Exception as e:
             traceback.print_exc()
             print(str(e))
             raise
         pkts = self.pkt_captures[interface_name]
         self.log.debug("    got %d packets" % len(pkts))
         if len(pkts) >= maxPackets:
             break
     return_pkts = []
     for _phdr, pdata in pkts:
         capture = TestService.CapturedPacket()
         capture.packet_data = pdata
         capture.packet_length = _phdr.getlen()
         return_pkts.append(capture)
     return return_pkts
示例#3
0
 def verify_hosts(self, fail_on_error=False):
     """ Verify each host is thrift reachable
             if fail_on_error is false, just remove unreachable
             hosts from our setup with a warning.
     """
     bad_hosts = []
     for host in self.test_hosts.values():
         try:
             with TestClient(host.name, host.port) as client:
                 if not client.status():
                     bad_hosts.append(host)
                 else:
                     self.log.info("Verified host %s" % host.name)
         except (FbossBaseError, TTransportException):
             bad_hosts.append(host)
     if bad_hosts:
         if fail_on_error:
             raise FbossBaseError("fail_on_error set and hosts down: %s" %
                                  " ".join(bad_hosts))
         else:
             for host in bad_hosts:
                 self.log.warning("Removing unreachable host: %s " %
                                     host.name)
                 self.remove_host(host)
             if len(self.test_hosts) == 0:
                 return False    # all hosts were bad
     return True
示例#4
0
 def verify_hosts(self,
                  fail_on_error=False,
                  min_hosts=0,
                  retries=10,
                  log=None):
     """ Verify each host is thrift reachable
             if fail_on_error is false, just remove unreachable
             hosts from our setup with a warning.
         zero min_hosts means we don't need any servers to run these tests
     """
     if not log:
         log = self.log
     bad_hosts = []
     for host in self.test_hosts.values():
         if not host.thrift_verify(retries=retries, log=log):
             bad_hosts.append(host.name)
     if bad_hosts:
         if fail_on_error:
             raise FbossBaseError("fail_on_error set and hosts down: %s" %
                                  " ".join(bad_hosts))
         else:
             for host_name in bad_hosts:
                 self.log.warning("Removing thrift-unreachable host: %s " %
                                  host_name)
                 self.remove_host(host_name)
     return len(self.test_hosts) >= min_hosts
示例#5
0
 def add_address(self, address, ifName):
     command = "ip addr add {} dev {}".format(address, ifName)
     try:
         self.check_output(command)
     except Exception as e:
         # Ignoring "File exists" error
         if "exit status 2" not in str(e):
             raise FbossBaseError("Error adding address: {}".format(str(e)))
     return True
示例#6
0
    def add_interface(self, ifName, deviceType):
        if ifName in self.added_interfaces:
            raise FbossBaseError("Device {} already exists".format(ifName))

        strDeviceType = self.DEVICE_TYPE_ENUM_TO_STRING.get(deviceType)
        if not strDeviceType:
            raise FbossBaseError(
                "DeviceType {} not found/supported (are you sure you used the enum?)"
                .format(deviceType))

        command = "ip link add name {} type {}".format(ifName, strDeviceType)
        try:
            self.check_output(command)
        except Exception as e:
            # Ignoring "File exists" error
            if "exit status 2" not in str(e):
                raise FbossBaseError("Error adding interface: {}".format(
                    str(e)))
        self.added_interfaces.add(ifName)
        return True
示例#7
0
 def timeout_handler(signum, frame):
     raise FbossBaseError("IPERF3 SERVER TIMEOUT")
示例#8
0
 def stopPktCapture(self, interface_name):
     if interface_name not in self.pcap_captures:
         raise FbossBaseError("Calling stopPktCapture() without " +
                              " startPktCapture()?")
     del self.pcap_captures[interface_name]