summaryrefslogtreecommitdiff
path: root/test-cli/test/tests/qethernet.py
diff options
context:
space:
mode:
Diffstat (limited to 'test-cli/test/tests/qethernet.py')
-rw-r--r--test-cli/test/tests/qethernet.py38
1 files changed, 26 insertions, 12 deletions
diff --git a/test-cli/test/tests/qethernet.py b/test-cli/test/tests/qethernet.py
index 2246029..da085d8 100644
--- a/test-cli/test/tests/qethernet.py
+++ b/test-cli/test/tests/qethernet.py
@@ -1,6 +1,7 @@
import unittest
import sh
import re
+import json
class Qethernet(unittest.TestCase):
@@ -9,11 +10,16 @@ class Qethernet(unittest.TestCase):
__bwexpected = None
__port = None
params = None
+ __bwreal = None
# varlist content: serverip, bwexpected, port
def __init__(self, testname, testfunc, varlist):
+ # save the parameters list
self.params = varlist
+ # configure the function to be executed when the test runs. "testfunc" is a name of a method inside this
+ # class, that in this situation, it can only be "execute".
super(Qethernet, self).__init__(testfunc)
+ # validate and get the parameters
if "serverip" in varlist:
self.__serverip = varlist["serverip"]
else:
@@ -32,8 +38,8 @@ class Qethernet(unittest.TestCase):
def execute(self):
# execute iperf command against the server
try:
- p = sh.iperf("-c", self.__serverip, "-x", "CMSV", "-n", self.__numbytestx, "-f", "m", "-p", self.__port,
- _timeout=20)
+ p = sh.iperf3("-c", self.__serverip, "-n", self.__numbytestx, "-f", "m", "-p", self.__port, "-J",
+ _timeout=20)
except sh.TimeoutException:
self.fail("failed: iperf timeout reached")
@@ -42,17 +48,25 @@ class Qethernet(unittest.TestCase):
if p.stdout == "":
self.fail("failed: error executing iperf command")
# analyze output string
- # split by lines
- lines = p.stdout.splitlines()
- # get first line
- dat = lines[1].decode('ascii')
- # search for the BW value
- a = re.search("\d+(\.\d)? Mbits/sec", dat)
- b = a.group().split()
- bwreal = b[0]
+ data = json.loads(p.stdout.decode('ascii'))
+ self.__bwreal = float(data['end']['sum_received']['bits_per_second'])/1024/1024
+ # save result file
+ with open('/tmp/ethernet-iperf.json', 'w') as outfile:
+ json.dump(data, outfile)
# check if BW is in the expected range
- self.failUnless(float(bwreal) > float(self.__bwexpected) * 0.9,
- "failed: speed is lower than spected. Speed(MB/s)" + str(bwreal))
+ self.failUnless(self.__bwreal > float(self.__bwexpected) * 0.9,
+ "failed: speed is lower than spected. Speed(Mbits/s)" + str(self.__bwreal))
else:
self.fail("failed: could not complete iperf command")
+
+ def getresults(self):
+ # resultlist is a python list of python dictionaries
+ resultlist = [
+ {
+ "desc": "iperf3 output",
+ "data": "/tmp/ethernet-iperf.json",
+ "type": "file"
+ }
+ ]
+ return resultlist