diff options
Diffstat (limited to 'vnftest/common')
-rw-r--r-- | vnftest/common/constants.py | 22 | ||||
-rw-r--r-- | vnftest/common/rest_client.py | 19 | ||||
-rw-r--r-- | vnftest/common/utils.py | 31 |
3 files changed, 45 insertions, 27 deletions
diff --git a/vnftest/common/constants.py b/vnftest/common/constants.py index acf14ea..9996ca6 100644 --- a/vnftest/common/constants.py +++ b/vnftest/common/constants.py @@ -82,23 +82,23 @@ if not SERVER_IP: # dir -CONF_DIR = get_param('dir.conf', join(VNFTEST_ROOT_PATH, 'etc/vnftest')) -IMAGE_DIR = get_param('dir.images', join(VNFTEST_ROOT_PATH, 'home/onap/images/')) -PACKAGE_DIR = get_param('dir.packages', join(VNFTEST_ROOT_PATH, 'home/onap/packages/')) +CONF_DIR = get_param('dir.conf', '/etc/vnftest') +IMAGE_DIR = get_param('dir.images', join(VNFTEST_ROOT_PATH, '../../images/')) +PACKAGE_DIR = get_param('dir.packages', join(VNFTEST_ROOT_PATH, '../../packages/')) CONF_FILE = join(CONF_DIR, 'vnftest.conf') -REPOS_DIR = get_param('dir.repos', join(VNFTEST_ROOT_PATH, 'home/onap/repos/vnftest')) -LOG_DIR = get_param('dir.log', join(VNFTEST_ROOT_PATH, 'var/log/vnftest/')) +REPOS_DIR = get_param('dir.repos', join(VNFTEST_ROOT_PATH, '..')) +LOG_DIR = get_param('dir.log', '/var/log/vnftest/') -TASK_LOG_DIR = get_param('dir.tasklog', join(VNFTEST_ROOT_PATH, 'var/log/vnftest/')) +TASK_LOG_DIR = get_param('dir.tasklog', '/var/log/vnftest/') CONF_SAMPLE_DIR = join(REPOS_DIR, 'etc/vnftest/') SAMPLE_CASE_DIR = join(REPOS_DIR, 'samples') -TESTCASE_DIR = join(REPOS_DIR, 'vnftest/test_config/onap/test_cases/') -TESTSUITE_DIR = join(REPOS_DIR, 'vnftest/test_config/onap/test_suites/') +TESTCASE_DIR = join(VNFTEST_ROOT_PATH, 'vnftest/test_config/onap/test_cases/') +TESTSUITE_DIR = join(VNFTEST_ROOT_PATH, 'vnftest/test_config/onap/test_suites/') # file -DEFAULT_OUTPUT_FILE = get_param('file.output_file', join(VNFTEST_ROOT_PATH, 'tmp/vnftest.out')) -DEFAULT_HTML_FILE = get_param('file.html_file', join(VNFTEST_ROOT_PATH, 'tmp/vnftest.htm')) -REPORTING_FILE = get_param('file.reporting_file', join(VNFTEST_ROOT_PATH, 'tmp/report.html')) +DEFAULT_OUTPUT_FILE = get_param('file.output_file', '/tmp/vnftest.out') +DEFAULT_HTML_FILE = get_param('file.html_file', '/tmp/vnftest.htm') +REPORTING_FILE = get_param('file.reporting_file', '/tmp/report.html') # api API_PORT = 5000 diff --git a/vnftest/common/rest_client.py b/vnftest/common/rest_client.py index 051f5dd..bd938e4 100644 --- a/vnftest/common/rest_client.py +++ b/vnftest/common/rest_client.py @@ -19,7 +19,8 @@ import logging import os import urllib2 import requests - +import sys +import traceback from vnftest.common import utils logger = logging.getLogger(__name__) @@ -39,8 +40,9 @@ def call(url, method, headers, data, logger): f = urllib2.urlopen(req) return_code = f.code response_body = f.read() - headers = f.headers - content_type = headers.dict['content-type'] if 'content-type' in headers.dict else 'application/json' + headers = f.headers.dict + + content_type = headers['content-type'] if 'content-type' in headers else 'application/json' f.close() if len(str(response_body)) == 0: response_body = "{}" @@ -48,9 +50,12 @@ def call(url, method, headers, data, logger): response_body = utils.xml_to_dict(response_body) else: response_body = json.loads(response_body) - result = {'return_code': return_code, 'body': response_body} + result = {'return_code': return_code, 'body': response_body, 'headers': headers} return result - + except urllib2.HTTPError as e: + error_message = e.read() + logger.exception(error_message) + raise RuntimeError(error_message) except Exception as e: message = "Cannot read content from {}, exception: {}".format(url, e) logger.exception(message) @@ -64,8 +69,8 @@ def upload_file(url, headers, file, logger): logger.debug("Upload file. URL: {}".format(url)) response = None try: - response = requests.post(url, headers=headers, files=file) - return {'return_code': response.status_code, 'body': response.json()} + response = requests.post(url, headers=headers, files=file, verify=False) + return {'return_code': response.status_code, 'body': response.json(), 'headers': response.headers} except Exception as e: message = "Error while uploading file to {}, exception: {}".format(url, e) logger.exception(message) diff --git a/vnftest/common/utils.py b/vnftest/common/utils.py index 9e2496e..eaf184a 100644 --- a/vnftest/common/utils.py +++ b/vnftest/common/utils.py @@ -156,7 +156,7 @@ def get_port_mac(sshclient, port): def get_port_ip(sshclient, port): cmd = "ifconfig %s |grep 'inet addr' |awk '{print $2}' " \ - "|cut -d ':' -f2 " % port + "|cut -d ':' -f2 " % port status, stdout, stderr = sshclient.execute(cmd) if status: @@ -483,24 +483,37 @@ def load_resource(path): return pkg_resources.resource_stream(package, split_path[1]) -def format(st, params): - if not isinstance(st, basestring): - return st +def format(in_obj, params): + if isinstance(in_obj, list): + ret_list = [] + for item in in_obj: + item = format(item, params) + ret_list.append(item) + return ret_list + if isinstance(in_obj, dict): + ret_dict = {} + for k, v in in_obj.items(): + v = format(v, params) + ret_dict[k] = v + return ret_dict + if not isinstance(in_obj, basestring): + return in_obj + dotdict(params) ret_str = "" ret_obj = None for literal_text, field_name, format_spec, conversion in \ - Formatter().parse(st): + Formatter().parse(in_obj): if field_name is None: ret_str = ret_str + literal_text else: - dict = ret_obj or params + tmp_dict = ret_obj or params try: - value = dict[field_name] + value = tmp_dict[field_name] except KeyError: - dict = dotdict(dict) + tmp_dict = dotdict(tmp_dict) field_name = '{' + field_name + '}' - value = field_name.format(**dict) + value = field_name.format(**tmp_dict) if isinstance(value, basestring): ret_str = ret_str + value else: |