1 # ============LICENSE_START=======================================================
3 # ================================================================================
4 # Copyright (c) 2018-2020 AT&T Intellectual Property. All rights reserved.
5 # Copyright (c) 2020 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
25 from common import do_deploy
26 from common import do_deploy_ext
27 from common import verify_external_cert
28 from common import verify_cert_post_processor
30 def test_deploy_full_tls(mockk8sapi):
31 ''' Deploy component with a full TLS configuration, to act as a server '''
33 dep, deployment_description = do_deploy({"use_tls": True, "cert_directory": "/path/to/container/cert/directory" })
35 app_container = dep.spec.template.spec.containers[0]
36 assert app_container.volume_mounts[2].mount_path == "/path/to/container/cert/directory"
38 def test_deploy_tls_off(mockk8sapi):
39 ''' TLS client only, but with cert directory configured '''
41 dep, deployment_description = do_deploy({"use_tls": False, "cert_directory": "/path/to/container/cert/directory" })
43 app_container = dep.spec.template.spec.containers[0]
44 assert app_container.volume_mounts[2].mount_path == "/path/to/container/cert/directory"
46 def test_deploy_no_tls_info(mockk8sapi):
47 ''' TLS client only, but with cert directory configured '''
49 dep, deployment_description = do_deploy()
51 app_container = dep.spec.template.spec.containers[0]
52 assert app_container.volume_mounts[2].mount_path == "/opt/dcae/cacert"
54 def test_deploy_external_cert(mockk8sapi):
55 ''' Deploy component with external TLS configuration '''
57 dep, deployment_description = do_deploy_ext({"external_cert_directory": "/path/to/container/cert/directory/",
58 "use_external_tls": True,
61 "external_certificate_parameters": {
62 "common_name": "mycommonname",
66 app_container = dep.spec.template.spec.containers[0]
67 assert app_container.volume_mounts[2].mount_path == "/opt/dcae/cacert"
69 # Make sure all of the external init container parameters are correct
70 verify_external_cert(dep)
71 verify_cert_post_processor(dep)