aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/common
diff options
context:
space:
mode:
authorchenjiankun <chenjiankun1@huawei.com>2016-12-01 07:34:23 +0000
committerchenjiankun <chenjiankun1@huawei.com>2016-12-04 09:50:31 +0000
commit99ff997e0f9caf6ab4ba831d4272d803d3047909 (patch)
treebcb654af22d6689a3b7e9f8724272966990c7626 /yardstick/common
parent78d6cbd462fc7db9dcdab4d2478f6c27437d4c88 (diff)
Add API and command support for yardstick env prepare
JIRA: YARDSTICK-406 Change-Id: Icf837a6f34a22158203566a43a6446fc269c096f Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
Diffstat (limited to 'yardstick/common')
-rw-r--r--yardstick/common/constants.py28
-rw-r--r--yardstick/common/httpClient.py3
-rw-r--r--yardstick/common/utils.py41
3 files changed, 69 insertions, 3 deletions
diff --git a/yardstick/common/constants.py b/yardstick/common/constants.py
index 07d869755..d541ead15 100644
--- a/yardstick/common/constants.py
+++ b/yardstick/common/constants.py
@@ -1,6 +1,4 @@
-CONFIG_SAMPLE = '/etc/yardstick/config.yaml'
-
-RELENG_DIR = 'releng.dir'
+import os
DOCKER_URL = 'unix://var/run/docker.sock'
@@ -14,3 +12,27 @@ INFLUXDB_TAG = '0.13'
GRAFANA_IMAGE = 'grafana/grafana'
GRAFANA_TAGS = '3.1.1'
+
+dirname = os.path.dirname
+abspath = os.path.abspath
+sep = os.path.sep
+
+INSTALLERS = ['apex', 'compass', 'fuel', 'joid']
+
+YARDSTICK_ROOT_PATH = dirname(dirname(dirname(abspath(__file__)))) + sep
+
+YARDSTICK_REPOS_DIR = '/home/opnfv/repos/yardstick'
+
+YARDSTICK_CONFIG_DIR = '/etc/yardstick/'
+
+YARDSTICK_CONFIG_FILE = os.path.join(YARDSTICK_CONFIG_DIR, 'config.yaml')
+
+RELENG_DIR = '/home/opnfv/repos/releng'
+
+OS_FETCH_SCRIPT = 'utils/fetch_os_creds.sh'
+
+LOAD_IMAGES_SCRIPT = 'tests/ci/load_images.sh'
+
+OPENSTACK_RC_FILE = os.path.join(YARDSTICK_CONFIG_DIR, 'openstack.creds')
+
+YARDSTICK_ENV_ACTION_API = 'http://localhost:5000/yardstick/env/action'
diff --git a/yardstick/common/httpClient.py b/yardstick/common/httpClient.py
index b6959b400..ab2e9a379 100644
--- a/yardstick/common/httpClient.py
+++ b/yardstick/common/httpClient.py
@@ -23,5 +23,8 @@ class HttpClient(object):
response = requests.post(url, data=data, headers=headers)
result = response.json()
logger.debug('The result is: %s', result)
+
+ return result
except Exception as e:
logger.debug('Failed: %s', e)
+ raise
diff --git a/yardstick/common/utils.py b/yardstick/common/utils.py
index afbe4e8ec..3ecb0ae20 100644
--- a/yardstick/common/utils.py
+++ b/yardstick/common/utils.py
@@ -19,10 +19,19 @@ import os
import sys
import yaml
import errno
+import subprocess
+import logging
+
from oslo_utils import importutils
+from keystoneauth1 import identity
+from keystoneauth1 import session
+from neutronclient.v2_0 import client
import yardstick
+logger = logging.getLogger(__name__)
+logger.setLevel(logging.DEBUG)
+
# Decorator for cli-args
def cliargs(*args, **kwargs):
@@ -100,3 +109,35 @@ def makedirs(d):
except OSError as e:
if e.errno != errno.EEXIST:
raise
+
+
+def execute_command(cmd):
+ exec_msg = "Executing command: '%s'" % cmd
+ logger.debug(exec_msg)
+
+ output = subprocess.check_output(cmd.split()).split(os.linesep)
+
+ return output
+
+
+def source_env(env_file):
+ p = subprocess.Popen(". %s; env" % env_file, stdout=subprocess.PIPE,
+ shell=True)
+ output = p.communicate()[0]
+ env = dict((line.split('=', 1) for line in output.splitlines()))
+ os.environ.update(env)
+ return env
+
+
+def get_openstack_session():
+ auth = identity.Password(auth_url=os.environ.get('OS_AUTH_URL'),
+ username=os.environ.get('OS_USERNAME'),
+ password=os.environ.get('OS_PASSWORD'),
+ tenant_name=os.environ.get('OS_TENANT_NAME'))
+ return session.Session(auth=auth)
+
+
+def get_neutron_client():
+ sess = get_openstack_session()
+ neutron_client = client.Client(session=sess)
+ return neutron_client