summaryrefslogtreecommitdiff
path: root/quantum/tests/unit/test_attributes.py
diff options
context:
space:
mode:
authorGary Kotton <gkotton@redhat.com>2012-08-06 09:45:20 -0400
committerGary Kotton <gkotton@redhat.com>2012-08-07 02:20:56 -0400
commitfe09214372f199d4cfbff76aabf76470543c26f2 (patch)
treed6fc226424ebe34e29d32a93ec358137b29a82ad /quantum/tests/unit/test_attributes.py
parent03079191cd26d98e3b20c90d8929e408853c2bf5 (diff)
downloadneutron-fe09214372f199d4cfbff76aabf76470543c26f2.tar.gz
Enhance Base MAC validation
Fixes bug 1033520 The base mac will now be validated when the configuration file is read. In addition to this the following has been done: 1. checks validaity of the base mac - for example it cannot be a multicast MAC 2. adds a framework for attributes tests Change-Id: Ibffab039ca7ee9e87eb79a7288e86401170bf129
Diffstat (limited to 'quantum/tests/unit/test_attributes.py')
-rw-r--r--quantum/tests/unit/test_attributes.py85
1 files changed, 85 insertions, 0 deletions
diff --git a/quantum/tests/unit/test_attributes.py b/quantum/tests/unit/test_attributes.py
new file mode 100644
index 0000000000..bb788b455a
--- /dev/null
+++ b/quantum/tests/unit/test_attributes.py
@@ -0,0 +1,85 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2012 OpenStack LLC
+# 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.
+
+import unittest2
+
+from quantum.api.v2 import attributes
+
+
+class TestAttributes(unittest2.TestCase):
+
+ def test_mac_addresses(self):
+ # Valid - 3 octets
+ base_mac = "fa:16:3e:00:00:00"
+ msg = attributes._validate_regex(base_mac,
+ attributes.MAC_PATTERN)
+ self.assertEquals(msg, None)
+
+ # Valid - 4 octets
+ base_mac = "fa:16:3e:4f:00:00"
+ msg = attributes._validate_regex(base_mac,
+ attributes.MAC_PATTERN)
+ self.assertEquals(msg, None)
+
+ # Invalid - not unicast
+ base_mac = "01:16:3e:4f:00:00"
+ msg = attributes._validate_regex(base_mac,
+ attributes.MAC_PATTERN)
+ error = '%s is not valid' % base_mac
+ self.assertEquals(msg, error)
+
+ # Invalid - invalid format
+ base_mac = "a:16:3e:4f:00:00"
+ msg = attributes._validate_regex(base_mac,
+ attributes.MAC_PATTERN)
+ error = '%s is not valid' % base_mac
+ self.assertEquals(msg, error)
+
+ # Invalid - invalid format
+ base_mac = "ffa:16:3e:4f:00:00"
+ msg = attributes._validate_regex(base_mac,
+ attributes.MAC_PATTERN)
+ error = '%s is not valid' % base_mac
+ self.assertEquals(msg, error)
+
+ # Invalid - invalid format
+ base_mac = "01163e4f0000"
+ msg = attributes._validate_regex(base_mac,
+ attributes.MAC_PATTERN)
+ error = '%s is not valid' % base_mac
+ self.assertEquals(msg, error)
+
+ # Invalid - invalid format
+ base_mac = "01-16-3e-4f-00-00"
+ msg = attributes._validate_regex(base_mac,
+ attributes.MAC_PATTERN)
+ error = '%s is not valid' % base_mac
+ self.assertEquals(msg, error)
+
+ # Invalid - invalid format
+ base_mac = "00:16:3:f:00:00"
+ msg = attributes._validate_regex(base_mac,
+ attributes.MAC_PATTERN)
+ error = '%s is not valid' % base_mac
+ self.assertEquals(msg, error)
+
+ # Invalid - invalid format
+ base_mac = "12:3:4:5:67:89ab"
+ msg = attributes._validate_regex(base_mac,
+ attributes.MAC_PATTERN)
+ error = '%s is not valid' % base_mac
+ self.assertEquals(msg, error)