diff options
author | Moshe <moshehoa@amdocs.com> | 2019-01-10 14:22:43 +0200 |
---|---|---|
committer | Moshe <moshehoa@amdocs.com> | 2019-01-10 14:22:50 +0200 |
commit | 1112c6e3e6eae3aa10680b2d7b0d653de1a4bc0b (patch) | |
tree | bca2c48047f1d525934324f2adb9d4920194b908 | |
parent | ce6df7403af5694aee412836cd3c86e33307e190 (diff) |
allow use of logical path for resources
Issue-ID: VNFSDK-350
Change-Id: I75a95412e4029389b2f1b39236339873a77db24e
Signed-off-by: Moshe <moshehoa@amdocs.com>
-rw-r--r-- | vnftest/common/utils.py | 4 | ||||
-rw-r--r-- | vnftest/core/task.py | 4 | ||||
-rw-r--r-- | vnftest/steps/rest_call.py | 5 |
3 files changed, 7 insertions, 6 deletions
diff --git a/vnftest/common/utils.py b/vnftest/common/utils.py index eaf184a..882403f 100644 --- a/vnftest/common/utils.py +++ b/vnftest/common/utils.py @@ -471,9 +471,9 @@ def resource_as_string(path): return resource.read() -def load_resource(path): +def load_resource(path, mode="r"): try: - return open(path) + return open(path, mode) except Exception: logger.info("path not loaded as file, trying load as package") split_path = os.path.split(path) diff --git a/vnftest/core/task.py b/vnftest/core/task.py index 065ad7e..41756af 100644 --- a/vnftest/core/task.py +++ b/vnftest/core/task.py @@ -124,7 +124,7 @@ class Task(object): # pragma: no cover task_args = task_args_list[i] try: if task_args_file: - with open(task_args_file) as f: + with utils.load_resource(task_args_file) as f: inputs.update(parse_task_args("task_args_file", f.read())) inputs.update(parse_task_args("task_args", task_args)) except TypeError: @@ -392,7 +392,7 @@ class TaskParser(object): # pragma: no cover LOG.info("\nParsing suite file:%s", self.path) try: - with open(self.path) as stream: + with utils.load_resource(self.path) as stream: cfg = yaml_load(stream) except IOError as ioerror: LOG.error("Open suite file failed", ioerror) diff --git a/vnftest/steps/rest_call.py b/vnftest/steps/rest_call.py index 7b034ec..3dde6f4 100644 --- a/vnftest/steps/rest_call.py +++ b/vnftest/steps/rest_call.py @@ -122,8 +122,9 @@ class RestCall(base.Step): if 'file' in operation: file_conf = operation['file'] LOG.info(file_conf) - files = {file_conf['key']: open(file_conf['path'])} - result = rest_client.upload_file(url, headers, files, LOG) + with utils.load_resource(file_conf['path']) as stream: + files = {file_conf['key']: stream} + result = rest_client.upload_file(url, headers, files, LOG) else: result = rest_client.call(url, operation['method'], |