Browse Source

This change is a squash of 2 different patches to pass the gate

1) Backport of subnet deleted handler
With [0] neutron introduced a mechanism to lock subnets and avoid
deletion of used subnets (see [1] for the bug details). As a side effect
this caused that after subnet deletion dhcp ports was not deleted as
no trigger arrived to call handle_port_update_event.
[0] https://review.opendev.org/713045
[1] https://bugs.launchpad.net/neutron/+bug/1865891
(cherry picked from commit ef420a935d)
Related-Bug: #1865891
Closes-Bug: #1876033

2) fix pep8 issues which mostly come from new version of isort
Fix pep8 job  and small fixes for functional jobs
New versions of isort broke pylint. This patch fixes it at 4.3.21.
The issue appeared on stable branches that functional jobs can't find
correct pip version and failed due to not actual neutron version.
Add mock to functional requirements.txt to make sure that neutron has it
in functional envrionment.
(cherry picked from commit e4367d7917)

Change-Id: I3aed8031c1b784c16dd7055afd41456ed935b7fc
changes/33/725533/7
elajkat 3 months ago
committed by Elod Illes
parent
commit
d31b0ef931
10 changed files with 59 additions and 8 deletions
  1. +2
    -0
      .zuul.d/jobs.yaml
  2. +1
    -1
      lower-constraints.txt
  3. +3
    -0
      networking_odl/common/constants.py
  4. +41
    -1
      networking_odl/dhcp/odl_dhcp_driver.py
  5. +3
    -3
      networking_odl/dhcp/odl_dhcp_driver_base.py
  6. +4
    -0
      networking_odl/tests/functional/requirements.txt
  7. +1
    -2
      networking_odl/tests/functional/test_odl_dhcp_driver.py
  8. +2
    -1
      networking_odl/tests/unit/dhcp/test_odl_dhcp_driver_base.py
  9. +1
    -0
      playbooks/functional/pre.yaml
  10. +1
    -0
      test-requirements.txt

+ 2
- 0
.zuul.d/jobs.yaml View File

@@ -162,6 +162,8 @@
Base job for devstack-based tests
pre-run: playbooks/devstack/pre.yaml
required-projects:
- openstack/neutron
- openstack/neutron-lib
- openstack/ceilometer
- openstack/networking-odl
- openstack/networking-l2gw


+ 1
- 1
lower-constraints.txt View File

@@ -52,7 +52,7 @@ httplib2==0.10.3
idna==2.6
imagesize==1.0.0
iso8601==0.1.12
isort==4.3.4
isort==4.3.21
Jinja2==2.10
jmespath==0.9.3
jsonpatch==1.21


+ 3
- 0
networking_odl/common/constants.py View File

@@ -68,6 +68,8 @@ ODL_BGPVPN_ROUTER_ASSOCIATIONS = 'bgpvpn_router_associations'

ODL_ML2_MECH_DRIVER_V2 = "opendaylight_v2"

ODL_DEVICE_ID_START = 'OpenDaylight'

ODL_CREATE = 'create'
ODL_UPDATE = 'update'
ODL_DELETE = 'delete'
@@ -80,6 +82,7 @@ COMPLETED = 'completed'

# Journal Callback events
BEFORE_COMPLETE = 'before_complete'
AFTER_DELETE = 'after_delete'

# dict to store url mappings
RESOURCE_URL_MAPPINGS = {


+ 41
- 1
networking_odl/dhcp/odl_dhcp_driver.py View File

@@ -44,6 +44,46 @@ class OdlDhcpDriver(driver_base.OdlDhcpDriverBase):
LOG.error("Error while processing %s subnet %s: %s", operation,
row.data['id'], e)

# Note(lajoskatona): When subnet locking was introduced in neutron
# (see [0]) that caused that subnet deletion wasn't triggered dhcp port
# deletion any more.
# To workaround this let's catch subnet after_delete event and delete port
# if that is a dhcp port.
# The new functionality can't be added to handle_subnet_event as here
# subnet context is not available.
# [0]: https://review.opendev.org/713045
@registry.receives(constants.ODL_SUBNET, [constants.AFTER_DELETE])
def handle_subnet_delete_event(self, resource, event, trigger,
context=None, operation=None, row=None,
**kwargs):
subnet = kwargs['subnet']
if event == constants.AFTER_DELETE:
try:
plugin = directory.get_plugin()
network_id = subnet['network_id']
device_id = constants.ODL_DEVICE_ID_START + '-' + subnet['id']
filters = {
'network_id': [network_id],
'device_id': [device_id],
'device_owner': [n_const.DEVICE_OWNER_DHCP]
}
LOG.debug("Retrieving ODL DHCP port for deleted subnet %s",
subnet['id'])
ports = plugin.get_ports(context, filters=filters)
if ports:
self._delete_port_if_dhcp(plugin, context, ports[0])
except Exception as e:
LOG.error("Error while deleting %s subnet %s: %s", operation,
subnet['id'], e)

def _delete_port_if_dhcp(self, plugin, context, port):
dev_owner = port['device_owner']
dev_id = port['device_id'] or ''
device_id_type = constants.ODL_DEVICE_ID_START
if (dev_owner == n_const.DEVICE_OWNER_DHCP and
dev_id.startswith(device_id_type)):
self._delete_port(plugin, context, port['id'])

@registry.receives(constants.ODL_PORT, [constants.BEFORE_COMPLETE])
def handle_port_update_event(self, resource, event, trigger,
context=None, operation=None,
@@ -70,7 +110,7 @@ class OdlDhcpDriver(driver_base.OdlDhcpDriverBase):
device_owner = row.data['device_owner']
device_id = row.data['device_id']
fixed_ips = row.data['fixed_ips']
device_id_type = driver_base.OPENDAYLIGHT_DEVICE_ID
device_id_type = constants.ODL_DEVICE_ID_START
if (device_owner and device_owner == n_const.DEVICE_OWNER_DHCP and
device_id and
device_id.startswith(device_id_type) and not fixed_ips):


+ 3
- 3
networking_odl/dhcp/odl_dhcp_driver_base.py View File

@@ -18,9 +18,9 @@ from neutron_lib import constants as n_const
from neutron_lib.plugins import utils as p_utils
from oslo_log import log as logging

from networking_odl.common import constants

LOG = logging.getLogger(__name__)
OPENDAYLIGHT_DEVICE_ID = 'OpenDaylight'


class OdlDhcpDriverBase(object):
@@ -60,7 +60,7 @@ class OdlDhcpDriverBase(object):
port_dict = dict(
name='',
admin_state_up=True,
device_id=OPENDAYLIGHT_DEVICE_ID + '-' + subnet_id,
device_id=constants.ODL_DEVICE_ID_START + '-' + subnet_id,
device_owner=n_const.DEVICE_OWNER_DHCP,
network_id=subnet_context.current['network_id'],
fixed_ips=[dict(subnet_id=subnet_id)],
@@ -74,7 +74,7 @@ class OdlDhcpDriverBase(object):
plugin_context = subnet_context._plugin_context
network_id = subnet_context._subnet['network_id']
subnet_id = subnet_context.current['id']
device_id = OPENDAYLIGHT_DEVICE_ID + '-' + subnet_id
device_id = constants.ODL_DEVICE_ID_START + '-' + subnet_id
LOG.debug("Retrieving ODL DHCP port for subnet %s", subnet_id)
filters = {
'network_id': [network_id],


+ 4
- 0
networking_odl/tests/functional/requirements.txt View File

@@ -11,3 +11,7 @@ python-subunit>=1.2.0 # Apache-2.0/BSD
PyMySQL>=0.6.2 # MIT License
stestr>=2.0.0 # Apache-2.0

# Make sure that mock is installed in functional environment
# for neutron
mock>=2.0.0 # BSD


+ 1
- 2
networking_odl/tests/functional/test_odl_dhcp_driver.py View File

@@ -19,7 +19,6 @@ from neutron_lib.plugins import directory
from oslo_config import fixture as config_fixture

from networking_odl.common import constants as odl_const
from networking_odl.dhcp import odl_dhcp_driver_base as driver_base
from networking_odl.tests.functional import base


@@ -34,7 +33,7 @@ class TestOdlDhcpDriver(base.V2DriverAdjustment, base.OdlTestsBase,

def get_port_data(self, network, subnet):
plugin = self.get_plugin()
device_id = driver_base.OPENDAYLIGHT_DEVICE_ID + \
device_id = odl_const.ODL_DEVICE_ID_START + \
'-' + subnet[odl_const.ODL_SUBNET]['id']
filters = {
'network_id': [network[odl_const.ODL_NETWORK]['id']],


+ 2
- 1
networking_odl/tests/unit/dhcp/test_odl_dhcp_driver_base.py View File

@@ -17,6 +17,7 @@ import testscenarios
from neutron_lib import constants as n_const
from neutron_lib.plugins import directory

from networking_odl.common import constants as odl_const
from networking_odl.dhcp import odl_dhcp_driver_base as driver_base
from networking_odl.ml2 import mech_driver_v2
from networking_odl.tests import base as odl_base
@@ -129,7 +130,7 @@ class OdlDhcpDriverTestBase(base_v2.OpenDaylightConfigBase):

def get_port_id(self, plugin, plugin_context, network_id, subnet_id):

device_id = driver_base.OPENDAYLIGHT_DEVICE_ID + '-' + subnet_id
device_id = odl_const.ODL_DEVICE_ID_START + '-' + subnet_id
filters = {
'network_id': [network_id],
'device_id': [device_id],


+ 1
- 0
playbooks/functional/pre.yaml View File

@@ -20,6 +20,7 @@
DEVSTACK_PATH=$GATE_DEST/devstack
NETWORKING_ODL_DIR=$GATE_DEST/networking-odl
IS_GATE=True
PYTHON3_VERSION=${PYTHON3_VERSION:-3}
source ./tools/configure_for_func_testing.sh
configure_host_for_func_testing
executable: /bin/bash


+ 1
- 0
test-requirements.txt View File

@@ -18,6 +18,7 @@ testtools>=2.3.0 # MIT
bandit!=1.6.0,>=1.4.0 # Apache-2.0
bashate>=0.5.1 # Apache-2.0
astroid==2.1.0;python_version>="3.0" # LGPLv2.1
isort==4.3.21 # MIT

# To test ceilometer client
ceilometer>=11.0.0

Loading…
Cancel
Save