Merge "Port allowed address pairs to OVO"
This commit is contained in:
commit
469516f5b8
57
neutron/objects/port/extensions/allowedaddresspairs.py
Normal file
57
neutron/objects/port/extensions/allowedaddresspairs.py
Normal file
@ -0,0 +1,57 @@
|
||||
# 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 netaddr
|
||||
|
||||
from oslo_versionedobjects import base as obj_base
|
||||
from oslo_versionedobjects import fields as obj_fields
|
||||
|
||||
from neutron.db import allowedaddresspairs_db as models
|
||||
from neutron.objects import base
|
||||
from neutron.objects import common_types
|
||||
|
||||
|
||||
@obj_base.VersionedObjectRegistry.register
|
||||
class AllowedAddressPair(base.NeutronDbObject):
|
||||
# Version 1.0: Initial version
|
||||
VERSION = '1.0'
|
||||
|
||||
db_model = models.AllowedAddressPair
|
||||
|
||||
primary_keys = ['port_id', 'mac_address', 'ip_address']
|
||||
|
||||
fields = {
|
||||
'port_id': obj_fields.UUIDField(),
|
||||
'mac_address': common_types.MACAddressField(),
|
||||
'ip_address': obj_fields.IPAddressField(),
|
||||
}
|
||||
|
||||
# TODO(mhickey): get rid of it once we switch the db model to using
|
||||
# custom types.
|
||||
def modify_fields_to_db(self, fields):
|
||||
result = super(AllowedAddressPair, self).modify_fields_to_db(fields)
|
||||
if 'ip_address' in result:
|
||||
result['ip_address'] = str(result['ip_address'])
|
||||
if 'mac_address' in result:
|
||||
result['mac_address'] = str(result['mac_address'])
|
||||
return result
|
||||
|
||||
# TODO(mhickey): get rid of it once we switch the db model to using
|
||||
# custom types.
|
||||
@classmethod
|
||||
def modify_fields_from_db(cls, db_obj):
|
||||
fields = super(AllowedAddressPair, cls).modify_fields_from_db(db_obj)
|
||||
if 'ip_address' in fields:
|
||||
fields['ip_address'] = netaddr.IPAddress(fields['ip_address'])
|
||||
if 'mac_address' in fields:
|
||||
fields['mac_address'] = netaddr.EUI(fields['mac_address'])
|
||||
return fields
|
@ -30,6 +30,7 @@ import six
|
||||
import neutron
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.common import constants
|
||||
from neutron.common import ipv6_utils
|
||||
|
||||
|
||||
class AttributeMapMemento(fixtures.Fixture):
|
||||
@ -268,6 +269,18 @@ def get_random_ip_network(version=4):
|
||||
return netaddr.IPNetwork(get_random_cidr(version=version))
|
||||
|
||||
|
||||
def get_random_ip_address(version=4):
|
||||
if version == 4:
|
||||
ip_string = '10.%d.%d.%d' % (random.randint(3, 254),
|
||||
random.randint(3, 254),
|
||||
random.randint(3, 254))
|
||||
return netaddr.IPAddress(ip_string)
|
||||
else:
|
||||
ip = ipv6_utils.get_ipv6_addr_by_EUI64('2001:db8::/64',
|
||||
get_random_mac())
|
||||
return ip
|
||||
|
||||
|
||||
def is_bsd():
|
||||
"""Return True on BSD-based systems."""
|
||||
|
||||
|
@ -0,0 +1,38 @@
|
||||
# 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 itertools
|
||||
|
||||
from neutron import context
|
||||
from neutron.objects.port.extensions import allowedaddresspairs
|
||||
from neutron.tests.unit.objects import test_base as obj_test_base
|
||||
from neutron.tests.unit import testlib_api
|
||||
|
||||
|
||||
class AllowedAddrPairsIfaceObjTestCase(obj_test_base.BaseObjectIfaceTestCase):
|
||||
|
||||
_test_class = allowedaddresspairs.AllowedAddressPair
|
||||
|
||||
|
||||
#TODO(mhickey): Add common base db test class specifically for port extensions
|
||||
class AllowedAddrPairsDbObjTestCase(obj_test_base.BaseDbObjectTestCase,
|
||||
testlib_api.SqlTestCase):
|
||||
|
||||
_test_class = allowedaddresspairs.AllowedAddressPair
|
||||
|
||||
def setUp(self):
|
||||
super(AllowedAddrPairsDbObjTestCase, self).setUp()
|
||||
self.context = context.get_admin_context()
|
||||
self._create_test_network()
|
||||
self._create_test_port(self._network)
|
||||
for obj in itertools.chain(self.db_objs, self.obj_fields):
|
||||
obj['port_id'] = self._port['id']
|
@ -240,6 +240,8 @@ FIELD_TYPE_VALUE_GENERATOR_MAP = {
|
||||
common_types.ListOfIPNetworksField: get_list_of_random_networks,
|
||||
common_types.IPVersionEnumField: tools.get_random_ip_version,
|
||||
obj_fields.DateTimeField: timeutils.utcnow,
|
||||
obj_fields.IPAddressField: tools.get_random_ip_address,
|
||||
common_types.MACAddressField: tools.get_random_EUI,
|
||||
}
|
||||
|
||||
|
||||
|
@ -28,6 +28,7 @@ from neutron.tests import tools
|
||||
object_data = {
|
||||
'ExtraDhcpOpt': '1.0-632f689cbeb36328995a7aed1d0a78d3',
|
||||
'PortSecurity': '1.0-cf5b382a0112080ec4e0f23f697c7ab2',
|
||||
'AllowedAddressPair': '1.0-0d7380d7d4a32f72e6ae509af1476297',
|
||||
'QosBandwidthLimitRule': '1.1-4e44a8f5c2895ab1278399f87b40a13d',
|
||||
'QosDscpMarkingRule': '1.1-0313c6554b34fd10c753cb63d638256c',
|
||||
'QosRuleType': '1.1-8a53fef4c6a43839d477a85b787d22ce',
|
||||
|
Loading…
Reference in New Issue
Block a user