def _run_server(self, cmd): logging.debug("running as server...") server = ShellProcess(cmd) try: server.wait() except OSError as e: if e.errno == errno.EINTR: server.kill()
def _run_client(self, cmd): logging.debug("running as client...") client = ShellProcess(cmd) try: rv = client.wait() except OSError as e: if e.errno == errno.EINTR: client.kill() output = client.read_nonblocking() if rv != 0: logging.info("Could not get performance throughput! Are you sure " "netperf is installed on both machines and machines " "are mutually accessible?") return (False, "Could not get performance throughput! Are you " "sure netperf is installed on both machines and " "machines are mutually accessible?") return self._parse_output(self.get_opt("threshold"), output)
def run_client(self, cmd): client = ShellProcess(cmd) try: client.wait() except OSError as e: # we got interrupted, let's gather data if e.errno == errno.EINTR: client.kill() output = client.read_nonblocking() if re.search("connect failed:", output): logging.info("Iperf connection failed!") return (False, "Iperf connection failed!") m = re.search("\[[^0-9]*[0-9]*\]\s*0.0+-\s*\d*\.\d+\s*sec\s*\d*(\.\d*){0,1}\s*[ kGMT]Bytes\s*(\d*(\.\d*){0,1}\s*[ kGMT]bits\/sec)", output, re.IGNORECASE) if m is None: logging.info("Could not get performance throughput!") return (False, "Could not get performance throughput!") rate = m.group(2) if self.threshold is not None: # check if expected threshold is reached result = self._rate_over_threshold(rate) if result: return (True, "Measured rate (%s) is over threshold (%s)." % (rate, self.threshold)) else: return (False, "Measured rate (%s) is below threshold (%s)!" % (rate, self.threshold)) else: return True, "Measured rate: %s" % rate
def run(self): nc = ShellProcess(self._compose_nc_cmd()) # check whether anything is being sent over the line td = ShellProcess(self._compose_tcpdump_cmd()) try: td.read_until_output_matches("10 packets captured", timeout=5) except ShellProcess.ProcessTerminatedError: return self.set_fail("tcpdump process died unexpectedly!") except ShellProcess.ProcessTimeoutError: return self.set_fail("No stream detected!") td.kill() duration = self.get_opt("duration", default=30) time.sleep(duration) nc.kill() logging.info("nc stream with duration of %s secs" % duration) return self.set_pass()
def run_server(self, cmd): server = ShellProcess(cmd) if not self._keep_server_running: time.sleep(float(self.duration)) server.read_nonblocking() server.kill() else: try: server.wait() except OSError as e: if e.errno == errno.EINTR: server.kill() server.read_nonblocking()
def _run_client(self, cmd): logging.debug("running as client...") res_data = {} res_data["testname"] = self._testname rv = 0 results = [] rates = [] for i in range(1, self._runs + 1): if self._runs > 1: logging.info("Netperf starting run %d" % i) clients = [] client_results = [] for i in range(0, self._num_parallel): clients.append(ShellProcess(cmd)) for client in clients: ret_code = None try: ret_code = client.wait() rv += ret_code except OSError as e: if e.errno == errno.EINTR: client.kill() output = client.read_nonblocking() logging.debug(output) if ret_code is not None and ret_code == 0: client_results.append(self._parse_output(output)) if len(client_results) > 0: #accumulate all the parallel results into one result = client_results[0] for res in client_results[1:]: result = self._sum_results(result, res) results.append(result) rates.append(results[-1]["rate"]) if results > 1: res_data["results"] = results if len(rates) > 0: rate = sum(rates) / len(rates) else: rate = 0.0 if len(rates) > 1: # setting deviation to 2xstd_deviation because of the 68-95-99.7 # rule this seems comparable to the -I 99 netperf setting res_data["std_deviation"] = std_deviation(rates) rate_deviation = 2 * res_data["std_deviation"] elif len(rates) == 1 and self._confidence is not None: result = results[0] rate_deviation = rate * (result["confidence"][1] / 100) else: rate_deviation = 0.0 res_data["rate"] = rate res_data["rate_deviation"] = rate_deviation rate_pretty = self._pretty_rate(rate) rate_dev_pretty = self._pretty_rate(rate_deviation, unit=rate_pretty["unit"]) if rv != 0 and self._runs == 1: res_data["msg"] = "Could not get performance throughput!" logging.info(res_data["msg"]) return (False, res_data) elif rv != 0 and self._runs > 1: res_data["msg"] = "At least one of the Netperf runs failed, "\ "check the logs and result data for more "\ "information." logging.info(res_data["msg"]) return (False, res_data) res_val = False res_data["msg"] = "Measured rate was %.2f +-%.2f %s" %\ (rate_pretty["rate"], rate_dev_pretty["rate"], rate_pretty["unit"]) if rate > 0.0: res_val = True else: res_val = False return (res_val, res_data) if self._max_deviation is not None: if self._max_deviation["type"] == "percent": percentual_deviation = (rate_deviation / rate) * 100 if percentual_deviation > self._max_deviation["value"]: res_val = False res_data["msg"] = "Measured rate %.2f +-%.2f %s has bigger "\ "deviation than allowed (+-%.2f %%)" %\ (rate_pretty["rate"], rate_dev_pretty["rate"], rate_pretty["unit"], self._max_deviation["value"]) return (res_val, res_data) elif self._max_deviation["type"] == "absolute": if rate_deviation > self._max_deviation["value"]["rate"]: pretty_deviation = self._pretty_rate( self._max_deviation["value"]["rate"]) res_val = False res_data["msg"] = "Measured rate %.2f +-%.2f %s has bigger "\ "deviation than allowed (+-%.2f %s)" %\ (rate_pretty["rate"], rate_dev_pretty["rate"], rate_pretty["unit"], pretty_deviation["rate"], pretty_deviation["unit"]) return (res_val, res_data) if self._threshold_interval is not None: result_interval = (rate - rate_deviation, rate + rate_deviation) threshold_pretty = self._pretty_rate(self._threshold["rate"]) threshold_dev_pretty = self._pretty_rate( self._threshold_deviation["rate"], unit=threshold_pretty["unit"]) if self._threshold_interval[0] > result_interval[1]: res_val = False res_data["msg"] = "Measured rate %.2f +-%.2f %s is lower "\ "than threshold %.2f +-%.2f %s" %\ (rate_pretty["rate"], rate_dev_pretty["rate"], rate_pretty["unit"], threshold_pretty["rate"], threshold_dev_pretty["rate"], threshold_pretty["unit"]) return (res_val, res_data) else: res_val = True res_data["msg"] = "Measured rate %.2f +-%.2f %s is higher "\ "than threshold %.2f +-%.2f %s" %\ (rate_pretty["rate"], rate_dev_pretty["rate"], rate_pretty["unit"], threshold_pretty["rate"], threshold_dev_pretty["rate"], threshold_pretty["unit"]) return (res_val, res_data) return (res_val, res_data)