1 # ============LICENSE_START=======================================================
3 # ================================================================================
4 # Copyright (c) 2018-2020 AT&T Intellectual Property. All rights reserved.
5 # Copyright (c) 2020-2021 Nokia. All rights reserved.
6 # ================================================================================
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 # ============LICENSE_END=========================================================
20 # Test k8sclient deployment functions
21 # Verify that for a given configuration and set of inputs, k8sclient generates the proper
24 from common import do_deploy, verify_ports, verify_image, verify_rediness_probe, verify_volumes, \
25 verify_logs, verify_env_variables, verify_deployment_desc, verify_label
26 from common import verify_external_cert
27 from common import verify_cert_post_processor
30 "image_pull_secrets": ["secret0", "secret1"],
32 "log_path": "/var/log/onap",
33 "data_path": "/usr/share/filebeat/data",
34 "config_path": "/usr/share/filebeat/filebeat.yml",
35 "config_subpath": "filebeat.yml",
36 "image": "filebeat-repo/filebeat:latest",
37 "config_map": "dcae-filebeat-configmap"
40 "cert_path": "/opt/certs",
41 "image": "tlsrepo/tls-init-container:1.2.3",
42 "component_cert_dir": "/opt/dcae/cacert"
45 "image_tag": "repo/oom-certservice-client:2.1.0",
46 "request_url": "https://request:1010/url",
49 "organization": "Linux-Foundation",
50 "state": "California",
51 "organizational_unit": "ONAP",
52 "location": "San-Francisco",
53 "keystore_password": "secret1",
54 "truststore_password": "secret2"
56 "cert_post_processor": {
57 "image_tag": "repo/oom-cert-post-processor:2.1.0"
60 "base_url": "https://config-binding-service:10443/service_component_all/test-component"
68 "path": "/path/on/host"
71 "bind": "/path/on/container",
85 "log_directory": "/path/to/container/log/directory"
103 KWARGS_WITH_FULL_TLS = {"tls_info": {"use_tls": True, "cert_directory": "/path/to/container/cert/directory"}}
104 KWARGS_TLS_OFF = {"tls_info": {"use_tls": False, "cert_directory": "/path/to/container/cert/directory"}}
105 KWARGS_WITH_EXTERNAL_CERT = {"external_cert": {"external_cert_directory": "/path/to/container/cert/directory/",
106 "use_external_tls": True,
109 "external_certificate_parameters": {
110 "common_name": "mycommonname",
114 KWARGS_WITH_CONFIG_MAP = {"config_volume": {"name": "myConfigMap"},
115 "container": {"bind": "/path/to/configMap", "mode": "ro"}}
118 test_data = [(KWARGS_WITH_EXTERNAL_CERT, "/opt/dcae/cacert"),
119 (BASIC_KWARGS, "/opt/dcae/cacert"),
120 (KWARGS_TLS_OFF, "/path/to/container/cert/directory"),
121 (KWARGS_WITH_FULL_TLS, "/path/to/container/cert/directory")]
124 @pytest.mark.parametrize("blueprint_dict, path", test_data)
125 def test_deploy(mockk8sapi, blueprint_dict, path):
127 kwargs = dict(BASIC_KWARGS)
128 kwargs.update(blueprint_dict)
131 dep, deployment_description = do_deploy(K8S_CONFIGURATION, kwargs)
132 app_container = dep.spec.template.spec.containers[0]
133 log_container = dep.spec.template.spec.containers[1]
137 assert app_container.volume_mounts[2].mount_path == path
138 verify_ports(app_container)
139 verify_image(app_container)
140 verify_rediness_probe(app_container)
141 verify_volumes(app_container)
142 verify_logs(log_container)
143 verify_env_variables(app_container)
144 verify_deployment_desc(deployment_description)
147 def test_deploy_external_cert(mockk8sapi):
148 """ Deploy component with external TLS configuration """
150 kwargs = dict(BASIC_KWARGS)
151 kwargs.update(KWARGS_WITH_EXTERNAL_CERT)
154 dep, deployment_description = do_deploy(K8S_CONFIGURATION, kwargs)
157 verify_external_cert(dep)
158 verify_cert_post_processor(dep)
161 def test_deploy_config_map(mockk8sapi):
162 """ Deploy component with configMap in volumes """
164 kwargs = dict(BASIC_KWARGS)
165 kwargs['volumes'].append(KWARGS_WITH_CONFIG_MAP)
168 dep, deployment_description = do_deploy(K8S_CONFIGURATION, kwargs)
169 app_container = dep.spec.template.spec.containers[0]
172 assert app_container.volume_mounts[1].mount_path == "/path/to/configMap"