iperf3: Allow changing port of iperf3 server

This way several servers can run sharing same IP address.

default port variable is moved inside class to be available to tests.

Change-Id: Id4eae7cefbb1a18ecf2676f9cb22c60cc91cec7c
This commit is contained in:
Pau Espin 2018-11-14 16:38:19 +01:00
parent 289383c914
commit cf6a360efe
1 changed files with 6 additions and 4 deletions

View File

@ -22,9 +22,6 @@ import json
from . import log, util, process, pcap_recorder
DEFAULT_SRV_PORT = 5003
def iperf3_result_to_json(file):
with open(file) as f:
# Sometimes iperf3 provides 2 dictionaries, the 2nd one being an error about being interrupted (by us).
@ -37,6 +34,8 @@ def iperf3_result_to_json(file):
class IPerf3Server(log.Origin):
DEFAULT_SRV_PORT = 5003
def __init__(self, suite_run, ip_address):
super().__init__(log.C_RUN, 'iperf3-srv_%s' % ip_address.get('addr'))
self.run_dir = None
@ -44,7 +43,7 @@ class IPerf3Server(log.Origin):
self.process = None
self.suite_run = suite_run
self.ip_address = ip_address
self._port = DEFAULT_SRV_PORT
self._port = IPerf3Server.DEFAULT_SRV_PORT
def start(self):
self.log('Starting iperf3-srv')
@ -62,6 +61,9 @@ class IPerf3Server(log.Origin):
self.suite_run.remember_to_stop(self.process)
self.process.launch()
def set_port(self, port):
self._port = port
def stop(self):
self.suite_run.stop_process(self.process)