summaryrefslogtreecommitdiffstats
path: root/k8s/tests/common.py
diff options
context:
space:
mode:
authorEdyta Krukowska <edyta.krukowska@nokia.com>2021-01-29 11:35:03 +0100
committerEdyta Krukowska <edyta.krukowska@nokia.com>2021-02-04 13:19:19 +0100
commit8527090d2034a4ff2a54adc5f99b934652cc3bfe (patch)
tree9cd94ca820d37a1715d3b7e757a58006fd9324f7 /k8s/tests/common.py
parentfd9ffee0836f1bfa8c14c9caa3b24e6a183aabf0 (diff)
Upgrade k8s to use configMap
Issue-ID: DCAEGEN2-2546 Signed-off-by: Edyta Krukowska <edyta.krukowska@nokia.com> Change-Id: I41bacf0b9de239e21cc9900c408f10cea75f83c1
Diffstat (limited to 'k8s/tests/common.py')
-rw-r--r--k8s/tests/common.py133
1 files changed, 65 insertions, 68 deletions
diff --git a/k8s/tests/common.py b/k8s/tests/common.py
index d135b73..685d4ef 100644
--- a/k8s/tests/common.py
+++ b/k8s/tests/common.py
@@ -3,7 +3,7 @@
# ================================================================================
# Copyright (c) 2019-2020 AT&T Intellectual Property. All rights reserved.
# Copyright (c) 2020 Pantheon.tech. All rights reserved.
-# Copyright (c) 2020 Nokia. All rights reserved.
+# Copyright (c) 2020-2021 Nokia. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -21,32 +21,32 @@
# Common functions for unit testing
def _set_k8s_configuration():
''' Set up the basic k8s configuration '''
- return {
- "image_pull_secrets" : ["secret0", "secret1"],
- "filebeat" : {
+ return {
+ "image_pull_secrets": ["secret0", "secret1"],
+ "filebeat": {
"log_path": "/var/log/onap",
"data_path": "/usr/share/filebeat/data",
"config_path": "/usr/share/filebeat/filebeat.yml",
"config_subpath": "filebeat.yml",
- "image" : "filebeat-repo/filebeat:latest",
- "config_map" : "dcae-filebeat-configmap"
+ "image": "filebeat-repo/filebeat:latest",
+ "config_map": "dcae-filebeat-configmap"
},
- "tls" : {
+ "tls": {
"cert_path": "/opt/certs",
"image": "tlsrepo/tls-init-container:1.2.3",
"component_cert_dir": "/opt/dcae/cacert"
},
"external_cert": {
"image_tag": "repo/oom-certservice-client:2.1.0",
- "request_url" : "https://request:1010/url",
- "timeout" : "30000",
- "country" : "US",
- "organization" : "Linux-Foundation",
- "state" : "California",
- "organizational_unit" : "ONAP",
- "location" : "San-Francisco",
- "keystore_password" : "secret1",
- "truststore_password" : "secret2"
+ "request_url": "https://request:1010/url",
+ "timeout": "30000",
+ "country": "US",
+ "organization": "Linux-Foundation",
+ "state": "California",
+ "organizational_unit": "ONAP",
+ "location": "San-Francisco",
+ "keystore_password": "secret1",
+ "truststore_password": "secret2"
},
"cert_post_processor": {
"image_tag": "repo/oom-cert-post-processor:2.1.0"
@@ -56,44 +56,53 @@ def _set_k8s_configuration():
}
}
+
def _set_resources():
''' Set resources '''
return {
"limits": {
- "cpu" : 0.5,
- "memory" : "2Gi"
+ "cpu": 0.5,
+ "memory": "2Gi"
},
"requests": {
- "cpu" : 0.5,
- "memory" : "2Gi"
+ "cpu": 0.5,
+ "memory": "2Gi"
}
}
-def _set_common_kwargs():
+
+def _set_common_kwargs(config_map=None):
''' Set kwargs common to all test cases '''
- return {
+ common_kwargs = {
"volumes": [
- {"host":{"path": "/path/on/host"}, "container":{"bind":"/path/on/container","mode":"rw"}}
+ {"host": {"path": "/path/on/host"}, "container": {"bind": "/path/on/container", "mode": "rw"}}
+
],
"ports": ["80:0", "443:0"],
"env": {"NAME0": "value0", "NAME1": "value1"},
"log_info": {"log_directory": "/path/to/container/log/directory"},
- "readiness": {"type": "http", "endpoint" : "/ready"}
+ "readiness": {"type": "http", "endpoint": "/ready"}
}
+ if config_map is not None:
+ common_kwargs["volumes"].append(config_map)
+ return common_kwargs
+
def _get_item_by_name(list, name):
- ''' Search a list of k8s API objects with the specified name '''
+ """ Search a list of k8s API objects with the specified name """
for item in list:
if item.name == name:
return item
return None
+
def check_env_var(env_list, name, value):
e = _get_item_by_name(env_list, name)
assert e and e.value == value
+
def verify_common(dep, deployment_description):
- ''' Check results common to all test cases '''
+ """ Check results common to all test cases """
assert deployment_description["deployment"] == "dep-testcomponent"
assert deployment_description["namespace"] == "k8stest"
assert deployment_description["services"][0] == "testcomponent"
@@ -108,9 +117,9 @@ def verify_common(dep, deployment_description):
assert app_container.ports[1].container_port == 443
assert app_container.readiness_probe.http_get.path == "/ready"
assert app_container.readiness_probe.http_get.scheme == "HTTP"
- assert len(app_container.volume_mounts) == 3
+ assert len(app_container.volume_mounts) >= 2
assert app_container.volume_mounts[0].mount_path == "/path/on/container"
- assert app_container.volume_mounts[1].mount_path == "/path/to/container/log/directory"
+ assert app_container.volume_mounts[-2].mount_path == "/path/to/container/log/directory"
# Check environment variables
env = app_container.env
@@ -130,6 +139,7 @@ def verify_common(dep, deployment_description):
# Needs to be correctly labeled so that the Service can find it
assert dep.spec.template.metadata.labels["app"] == "testcomponent"
+
def verify_external_cert(dep):
cert_container = dep.spec.template.spec.init_containers[1]
print(cert_container)
@@ -142,27 +152,28 @@ def verify_external_cert(dep):
assert cert_container.volume_mounts[1].mount_path == "/etc/onap/oom/certservice/certs/"
expected_envs = {
- "REQUEST_URL": "https://request:1010/url",
- "REQUEST_TIMEOUT": "30000",
- "OUTPUT_PATH": "/path/to/container/cert/directory/external",
- "OUTPUT_TYPE": "P12",
- "CA_NAME": "myname",
- "COMMON_NAME": "mycommonname",
- "ORGANIZATION": "Linux-Foundation",
- "ORGANIZATION_UNIT": "ONAP",
- "LOCATION": "San-Francisco",
- "STATE": "California",
- "COUNTRY": "US",
- "SANS": "mysans",
- "KEYSTORE_PATH": "/etc/onap/oom/certservice/certs/certServiceClient-keystore.jks",
- "KEYSTORE_PASSWORD": "secret1",
- "TRUSTSTORE_PATH": "/etc/onap/oom/certservice/certs/truststore.jks",
- "TRUSTSTORE_PASSWORD": "secret2"}
+ "REQUEST_URL": "https://request:1010/url",
+ "REQUEST_TIMEOUT": "30000",
+ "OUTPUT_PATH": "/path/to/container/cert/directory/external",
+ "OUTPUT_TYPE": "P12",
+ "CA_NAME": "myname",
+ "COMMON_NAME": "mycommonname",
+ "ORGANIZATION": "Linux-Foundation",
+ "ORGANIZATION_UNIT": "ONAP",
+ "LOCATION": "San-Francisco",
+ "STATE": "California",
+ "COUNTRY": "US",
+ "SANS": "mysans",
+ "KEYSTORE_PATH": "/etc/onap/oom/certservice/certs/certServiceClient-keystore.jks",
+ "KEYSTORE_PASSWORD": "secret1",
+ "TRUSTSTORE_PATH": "/etc/onap/oom/certservice/certs/truststore.jks",
+ "TRUSTSTORE_PASSWORD": "secret2"}
envs = {k.name: k.value for k in cert_container.env}
for k in expected_envs:
assert (k in envs and expected_envs[k] == envs[k])
+
def verify_cert_post_processor(dep):
cert_container = dep.spec.template.spec.init_containers[2]
print(cert_container)
@@ -176,7 +187,7 @@ def verify_cert_post_processor(dep):
"TRUSTSTORES_PATHS": "/opt/dcae/cacert/trust.jks:/opt/dcae/cacert/external/truststore.p12",
"TRUSTSTORES_PASSWORDS_PATHS": "/opt/dcae/cacert/trust.pass:/opt/dcae/cacert/external/truststore.pass",
"KEYSTORE_SOURCE_PATHS": "/opt/dcae/cacert/external/keystore.p12:/opt/dcae/cacert/external/keystore.pass",
- "KEYSTORE_DESTINATION_PATHS": "/opt/dcae/cacert/cert.p12:/opt/dcae/cacert/p12.pass"
+ "KEYSTORE_DESTINATION_PATHS": "/opt/dcae/cacert/cert.p12:/opt/dcae/cacert/p12.pass"
}
envs = {k.name: k.value for k in cert_container.env}
@@ -184,19 +195,23 @@ def verify_cert_post_processor(dep):
assert (k in envs and expected_envs[k] == envs[k])
-def do_deploy(tls_info=None):
- ''' Common deployment operations '''
+def do_deploy(config_map=None, tls_info=None, ext_tls_info=None):
+ """ Common deployment operations """
import k8sclient.k8sclient
k8s_test_config = _set_k8s_configuration()
- kwargs = _set_common_kwargs()
+ kwargs = _set_common_kwargs(config_map)
kwargs['resources'] = _set_resources()
if tls_info:
kwargs["tls_info"] = tls_info
+ if ext_tls_info:
+ kwargs["external_cert"] = ext_tls_info
- dep, deployment_description = k8sclient.k8sclient.deploy(k8s_ctx(), "k8stest", "testcomponent", "example.com/testcomponent:1.4.3", 1, False, k8s_test_config, **kwargs)
+ dep, deployment_description = k8sclient.k8sclient.deploy(k8s_ctx(), "k8stest", "testcomponent",
+ "example.com/testcomponent:1.4.3", 1, False,
+ k8s_test_config, **kwargs)
# Make sure all of the basic k8s parameters are correct
verify_common(dep, deployment_description)
@@ -204,28 +219,10 @@ def do_deploy(tls_info=None):
return dep, deployment_description
-def do_deploy_ext(ext_tls_info):
- ''' Common deployment operations '''
- import k8sclient.k8sclient
-
- k8s_test_config = _set_k8s_configuration()
-
- kwargs = _set_common_kwargs()
- kwargs['resources'] = _set_resources()
- kwargs["external_cert"] = ext_tls_info
-
- dep, deployment_description = k8sclient.k8sclient.deploy(k8s_ctx(), "k8stest", "testcomponent", "example.com/testcomponent:1.4.3", 1, False, k8s_test_config, **kwargs)
-
- # Make sure all of the basic k8s parameters are correct
- verify_common(dep, deployment_description)
-
- return dep, deployment_description
-
class k8s_logger:
def info(self, text):
print(text)
+
class k8s_ctx:
logger = k8s_logger()
-
-