Add delay option to std.echo to emulate external lags.

Change-Id: Id177246996434d2ad1c111b0b7bf78664390045a
Signed-off-by: Oleg Ovcharuk <vgvoleg@gmail.com>
This commit is contained in:
Oleg Ovcharuk 2019-04-12 17:33:57 +03:00 committed by Renat Akhmerov
parent a461e07916
commit f9f994751a
2 changed files with 15 additions and 2 deletions

View File

@ -1118,6 +1118,8 @@ Input parameters:
- **output** - Value of any type that needs to be returned as a result
of the action. *Required*.
- **delay** - Float value that defines with what delay (in seconds)
the result should be returned. *Optional*.
std.javascript
''''''''''''''

View File

@ -42,13 +42,24 @@ class EchoAction(actions.Action):
stub.
"""
def __init__(self, output):
def __init__(self, output, delay=0):
super(EchoAction, self).__init__()
self.output = output
try:
self._delay = float(delay)
self._delay = 0 if self._delay < 0 else self._delay
except ValueError:
self._delay = 0
def run(self, context):
LOG.info('Running echo action [output=%s]', self.output)
LOG.info(
'Running echo action [output=%s, delay=%s]',
self.output,
self._delay
)
time.sleep(self._delay)
return self.output