Make UUIDField actually validate UUIDs
Instead of using oslo.versionedobjects UUID type, use a custom UUIDField class located in common_types that will actually validate passed values for UUID-ness. Closes-Bug: #1614537 Change-Id: I20b24ee57c521b1c68977c2ff7ae56b56875dd64
This commit is contained in:
parent
a405b42a03
commit
bb78621a72
@ -28,7 +28,7 @@ class AddressScope(base.NeutronDbObject):
|
||||
db_model = models.AddressScope
|
||||
|
||||
fields = {
|
||||
'id': obj_fields.UUIDField(),
|
||||
'id': common_types.UUIDField(),
|
||||
'tenant_id': obj_fields.StringField(nullable=True),
|
||||
'name': obj_fields.StringField(),
|
||||
'shared': obj_fields.BooleanField(),
|
||||
|
@ -19,6 +19,7 @@ from oslo_versionedobjects import fields as obj_fields
|
||||
from neutron.agent.common import utils
|
||||
from neutron.db.models import agent as agent_model
|
||||
from neutron.objects import base
|
||||
from neutron.objects import common_types
|
||||
|
||||
|
||||
@obj_base.VersionedObjectRegistry.register
|
||||
@ -29,7 +30,7 @@ class Agent(base.NeutronDbObject):
|
||||
db_model = agent_model.Agent
|
||||
|
||||
fields = {
|
||||
'id': obj_fields.UUIDField(),
|
||||
'id': common_types.UUIDField(),
|
||||
'agent_type': obj_fields.StringField(),
|
||||
'binary': obj_fields.StringField(),
|
||||
'topic': obj_fields.StringField(),
|
||||
|
@ -12,6 +12,7 @@
|
||||
# under the License.
|
||||
|
||||
import itertools
|
||||
import uuid
|
||||
|
||||
import netaddr
|
||||
from neutron_lib import constants as lib_constants
|
||||
@ -207,3 +208,13 @@ class IPNetwork(obj_fields.FieldType):
|
||||
|
||||
class IPNetworkField(obj_fields.AutoTypedField):
|
||||
AUTO_TYPE = IPNetwork()
|
||||
|
||||
|
||||
class UUID(obj_fields.UUID):
|
||||
def coerce(self, obj, attr, value):
|
||||
uuid.UUID(str(value))
|
||||
return str(value)
|
||||
|
||||
|
||||
class UUIDField(obj_fields.AutoTypedField):
|
||||
AUTO_TYPE = UUID()
|
||||
|
@ -14,11 +14,12 @@ from oslo_versionedobjects import fields as obj_fields
|
||||
|
||||
from neutron.extensions import portsecurity
|
||||
from neutron.objects import base
|
||||
from neutron.objects import common_types
|
||||
|
||||
|
||||
class _PortSecurity(base.NeutronDbObject):
|
||||
fields = {
|
||||
'id': obj_fields.UUIDField(),
|
||||
'id': common_types.UUIDField(),
|
||||
'port_security_enabled': obj_fields.BooleanField(
|
||||
default=portsecurity.DEFAULT_PORT_SECURITY),
|
||||
}
|
||||
|
@ -13,7 +13,6 @@
|
||||
# under the License.
|
||||
|
||||
from oslo_versionedobjects import base as obj_base
|
||||
from oslo_versionedobjects import fields as obj_fields
|
||||
|
||||
from neutron.db.models import dns as models
|
||||
from neutron.objects import base
|
||||
@ -30,7 +29,7 @@ class FloatingIPDNS(base.NeutronDbObject):
|
||||
primary_keys = ['floatingip_id']
|
||||
|
||||
fields = {
|
||||
'floatingip_id': obj_fields.UUIDField(),
|
||||
'floatingip_id': common_types.UUIDField(),
|
||||
'dns_name': common_types.DomainNameField(),
|
||||
'dns_domain': common_types.DomainNameField(),
|
||||
'published_dns_name': common_types.DomainNameField(),
|
||||
|
@ -38,8 +38,8 @@ class NetworkSegment(base.NeutronDbObject):
|
||||
db_model = segment_model.NetworkSegment
|
||||
|
||||
fields = {
|
||||
'id': obj_fields.UUIDField(),
|
||||
'network_id': obj_fields.UUIDField(),
|
||||
'id': common_types.UUIDField(),
|
||||
'network_id': common_types.UUIDField(),
|
||||
'name': obj_fields.StringField(),
|
||||
'network_type': obj_fields.StringField(),
|
||||
'physical_network': obj_fields.StringField(nullable=True),
|
||||
@ -85,7 +85,7 @@ class Network(rbac_db.NeutronRbacObject):
|
||||
db_model = models_v2.Network
|
||||
|
||||
fields = {
|
||||
'id': obj_fields.UUIDField(),
|
||||
'id': common_types.UUIDField(),
|
||||
'project_id': obj_fields.StringField(nullable=True),
|
||||
'name': obj_fields.StringField(nullable=True),
|
||||
'status': obj_fields.StringField(nullable=True),
|
||||
@ -106,7 +106,7 @@ class Network(rbac_db.NeutronRbacObject):
|
||||
'segments': obj_fields.ListOfObjectsField(
|
||||
'NetworkSegment', nullable=True),
|
||||
'dns_domain': common_types.DomainNameField(nullable=True),
|
||||
'qos_policy_id': obj_fields.UUIDField(nullable=True, default=None),
|
||||
'qos_policy_id': common_types.UUIDField(nullable=True, default=None),
|
||||
|
||||
# TODO(ihrachys): add support for tags, probably through a base class
|
||||
# since it's a feature that will probably later be added for other
|
||||
@ -228,7 +228,7 @@ class SegmentHostMapping(base.NeutronDbObject):
|
||||
db_model = segment_model.SegmentHostMapping
|
||||
|
||||
fields = {
|
||||
'segment_id': obj_fields.UUIDField(),
|
||||
'segment_id': common_types.UUIDField(),
|
||||
'host': obj_fields.StringField(),
|
||||
}
|
||||
|
||||
@ -245,7 +245,7 @@ class NetworkDNSDomain(base.NeutronDbObject):
|
||||
primary_keys = ['network_id']
|
||||
|
||||
fields = {
|
||||
'network_id': obj_fields.UUIDField(),
|
||||
'network_id': common_types.UUIDField(),
|
||||
'dns_domain': common_types.DomainNameField(),
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,6 @@
|
||||
# under the License.
|
||||
|
||||
from oslo_versionedobjects import base as obj_base
|
||||
from oslo_versionedobjects import fields as obj_fields
|
||||
|
||||
from neutron.common import utils
|
||||
from neutron.db.models import allowed_address_pair as models
|
||||
@ -29,7 +28,7 @@ class AllowedAddressPair(base.NeutronDbObject):
|
||||
primary_keys = ['port_id', 'mac_address', 'ip_address']
|
||||
|
||||
fields = {
|
||||
'port_id': obj_fields.UUIDField(),
|
||||
'port_id': common_types.UUIDField(),
|
||||
'mac_address': common_types.MACAddressField(),
|
||||
'ip_address': common_types.IPNetworkField(),
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ from oslo_versionedobjects import fields as obj_fields
|
||||
|
||||
from neutron.db.extra_dhcp_opt import models
|
||||
from neutron.objects import base
|
||||
from neutron.objects import common_types
|
||||
|
||||
|
||||
@obj_base.VersionedObjectRegistry.register
|
||||
@ -25,8 +26,8 @@ class ExtraDhcpOpt(base.NeutronDbObject):
|
||||
db_model = models.ExtraDhcpOpt
|
||||
|
||||
fields = {
|
||||
'id': obj_fields.UUIDField(),
|
||||
'port_id': obj_fields.UUIDField(),
|
||||
'id': common_types.UUIDField(),
|
||||
'port_id': common_types.UUIDField(),
|
||||
'opt_name': obj_fields.StringField(),
|
||||
'opt_value': obj_fields.StringField(),
|
||||
'ip_version': obj_fields.IntegerField(),
|
||||
|
@ -62,7 +62,7 @@ class PortBinding(PortBindingBase):
|
||||
db_model = ml2_models.PortBinding
|
||||
|
||||
fields = {
|
||||
'port_id': obj_fields.UUIDField(),
|
||||
'port_id': common_types.UUIDField(),
|
||||
'host': obj_fields.StringField(),
|
||||
'profile': obj_fields.StringField(),
|
||||
'vif_type': obj_fields.StringField(),
|
||||
@ -81,7 +81,7 @@ class DistributedPortBinding(PortBindingBase):
|
||||
db_model = ml2_models.DistributedPortBinding
|
||||
|
||||
fields = {
|
||||
'port_id': obj_fields.UUIDField(),
|
||||
'port_id': common_types.UUIDField(),
|
||||
'host': obj_fields.StringField(),
|
||||
'profile': obj_fields.StringField(),
|
||||
'vif_type': obj_fields.StringField(),
|
||||
@ -107,7 +107,7 @@ class PortBindingLevel(base.NeutronDbObject):
|
||||
primary_keys = ['port_id', 'host', 'level']
|
||||
|
||||
fields = {
|
||||
'port_id': obj_fields.UUIDField(),
|
||||
'port_id': common_types.UUIDField(),
|
||||
'host': obj_fields.StringField(),
|
||||
'level': obj_fields.IntegerField(),
|
||||
'driver': obj_fields.StringField(nullable=True),
|
||||
@ -142,9 +142,9 @@ class IPAllocation(base.NeutronDbObject):
|
||||
db_model = models_v2.IPAllocation
|
||||
|
||||
fields = {
|
||||
'port_id': obj_fields.UUIDField(nullable=True),
|
||||
'subnet_id': obj_fields.UUIDField(),
|
||||
'network_id': obj_fields.UUIDField(),
|
||||
'port_id': common_types.UUIDField(nullable=True),
|
||||
'subnet_id': common_types.UUIDField(),
|
||||
'network_id': common_types.UUIDField(),
|
||||
'ip_address': obj_fields.IPAddressField(),
|
||||
}
|
||||
|
||||
@ -187,7 +187,7 @@ class PortDNS(base.NeutronDbObject):
|
||||
}
|
||||
|
||||
fields = {
|
||||
'port_id': obj_fields.UUIDField(),
|
||||
'port_id': common_types.UUIDField(),
|
||||
'current_dns_name': common_types.DomainNameField(),
|
||||
'current_dns_domain': common_types.DomainNameField(),
|
||||
'previous_dns_name': common_types.DomainNameField(),
|
||||
@ -204,10 +204,10 @@ class Port(base.NeutronDbObject):
|
||||
db_model = models_v2.Port
|
||||
|
||||
fields = {
|
||||
'id': obj_fields.UUIDField(),
|
||||
'id': common_types.UUIDField(),
|
||||
'project_id': obj_fields.StringField(nullable=True),
|
||||
'name': obj_fields.StringField(nullable=True),
|
||||
'network_id': obj_fields.UUIDField(),
|
||||
'network_id': common_types.UUIDField(),
|
||||
'mac_address': common_types.MACAddressField(),
|
||||
'admin_state_up': obj_fields.BooleanField(),
|
||||
'device_id': obj_fields.StringField(),
|
||||
@ -239,7 +239,7 @@ class Port(base.NeutronDbObject):
|
||||
# TODO(ihrachys): how do we safely pass a mutable default?
|
||||
default=None,
|
||||
),
|
||||
'qos_policy_id': obj_fields.UUIDField(nullable=True, default=None),
|
||||
'qos_policy_id': common_types.UUIDField(nullable=True, default=None),
|
||||
|
||||
'binding_levels': obj_fields.ListOfObjectsField(
|
||||
'PortBindingLevel', nullable=True
|
||||
|
@ -27,6 +27,7 @@ from neutron.db import models_v2
|
||||
from neutron.db.qos import api as qos_db_api
|
||||
from neutron.db.qos import models as qos_db_model
|
||||
from neutron.db.rbac_db_models import QosPolicyRBAC
|
||||
from neutron.objects import common_types
|
||||
from neutron.objects.db import api as obj_db_api
|
||||
from neutron.objects.qos import rule as rule_obj_impl
|
||||
from neutron.objects import rbac_db
|
||||
@ -48,7 +49,7 @@ class QosPolicy(rbac_db.NeutronRbacObject):
|
||||
network_binding_model = qos_db_model.QosNetworkPolicyBinding
|
||||
|
||||
fields = {
|
||||
'id': obj_fields.UUIDField(),
|
||||
'id': common_types.UUIDField(),
|
||||
'tenant_id': obj_fields.StringField(),
|
||||
'name': obj_fields.StringField(),
|
||||
'shared': obj_fields.BooleanField(default=False),
|
||||
|
@ -57,8 +57,8 @@ class QosRule(base.NeutronDbObject):
|
||||
VERSION = '1.2'
|
||||
|
||||
fields = {
|
||||
'id': obj_fields.UUIDField(),
|
||||
'qos_policy_id': obj_fields.UUIDField()
|
||||
'id': common_types.UUIDField(),
|
||||
'qos_policy_id': common_types.UUIDField()
|
||||
}
|
||||
|
||||
fields_no_update = ['id', 'qos_policy_id']
|
||||
|
@ -31,7 +31,7 @@ class RouterRoute(base.NeutronDbObject):
|
||||
db_model = l3.RouterRoute
|
||||
|
||||
fields = {
|
||||
'router_id': obj_fields.UUIDField(),
|
||||
'router_id': common_types.UUIDField(),
|
||||
'destination': common_types.IPNetworkField(),
|
||||
'nexthop': obj_fields.IPAddressField()
|
||||
}
|
||||
@ -67,7 +67,7 @@ class RouterExtraAttributes(base.NeutronDbObject):
|
||||
db_model = l3_attrs.RouterExtraAttributes
|
||||
|
||||
fields = {
|
||||
'router_id': obj_fields.UUIDField(),
|
||||
'router_id': common_types.UUIDField(),
|
||||
'distributed': obj_fields.BooleanField(default=False),
|
||||
'service_router': obj_fields.BooleanField(default=False),
|
||||
'ha': obj_fields.BooleanField(default=False),
|
||||
|
@ -28,7 +28,7 @@ class SecurityGroup(base.NeutronDbObject):
|
||||
db_model = sg_models.SecurityGroup
|
||||
|
||||
fields = {
|
||||
'id': obj_fields.UUIDField(),
|
||||
'id': common_types.UUIDField(),
|
||||
'name': obj_fields.StringField(nullable=True),
|
||||
'project_id': obj_fields.StringField(nullable=True),
|
||||
'is_default': obj_fields.BooleanField(default=False),
|
||||
@ -74,7 +74,7 @@ class _DefaultSecurityGroup(base.NeutronDbObject):
|
||||
|
||||
fields = {
|
||||
'project_id': obj_fields.StringField(),
|
||||
'security_group_id': obj_fields.UUIDField(),
|
||||
'security_group_id': common_types.UUIDField(),
|
||||
}
|
||||
|
||||
fields_no_update = ['security_group_id']
|
||||
@ -90,10 +90,10 @@ class SecurityGroupRule(base.NeutronDbObject):
|
||||
db_model = sg_models.SecurityGroupRule
|
||||
|
||||
fields = {
|
||||
'id': obj_fields.UUIDField(),
|
||||
'id': common_types.UUIDField(),
|
||||
'project_id': obj_fields.StringField(nullable=True),
|
||||
'security_group_id': obj_fields.UUIDField(),
|
||||
'remote_group_id': obj_fields.UUIDField(nullable=True),
|
||||
'security_group_id': common_types.UUIDField(),
|
||||
'remote_group_id': common_types.UUIDField(nullable=True),
|
||||
'direction': common_types.FlowDirectionEnumField(nullable=True),
|
||||
'ethertype': common_types.EtherTypeEnumField(nullable=True),
|
||||
'protocol': common_types.IpProtocolEnumField(nullable=True),
|
||||
|
@ -18,6 +18,7 @@ from oslo_versionedobjects import fields as obj_fields
|
||||
|
||||
from neutron.db.models import servicetype as models
|
||||
from neutron.objects import base
|
||||
from neutron.objects import common_types
|
||||
|
||||
|
||||
@obj_base.VersionedObjectRegistry.register
|
||||
@ -31,5 +32,5 @@ class ProviderResourceAssociation(base.NeutronDbObject):
|
||||
|
||||
fields = {
|
||||
'provider_name': obj_fields.StringField(),
|
||||
'resource_id': obj_fields.UUIDField(),
|
||||
'resource_id': common_types.UUIDField(),
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ class DNSNameServer(base.NeutronDbObject):
|
||||
|
||||
fields = {
|
||||
'address': obj_fields.StringField(),
|
||||
'subnet_id': obj_fields.UUIDField(),
|
||||
'subnet_id': common_types.UUIDField(),
|
||||
'order': obj_fields.IntegerField()
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ class Route(base.NeutronDbObject):
|
||||
foreign_keys = {'Subnet': {'subnet_id': 'id'}}
|
||||
|
||||
fields = {
|
||||
'subnet_id': obj_fields.UUIDField(),
|
||||
'subnet_id': common_types.UUIDField(),
|
||||
'destination': common_types.IPNetworkField(),
|
||||
'nexthop': obj_fields.IPAddressField()
|
||||
}
|
||||
@ -110,8 +110,8 @@ class IPAllocationPool(base.NeutronDbObject):
|
||||
}
|
||||
|
||||
fields = {
|
||||
'id': obj_fields.UUIDField(),
|
||||
'subnet_id': obj_fields.UUIDField(),
|
||||
'id': common_types.UUIDField(),
|
||||
'subnet_id': common_types.UUIDField(),
|
||||
'start': obj_fields.IPAddressField(),
|
||||
'end': obj_fields.IPAddressField()
|
||||
}
|
||||
@ -149,7 +149,7 @@ class SubnetServiceType(base.NeutronDbObject):
|
||||
primary_keys = ['subnet_id', 'service_type']
|
||||
|
||||
fields = {
|
||||
'subnet_id': obj_fields.UUIDField(),
|
||||
'subnet_id': common_types.UUIDField(),
|
||||
'service_type': obj_fields.StringField()
|
||||
}
|
||||
|
||||
@ -169,12 +169,12 @@ class Subnet(base.NeutronDbObject):
|
||||
db_model = models_v2.Subnet
|
||||
|
||||
fields = {
|
||||
'id': obj_fields.UUIDField(),
|
||||
'id': common_types.UUIDField(),
|
||||
'project_id': obj_fields.StringField(nullable=True),
|
||||
'name': obj_fields.StringField(nullable=True),
|
||||
'network_id': obj_fields.UUIDField(),
|
||||
'segment_id': obj_fields.UUIDField(nullable=True),
|
||||
'subnetpool_id': obj_fields.UUIDField(nullable=True),
|
||||
'network_id': common_types.UUIDField(),
|
||||
'segment_id': common_types.UUIDField(nullable=True),
|
||||
'subnetpool_id': common_types.UUIDField(nullable=True),
|
||||
'ip_version': common_types.IPVersionEnumField(),
|
||||
'cidr': common_types.IPNetworkField(),
|
||||
'gateway_ip': obj_fields.IPAddressField(nullable=True),
|
||||
|
@ -31,7 +31,7 @@ class SubnetPool(base.NeutronDbObject):
|
||||
db_model = models.SubnetPool
|
||||
|
||||
fields = {
|
||||
'id': obj_fields.UUIDField(),
|
||||
'id': common_types.UUIDField(),
|
||||
'tenant_id': obj_fields.StringField(nullable=True),
|
||||
'name': obj_fields.StringField(nullable=True),
|
||||
'ip_version': common_types.IPVersionEnumField(),
|
||||
@ -42,7 +42,7 @@ class SubnetPool(base.NeutronDbObject):
|
||||
'is_default': obj_fields.BooleanField(),
|
||||
'default_quota': obj_fields.IntegerField(nullable=True),
|
||||
'hash': obj_fields.StringField(nullable=True),
|
||||
'address_scope_id': obj_fields.UUIDField(nullable=True),
|
||||
'address_scope_id': common_types.UUIDField(nullable=True),
|
||||
'prefixes': common_types.ListOfIPNetworksField(nullable=True)
|
||||
}
|
||||
|
||||
@ -138,7 +138,7 @@ class SubnetPoolPrefix(base.NeutronDbObject):
|
||||
db_model = models.SubnetPoolPrefix
|
||||
|
||||
fields = {
|
||||
'subnetpool_id': obj_fields.UUIDField(),
|
||||
'subnetpool_id': common_types.UUIDField(),
|
||||
'cidr': obj_fields.IPNetworkField(),
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ from oslo_versionedobjects import fields as obj_fields
|
||||
|
||||
from neutron.db import api as db_api
|
||||
from neutron.objects import base
|
||||
from neutron.objects import common_types
|
||||
from neutron.objects import exceptions as o_exc
|
||||
from neutron.services.trunk import exceptions as t_exc
|
||||
from neutron.services.trunk import models
|
||||
@ -36,8 +37,8 @@ class SubPort(base.NeutronDbObject):
|
||||
foreign_keys = {'Trunk': {'trunk_id': 'id'}}
|
||||
|
||||
fields = {
|
||||
'port_id': obj_fields.UUIDField(),
|
||||
'trunk_id': obj_fields.UUIDField(),
|
||||
'port_id': common_types.UUIDField(),
|
||||
'trunk_id': common_types.UUIDField(),
|
||||
'segmentation_type': obj_fields.StringField(),
|
||||
'segmentation_id': obj_fields.IntegerField(),
|
||||
}
|
||||
@ -89,10 +90,10 @@ class Trunk(base.NeutronDbObject):
|
||||
|
||||
fields = {
|
||||
'admin_state_up': obj_fields.BooleanField(),
|
||||
'id': obj_fields.UUIDField(),
|
||||
'id': common_types.UUIDField(),
|
||||
'tenant_id': obj_fields.StringField(),
|
||||
'name': obj_fields.StringField(),
|
||||
'port_id': obj_fields.UUIDField(),
|
||||
'port_id': common_types.UUIDField(),
|
||||
'status': obj_fields.StringField(),
|
||||
'sub_ports': obj_fields.ListOfObjectsField(SubPort.__name__),
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ from neutron.api.rpc.handlers import resources_rpc
|
||||
from neutron.common import topics
|
||||
from neutron import context
|
||||
from neutron.objects import base as objects_base
|
||||
from neutron.objects import common_types
|
||||
from neutron.tests import base
|
||||
|
||||
|
||||
@ -55,7 +56,7 @@ class FakeResource(BaseFakeResource):
|
||||
VERSION = TEST_VERSION
|
||||
|
||||
fields = {
|
||||
'id': obj_fields.UUIDField(),
|
||||
'id': common_types.UUIDField(),
|
||||
'field': obj_fields.StringField()
|
||||
}
|
||||
|
||||
@ -64,7 +65,7 @@ class FakeResource2(BaseFakeResource):
|
||||
VERSION = TEST_VERSION
|
||||
|
||||
fields = {
|
||||
'id': obj_fields.UUIDField(),
|
||||
'id': common_types.UUIDField(),
|
||||
'field': obj_fields.StringField()
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
import mock
|
||||
from neutron_lib import exceptions as n_exc
|
||||
from oslo_config import cfg
|
||||
from oslo_utils import uuidutils
|
||||
import webob.exc as webexc
|
||||
import webtest
|
||||
|
||||
@ -117,17 +118,23 @@ class ServiceTypeManagerTestCase(testlib_api.SqlTestCase):
|
||||
self._set_override([constants.DUMMY + ':dummy1:driver_path',
|
||||
constants.DUMMY + ':dummy2:driver_path2'])
|
||||
ctx = context.get_admin_context()
|
||||
test_data = [{'provider_name': 'dummy1',
|
||||
'resource_id': uuidutils.generate_uuid()},
|
||||
{'provider_name': 'dummy1',
|
||||
'resource_id': uuidutils.generate_uuid()},
|
||||
{'provider_name': 'dummy2',
|
||||
'resource_id': uuidutils.generate_uuid()}]
|
||||
self.manager.add_resource_association(ctx, constants.DUMMY,
|
||||
'dummy1', '1')
|
||||
**test_data[0])
|
||||
self.manager.add_resource_association(ctx, constants.DUMMY,
|
||||
'dummy1', '2')
|
||||
**test_data[1])
|
||||
self.manager.add_resource_association(ctx, constants.DUMMY,
|
||||
'dummy2', '3')
|
||||
**test_data[2])
|
||||
names_by_id = self.manager.get_provider_names_by_resource_ids(
|
||||
ctx, ['1', '2', '3', '4'])
|
||||
ctx, [td['resource_id'] for td in test_data])
|
||||
# unmatched IDs will be excluded from the result
|
||||
self.assertEqual({'1': 'dummy1', '2': 'dummy1', '3': 'dummy2'},
|
||||
names_by_id)
|
||||
self.assertEqual({td['resource_id']: td['provider_name']
|
||||
for td in test_data}, names_by_id)
|
||||
|
||||
def test_add_resource_association(self):
|
||||
self._set_override([constants.LOADBALANCER +
|
||||
@ -137,7 +144,8 @@ class ServiceTypeManagerTestCase(testlib_api.SqlTestCase):
|
||||
ctx = context.get_admin_context()
|
||||
self.manager.add_resource_association(ctx,
|
||||
constants.LOADBALANCER,
|
||||
'lbaas1', '123-123')
|
||||
'lbaas1',
|
||||
uuidutils.generate_uuid())
|
||||
self.assertEqual(ctx.session.
|
||||
query(st_model.ProviderResourceAssociation).count(),
|
||||
1)
|
||||
|
@ -19,6 +19,7 @@ import sqlalchemy as sa
|
||||
|
||||
from neutron.db import standard_attr
|
||||
from neutron.objects import base as objects_base
|
||||
from neutron.objects import common_types
|
||||
from neutron.tests.unit.objects import test_base
|
||||
from neutron.tests.unit import testlib_api
|
||||
|
||||
@ -35,7 +36,7 @@ class FakeObjectWithStandardAttributes(objects_base.NeutronDbObject):
|
||||
VERSION = '1.0'
|
||||
db_model = FakeDbModelWithStandardAttributes
|
||||
fields = {
|
||||
'id': obj_fields.UUIDField(),
|
||||
'id': common_types.UUIDField(),
|
||||
'item': obj_fields.StringField(),
|
||||
}
|
||||
|
||||
|
@ -79,9 +79,9 @@ class FakeSmallNeutronObject(base.NeutronDbObject):
|
||||
}
|
||||
|
||||
fields = {
|
||||
'field1': obj_fields.UUIDField(),
|
||||
'field2': obj_fields.UUIDField(),
|
||||
'field3': obj_fields.UUIDField(),
|
||||
'field1': common_types.UUIDField(),
|
||||
'field2': common_types.UUIDField(),
|
||||
'field3': common_types.UUIDField(),
|
||||
}
|
||||
|
||||
|
||||
@ -100,7 +100,7 @@ class FakeSmallNeutronObjectWithMultipleParents(base.NeutronDbObject):
|
||||
}
|
||||
|
||||
fields = {
|
||||
'field1': obj_fields.UUIDField(),
|
||||
'field1': common_types.UUIDField(),
|
||||
'field2': obj_fields.StringField(),
|
||||
}
|
||||
|
||||
@ -115,7 +115,7 @@ class FakeParent(base.NeutronDbObject):
|
||||
primary_keys = ['field1', 'field2']
|
||||
|
||||
fields = {
|
||||
'id': obj_fields.UUIDField(),
|
||||
'id': common_types.UUIDField(),
|
||||
'children': obj_fields.ListOfObjectsField(
|
||||
'FakeSmallNeutronObjectWithMultipleParents',
|
||||
nullable=True)
|
||||
@ -139,7 +139,7 @@ class FakeWeirdKeySmallNeutronObject(base.NeutronDbObject):
|
||||
}
|
||||
|
||||
fields = {
|
||||
'field1': obj_fields.UUIDField(),
|
||||
'field1': common_types.UUIDField(),
|
||||
'field2': obj_fields.StringField(),
|
||||
}
|
||||
|
||||
@ -152,7 +152,7 @@ class FakeNeutronDbObject(base.NeutronDbObject):
|
||||
db_model = FakeModel
|
||||
|
||||
fields = {
|
||||
'id': obj_fields.UUIDField(),
|
||||
'id': common_types.UUIDField(),
|
||||
'field1': obj_fields.StringField(),
|
||||
'obj_field': obj_fields.ObjectField('FakeSmallNeutronObject',
|
||||
nullable=True)
|
||||
@ -175,7 +175,7 @@ class FakeNeutronObjectNonStandardPrimaryKey(base.NeutronDbObject):
|
||||
primary_keys = ['weird_key']
|
||||
|
||||
fields = {
|
||||
'weird_key': obj_fields.UUIDField(),
|
||||
'weird_key': common_types.UUIDField(),
|
||||
'field1': obj_fields.StringField(),
|
||||
'obj_field': obj_fields.ListOfObjectsField(
|
||||
'FakeWeirdKeySmallNeutronObject'),
|
||||
@ -195,7 +195,7 @@ class FakeNeutronObjectCompositePrimaryKey(base.NeutronDbObject):
|
||||
primary_keys = ['weird_key', 'field1']
|
||||
|
||||
fields = {
|
||||
'weird_key': obj_fields.UUIDField(),
|
||||
'weird_key': common_types.UUIDField(),
|
||||
'field1': obj_fields.StringField(),
|
||||
'obj_field': obj_fields.ListOfObjectsField(
|
||||
'FakeWeirdKeySmallNeutronObject')
|
||||
@ -215,8 +215,8 @@ class FakeNeutronObjectUniqueKey(base.NeutronDbObject):
|
||||
unique_keys = [['unique_key'], ['id2']]
|
||||
|
||||
fields = {
|
||||
'id': obj_fields.UUIDField(),
|
||||
'id2': obj_fields.UUIDField(),
|
||||
'id': common_types.UUIDField(),
|
||||
'id2': common_types.UUIDField(),
|
||||
'unique_key': obj_fields.StringField(),
|
||||
'field1': obj_fields.StringField(),
|
||||
'obj_field': obj_fields.ObjectField('FakeSmallNeutronObject',
|
||||
@ -242,7 +242,7 @@ class FakeNeutronObjectRenamedField(base.NeutronDbObject):
|
||||
primary_keys = ['id']
|
||||
|
||||
fields = {
|
||||
'id': obj_fields.UUIDField(),
|
||||
'id': common_types.UUIDField(),
|
||||
'field_ovo': obj_fields.StringField(),
|
||||
'field2': obj_fields.StringField()
|
||||
}
|
||||
@ -262,7 +262,7 @@ class FakeNeutronObjectCompositePrimaryKeyWithId(base.NeutronDbObject):
|
||||
primary_keys = ['id', 'field1']
|
||||
|
||||
fields = {
|
||||
'id': obj_fields.UUIDField(),
|
||||
'id': common_types.UUIDField(),
|
||||
'field1': obj_fields.StringField(),
|
||||
'obj_field': obj_fields.ListOfObjectsField('FakeSmallNeutronObject')
|
||||
}
|
||||
@ -282,8 +282,8 @@ class FakeNeutronObjectMultipleForeignKeys(base.NeutronDbObject):
|
||||
}
|
||||
|
||||
fields = {
|
||||
'field1': obj_fields.UUIDField(),
|
||||
'field2': obj_fields.UUIDField(),
|
||||
'field1': common_types.UUIDField(),
|
||||
'field2': common_types.UUIDField(),
|
||||
}
|
||||
|
||||
|
||||
@ -295,7 +295,7 @@ class FakeNeutronObjectSyntheticField(base.NeutronDbObject):
|
||||
db_model = FakeModel
|
||||
|
||||
fields = {
|
||||
'id': obj_fields.UUIDField(),
|
||||
'id': common_types.UUIDField(),
|
||||
'obj_field': obj_fields.ListOfObjectsField(
|
||||
'FakeNeutronObjectMultipleForeignKeys')
|
||||
}
|
||||
@ -311,7 +311,7 @@ class FakeNeutronObjectSyntheticField2(base.NeutronDbObject):
|
||||
db_model = FakeModel
|
||||
|
||||
fields = {
|
||||
'id': obj_fields.UUIDField(),
|
||||
'id': common_types.UUIDField(),
|
||||
'obj_field': obj_fields.ObjectField('FakeSmallNeutronObject')
|
||||
}
|
||||
|
||||
@ -326,9 +326,9 @@ class FakeNeutronObjectWithProjectId(base.NeutronDbObject):
|
||||
db_model = FakeModel
|
||||
|
||||
fields = {
|
||||
'id': obj_fields.UUIDField(),
|
||||
'id': common_types.UUIDField(),
|
||||
'project_id': obj_fields.StringField(),
|
||||
'field2': obj_fields.UUIDField(),
|
||||
'field2': common_types.UUIDField(),
|
||||
}
|
||||
|
||||
|
||||
@ -338,9 +338,9 @@ class FakeNeutronObject(base.NeutronObject):
|
||||
VERSION = '1.0'
|
||||
|
||||
fields = {
|
||||
'id': obj_fields.UUIDField(),
|
||||
'id': common_types.UUIDField(),
|
||||
'project_id': obj_fields.StringField(),
|
||||
'field2': obj_fields.UUIDField(),
|
||||
'field2': common_types.UUIDField(),
|
||||
}
|
||||
|
||||
@classmethod
|
||||
@ -399,7 +399,7 @@ FIELD_TYPE_VALUE_GENERATOR_MAP = {
|
||||
obj_fields.IntegerField: tools.get_random_integer,
|
||||
obj_fields.StringField: tools.get_random_string,
|
||||
obj_fields.ListOfStringsField: tools.get_random_string_list,
|
||||
obj_fields.UUIDField: uuidutils.generate_uuid,
|
||||
common_types.UUIDField: uuidutils.generate_uuid,
|
||||
obj_fields.ObjectField: lambda: None,
|
||||
obj_fields.ListOfObjectsField: lambda: [],
|
||||
obj_fields.DictOfStringsField: get_random_dict_of_strings,
|
||||
@ -1034,10 +1034,10 @@ class UniqueKeysTestCase(test_base.BaseTestCase):
|
||||
primary_keys = ['id']
|
||||
|
||||
fields = {
|
||||
'id': obj_fields.UUIDField(),
|
||||
'field1': obj_fields.UUIDField(),
|
||||
'field2': obj_fields.UUIDField(),
|
||||
'field3': obj_fields.UUIDField(),
|
||||
'id': common_types.UUIDField(),
|
||||
'field1': common_types.UUIDField(),
|
||||
'field2': common_types.UUIDField(),
|
||||
'field3': common_types.UUIDField(),
|
||||
}
|
||||
|
||||
fields_need_translation = {'field3': 'db_field3'}
|
||||
|
@ -246,3 +246,23 @@ class IpProtocolEnumFieldTest(test_base.BaseTestCase, TestField):
|
||||
def test_stringify(self):
|
||||
for in_val, out_val in self.coerce_good_values:
|
||||
self.assertEqual("'%s'" % in_val, self.field.stringify(in_val))
|
||||
|
||||
|
||||
class UUIDFieldTest(test_base.BaseTestCase, TestField):
|
||||
def setUp(self):
|
||||
super(UUIDFieldTest, self).setUp()
|
||||
self.field = common_types.UUIDField()
|
||||
self.coerce_good_values = [
|
||||
('f1d9cb3f-c263-45d3-907c-d12a9ef1629e',
|
||||
'f1d9cb3f-c263-45d3-907c-d12a9ef1629e'),
|
||||
('7188f6637cbd4097a3b1d1bb7897c7c0',
|
||||
'7188f6637cbd4097a3b1d1bb7897c7c0')]
|
||||
self.coerce_bad_values = [
|
||||
'f1d9cb3f-c263-45d3-907c-d12a9ef16zzz',
|
||||
'7188f6637cbd4097a3b1d1bb7897']
|
||||
self.to_primitive_values = self.coerce_good_values
|
||||
self.from_primitive_values = self.coerce_good_values
|
||||
|
||||
def test_stringify(self):
|
||||
for in_val, out_val in self.coerce_good_values:
|
||||
self.assertEqual('%s' % in_val, self.field.stringify(in_val))
|
||||
|
@ -22,6 +22,7 @@ from neutron.callbacks import events
|
||||
from neutron import context as n_context
|
||||
from neutron.db import rbac_db_models
|
||||
from neutron.extensions import rbac as ext_rbac
|
||||
from neutron.objects import common_types
|
||||
from neutron.objects.db import api as obj_db_api
|
||||
from neutron.objects import rbac_db
|
||||
from neutron.tests.unit.objects import test_base
|
||||
@ -49,7 +50,7 @@ class FakeNeutronDbObject(rbac_db.NeutronRbacObject):
|
||||
db_model = FakeDbModel
|
||||
|
||||
fields = {
|
||||
'id': obj_fields.UUIDField(),
|
||||
'id': common_types.UUIDField(),
|
||||
'field1': obj_fields.StringField(),
|
||||
'field2': obj_fields.StringField(),
|
||||
'shared': obj_fields.BooleanField(default=False),
|
||||
|
@ -16,6 +16,7 @@ import mock
|
||||
from neutron_lib import constants
|
||||
from neutron_lib import exceptions as lib_exc
|
||||
from neutron_lib.plugins import directory
|
||||
from oslo_utils import uuidutils
|
||||
import testtools
|
||||
|
||||
from neutron import context
|
||||
@ -48,23 +49,27 @@ class TestDriverController(testlib_api.SqlTestCase):
|
||||
def test_uses_scheduler(self):
|
||||
self._return_provider_for_flavor('dvrha')
|
||||
router_db = mock.Mock()
|
||||
router = dict(id='router_id', flavor_id='abc123')
|
||||
flavor_id = uuidutils.generate_uuid()
|
||||
router_id = uuidutils.generate_uuid()
|
||||
router = dict(id=router_id, flavor_id=flavor_id)
|
||||
self.dc._set_router_provider('router', 'PRECOMMIT_CREATE', self,
|
||||
self.ctx, router, router_db)
|
||||
self.assertTrue(self.dc.uses_scheduler(self.ctx, 'router_id'))
|
||||
self.assertTrue(self.dc.uses_scheduler(self.ctx, router_id))
|
||||
self.dc.drivers['dvrha'].use_integrated_agent_scheduler = False
|
||||
self.assertFalse(self.dc.uses_scheduler(self.ctx, 'router_id'))
|
||||
self.assertFalse(self.dc.uses_scheduler(self.ctx, router_id))
|
||||
|
||||
def test__set_router_provider_flavor_specified(self):
|
||||
self._return_provider_for_flavor('dvrha')
|
||||
router_db = mock.Mock()
|
||||
router = dict(id='router_id', flavor_id='abc123')
|
||||
flavor_id = uuidutils.generate_uuid()
|
||||
router_id = uuidutils.generate_uuid()
|
||||
router = dict(id=router_id, flavor_id=flavor_id)
|
||||
self.dc._set_router_provider('router', 'PRECOMMIT_CREATE', self,
|
||||
self.ctx, router, router_db)
|
||||
self.assertEqual('abc123', router_db.flavor_id)
|
||||
self.assertEqual(flavor_id, router_db.flavor_id)
|
||||
self.assertEqual(self.dc.drivers['dvrha'],
|
||||
self.dc._get_provider_for_router(self.ctx,
|
||||
'router_id'))
|
||||
router_id))
|
||||
|
||||
def test__update_router_provider_invalid(self):
|
||||
test_dc = driver_controller.DriverController(self.fake_l3)
|
||||
@ -83,21 +88,30 @@ class TestDriverController(testlib_api.SqlTestCase):
|
||||
|
||||
def test__set_router_provider_attr_lookups(self):
|
||||
# ensure correct drivers are looked up based on attrs
|
||||
router_id1 = uuidutils.generate_uuid()
|
||||
router_id2 = uuidutils.generate_uuid()
|
||||
router_id3 = uuidutils.generate_uuid()
|
||||
router_id4 = uuidutils.generate_uuid()
|
||||
router_id5 = uuidutils.generate_uuid()
|
||||
router_id6 = uuidutils.generate_uuid()
|
||||
router_id7 = uuidutils.generate_uuid()
|
||||
router_id8 = uuidutils.generate_uuid()
|
||||
router_id9 = uuidutils.generate_uuid()
|
||||
cases = [
|
||||
('dvrha', dict(id='router_id1', distributed=True, ha=True)),
|
||||
('dvr', dict(id='router_id2', distributed=True, ha=False)),
|
||||
('ha', dict(id='router_id3', distributed=False, ha=True)),
|
||||
('single_node', dict(id='router_id4', distributed=False,
|
||||
('dvrha', dict(id=router_id1, distributed=True, ha=True)),
|
||||
('dvr', dict(id=router_id2, distributed=True, ha=False)),
|
||||
('ha', dict(id=router_id3, distributed=False, ha=True)),
|
||||
('single_node', dict(id=router_id4, distributed=False,
|
||||
ha=False)),
|
||||
('ha', dict(id='router_id5', ha=True,
|
||||
('ha', dict(id=router_id5, ha=True,
|
||||
distributed=constants.ATTR_NOT_SPECIFIED)),
|
||||
('dvr', dict(id='router_id6', distributed=True,
|
||||
('dvr', dict(id=router_id6, distributed=True,
|
||||
ha=constants.ATTR_NOT_SPECIFIED)),
|
||||
('single_node', dict(id='router_id7', ha=False,
|
||||
('single_node', dict(id=router_id7, ha=False,
|
||||
distributed=constants.ATTR_NOT_SPECIFIED)),
|
||||
('single_node', dict(id='router_id8', distributed=False,
|
||||
('single_node', dict(id=router_id8, distributed=False,
|
||||
ha=constants.ATTR_NOT_SPECIFIED)),
|
||||
('single_node', dict(id='router_id9',
|
||||
('single_node', dict(id=router_id9,
|
||||
distributed=constants.ATTR_NOT_SPECIFIED,
|
||||
ha=constants.ATTR_NOT_SPECIFIED)),
|
||||
]
|
||||
@ -111,7 +125,8 @@ class TestDriverController(testlib_api.SqlTestCase):
|
||||
|
||||
def test__clear_router_provider(self):
|
||||
# ensure correct drivers are looked up based on attrs
|
||||
body = dict(id='router_id1', distributed=True, ha=True)
|
||||
router_id1 = uuidutils.generate_uuid()
|
||||
body = dict(id=router_id1, distributed=True, ha=True)
|
||||
self.dc._set_router_provider('router', 'PRECOMMIT_CREATE', self,
|
||||
self.ctx, body, mock.Mock())
|
||||
self.assertEqual(self.dc.drivers['dvrha'],
|
||||
|
Loading…
Reference in New Issue
Block a user