Allow 0 in port range for securitygrouprule object

We allow 0 in port_range_min and port_range_max for the
non TCP/UDP use cases (e.g. ICMP). This adjusts the securitygrouprule
OVO object to use a new PortRangeWith0Field to allow 0.

Change-Id: I00f7a91202ccfcad1b8edb8759983332c6e79791
This commit is contained in:
Kevin Benton 2017-01-19 12:53:17 -08:00
parent 0fdfb11e0b
commit e834986084
4 changed files with 11 additions and 6 deletions

View File

@ -65,8 +65,8 @@ class IPNetworkPrefixLenField(obj_fields.AutoTypedField):
class PortRange(RangeConstrainedInteger):
def __init__(self, **kwargs):
super(PortRange, self).__init__(start=constants.PORT_RANGE_MIN,
def __init__(self, start=constants.PORT_RANGE_MIN, **kwargs):
super(PortRange, self).__init__(start=start,
end=constants.PORT_RANGE_MAX, **kwargs)
@ -74,6 +74,10 @@ class PortRangeField(obj_fields.AutoTypedField):
AUTO_TYPE = PortRange()
class PortRangeWith0Field(obj_fields.AutoTypedField):
AUTO_TYPE = PortRange(start=0)
class VlanIdRange(RangeConstrainedInteger):
def __init__(self, **kwargs):
super(VlanIdRange, self).__init__(start=plugin_constants.MIN_VLAN_TAG,

View File

@ -97,8 +97,8 @@ class SecurityGroupRule(base.NeutronDbObject):
'direction': common_types.FlowDirectionEnumField(nullable=True),
'ethertype': common_types.EtherTypeEnumField(nullable=True),
'protocol': common_types.IpProtocolEnumField(nullable=True),
'port_range_min': common_types.PortRangeField(nullable=True),
'port_range_max': common_types.PortRangeField(nullable=True),
'port_range_min': common_types.PortRangeWith0Field(nullable=True),
'port_range_max': common_types.PortRangeWith0Field(nullable=True),
'remote_ip_prefix': common_types.IPNetworkField(nullable=True),
}

View File

@ -234,8 +234,8 @@ def get_random_prefixlen(version=4):
return random.randint(0, maxlen)
def get_random_port():
return random.randint(n_const.PORT_RANGE_MIN, n_const.PORT_RANGE_MAX)
def get_random_port(start=n_const.PORT_RANGE_MIN):
return random.randint(start, n_const.PORT_RANGE_MAX)
def get_random_vlan():

View File

@ -439,6 +439,7 @@ FIELD_TYPE_VALUE_GENERATOR_MAP = {
common_types.ListOfIPNetworksField: get_list_of_random_networks,
common_types.MACAddressField: tools.get_random_EUI,
common_types.PortRangeField: tools.get_random_port,
common_types.PortRangeWith0Field: lambda: tools.get_random_port(0),
common_types.SetOfUUIDsField: get_set_of_random_uuids,
common_types.UUIDField: uuidutils.generate_uuid,
common_types.VlanIdRangeField: tools.get_random_vlan,