Skip to content

Commit 44ec1f1

Browse files
fernandoroyosanchezcubeek
authored andcommitted
Avoid register config options on imports
Continue similar approach following in [1], where some project imports collide with config options. As part of the change, a wrapped decorator has been implemented to cover those functions that include any of the ovn config options as value to the decorators arguments (e.g. tenacity retry). This way we avoid requiring the options to be registered as soon as the module is imported, where they have not yet been registered by a main process. [1] https://review.opendev.org/c/openstack/neutron/+/837392 Co-authored-by: Jakub Libosvar <[email protected]> Co-authored-by: Fernando Royo <[email protected]> Conflicts: neutron/agent/ovn/metadata_agent.py neutron/cmd/ovn/neutron_ovn_db_sync_util.py neutron/common/ovn/utils.py neutron/plugins/ml2/drivers/ovn/mech_driver/mech_driver.py Change-Id: I4bccb094ee7f690cbc352c38b5b39d505e6ea460 (cherry picked from commit 227c5f8)
1 parent 9a83017 commit 44ec1f1

File tree

18 files changed

+95
-15
lines changed

18 files changed

+95
-15
lines changed

neutron/agent/ovn/metadata/agent.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from oslo_utils import netutils
2525
from ovsdbapp.backend.ovs_idl import event as row_event
2626
from ovsdbapp.backend.ovs_idl import vlog
27-
import tenacity
2827

2928
from neutron.agent.linux import external_process
3029
from neutron.agent.linux import ip_lib
@@ -280,10 +279,7 @@ def start(self):
280279

281280
self._proxy.wait()
282281

283-
@tenacity.retry(
284-
wait=tenacity.wait_exponential(
285-
max=config.get_ovn_ovsdb_retry_max_interval()),
286-
reraise=True)
282+
@ovn_utils.retry()
287283
def register_metadata_agent(self):
288284
# NOTE(lucasagomes): db_add() will not overwrite the UUID if
289285
# it's already set.

neutron/agent/ovn/metadata/ovsdb.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
from ovsdbapp.backend.ovs_idl import connection
1818
from ovsdbapp.backend.ovs_idl import idlutils
1919
from ovsdbapp.schema.open_vswitch import impl_idl as idl_ovs
20-
import tenacity
2120

21+
from neutron.common.ovn import utils as ovn_utils
2222
from neutron.conf.plugins.ml2.drivers.ovn import ovn_conf as config
2323
from neutron.plugins.ml2.drivers.ovn.mech_driver.ovsdb import impl_idl_ovn
2424
from neutron.plugins.ml2.drivers.ovn.mech_driver.ovsdb import ovsdb_monitor
@@ -54,16 +54,11 @@ def __init__(self, chassis=None, events=None, tables=None):
5454
if events:
5555
self.notify_handler.watch_events(events)
5656

57-
@tenacity.retry(
58-
wait=tenacity.wait_exponential(max=180),
59-
reraise=True)
57+
@ovn_utils.retry(max_=180)
6058
def _get_ovsdb_helper(self, connection_string):
6159
return idlutils.get_schema_helper(connection_string, self.SCHEMA)
6260

63-
@tenacity.retry(
64-
wait=tenacity.wait_exponential(
65-
max=config.get_ovn_ovsdb_retry_max_interval()),
66-
reraise=True)
61+
@ovn_utils.retry()
6762
def start(self):
6863
LOG.info('Getting OvsdbSbOvnIdl for MetadataAgent with retry')
6964
conn = connection.Connection(

neutron/agent/ovn/metadata_agent.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
from neutron.agent.ovn.metadata import agent
2222
from neutron.conf.agent.metadata import config as meta
2323
from neutron.conf.agent.ovn.metadata import config as ovn_meta
24+
from neutron.conf.plugins.ml2.drivers.ovn import ovn_conf
2425

2526
LOG = logging.getLogger(__name__)
2627

2728

2829
def main():
30+
ovn_conf.register_opts()
2931
ovn_meta.register_meta_conf_opts(meta.SHARED_OPTS)
3032
ovn_meta.register_meta_conf_opts(meta.UNIX_DOMAIN_METADATA_PROXY_OPTS)
3133
ovn_meta.register_meta_conf_opts(meta.METADATA_PROXY_HANDLER_OPTS)

neutron/cmd/ovn/neutron_ovn_db_sync_util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ def security_groups_provider_updated(self, context,
137137

138138
def setup_conf():
139139
conf = cfg.CONF
140+
ovn_conf.register_opts()
140141
ml2_group, ml2_opts = neutron_options.list_ml2_conf_opts()[0]
141142
cfg.CONF.register_cli_opts(ml2_opts, ml2_group)
142143
cfg.CONF.register_cli_opts(securitygroups_rpc.security_group_opts,

neutron/common/ovn/utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from oslo_utils import netutils
3434
from oslo_utils import strutils
3535
from ovsdbapp import constants as ovsdbapp_const
36+
import tenacity
3637

3738
from neutron._i18n import _
3839
from neutron.common.ovn import constants
@@ -685,3 +686,14 @@ def is_port_external(port):
685686

686687
return (vnic_type in constants.EXTERNAL_PORT_TYPES and
687688
constants.PORT_CAP_SWITCHDEV not in capabilities)
689+
690+
691+
def retry(max_=None):
692+
def inner(func):
693+
def wrapper(*args, **kwargs):
694+
local_max = max_ or ovn_conf.get_ovn_ovsdb_retry_max_interval()
695+
return tenacity.retry(
696+
wait=tenacity.wait_exponential(max=local_max),
697+
reraise=True)(func)(*args, **kwargs)
698+
return wrapper
699+
return inner

neutron/conf/plugins/ml2/drivers/ovn/ovn_conf.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,10 @@
199199
'br-int | grep "Check pkt length action".')),
200200
]
201201

202-
cfg.CONF.register_opts(ovn_opts, group='ovn')
203-
ovs_conf.register_ovs_agent_opts()
202+
203+
def register_opts():
204+
cfg.CONF.register_opts(ovn_opts, group='ovn')
205+
ovs_conf.register_ovs_agent_opts()
204206

205207

206208
def list_opts():

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ def initialize(self):
117117
self.node_uuid = None
118118
self.hash_ring_group = ovn_const.HASH_RING_ML2_GROUP
119119
self.sg_enabled = ovn_acl.is_sg_enabled()
120+
ovn_conf.register_opts()
120121
self._post_fork_event = threading.Event()
121122
if cfg.CONF.SECURITYGROUP.firewall_driver:
122123
LOG.warning('Firewall driver configuration is ignored')

neutron/tests/functional/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ def setUp(self, maintenance_worker=False, service_plugins=None):
184184
# ensure viable minimum is set for OVN's Geneve
185185
ml2_config.cfg.CONF.set_override('max_header_size', 38,
186186
group='ml2_type_geneve')
187+
ovn_conf.register_opts()
187188
ovn_conf.cfg.CONF.set_override('dns_servers',
188189
['10.10.10.10'],
189190
group='ovn')

neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_impl_idl.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from ovsdbapp.tests import utils
2323

2424
from neutron.common.ovn import constants as ovn_const
25+
from neutron.conf.plugins.ml2.drivers.ovn import ovn_conf
2526
from neutron.plugins.ml2.drivers.ovn.mech_driver.ovsdb \
2627
import impl_idl_ovn as impl
2728
from neutron.services.portforwarding import constants as pf_const
@@ -38,6 +39,7 @@ class BaseOvnIdlTest(n_base.BaseLoggingTestCase,
3839

3940
def setUp(self):
4041
super(BaseOvnIdlTest, self).setUp()
42+
ovn_conf.register_opts()
4143
self.api = impl.OvsdbSbOvnIdl(self.connection['OVN_Southbound'])
4244
self.nbapi = impl.OvsdbNbOvnIdl(self.connection['OVN_Northbound'])
4345
self.handler = ovsdb_event.RowEventHandler()

neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/test_mech_driver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,7 @@ class TestCreateDefaultDropPortGroup(base.BaseLoggingTestCase,
801801

802802
def setUp(self):
803803
super(TestCreateDefaultDropPortGroup, self).setUp()
804+
ovn_conf.register_opts()
804805
self.api = impl_idl_ovn.OvsdbNbOvnIdl(
805806
self.connection['OVN_Northbound'])
806807
self.addCleanup(self.api.pg_del(self.PG_NAME, if_exists=True).execute,

0 commit comments

Comments
 (0)