]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Add local type driver unittests
authorCedric Brandily <zzelle@gmail.com>
Mon, 2 Jun 2014 10:07:15 +0000 (12:07 +0200)
committerCedric Brandily <zzelle@gmail.com>
Tue, 3 Jun 2014 19:59:34 +0000 (21:59 +0200)
Partial-Bug: #1269127

Change-Id: I5b34dc09128bcb879ea46be64cc5104eeefd4ab4

neutron/tests/unit/ml2/test_type_local.py [new file with mode: 0644]

diff --git a/neutron/tests/unit/ml2/test_type_local.py b/neutron/tests/unit/ml2/test_type_local.py
new file mode 100644 (file)
index 0000000..8d835bf
--- /dev/null
@@ -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)