Disable the check of the release notes
[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
39 config = {
40 "ca_cert": "/path/to/certfile",
41 "project": "test_project",
42 "domain": "test_default",
43 "asn": "test_asn",
44 "fabric": "test_fabric",
45 }
46
47 underlay_api_config = {
48 "auth_url": self.wim,
49 "verify": config["ca_cert"],
50 "user": self.wim_account["user"],
51 "password": self.wim_account["password"],
52 }
53 expected_underlay_api_call = [
54 self.wim,
55 underlay_api_config,
56 self.wim_account["user"],
57 self.wim_account["password"],
58 self.mock_logger,
59 ]
60
61 JuniperContrail(self.wim, self.wim_account, config, self.logger)
62 mock_underlay_api.called_once_with(expected_underlay_api_call)
63
64 @patch("osm_rosdn_juniper_contrail.sdn_api.UnderlayApi")
65 def test_juniper_contrail_sdn_insecure_connection(self, mock_underlay_api):
66 config = {
67 "insecure": True,
68 "project": "test_project",
69 "domain": "test_default",
70 "asn": "test_asn",
71 "fabric": "test_fabric",
72 }
73 underlay_api_config = {
74 "auth_url": self.wim,
75 "verify": False,
76 "user": self.wim_account["user"],
77 "password": self.wim_account["password"],
78 }
79 expected_underlay_api_call = [
80 self.wim,
81 underlay_api_config,
82 self.wim_account["user"],
83 self.wim_account["password"],
84 self.mock_logger,
85 ]
86
87 JuniperContrail(self.wim, self.wim_account, config, self.logger)
88 mock_underlay_api.called_once_with(expected_underlay_api_call)
89
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
93 ):
94 config = {
95 "project": "test_project",
96 "domain": "test_default",
97 "asn": "test_asn",
98 "fabric": "test_fabric",
99 }
100 with self.assertRaises(SdnConnectorError):
101 JuniperContrail(self.wim, self.wim_account, config, self.logger)
102
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
106 ):
107 config = {
108 "project": "test_project",
109 "domain": "test_default",
110 "asn": "test_asn",
111 "fabric": "test_fabric",
112 "insecure": True,
113 "ca_cert": "/path/to/certfile",
114 }
115
116 with self.assertRaises(SdnConnectorError):
117 JuniperContrail(self.wim, self.wim_account, config, self.logger)