summaryrefslogtreecommitdiffstats
path: root/tests/functional/utils.py
diff options
context:
space:
mode:
authorkubi <jean.gaoliang@huawei.com>2015-09-15 03:37:14 -0400
committerkubi <jean.gaoliang@huawei.com>2015-09-25 15:32:26 +0800
commit531ac9968cf8703ad7a2c70f45837ce0e81dbec9 (patch)
treeed1a8d5e8bcb1665b49a8521858a1ac6207a5cbf /tests/functional/utils.py
parent735af0fc05d73cbc7bd97b52a230d966cbfec6c3 (diff)
Add functional tests in verify and merge
As Ana said ,"The first functional test should be as simple as a "Hello world", it shall be possible to run the "Hello world" test without using OpenStack." so i just finish functional test framework and do functional test for subcommand "runner"and"scenario" without using Openstack. JIRA:YARDSTICK-103 Change-Id: I673ae61f9922536a685d32ae62e5ad5165472f9d Signed-off-by: kubi <jean.gaoliang@huawei.com>
Diffstat (limited to 'tests/functional/utils.py')
-rwxr-xr-xtests/functional/utils.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/functional/utils.py b/tests/functional/utils.py
new file mode 100755
index 000000000..aaaaaac22
--- /dev/null
+++ b/tests/functional/utils.py
@@ -0,0 +1,63 @@
+##############################################################################
+# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+import copy
+import json
+import os
+import shutil
+import subprocess
+
+
+from oslo_utils import encodeutils
+
+
+class Yardstick(object):
+ """Create and represent separate yardstick installation.
+
+ Usage:
+ yardstick = yardstick()
+ output = yardstick("runner list")
+
+ """
+
+ def __init__(self, fake=False):
+
+ self.args = ["yardstick"]
+ self.env = copy.deepcopy(os.environ)
+
+ def __del__(self):
+ pass
+
+ def __call__(self, cmd, getjson=False, report_path=None, raw=False,
+ suffix=None, extension=None, keep_old=False,
+ write_report=False):
+ """Call yardstick in the shell
+
+ :param cmd: yardstick command
+ :param getjson: in cases, when yardstick prints JSON, you can catch output
+ deserialized
+ TO DO:
+ :param report_path: if present, yardstick command and its output will be
+ written to file with passed file name
+ :param raw: don't write command itself to report file. Only output
+ will be written
+ """
+
+ if not isinstance(cmd, list):
+ cmd = cmd.split(" ")
+ try:
+ output = encodeutils.safe_decode(subprocess.check_output(
+ self.args + cmd, stderr=subprocess.STDOUT, env=self.env))
+
+ if getjson:
+ return json.loads(output)
+ return output
+ except subprocess.CalledProcessError as e:
+ raise e
+