From 8fade4123cff75a6f684eb42dbbf946cc9c31c04 Mon Sep 17 00:00:00 2001 From: Hiromu Asahina Date: Fri, 4 Feb 2022 09:21:02 +0900 Subject: [PATCH] Change test utils to use absolute path In the current implementation, a relative path from the project root is used to get sample files (e.g., VNF packages) for tests. Due to this, it's not possible to run a specific test in different place from the project root. This patch solves this problem by obtaining absolute paths from a test file. Change-Id: I541ea67965fc24121f0dca6aabd9d4b9210d9175 --- tacker/tests/utils.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/tacker/tests/utils.py b/tacker/tests/utils.py index 2d06b2631..5cd861fac 100644 --- a/tacker/tests/utils.py +++ b/tacker/tests/utils.py @@ -73,6 +73,8 @@ def create_csar_with_unique_vnfd_id(csar_dir): - csar_file_name - vnfd_id """ + current_dir = os.path.dirname(os.path.abspath(__file__)) + csar_dir = os.path.join(current_dir, "../../", csar_dir) unique_id = uuidutils.generate_uuid() tempfd, tempname = tempfile.mkstemp(suffix=".zip", dir=os.path.dirname(csar_dir)) @@ -217,11 +219,12 @@ def copy_csar_files(fake_csar_path, csar_dir_name, :param read_vnfd_only: when set to 'True', it won't copy the image file from source directory. """ - sample_vnf_package = os.path.join( - "./tacker/tests/etc/samples/etsi/nfv", csar_dir_name) + current_dir = os.path.dirname(os.path.abspath(__file__)) + sample_vnf_package = os.path.join(current_dir, "etc/samples/etsi/nfv", + csar_dir_name) shutil.copytree(sample_vnf_package, fake_csar_path) - common_files_path = os.path.join( - "./tacker/tests/etc/samples/etsi/nfv/common/") + common_files_path = os.path.join(current_dir, + "etc/samples/etsi/nfv/common/") if not read_vnfd_only: # Copying image file. @@ -245,11 +248,13 @@ def copy_csar_files(fake_csar_path, csar_dir_name, def copy_artifact_files(fake_csar_path, csar_dir_name, csar_without_tosca_meta=False, read_vnfd_only=False): - sample_vnf_package = os.path.join( - "./tacker/tests/etc/samples/etsi/nfv", csar_dir_name) + current_dir = os.path.dirname(os.path.abspath(__file__)) + sample_vnf_package = os.path.join(current_dir, + "etc/samples/etsi/nfv", + csar_dir_name) shutil.copytree(sample_vnf_package, fake_csar_path) - common_files_path = os.path.join( - "./tacker/tests/etc/samples/etsi/nfv/") + common_files_path = os.path.join(current_dir, + "etc/samples/etsi/nfv/") if not read_vnfd_only: # Copying image file.