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
):
40 "ca_cert": "/path/to/certfile",
41 "project": "test_project",
42 "domain": "test_default",
44 "fabric": "test_fabric",
47 underlay_api_config
= {
49 "verify": config
["ca_cert"],
50 "user": self
.wim_account
["user"],
51 "password": self
.wim_account
["password"],
53 expected_underlay_api_call
= [
56 self
.wim_account
["user"],
57 self
.wim_account
["password"],
61 JuniperContrail(self
.wim
, self
.wim_account
, config
, self
.logger
)
62 mock_underlay_api
.called_once_with(expected_underlay_api_call
)
64 @patch("osm_rosdn_juniper_contrail.sdn_api.UnderlayApi")
65 def test_juniper_contrail_sdn_insecure_connection(self
, mock_underlay_api
):
68 "project": "test_project",
69 "domain": "test_default",
71 "fabric": "test_fabric",
73 underlay_api_config
= {
76 "user": self
.wim_account
["user"],
77 "password": self
.wim_account
["password"],
79 expected_underlay_api_call
= [
82 self
.wim_account
["user"],
83 self
.wim_account
["password"],
87 JuniperContrail(self
.wim
, self
.wim_account
, config
, self
.logger
)
88 mock_underlay_api
.called_once_with(expected_underlay_api_call
)
90 @patch("osm_rosdn_juniper_contrail.sdn_api.UnderlayApi")
91 def test_juniper_contrail_sdn_config_does_not_include_ssl_config_options(
92 self
, mock_underlay_api
95 "project": "test_project",
96 "domain": "test_default",
98 "fabric": "test_fabric",
100 with self
.assertRaises(SdnConnectorError
):
101 JuniperContrail(self
.wim
, self
.wim_account
, config
, self
.logger
)
103 @patch("osm_rosdn_juniper_contrail.sdn_api.UnderlayApi")
104 def test_juniper_contrail_sdn_config_includes_both_ca_cert_and_insecure(
105 self
, mock_underlay_api
108 "project": "test_project",
109 "domain": "test_default",
111 "fabric": "test_fabric",
113 "ca_cert": "/path/to/certfile",
116 with self
.assertRaises(SdnConnectorError
):
117 JuniperContrail(self
.wim
, self
.wim_account
, config
, self
.logger
)