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 |
1 |
import unittest |
19 |
1 |
from unittest.mock import patch |
20 |
|
|
21 |
1 |
from osm_ro_plugin.sdnconn import SdnConnectorError |
22 |
1 |
from osm_rosdn_juniper_contrail.sdn_assist_juniper_contrail import JuniperContrail |
23 |
|
|
24 |
|
|
25 |
1 |
class TestJuniperContrail(unittest.TestCase): |
26 |
1 |
@patch("logging.getLogger") |
27 |
1 |
def setUp(self, mock_logger): |
28 |
1 |
self.wim = {"wim_url": "http://dummy.url"} |
29 |
1 |
self.wim_account = { |
30 |
|
"user": "sdn_user", |
31 |
|
"password": "dummy_pass", |
32 |
|
} |
33 |
1 |
self.logger = None |
34 |
1 |
self.mock_logger = mock_logger |
35 |
|
|
36 |
1 |
@patch("osm_rosdn_juniper_contrail.sdn_api.UnderlayApi") |
37 |
1 |
def test_juniper_contrail_sdn_with_ssl_cert(self, mock_underlay_api): |
38 |
1 |
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 |
1 |
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 |
1 |
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 |
1 |
JuniperContrail(self.wim, self.wim_account, config, self.logger) |
61 |
1 |
mock_underlay_api.called_once_with(expected_underlay_api_call) |
62 |
|
|
63 |
1 |
@patch("osm_rosdn_juniper_contrail.sdn_api.UnderlayApi") |
64 |
1 |
def test_juniper_contrail_sdn_insecure_connection(self, mock_underlay_api): |
65 |
1 |
config = { |
66 |
|
"insecure": True, |
67 |
|
"project": "test_project", |
68 |
|
"domain": "test_default", |
69 |
|
"asn": "test_asn", |
70 |
|
"fabric": "test_fabric", |
71 |
|
} |
72 |
1 |
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 |
1 |
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 |
1 |
JuniperContrail(self.wim, self.wim_account, config, self.logger) |
87 |
1 |
mock_underlay_api.called_once_with(expected_underlay_api_call) |
88 |
|
|
89 |
1 |
@patch("osm_rosdn_juniper_contrail.sdn_api.UnderlayApi") |
90 |
1 |
def test_juniper_contrail_sdn_config_does_not_include_ssl_config_options( |
91 |
|
self, mock_underlay_api |
92 |
|
): |
93 |
1 |
config = { |
94 |
|
"project": "test_project", |
95 |
|
"domain": "test_default", |
96 |
|
"asn": "test_asn", |
97 |
|
"fabric": "test_fabric", |
98 |
|
} |
99 |
1 |
with self.assertRaises(SdnConnectorError): |
100 |
1 |
JuniperContrail(self.wim, self.wim_account, config, self.logger) |
101 |
|
|
102 |
1 |
@patch("osm_rosdn_juniper_contrail.sdn_api.UnderlayApi") |
103 |
1 |
def test_juniper_contrail_sdn_config_includes_both_ca_cert_and_insecure( |
104 |
|
self, mock_underlay_api |
105 |
|
): |
106 |
1 |
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 |
1 |
with self.assertRaises(SdnConnectorError): |
116 |
1 |
JuniperContrail(self.wim, self.wim_account, config, self.logger) |