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
This commit is contained in:
Hiromu Asahina 2022-02-04 09:21:02 +09:00
parent e501198b0f
commit 8fade4123c
1 changed files with 13 additions and 8 deletions

View File

@ -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.