Add option to use services with ipv6
[dcaegen2/platform/plugins.git] / k8s / tests / test_k8sclient_deploy.py
1 # ============LICENSE_START=======================================================
2 # org.onap.dcae
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
10 #
11 #      http://www.apache.org/licenses/LICENSE-2.0
12 #
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=========================================================
19
20 # Test k8sclient deployment functions
21 # Verify that for a given configuration and set of inputs, k8sclient generates the proper
22 # Kubernetes entities
23
24 import pytest
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
29
30 def test_deploy_full_tls(mockk8sapi):
31     ''' Deploy component with a full TLS configuration, to act as a server '''
32
33     dep, deployment_description = do_deploy({"use_tls": True, "cert_directory": "/path/to/container/cert/directory" })
34
35     app_container = dep.spec.template.spec.containers[0]
36     assert app_container.volume_mounts[2].mount_path == "/path/to/container/cert/directory"
37
38 def test_deploy_tls_off(mockk8sapi):
39     ''' TLS client only, but with cert directory configured '''
40
41     dep, deployment_description = do_deploy({"use_tls": False, "cert_directory": "/path/to/container/cert/directory" })
42
43     app_container = dep.spec.template.spec.containers[0]
44     assert app_container.volume_mounts[2].mount_path == "/path/to/container/cert/directory"
45
46 def test_deploy_no_tls_info(mockk8sapi):
47     ''' TLS client only, but with cert directory configured '''
48
49     dep, deployment_description = do_deploy()
50
51     app_container = dep.spec.template.spec.containers[0]
52     assert app_container.volume_mounts[2].mount_path == "/opt/dcae/cacert"
53
54 def test_deploy_external_cert(mockk8sapi):
55     ''' Deploy component with external TLS configuration '''
56
57     dep, deployment_description = do_deploy_ext({"external_cert_directory": "/path/to/container/cert/directory/",
58                                                  "use_external_tls": True,
59                                                  "cert_type": "P12",
60                                                  "ca_name": "myname",
61                                                  "external_certificate_parameters": {
62                                                      "common_name": "mycommonname",
63                                                      "sans": "mysans"}
64                                                  })
65
66     app_container = dep.spec.template.spec.containers[0]
67     assert app_container.volume_mounts[2].mount_path == "/opt/dcae/cacert"
68
69     # Make sure all of the external init container parameters are correct
70     verify_external_cert(dep)
71     verify_cert_post_processor(dep)
72
73