Reformat files according to new black validation
[osm/RO.git] / RO-SDN-juniper_contrail / osm_rosdn_juniper_contrail / tests / test_sdn_asssist_juniper_contrail.py
1 #######################################################################################
2 # Copyright ETSI Contributors and Others.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 # implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #######################################################################################
17
18 import unittest
19 from unittest.mock import patch
20
21 from osm_ro_plugin.sdnconn import SdnConnectorError
22 from osm_rosdn_juniper_contrail.sdn_assist_juniper_contrail import JuniperContrail
23
24
25 class TestJuniperContrail(unittest.TestCase):
26 @patch("logging.getLogger")
27 def setUp(self, mock_logger):
28 self.wim = {"wim_url": "http://dummy.url"}
29 self.wim_account = {
30 "user": "sdn_user",
31 "password": "dummy_pass",
32 }
33 self.logger = None
34 self.mock_logger = mock_logger
35
36 @patch("osm_rosdn_juniper_contrail.sdn_api.UnderlayApi")
37 def test_juniper_contrail_sdn_with_ssl_cert(self, mock_underlay_api):
38 config = {
39 "ca_cert": "/path/to/certfile",
40 "project": "test_project",
41 "domain": "test_default",
42 "asn": "test_asn",
43 "fabric": "test_fabric",
44 }
45
46 underlay_api_config = {
47 "auth_url": self.wim,
48 "verify": config["ca_cert"],
49 "user": self.wim_account["user"],
50 "password": self.wim_account["password"],
51 }
52 expected_underlay_api_call = [
53 self.wim,
54 underlay_api_config,
55 self.wim_account["user"],
56 self.wim_account["password"],
57 self.mock_logger,
58 ]
59
60 JuniperContrail(self.wim, self.wim_account, config, self.logger)
61 mock_underlay_api.called_once_with(expected_underlay_api_call)
62
63 @patch("osm_rosdn_juniper_contrail.sdn_api.UnderlayApi")
64 def test_juniper_contrail_sdn_insecure_connection(self, mock_underlay_api):
65 config = {
66 "insecure": True,
67 "project": "test_project",
68 "domain": "test_default",
69 "asn": "test_asn",
70 "fabric": "test_fabric",
71 }
72 underlay_api_config = {
73 "auth_url": self.wim,
74 "verify": False,
75 "user": self.wim_account["user"],
76 "password": self.wim_account["password"],
77 }
78 expected_underlay_api_call = [
79 self.wim,
80 underlay_api_config,
81 self.wim_account["user"],
82 self.wim_account["password"],
83 self.mock_logger,
84 ]
85
86 JuniperContrail(self.wim, self.wim_account, config, self.logger)
87 mock_underlay_api.called_once_with(expected_underlay_api_call)
88
89 @patch("osm_rosdn_juniper_contrail.sdn_api.UnderlayApi")
90 def test_juniper_contrail_sdn_config_does_not_include_ssl_config_options(
91 self, mock_underlay_api
92 ):
93 config = {
94 "project": "test_project",
95 "domain": "test_default",
96 "asn": "test_asn",
97 "fabric": "test_fabric",
98 }
99 with self.assertRaises(SdnConnectorError):
100 JuniperContrail(self.wim, self.wim_account, config, self.logger)
101
102 @patch("osm_rosdn_juniper_contrail.sdn_api.UnderlayApi")
103 def test_juniper_contrail_sdn_config_includes_both_ca_cert_and_insecure(
104 self, mock_underlay_api
105 ):
106 config = {
107 "project": "test_project",
108 "domain": "test_default",
109 "asn": "test_asn",
110 "fabric": "test_fabric",
111 "insecure": True,
112 "ca_cert": "/path/to/certfile",
113 }
114
115 with self.assertRaises(SdnConnectorError):
116 JuniperContrail(self.wim, self.wim_account, config, self.logger)