1 #######################################################################################
2 # Copyright ETSI Contributors and Others.
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #######################################################################################
19 from unittest
.mock
import patch
21 from osm_ro_plugin
.sdnconn
import SdnConnectorError
22 from osm_rosdn_juniper_contrail
.sdn_assist_juniper_contrail
import JuniperContrail
25 class TestJuniperContrail(unittest
.TestCase
):
26 @patch("logging.getLogger")
27 def setUp(self
, mock_logger
):
28 self
.wim
= {"wim_url": "http://dummy.url"}
31 "password": "dummy_pass",
34 self
.mock_logger
= mock_logger
36 @patch("osm_rosdn_juniper_contrail.sdn_api.UnderlayApi")
37 def test_juniper_contrail_sdn_with_ssl_cert(self
, mock_underlay_api
):
39 "ca_cert": "/path/to/certfile",
40 "project": "test_project",
41 "domain": "test_default",
43 "fabric": "test_fabric",
46 underlay_api_config
= {
48 "verify": config
["ca_cert"],
49 "user": self
.wim_account
["user"],
50 "password": self
.wim_account
["password"],
52 expected_underlay_api_call
= [
55 self
.wim_account
["user"],
56 self
.wim_account
["password"],
60 JuniperContrail(self
.wim
, self
.wim_account
, config
, self
.logger
)
61 mock_underlay_api
.called_once_with(expected_underlay_api_call
)
63 @patch("osm_rosdn_juniper_contrail.sdn_api.UnderlayApi")
64 def test_juniper_contrail_sdn_insecure_connection(self
, mock_underlay_api
):
67 "project": "test_project",
68 "domain": "test_default",
70 "fabric": "test_fabric",
72 underlay_api_config
= {
75 "user": self
.wim_account
["user"],
76 "password": self
.wim_account
["password"],
78 expected_underlay_api_call
= [
81 self
.wim_account
["user"],
82 self
.wim_account
["password"],
86 JuniperContrail(self
.wim
, self
.wim_account
, config
, self
.logger
)
87 mock_underlay_api
.called_once_with(expected_underlay_api_call
)
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
94 "project": "test_project",
95 "domain": "test_default",
97 "fabric": "test_fabric",
99 with self
.assertRaises(SdnConnectorError
):
100 JuniperContrail(self
.wim
, self
.wim_account
, config
, self
.logger
)
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
107 "project": "test_project",
108 "domain": "test_default",
110 "fabric": "test_fabric",
112 "ca_cert": "/path/to/certfile",
115 with self
.assertRaises(SdnConnectorError
):
116 JuniperContrail(self
.wim
, self
.wim_account
, config
, self
.logger
)