@@ -318,7 +318,7 @@ def _validate_projects_have_access_to_network(self, network, project_ids):
318
318
if project_ids - allowed_projects :
319
319
raise exc .InvalidSharedSetting (network = network .name )
320
320
321
- def _validate_ipv6_attributes (self , subnet , cur_subnet ):
321
+ def _validate_ipv6_attributes (self , subnet , cur_subnet , has_cidr ):
322
322
if cur_subnet :
323
323
self ._validate_ipv6_update_dhcp (subnet , cur_subnet )
324
324
return
@@ -330,7 +330,7 @@ def _validate_ipv6_attributes(self, subnet, cur_subnet):
330
330
if ra_mode_set and address_mode_set :
331
331
self ._validate_ipv6_combination (subnet ['ipv6_ra_mode' ],
332
332
subnet ['ipv6_address_mode' ])
333
- if address_mode_set or ra_mode_set :
333
+ if has_cidr and ( address_mode_set or ra_mode_set ) :
334
334
self ._validate_eui64_applicable (subnet )
335
335
336
336
def _validate_eui64_applicable (self , subnet ):
@@ -607,16 +607,21 @@ def _validate_subnet(self, context, s, cur_subnet=None):
607
607
608
608
ip_ver = s ['ip_version' ]
609
609
610
+ # We could be called without a cidr if a subnet pool is being used,
611
+ # so remember that since some checks below require one and should
612
+ # be skipped.
613
+ has_cidr = False
610
614
if validators .is_attr_set (s .get ('cidr' )):
611
615
self ._validate_ip_version (ip_ver , s ['cidr' ], 'cidr' )
616
+ has_cidr = True
612
617
613
618
# TODO(watanabe.isao): After we found a way to avoid the re-sync
614
619
# from the agent side, this restriction could be removed.
615
620
if cur_subnet :
616
621
dhcp_was_enabled = cur_subnet .enable_dhcp
617
622
else :
618
623
dhcp_was_enabled = False
619
- if s .get ('enable_dhcp' ) and not dhcp_was_enabled :
624
+ if has_cidr and s .get ('enable_dhcp' ) and not dhcp_was_enabled :
620
625
subnet_prefixlen = netaddr .IPNetwork (s ['cidr' ]).prefixlen
621
626
error_message = _ ("Subnet has a prefix length that is "
622
627
"incompatible with DHCP service enabled" )
@@ -640,12 +645,13 @@ def _validate_subnet(self, context, s, cur_subnet=None):
640
645
641
646
if validators .is_attr_set (s .get ('gateway_ip' )):
642
647
self ._validate_ip_version (ip_ver , s ['gateway_ip' ], 'gateway_ip' )
643
- is_gateway_not_valid = (
644
- ipam .utils .check_gateway_invalid_in_subnet (
645
- s ['cidr' ], s ['gateway_ip' ]))
646
- if is_gateway_not_valid :
647
- error_message = _ ("Gateway is not valid on subnet" )
648
- raise exc .InvalidInput (error_message = error_message )
648
+ if has_cidr :
649
+ is_gateway_not_valid = (
650
+ ipam .utils .check_gateway_invalid_in_subnet (
651
+ s ['cidr' ], s ['gateway_ip' ]))
652
+ if is_gateway_not_valid :
653
+ error_message = _ ("Gateway is not valid on subnet" )
654
+ raise exc .InvalidInput (error_message = error_message )
649
655
# Ensure the gateway IP is not assigned to any port
650
656
# skip this check in case of create (s parameter won't have id)
651
657
# NOTE(salv-orlando): There is slight chance of a race, when
@@ -698,7 +704,7 @@ def _validate_subnet(self, context, s, cur_subnet=None):
698
704
error_message = (_ ("ipv6_address_mode is not valid when "
699
705
"ip_version is 4" )))
700
706
if ip_ver == 6 :
701
- self ._validate_ipv6_attributes (s , cur_subnet )
707
+ self ._validate_ipv6_attributes (s , cur_subnet , has_cidr )
702
708
703
709
def _validate_subnet_for_pd (self , subnet ):
704
710
"""Validates that subnet parameters are correct for IPv6 PD"""
@@ -860,6 +866,7 @@ def _create_subnet_precommit(self, context, subnet):
860
866
msg = _ ('a subnetpool must be specified in the absence of a cidr' )
861
867
raise exc .BadRequest (resource = 'subnets' , msg = msg )
862
868
869
+ validate = True
863
870
if subnetpool_id :
864
871
self .ipam .validate_pools_with_subnetpool (s )
865
872
if subnetpool_id == constants .IPV6_PD_POOL_ID :
@@ -868,16 +875,18 @@ def _create_subnet_precommit(self, context, subnet):
868
875
# cidr with IPv6 prefix delegation. Set the subnetpool_id
869
876
# to None and allow the request to continue as normal.
870
877
subnetpool_id = None
871
- self ._validate_subnet (context , s )
872
878
else :
873
879
prefix = constants .PROVISIONAL_IPV6_PD_PREFIX
874
880
subnet ['subnet' ]['cidr' ] = prefix
875
881
self ._validate_subnet_for_pd (s )
882
+ validate = False
876
883
else :
877
884
if not has_cidr :
878
885
msg = _ ('A cidr must be specified in the absence of a '
879
886
'subnet pool' )
880
887
raise exc .BadRequest (resource = 'subnets' , msg = msg )
888
+
889
+ if validate :
881
890
self ._validate_subnet (context , s )
882
891
883
892
with db_api .CONTEXT_WRITER .using (context ):
0 commit comments