From 334a204a6e0ce7e7a28de8ac3f8fb008bcc5683a Mon Sep 17 00:00:00 2001 From: Jan Malkiewicz Date: Fri, 25 Sep 2020 07:02:24 +0200 Subject: [OOM-CMPv2] Refator names in oom-certservice-post-processor tests. Issue-ID: DCAEGEN2-2253 Signed-off-by: Jan Malkiewicz Change-Id: I6aa0bc0428724860b5538dc3e2d698e2023074e2 --- .../certservice-postprocessor-test.robot | 96 +++++++++++----------- .../libraries/PostProcessorDockerContainerUtils.py | 47 +++++++++++ .../postprocessor/libraries/TrustMergerManager.py | 47 ----------- .../postprocessor/resources/test-keywords.robot | 34 ++++---- .../postprocessor/resources/test-properties.robot | 4 +- 5 files changed, 114 insertions(+), 114 deletions(-) create mode 100644 tests/oom-platform-cert-service/postprocessor/libraries/PostProcessorDockerContainerUtils.py delete mode 100644 tests/oom-platform-cert-service/postprocessor/libraries/TrustMergerManager.py diff --git a/tests/oom-platform-cert-service/postprocessor/certservice-postprocessor-test.robot b/tests/oom-platform-cert-service/postprocessor/certservice-postprocessor-test.robot index 67d1af60..338f16ff 100644 --- a/tests/oom-platform-cert-service/postprocessor/certservice-postprocessor-test.robot +++ b/tests/oom-platform-cert-service/postprocessor/certservice-postprocessor-test.robot @@ -6,83 +6,83 @@ Resource ./resources/test-keywords.robot *** Test Cases *** -Trust Merger fails when file extension is invalid - [Tags] OOM-TRUST-STORE-MERGER +Cert Post Processor fails when file extension is invalid (merger) + [Tags] OOM-CERTSERVICE-POST-PROCESSOR [Documentation] Run with invalid truststore extension env and expect error code - Run Trust Merger And Expect Error ${ENV_FILE_INVALID_FILE_EXTENSION} ${EXITCODE_CERTIFICATES_PATHS_VALIDATION_EXCEPTION} + Run Cert Service Post Processor And Expect Error ${ENV_FILE_INVALID_FILE_EXTENSION} ${EXITCODE_CERTIFICATES_PATHS_VALIDATION_EXCEPTION} -Trust Merger fails when a variable is empty - [Tags] OOM-TRUST-STORE-MERGER +Cert Post Processor fails when a variable is empty (merger) + [Tags] OOM-CERTSERVICE-POST-PROCESSOR [Documentation] Run with empty truststore password path env and expect error code - Run Trust Merger And Expect Error ${ENV_FILE_EMPTY_PASSWORDS} ${EXITCODE_CERTIFICATES_PATHS_VALIDATION_EXCEPTION} + Run Cert Service Post Processor And Expect Error ${ENV_FILE_EMPTY_PASSWORDS} ${EXITCODE_CERTIFICATES_PATHS_VALIDATION_EXCEPTION} -Trust Merger fails when truststore and passwords envs not provided - [Tags] OOM-TRUST-STORE-MERGER +Cert Post Processor fails when truststore and passwords envs not provided (merger) + [Tags] OOM-CERTSERVICE-POST-PROCESSOR [Documentation] Run with invalid empty envs and expect error code - Run Trust Merger And Expect Error ${ENV_FILE_EMPTY} ${EXITCODE_CONFIGURATION_EXCEPTION} + Run Cert Service Post Processor And Expect Error ${ENV_FILE_EMPTY} ${EXITCODE_CONFIGURATION_EXCEPTION} -Trust Merger fails when list sizes are different - [Tags] OOM-TRUST-STORE-MERGER +Cert Post Processor fails when list sizes are different (merger) + [Tags] OOM-CERTSERVICE-POST-PROCESSOR [Documentation] Run with different truststore and password envs size and expect error code - Run Trust Merger And Expect Error ${ENV_FILE_INVALID_FILE_LIST_SIZE} ${EXITCODE_CONFIGURATION_EXCEPTION} + Run Cert Service Post Processor And Expect Error ${ENV_FILE_INVALID_FILE_LIST_SIZE} ${EXITCODE_CONFIGURATION_EXCEPTION} -Trust Merger fails when truststore paths are invalid - [Tags] OOM-TRUST-STORE-MERGER +Cert Post Processor fails when truststore paths are invalid (merger) + [Tags] OOM-CERTSERVICE-POST-PROCESSOR [Documentation] Run with invalid truststore path and expect error code - Run Trust Merger And Expect Error ${ENV_FILE_INVALID_TRUSTSTORE_PATHS} ${EXITCODE_TRUSTSTORE_FILE_FACTORY_EXCEPTION} + Run Cert Service Post Processor And Expect Error ${ENV_FILE_INVALID_TRUSTSTORE_PATHS} ${EXITCODE_TRUSTSTORE_FILE_FACTORY_EXCEPTION} -Trust Merger fails when password path is invalid - [Tags] OOM-TRUST-STORE-MERGER +Cert Post Processor fails when password path is invalid (merger) + [Tags] OOM-CERTSERVICE-POST-PROCESSOR [Documentation] Run with invalid password path and expect error code - Run Trust Merger And Expect Error ${ENV_FILE_INVALID_PASSWORD_PATHS} ${EXITCODE_PASSWORD_READER_EXCEPTION} + Run Cert Service Post Processor And Expect Error ${ENV_FILE_INVALID_PASSWORD_PATHS} ${EXITCODE_PASSWORD_READER_EXCEPTION} -Trust Merger fails when password file pair is invalid - [Tags] OOM-TRUST-STORE-MERGER +Cert Post Processor fails when password file pair is invalid (merger) + [Tags] OOM-CERTSERVICE-POST-PROCESSOR [Documentation] Run with incorrect password env and expect error code - Run Trust Merger And Expect Error ${ENV_FILE_INVALID_PASSWORD} ${EXITCODE_TRUSTSTORE_LOAD_FILE_EXCEPTION} + Run Cert Service Post Processor And Expect Error ${ENV_FILE_INVALID_PASSWORD} ${EXITCODE_TRUSTSTORE_LOAD_FILE_EXCEPTION} -Trust Merger fails when pem does not contain cert - [Tags] OOM-TRUST-STORE-MERGER +Cert Post Processor fails when pem does not contain cert (merger) + [Tags] OOM-CERTSERVICE-POST-PROCESSOR [Documentation] Run with empty pem truststore and expect error code - Run Trust Merger And Expect Error ${ENV_FILE_EMPTY_CERTS} ${EXITCODE_MISSING_TRUSTSTORE_EXCEPTIONSUCCESS} + Run Cert Service Post Processor And Expect Error ${ENV_FILE_EMPTY_CERTS} ${EXITCODE_MISSING_TRUSTSTORE_EXCEPTIONSUCCESS} -Trust Merger fails when aliases are duplicated - [Tags] OOM-TRUST-STORE-MERGER +Cert Post Processor fails when aliases are duplicated (merger) + [Tags] OOM-CERTSERVICE-POST-PROCESSOR [Documentation] Run with duplicated aliases in truststores and expect error code - Run Trust Merger And Expect Error ${ENV_FILE_DUPLICATED_ALIASES} ${EXITCODE_ALIAS_CONFLICT_EXCEPTION} + Run Cert Service Post Processor And Expect Error ${ENV_FILE_DUPLICATED_ALIASES} ${EXITCODE_ALIAS_CONFLICT_EXCEPTION} -Trust Merger merges successfully jks pem p12 - [Tags] OOM-TRUST-STORE-MERGER +Cert Post Processor merges successfully jks pem p12 (merger) + [Tags] OOM-CERTSERVICE-POST-PROCESSOR [Documentation] Run with valid env file and expect merged certs from jks, pem and p12 - Run Trust Merger And Merge Truststore Files To Jks ${ENV_FILE_JKS_PEM_P12} ${EXITCODE_SUCCESS} ${JKS_TRUSTSTORE_MOUNT_PATH} ${TRUSTSTORE_JKS_PASS} ${JKS_TRUSTSTORE_EXPECTED_PATH} + Run Cert Service Post Processor And Merge Truststore Files To Jks ${ENV_FILE_JKS_PEM_P12} ${EXITCODE_SUCCESS} ${JKS_TRUSTSTORE_MOUNT_PATH} ${TRUSTSTORE_JKS_PASS} ${JKS_TRUSTSTORE_EXPECTED_PATH} -Trust Merger merges successfully pem p12 - [Tags] OOM-TRUST-STORE-MERGER +Cert Post Processor merges successfully pem p12 (merger) + [Tags] OOM-CERTSERVICE-POST-PROCESSOR [Documentation] Run with valid env file and expect merged certs from pem and p12 - Run Trust Merger And Merge Truststore Files To Pem ${ENV_FILE_PEM_P12} ${EXITCODE_SUCCESS} ${PEM_TRUSTSTORE_MOUNT_PATH} ${PEM_TRUSTSTORE_EXPECTED_PATH} + Run Cert Service Post Processor And Merge Truststore Files To Pem ${ENV_FILE_PEM_P12} ${EXITCODE_SUCCESS} ${PEM_TRUSTSTORE_MOUNT_PATH} ${PEM_TRUSTSTORE_EXPECTED_PATH} -Trust Merger ends successfully with single truststore - [Tags] OOM-TRUST-STORE-MERGER +Cert Post Processor ends successfully with single truststore (merger) + [Tags] OOM-CERTSERVICE-POST-PROCESSOR [Documentation] Run with one truststore in env file and expect code 0 - Run Trust Merger And Merge Truststore Files To Jks ${ENV_FILE_SINGLE_TRUSTSTORE} ${EXITCODE_SUCCESS} ${JKS_TRUSTSTORE_MOUNT_PATH} ${TRUSTSTORE_JKS_PASS} ${TRUSTSTORE_JKS} + Run Cert Service Post Processor And Merge Truststore Files To Jks ${ENV_FILE_SINGLE_TRUSTSTORE} ${EXITCODE_SUCCESS} ${JKS_TRUSTSTORE_MOUNT_PATH} ${TRUSTSTORE_JKS_PASS} ${TRUSTSTORE_JKS} -Trust Merger fails when file to copy does not exist - [Tags] OOM-TRUST-STORE-MERGER +Cert Post Processor fails when file to copy does not exist (merger) + [Tags] OOM-CERTSERVICE-POST-PROCESSOR [Documentation] Run with invalid extra optional env as a path to file and expect error code - Run Trust Merger And Expect Error ${ENV_FILE_INVALID_KEYSTORE_SOURCE_PATHS} ${EXITCODE_KEYSTORE_NOT_EXIST_EXCEPTION} + Run Cert Service Post Processor And Expect Error ${ENV_FILE_INVALID_KEYSTORE_SOURCE_PATHS} ${EXITCODE_KEYSTORE_NOT_EXIST_EXCEPTION} -Trust Merger fails when only one extra optional env is set - [Tags] OOM-TRUST-STORE-MERGER +Cert Post Processor fails when only one extra optional env is set (merger) + [Tags] OOM-CERTSERVICE-POST-PROCESSOR [Documentation] Run with empty extra optional env and expect code - Run Trust Merger And Expect Error ${ENV_FILE_EMPTY_KEYSTORE_DESTINATION_PATH} ${EXITCODE_CONFIGURATION_EXCEPTION} + Run Cert Service Post Processor And Expect Error ${ENV_FILE_EMPTY_KEYSTORE_DESTINATION_PATH} ${EXITCODE_CONFIGURATION_EXCEPTION} -Trust Merger's Copier successfully backs up files - [Tags] OOM-TRUST-STORE-MERGER +Cert Post Processor successfully backs up files (copier) + [Tags] OOM-CERTSERVICE-POST-PROCESSOR [Documentation] Run with valid env file and expect successfully backed up file - Run Trust Merger And Check Copied Keystore Files ${ENV_FILE_EXTRA_OPTIONAL_ENVS} ${EXITCODE_SUCCESS} ${JKS_KEYSTORE_MOUNT_PATH} ${KEYSTORE_JKS_PASS} ${JKSBAK_KEYSTORE_EXPECTED_PATH} + Run Cert Service Post Processor And Check Copied Keystore Files ${ENV_FILE_EXTRA_OPTIONAL_ENVS} ${EXITCODE_SUCCESS} ${JKS_KEYSTORE_MOUNT_PATH} ${KEYSTORE_JKS_PASS} ${JKSBAK_KEYSTORE_EXPECTED_PATH} -Trust Merger's Copier successfully copies file - [Tags] OOM-TRUST-STORE-MERGER +Cert Post Processor successfully copies file (copier) + [Tags] OOM-CERTSERVICE-POST-PROCESSOR [Documentation] Run with valid env file and expect successfully copied file - Run Trust Merger And Check Copied Keystore Files ${ENV_FILE_EXTRA_OPTIONAL_ENVS} ${EXITCODE_SUCCESS} ${JKS_KEYSTORE_MOUNT_PATH} ${KEYSTORE_JKS_PASS} ${JKS_KEYSTORE_EXPECTED_PATH} + Run Cert Service Post Processor And Check Copied Keystore Files ${ENV_FILE_EXTRA_OPTIONAL_ENVS} ${EXITCODE_SUCCESS} ${JKS_KEYSTORE_MOUNT_PATH} ${KEYSTORE_JKS_PASS} ${JKS_KEYSTORE_EXPECTED_PATH} diff --git a/tests/oom-platform-cert-service/postprocessor/libraries/PostProcessorDockerContainerUtils.py b/tests/oom-platform-cert-service/postprocessor/libraries/PostProcessorDockerContainerUtils.py new file mode 100644 index 00000000..e0563b3f --- /dev/null +++ b/tests/oom-platform-cert-service/postprocessor/libraries/PostProcessorDockerContainerUtils.py @@ -0,0 +1,47 @@ +import docker +import os +import shutil +from EnvsReader import EnvsReader +from docker.types import Mount + +ARCHIVES_PATH = os.getenv("WORKSPACE") + "/archives/" + + +class PostProcessorDockerContainerUtils: + + def __init__(self, mount_path, truststores_path): + self.mount_path = mount_path + self.truststores_path = truststores_path + + def run_container(self, docker_image, image_name, path_to_env): + self.remove_mount_dir() + shutil.copytree(self.truststores_path, self.mount_path) + client = docker.from_env() + environment = EnvsReader().read_env_list_from_file(path_to_env) + container = client.containers.run( + image=docker_image, + name=image_name, + environment=environment, + user='root', # Run container as root to avoid permission issues with volume mount access + mounts=[Mount(target='/var/certs', source=self.mount_path, type='bind')], + detach=True + ) + exitcode = container.wait() + return exitcode + + def create_mount_dir(self): + if not os.path.exists(self.mount_path): + os.makedirs(self.mount_path) + + def remove_mount_dir(self): + if os.path.exists(self.mount_path): + shutil.rmtree(self.mount_path) + + def remove_container_and_save_logs(self, container_name, log_file_name): + client = docker.from_env() + container = client.containers.get(container_name) + text_file = open(ARCHIVES_PATH + "certservice_postprocessor_container_" + log_file_name + ".log", "w") + text_file.write(container.logs()) + text_file.close() + container.remove() + self.remove_mount_dir() diff --git a/tests/oom-platform-cert-service/postprocessor/libraries/TrustMergerManager.py b/tests/oom-platform-cert-service/postprocessor/libraries/TrustMergerManager.py deleted file mode 100644 index f7a493c4..00000000 --- a/tests/oom-platform-cert-service/postprocessor/libraries/TrustMergerManager.py +++ /dev/null @@ -1,47 +0,0 @@ -import docker -import os -import shutil -from EnvsReader import EnvsReader -from docker.types import Mount - -ARCHIVES_PATH = os.getenv("WORKSPACE") + "/archives/" - - -class TrustMergerManager: - - def __init__(self, mount_path, truststores_path): - self.mount_path = mount_path - self.truststores_path = truststores_path - - def run_merger_container(self, merger_image, merger_name, path_to_env): - self.remove_mount_dir() - shutil.copytree(self.truststores_path, self.mount_path) - client = docker.from_env() - environment = EnvsReader().read_env_list_from_file(path_to_env) - container = client.containers.run( - image=merger_image, - name=merger_name, - environment=environment, - user='root', # Run container as root to avoid permission issues with volume mount access - mounts=[Mount(target='/var/certs', source=self.mount_path, type='bind')], - detach=True - ) - exitcode = container.wait() - return exitcode - - def create_mount_dir(self): - if not os.path.exists(self.mount_path): - os.makedirs(self.mount_path) - - def remove_mount_dir(self): - if os.path.exists(self.mount_path): - shutil.rmtree(self.mount_path) - - def remove_merger_container_and_save_logs(self, container_name, log_file_name): - client = docker.from_env() - container = client.containers.get(container_name) - text_file = open(ARCHIVES_PATH + "merger_container_" + log_file_name + ".log", "w") - text_file.write(container.logs()) - text_file.close() - container.remove() - self.remove_mount_dir() diff --git a/tests/oom-platform-cert-service/postprocessor/resources/test-keywords.robot b/tests/oom-platform-cert-service/postprocessor/resources/test-keywords.robot index 514e2391..404ec0ae 100644 --- a/tests/oom-platform-cert-service/postprocessor/resources/test-keywords.robot +++ b/tests/oom-platform-cert-service/postprocessor/resources/test-keywords.robot @@ -2,43 +2,43 @@ Resource ../../../common.robot Resource ./test-properties.robot -Library ../libraries/TrustMergerManager.py ${MOUNT_PATH} ${TRUSTSTORES_PATH} +Library ../libraries/PostProcessorDockerContainerUtils.py ${MOUNT_PATH} ${TRUSTSTORES_PATH} Library ../libraries/JksValidator.py Library ../libraries/PemTruststoreValidator.py *** Keywords *** -Run Trust Merger And Expect Error - [Documentation] Run Truststore Merger Container And Validate Exit Code +Run Cert Service Post Processor And Expect Error + [Documentation] Run Cert Service Post Processor Container And Validate Exit Code [Arguments] ${env_file} ${expected_exit_code} - ${exit_code}= Run Merger Container ${DOCKER_MERGER_IMAGE} ${MERGER_CONTAINER_NAME} ${env_file} - Remove Merger Container And Save Logs ${MERGER_CONTAINER_NAME} negative_path + ${exit_code}= Run Container ${CERT_POST_PROCESSOR_DOCKER_IMAGE} ${CERT_POST_PROCESSOR_CONTAINER_NAME} ${env_file} + Remove Container And Save Logs ${CERT_POST_PROCESSOR_CONTAINER_NAME} negative_path Should Be Equal As Strings ${exit_code} ${expected_exit_code} Client return unexpected exit code return: ${exitcode} , but expected: ${expected_exit_code} -Run Trust Merger And Merge Truststore Files To Jks - [Documentation] Run Truststore Merger Container And Validate Exit Code And Provided Truststore Files +Run Cert Service Post Processor And Merge Truststore Files To Jks + [Documentation] Run Cert Service Post Processor Container And Validate Exit Code And Provided Truststore Files [Arguments] ${env_file} ${expected_exit_code} ${jks_path} ${jks_password} ${expected_jks_path} - ${exit_code}= Run Merger Container ${DOCKER_MERGER_IMAGE} ${MERGER_CONTAINER_NAME} ${env_file} + ${exit_code}= Run Container ${CERT_POST_PROCESSOR_DOCKER_IMAGE} ${CERT_POST_PROCESSOR_CONTAINER_NAME} ${env_file} ${files_equal}= Assert Jks Truststores Equal ${jks_path} ${jks_password} ${expected_jks_path} - Remove Merger Container And Save Logs ${MERGER_CONTAINER_NAME} positive_path + Remove Container And Save Logs ${CERT_POST_PROCESSOR_CONTAINER_NAME} positive_path Should Be Equal As Strings ${exit_code} ${expected_exit_code} Client return unexpected exit code return: ${exitcode} , but expected: ${expected_exit_code} Should Be True ${files_equal} -Run Trust Merger And Check Copied Keystore Files - [Documentation] Run Truststore Merger Container And Validate Exit Code And Provided Keystore Files +Run Cert Service Post Processor And Check Copied Keystore Files + [Documentation] Run Cert Service Post Processor Container And Validate Exit Code And Provided Keystore Files [Arguments] ${env_file} ${expected_exit_code} ${jks_path} ${jks_password} ${expected_jks_path} - ${exit_code}= Run Merger Container ${DOCKER_MERGER_IMAGE} ${MERGER_CONTAINER_NAME} ${env_file} + ${exit_code}= Run Container ${CERT_POST_PROCESSOR_DOCKER_IMAGE} ${CERT_POST_PROCESSOR_CONTAINER_NAME} ${env_file} ${files_equal}= Assert Jks Keystores Equal ${jks_path} ${jks_password} ${expected_jks_path} - Remove Merger Container And Save Logs ${MERGER_CONTAINER_NAME} positive_path + Remove Container And Save Logs ${CERT_POST_PROCESSOR_CONTAINER_NAME} positive_path Should Be Equal As Strings ${exit_code} ${expected_exit_code} Client return unexpected exit code return: ${exitcode} , but expected: ${expected_exit_code} Should Be True ${files_equal} -Run Trust Merger And Merge Truststore Files To Pem - [Documentation] Run Truststore Merger Container And Validate Exit Code And Files +Run Cert Service Post Processor And Merge Truststore Files To Pem + [Documentation] Run Cert Service Post Processor Container And Validate Exit Code And Files [Arguments] ${env_file} ${expected_exit_code} ${pem_path} ${expected_pem_path} - ${exit_code}= Run Merger Container ${DOCKER_MERGER_IMAGE} ${MERGER_CONTAINER_NAME} ${env_file} + ${exit_code}= Run Container ${CERT_POST_PROCESSOR_DOCKER_IMAGE} ${CERT_POST_PROCESSOR_CONTAINER_NAME} ${env_file} ${files_equal}= Assert Pem Truststores Equal ${pem_path} ${expected_pem_path} - Remove Merger Container And Save Logs ${MERGER_CONTAINER_NAME} positive_path + Remove Container And Save Logs ${CERT_POST_PROCESSOR_CONTAINER_NAME} positive_path Should Be Equal As Strings ${exit_code} ${expected_exit_code} Client return unexpected exit code return: ${exitcode} , but expected: ${expected_exit_code} Should Be True ${files_equal} diff --git a/tests/oom-platform-cert-service/postprocessor/resources/test-properties.robot b/tests/oom-platform-cert-service/postprocessor/resources/test-properties.robot index ab4c18ba..80fc06af 100644 --- a/tests/oom-platform-cert-service/postprocessor/resources/test-properties.robot +++ b/tests/oom-platform-cert-service/postprocessor/resources/test-properties.robot @@ -1,7 +1,7 @@ *** Variables *** -${DOCKER_MERGER_IMAGE} nexus3.onap.org:10001/onap/org.onap.oom.platform.cert-service.oom-certservice-post-processor:latest -${MERGER_CONTAINER_NAME} %{CertServicePostProcessorContainerName} +${CERT_POST_PROCESSOR_DOCKER_IMAGE} nexus3.onap.org:10001/onap/org.onap.oom.platform.cert-service.oom-certservice-post-processor:latest +${CERT_POST_PROCESSOR_CONTAINER_NAME} %{CertServicePostProcessorContainerName} ${BASE_PATH} %{WORKSPACE}/tests/oom-platform-cert-service/postprocessor ${MOUNT_PATH} ${BASE_PATH}/tmp ${TRUSTSTORES_PATH} ${BASE_PATH}/assets/truststores -- cgit 1.2.3-korg