X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FRO.git;a=blobdiff_plain;f=RO-SDN-juniper_contrail%2Fosm_rosdn_juniper_contrail%2Ftests%2Ftest_sdn_asssist_juniper_contrail.py;fp=RO-SDN-juniper_contrail%2Fosm_rosdn_juniper_contrail%2Ftests%2Ftest_sdn_asssist_juniper_contrail.py;h=8ef04e1b86d6c862da37db97cf58504f6743e1a9;hp=0000000000000000000000000000000000000000;hb=409d5af00f8c508db5906b696831dd209a2fc633;hpb=7b521f73dd996a279f23b2f512cd89a42c1c79f6 diff --git a/RO-SDN-juniper_contrail/osm_rosdn_juniper_contrail/tests/test_sdn_asssist_juniper_contrail.py b/RO-SDN-juniper_contrail/osm_rosdn_juniper_contrail/tests/test_sdn_asssist_juniper_contrail.py new file mode 100644 index 00000000..8ef04e1b --- /dev/null +++ b/RO-SDN-juniper_contrail/osm_rosdn_juniper_contrail/tests/test_sdn_asssist_juniper_contrail.py @@ -0,0 +1,117 @@ +####################################################################################### +# Copyright ETSI Contributors and Others. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. +####################################################################################### + +import unittest +from unittest.mock import patch + +from osm_ro_plugin.sdnconn import SdnConnectorError +from osm_rosdn_juniper_contrail.sdn_assist_juniper_contrail import JuniperContrail + + +class TestJuniperContrail(unittest.TestCase): + @patch("logging.getLogger") + def setUp(self, mock_logger): + self.wim = {"wim_url": "http://dummy.url"} + self.wim_account = { + "user": "sdn_user", + "password": "dummy_pass", + } + self.logger = None + self.mock_logger = mock_logger + + @patch("osm_rosdn_juniper_contrail.sdn_api.UnderlayApi") + def test_juniper_contrail_sdn_with_ssl_cert(self, mock_underlay_api): + + config = { + "ca_cert": "/path/to/certfile", + "project": "test_project", + "domain": "test_default", + "asn": "test_asn", + "fabric": "test_fabric", + } + + underlay_api_config = { + "auth_url": self.wim, + "verify": config["ca_cert"], + "user": self.wim_account["user"], + "password": self.wim_account["password"], + } + expected_underlay_api_call = [ + self.wim, + underlay_api_config, + self.wim_account["user"], + self.wim_account["password"], + self.mock_logger, + ] + + JuniperContrail(self.wim, self.wim_account, config, self.logger) + mock_underlay_api.called_once_with(expected_underlay_api_call) + + @patch("osm_rosdn_juniper_contrail.sdn_api.UnderlayApi") + def test_juniper_contrail_sdn_insecure_connection(self, mock_underlay_api): + config = { + "insecure": True, + "project": "test_project", + "domain": "test_default", + "asn": "test_asn", + "fabric": "test_fabric", + } + underlay_api_config = { + "auth_url": self.wim, + "verify": False, + "user": self.wim_account["user"], + "password": self.wim_account["password"], + } + expected_underlay_api_call = [ + self.wim, + underlay_api_config, + self.wim_account["user"], + self.wim_account["password"], + self.mock_logger, + ] + + JuniperContrail(self.wim, self.wim_account, config, self.logger) + mock_underlay_api.called_once_with(expected_underlay_api_call) + + @patch("osm_rosdn_juniper_contrail.sdn_api.UnderlayApi") + def test_juniper_contrail_sdn_config_does_not_include_ssl_config_options( + self, mock_underlay_api + ): + config = { + "project": "test_project", + "domain": "test_default", + "asn": "test_asn", + "fabric": "test_fabric", + } + with self.assertRaises(SdnConnectorError): + JuniperContrail(self.wim, self.wim_account, config, self.logger) + + @patch("osm_rosdn_juniper_contrail.sdn_api.UnderlayApi") + def test_juniper_contrail_sdn_config_includes_both_ca_cert_and_insecure( + self, mock_underlay_api + ): + config = { + "project": "test_project", + "domain": "test_default", + "asn": "test_asn", + "fabric": "test_fabric", + "insecure": True, + "ca_cert": "/path/to/certfile", + } + + with self.assertRaises(SdnConnectorError): + JuniperContrail(self.wim, self.wim_account, config, self.logger)