From 45984e716354e2824a5199498dabefa723a6769a Mon Sep 17 00:00:00 2001 From: Cedric Brandily Date: Mon, 2 Jun 2014 12:07:15 +0200 Subject: [PATCH] Add local type driver unittests Partial-Bug: #1269127 Change-Id: I5b34dc09128bcb879ea46be64cc5104eeefd4ab4 --- neutron/tests/unit/ml2/test_type_local.py | 56 +++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 neutron/tests/unit/ml2/test_type_local.py diff --git a/neutron/tests/unit/ml2/test_type_local.py b/neutron/tests/unit/ml2/test_type_local.py new file mode 100644 index 000000000..8d835bfd4 --- /dev/null +++ b/neutron/tests/unit/ml2/test_type_local.py @@ -0,0 +1,56 @@ +# Copyright (c) 2014 Thales Services SAS +# All Rights Reserved. +# +# 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. + +from neutron.common import exceptions as exc +from neutron.plugins.common import constants as p_const +from neutron.plugins.ml2 import driver_api as api +from neutron.plugins.ml2.drivers import type_local +from neutron.tests import base + + +class LocalTypeTest(base.BaseTestCase): + + def setUp(self): + super(LocalTypeTest, self).setUp() + self.driver = type_local.LocalTypeDriver() + self.session = None + + def test_validate_provider_segment(self): + segment = {api.NETWORK_TYPE: p_const.TYPE_LOCAL} + self.driver.validate_provider_segment(segment) + + def test_validate_provider_segment_with_unallowed_physical_network(self): + segment = {api.NETWORK_TYPE: p_const.TYPE_LOCAL, + api.PHYSICAL_NETWORK: 'phys_net'} + self.assertRaises(exc.InvalidInput, + self.driver.validate_provider_segment, + segment) + + def test_validate_provider_segment_with_unallowed_segmentation_id(self): + segment = {api.NETWORK_TYPE: p_const.TYPE_LOCAL, + api.SEGMENTATION_ID: 2} + self.assertRaises(exc.InvalidInput, + self.driver.validate_provider_segment, + segment) + + def test_reserve_provider_segment(self): + segment = {api.NETWORK_TYPE: p_const.TYPE_LOCAL} + self.driver.reserve_provider_segment(self.session, segment) + self.driver.release_segment(self.session, segment) + + def test_allocate_tenant_segment(self): + expected = {api.NETWORK_TYPE: p_const.TYPE_LOCAL} + observed = self.driver.allocate_tenant_segment(self.session) + self.assertEqual(expected, observed) -- 2.45.2