Skip to content

Commit cd55efd

Browse files
authored
Merge pull request #99 from stackhpc/upstream/2023.1-2023-12-18
Synchronise 2023.1 with upstream
2 parents 1a5c94d + 98a3eae commit cd55efd

File tree

3 files changed

+64
-11
lines changed

3 files changed

+64
-11
lines changed

neutron/db/db_base_plugin_v2.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def _validate_projects_have_access_to_network(self, network, project_ids):
318318
if project_ids - allowed_projects:
319319
raise exc.InvalidSharedSetting(network=network.name)
320320

321-
def _validate_ipv6_attributes(self, subnet, cur_subnet):
321+
def _validate_ipv6_attributes(self, subnet, cur_subnet, has_cidr):
322322
if cur_subnet:
323323
self._validate_ipv6_update_dhcp(subnet, cur_subnet)
324324
return
@@ -330,7 +330,7 @@ def _validate_ipv6_attributes(self, subnet, cur_subnet):
330330
if ra_mode_set and address_mode_set:
331331
self._validate_ipv6_combination(subnet['ipv6_ra_mode'],
332332
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):
334334
self._validate_eui64_applicable(subnet)
335335

336336
def _validate_eui64_applicable(self, subnet):
@@ -607,16 +607,21 @@ def _validate_subnet(self, context, s, cur_subnet=None):
607607

608608
ip_ver = s['ip_version']
609609

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
610614
if validators.is_attr_set(s.get('cidr')):
611615
self._validate_ip_version(ip_ver, s['cidr'], 'cidr')
616+
has_cidr = True
612617

613618
# TODO(watanabe.isao): After we found a way to avoid the re-sync
614619
# from the agent side, this restriction could be removed.
615620
if cur_subnet:
616621
dhcp_was_enabled = cur_subnet.enable_dhcp
617622
else:
618623
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:
620625
subnet_prefixlen = netaddr.IPNetwork(s['cidr']).prefixlen
621626
error_message = _("Subnet has a prefix length that is "
622627
"incompatible with DHCP service enabled")
@@ -640,12 +645,13 @@ def _validate_subnet(self, context, s, cur_subnet=None):
640645

641646
if validators.is_attr_set(s.get('gateway_ip')):
642647
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)
649655
# Ensure the gateway IP is not assigned to any port
650656
# skip this check in case of create (s parameter won't have id)
651657
# NOTE(salv-orlando): There is slight chance of a race, when
@@ -698,7 +704,7 @@ def _validate_subnet(self, context, s, cur_subnet=None):
698704
error_message=(_("ipv6_address_mode is not valid when "
699705
"ip_version is 4")))
700706
if ip_ver == 6:
701-
self._validate_ipv6_attributes(s, cur_subnet)
707+
self._validate_ipv6_attributes(s, cur_subnet, has_cidr)
702708

703709
def _validate_subnet_for_pd(self, subnet):
704710
"""Validates that subnet parameters are correct for IPv6 PD"""
@@ -860,6 +866,7 @@ def _create_subnet_precommit(self, context, subnet):
860866
msg = _('a subnetpool must be specified in the absence of a cidr')
861867
raise exc.BadRequest(resource='subnets', msg=msg)
862868

869+
validate = True
863870
if subnetpool_id:
864871
self.ipam.validate_pools_with_subnetpool(s)
865872
if subnetpool_id == constants.IPV6_PD_POOL_ID:
@@ -868,16 +875,18 @@ def _create_subnet_precommit(self, context, subnet):
868875
# cidr with IPv6 prefix delegation. Set the subnetpool_id
869876
# to None and allow the request to continue as normal.
870877
subnetpool_id = None
871-
self._validate_subnet(context, s)
872878
else:
873879
prefix = constants.PROVISIONAL_IPV6_PD_PREFIX
874880
subnet['subnet']['cidr'] = prefix
875881
self._validate_subnet_for_pd(s)
882+
validate = False
876883
else:
877884
if not has_cidr:
878885
msg = _('A cidr must be specified in the absence of a '
879886
'subnet pool')
880887
raise exc.BadRequest(resource='subnets', msg=msg)
888+
889+
if validate:
881890
self._validate_subnet(context, s)
882891

883892
with db_api.CONTEXT_WRITER.using(context):

neutron/plugins/ml2/drivers/ovn/mech_driver/mech_driver.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,9 @@ def post_fork_initialize(self, resource, event, trigger, payload=None):
390390
self._maintenance_thread.start()
391391
LOG.info("Maintenance task thread has started")
392392

393+
LOG.info('%s process has finished the post initialization',
394+
worker_class.__name__)
395+
393396
def _create_security_group_precommit(self, resource, event, trigger,
394397
payload):
395398
context = payload.context

neutron/tests/unit/db/test_db_base_plugin_v2.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6641,6 +6641,47 @@ def test_allocate_any_ipv4_subnet_ipv6_pool(self):
66416641
res = req.get_response(self.api)
66426642
self.assertEqual(400, res.status_int)
66436643

6644+
def _test_allocate_any_subnet_wrong_dns(self, pool_cidr, ip_version,
6645+
nameservers):
6646+
with self.network() as network:
6647+
sp = self._test_create_subnetpool([pool_cidr],
6648+
tenant_id=self._tenant_id,
6649+
name=self._POOL_NAME)
6650+
6651+
# Specify a DNS nameserver of the wrong IP version
6652+
data = {'subnet': {'network_id': network['network']['id'],
6653+
'subnetpool_id': sp['subnetpool']['id'],
6654+
'ip_version': ip_version,
6655+
'dns_nameservers': nameservers,
6656+
'tenant_id': network['network']['tenant_id']}}
6657+
req = self.new_create_request('subnets', data)
6658+
res = req.get_response(self.api)
6659+
self.assertEqual(400, res.status_int)
6660+
6661+
def test_allocate_any_v4_subnet_wrong_dns_v6(self):
6662+
self._test_allocate_any_subnet_wrong_dns('10.0.0.0/16',
6663+
constants.IP_VERSION_4, ['2001:db8:1:2::1'])
6664+
6665+
def test_allocate_any_v6_subnet_wrong_dns_v4(self):
6666+
self._test_allocate_any_subnet_wrong_dns('2001:db8:1:2::/63',
6667+
constants.IP_VERSION_6, ['10.0.0.1'])
6668+
6669+
def test_allocate_any_v4_subnet_wrong_dns_v6_multiple(self):
6670+
self._test_allocate_any_subnet_wrong_dns('10.0.0.0/16',
6671+
constants.IP_VERSION_4, ['2001:db8:1:2::1', '2001:db8:2:2::1'])
6672+
6673+
def test_allocate_any_v6_subnet_wrong_dns_v4_multiple(self):
6674+
self._test_allocate_any_subnet_wrong_dns('2001:db8:1:2::/63',
6675+
constants.IP_VERSION_6, ['11.0.0.11', '12.0.0.12'])
6676+
6677+
def test_allocate_any_v4_subnet_wrong_dns_mixed(self):
6678+
self._test_allocate_any_subnet_wrong_dns('10.0.0.0/16',
6679+
constants.IP_VERSION_4, ['11.0.0.11', '2001:db8:1:2::1'])
6680+
6681+
def test_allocate_any_v6_subnet_wrong_dns_mixed(self):
6682+
self._test_allocate_any_subnet_wrong_dns('2001:db8:1:2::/63',
6683+
constants.IP_VERSION_6, ['11.0.0.11', '2001:db8:1:2::1'])
6684+
66446685

66456686
class DbModelMixin(object):
66466687
"""DB model tests."""

0 commit comments

Comments
 (0)