diff options
Diffstat (limited to 'test/csit/tests/dcaegen2-collectors-hv-ves/testcases/libraries/VesHvContainersUtilsLibrary.py')
-rw-r--r-- | test/csit/tests/dcaegen2-collectors-hv-ves/testcases/libraries/VesHvContainersUtilsLibrary.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/test/csit/tests/dcaegen2-collectors-hv-ves/testcases/libraries/VesHvContainersUtilsLibrary.py b/test/csit/tests/dcaegen2-collectors-hv-ves/testcases/libraries/VesHvContainersUtilsLibrary.py index 4db04612e..989a796ce 100644 --- a/test/csit/tests/dcaegen2-collectors-hv-ves/testcases/libraries/VesHvContainersUtilsLibrary.py +++ b/test/csit/tests/dcaegen2-collectors-hv-ves/testcases/libraries/VesHvContainersUtilsLibrary.py @@ -2,6 +2,10 @@ from time import time from robot.api import logger import os.path +import docker +from io import BytesIO +from os.path import basename +from tarfile import TarFile, TarInfo LOCALHOST = "localhost" @@ -14,6 +18,14 @@ class VesHvContainersUtilsLibrary: self.get_instance_address(image_name, port) ) + def get_xnf_sim_api_access_url(self, method, host): + if is_running_inside_docker(): + return self.create_url(method, host) + else: + logger.info("File `/.dockerenv` not found. Assuming local environment and using localhost.") + port_from_container_name = str(host)[-4:] + return self.create_url(method, LOCALHOST + ":" + port_from_container_name) + def get_dcae_app_api_access_url(self, method, image_name, port): return self.create_url( method, @@ -32,3 +44,26 @@ class VesHvContainersUtilsLibrary: def is_running_inside_docker(): return os.path.isfile("/.dockerenv") + +def copy_to_container(container_id, filepaths, path='/etc/ves-hv'): + with create_archive(filepaths) as archive: + docker.APIClient('unix:///var/run/docker.sock') \ + .put_archive(container=container_id, path=(path), data=archive) + + +def create_archive(filepaths): + tarstream = BytesIO() + tarfile = TarFile(fileobj=tarstream, mode='w') + for filepath in filepaths: + file = open(filepath, 'r') + file_data = file.read() + + tarinfo = TarInfo(name=basename(file.name)) + tarinfo.size = len(file_data) + tarinfo.mtime = time() + + tarfile.addfile(tarinfo, BytesIO(file_data)) + + tarfile.close() + tarstream.seek(0) + return tarstream |