Address k8s plugin code smells reported by sonar
[dcaegen2/platform/plugins.git] / k8s / tests / test_k8sclient_deploy.py
1 # ============LICENSE_START=======================================================
2 # org.onap.dcae
3 # ================================================================================
4 # Copyright (c) 2018-2019 AT&T Intellectual Property. All rights reserved.
5 # ================================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 #      http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 # ============LICENSE_END=========================================================
18
19 # Test k8sclient deployment functions
20 # Verify that for a given configuration and set of inputs, k8sclient generates the proper
21 # Kubernetes entities
22
23 import pytest
24 from common import do_deploy
25
26 def test_deploy_full_tls(mockk8sapi):
27     ''' Deploy component with a full TLS configuration, to act as a server '''
28
29     dep, deployment_description = do_deploy({"use_tls": True, "cert_directory": "/path/to/container/cert/directory" })
30
31     app_container = dep.spec.template.spec.containers[0]
32     assert app_container.volume_mounts[2].mount_path == "/path/to/container/cert/directory"
33
34 def test_deploy_tls_off(mockk8sapi):
35     ''' TLS client only, but with cert directory configured '''
36
37     dep, deployment_description = do_deploy({"use_tls": False, "cert_directory": "/path/to/container/cert/directory" })
38
39     app_container = dep.spec.template.spec.containers[0]
40     assert app_container.volume_mounts[2].mount_path == "/path/to/container/cert/directory"
41
42 def test_deploy_no_tls_info(mockk8sapi):
43     ''' TLS client only, but with cert directory configured '''
44
45     dep, deployment_description = do_deploy()
46
47     app_container = dep.spec.template.spec.containers[0]
48     assert app_container.volume_mounts[2].mount_path == "/opt/dcae/cacert"