aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/common/utils.py
diff options
context:
space:
mode:
authorRoss Brattain <ross.b.brattain@intel.com>2017-03-13 22:08:06 -0700
committerRoss Brattain <ross.b.brattain@intel.com>2017-08-11 21:09:17 -0700
commitc2f99db8b4d8f021b29a4e3aae483ba715936a66 (patch)
treece5cbf8443c14d1078aef5ae870235c7f706d0ad /yardstick/common/utils.py
parentae6f51c15a61e345cdc609f372ad04859d2e999d (diff)
Add Ansible executor class for node context
import the AnsibleCommon class to execute Ansible playbooks Update node context support to use AnsibleCommon needs unittests We must call ansible-playbook as an executable, so we must create temp files for inventory, and for the playbooks. AnsibleCommon has evolved to be quite flexible, it auto-generates the inventory from the context['nodes'] and generates groups from the node Role. We also support either a single playbook filename, or a list of filenames. If given a list we dynamically generate a playbook that includes the other playbooks. We support adding any number of extra_vars using a temp JSON file. Also designed to be extended by subclassing. Change-Id: I5bd0a2b4547feaadd70b7e2b8801f19371b99df0 Signed-off-by: Ross Brattain <ross.b.brattain@intel.com>
Diffstat (limited to 'yardstick/common/utils.py')
-rw-r--r--yardstick/common/utils.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/yardstick/common/utils.py b/yardstick/common/utils.py
index 729bc1db9..759f43d7c 100644
--- a/yardstick/common/utils.py
+++ b/yardstick/common/utils.py
@@ -18,6 +18,7 @@
from __future__ import absolute_import
from __future__ import print_function
+import datetime
import errno
import logging
import os
@@ -382,3 +383,19 @@ class ErrorClass(object):
def __getattr__(self, item):
raise AttributeError
+
+
+class Timer(object):
+ def __init__(self):
+ super(Timer, self).__init__()
+ self.start = self.delta = None
+
+ def __enter__(self):
+ self.start = datetime.datetime.now()
+ return self
+
+ def __exit__(self, *_):
+ self.delta = datetime.datetime.now() - self.start
+
+ def __getattr__(self, item):
+ return getattr(self.delta, item)