summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane/client/trex_client.py
diff options
context:
space:
mode:
authorYaroslav Brustinov <ybrustin@cisco.com>2015-12-21 11:27:58 +0200
committerYaroslav Brustinov <ybrustin@cisco.com>2015-12-21 11:27:58 +0200
commitdbd2b47ce0683051288d3fa225285956fab5ab3f (patch)
tree0fafb61251d46cb82ffac484a6d5a0f5990c0882 /scripts/automation/trex_control_plane/client/trex_client.py
parent5cef472bcdc6c0b7e20e5cc42485ed5570c10f8c (diff)
latency.cpp: update ports stats at CLatencyManager::update, instead of CCPortLatency::DumpShort
Python API added: * is_idle(): determine if TRex is in idle state * sample_x_seconds(): sample TRex for given number of seconds, useful for changing device (router etc.) config afterwards.
Diffstat (limited to 'scripts/automation/trex_control_plane/client/trex_client.py')
-rwxr-xr-xscripts/automation/trex_control_plane/client/trex_client.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/scripts/automation/trex_control_plane/client/trex_client.py b/scripts/automation/trex_control_plane/client/trex_client.py
index 5709b7a5..40a8a45d 100755
--- a/scripts/automation/trex_control_plane/client/trex_client.py
+++ b/scripts/automation/trex_control_plane/client/trex_client.py
@@ -294,6 +294,34 @@ class CTRexClient(object):
finally:
self.prompt_verbose_data()
+ def is_idle (self):
+ """
+ Poll for TRex running status, check if TRex is in Idle state.
+
+ :parameters:
+ None
+
+ :return:
+ + **True** if TRex is idle.
+ + **False** if TRex is starting or running.
+
+ :raises:
+ + :exc:`trex_exceptions.TRexIncompleteRunError`, in case one of failed TRex run (unexpected termination).
+ + :exc:`TypeError`, in case JSON stream decoding error.
+ + ProtocolError, in case of error in JSON-RPC protocol.
+
+ """
+ try:
+ if self.get_running_status()['state'] == TRexStatus.Idle:
+ return True
+ return False
+ except TRexException:
+ raise
+ except ProtocolError as err:
+ raise
+ finally:
+ self.prompt_verbose_data()
+
def get_trex_files_path (self):
"""
Fetches the local path in which files are stored when pushed to TRex server from client.
@@ -455,6 +483,41 @@ class CTRexClient(object):
results = self.get_result_obj()
return results
+ def sample_x_seconds (self, sample_time, time_between_samples = 5):
+ """
+ Automatically sets ongoing sampling of TRex data for sample_time seconds, with sampling rate described by time_between_samples.
+ Does not stop the TRex afterwards!
+
+ .. tip:: Useful for changing the device (Router, ASA etc.) configuration after given time.
+
+ :parameters:
+ sample_time : int
+ sample the TRex this number of seconds
+
+ time_between_samples : int
+ determines the time between each sample of the server
+
+ default value : **5**
+
+ :return:
+ the first result object (see :class:`CTRexResult` for further details) of the TRex run after given sample_time.
+
+ :raises:
+ + :exc:`UserWarning`, in case the TRex run ended before sample_time duration
+ + :exc:`trex_exceptions.TRexIncompleteRunError`, in case one of failed TRex run (unexpected termination).
+ + :exc:`TypeError`, in case JSON stream decoding error.
+ + ProtocolError, in case of error in JSON-RPC protocol.
+
+ """
+ # make sure TRex is running. raise exceptions here if any
+ self.wait_until_kickoff_finish()
+ elapsed_time = 0
+ while self.is_running():
+ if elapsed_time >= sample_time:
+ return self.get_result_obj()
+ time.sleep(time_between_samples)
+ elapsed_time += time_between_samples
+ raise UserWarning("TRex has stopped at %s seconds (before expected %s seconds)\nTry increasing test duration or decreasing sample_time" % (elapsed_time, sample_time))
def get_result_obj (self, copy_obj = True):
"""