From: sridhargaddam Date: Mon, 13 Jul 2015 14:00:20 +0000 (+0000) Subject: Disable port creation when invalid MAC address is provided X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=1ba38bfd3f4e505d53c40f3e1bee603bfc705b64;p=openstack-build%2Fneutron-build.git Disable port creation when invalid MAC address is provided When a port is manually created with an invalid mac address like '00:00:00:00:00:00' and associated to neutron router, we see an exception in L3-agent logs. Since we do not have any valid use-case to have a port with a mac_address of all zeros, this patch disables the corresponding port creation/updation request. Along with all zeros MAC, validation aganist broadcast MAC is also included in this patch. DocImpact Closes-Bug: #1472243 Change-Id: I93875716550dbc1f299aee95c45144e4904af233 --- diff --git a/neutron/api/v2/attributes.py b/neutron/api/v2/attributes.py index 64a45e891..b1a9f1a34 100644 --- a/neutron/api/v2/attributes.py +++ b/neutron/api/v2/attributes.py @@ -170,6 +170,10 @@ def _validate_mac_address(data, valid_values=None): valid_mac = netaddr.valid_mac(_validate_no_whitespace(data)) except Exception: valid_mac = False + + if valid_mac: + valid_mac = not netaddr.EUI(data) in map(netaddr.EUI, + constants.INVALID_MAC_ADDRESSES) # TODO(arosen): The code in this file should be refactored # so it catches the correct exceptions. _validate_no_whitespace # raises AttributeError if data is None. diff --git a/neutron/common/constants.py b/neutron/common/constants.py index fc9c4b246..0c4af837a 100644 --- a/neutron/common/constants.py +++ b/neutron/common/constants.py @@ -72,6 +72,8 @@ IP_VERSION_6 = 6 IPv4_BITS = 32 IPv6_BITS = 128 +INVALID_MAC_ADDRESSES = ['00:00:00:00:00:00', 'FF:FF:FF:FF:FF:FF'] + IPv4_ANY = '0.0.0.0/0' IPv6_ANY = '::/0' IP_ANY = {IP_VERSION_4: IPv4_ANY, IP_VERSION_6: IPv6_ANY} diff --git a/neutron/tests/unit/api/v2/test_attributes.py b/neutron/tests/unit/api/v2/test_attributes.py index 512fc3022..0f0828a4c 100644 --- a/neutron/tests/unit/api/v2/test_attributes.py +++ b/neutron/tests/unit/api/v2/test_attributes.py @@ -19,6 +19,7 @@ import testtools import mock from neutron.api.v2 import attributes +from neutron.common import constants from neutron.common import exceptions as n_exc from neutron.tests import base from neutron.tests import tools @@ -187,6 +188,10 @@ class TestAttributes(base.BaseTestCase): err_msg = "'%s' is not a valid MAC address" self.assertEqual(err_msg % mac_addr, msg) + for invalid_mac_addr in constants.INVALID_MAC_ADDRESSES: + msg = validator(invalid_mac_addr) + self.assertEqual(err_msg % invalid_mac_addr, msg) + mac_addr = "123" msg = validator(mac_addr) self.assertEqual(err_msg % mac_addr, msg)