summaryrefslogtreecommitdiffstats
path: root/yardstick/common
diff options
context:
space:
mode:
authorRodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>2018-05-24 14:02:03 +0100
committerEmma Foley <emma.l.foley@intel.com>2018-06-26 13:09:43 +0100
commitf8edcdb38572642ad5aec443bac7ca3544f52a02 (patch)
tree5be043bedca448f4dfc8e4ffdebcc82317834964 /yardstick/common
parent4cbc1fef5a639ae9d762a64e8e4285f88044e4f2 (diff)
Refactor RFC2455 TRex traffic profile injection
The TRex RFC2455 traffic profile configures the duration of the traffic injection. Once the traffic is started, the traffic profile should poll the traffic injector client for the injection status. When the injection is finished, the traffic execution should end. Instead of this, the traffic profile waits a fixed time (using time.sleep method) and then stops the traffic. This approach is not accurate and may cause shorter injection periods. JIRA: YARDSTICK-1197 Change-Id: I5090df81ef4ec7945ff6c1aff070656b48e0fe77 Signed-off-by: Rodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com> (cherry picked from commit 340be73be5fd20067c23a7ddce9073639e355d3a)
Diffstat (limited to 'yardstick/common')
-rw-r--r--yardstick/common/utils.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/yardstick/common/utils.py b/yardstick/common/utils.py
index 869db469b..f9fe0e336 100644
--- a/yardstick/common/utils.py
+++ b/yardstick/common/utils.py
@@ -422,13 +422,18 @@ class ErrorClass(object):
class Timer(object):
- def __init__(self, timeout=None):
+ def __init__(self, timeout=None, raise_exception=True):
super(Timer, self).__init__()
self.start = self.delta = None
self._timeout = int(timeout) if timeout else None
+ self._timeout_flag = False
+ self._raise_exception = raise_exception
def _timeout_handler(self, *args):
- raise exceptions.TimerTimeout(timeout=self._timeout)
+ self._timeout_flag = True
+ if self._raise_exception:
+ raise exceptions.TimerTimeout(timeout=self._timeout)
+ self.__exit__()
def __enter__(self):
self.start = datetime.datetime.now()
@@ -445,6 +450,23 @@ class Timer(object):
def __getattr__(self, item):
return getattr(self.delta, item)
+ def __iter__(self):
+ self._raise_exception = False
+ return self.__enter__()
+
+ def next(self): # pragma: no cover
+ # NOTE(ralonsoh): Python 2 support.
+ if not self._timeout_flag:
+ return datetime.datetime.now()
+ raise StopIteration()
+
+ def __next__(self): # pragma: no cover
+ # NOTE(ralonsoh): Python 3 support.
+ return self.next()
+
+ def __del__(self): # pragma: no cover
+ signal.alarm(0)
+
def read_meminfo(ssh_client):
"""Read "/proc/meminfo" file and parse all keys and values"""