Browse Source

Define dhcp_agents_per_network with min=1

The minimum value for dhcp_agents_per_network was being
inforced with an explicit check in code but we can do that
with simply defining the min value in the option itself.

This adds the minimum to the option definition and removes
the explicit check in the code. Note that as a result the
validate_post_plugin_load method needed to be removed
otherwise it fails the E1128 pylint check.

Change-Id: I103855d363c49fad4119ac850aed0a166d8c046d
changes/56/659356/1
Matt Riedemann 2 years ago
parent
commit
8eb6c8cc6f
  1. 1
      neutron/conf/agent/database/agentschedulers_db.py
  2. 17
      neutron/manager.py
  3. 15
      neutron/tests/unit/test_manager.py

1
neutron/conf/agent/database/agentschedulers_db.py

@ -27,6 +27,7 @@ AGENTS_SCHEDULER_OPTS = [
help=_('Automatically remove networks from offline DHCP '
'agents.')),
cfg.IntOpt('dhcp_agents_per_network', default=1,
min=1,
help=_('Number of DHCP agents scheduled to host a tenant '
'network. If this number is greater than 1, the '
'scheduler automatically assigns multiple DHCP agents '

17
neutron/manager.py

@ -73,19 +73,6 @@ class Manager(periodic_task.PeriodicTasks):
pass
def validate_post_plugin_load():
"""Checks if the configuration variables are valid.
If the configuration is invalid then the method will return an error
message. If all is OK then it will return None.
"""
if ('dhcp_agents_per_network' in cfg.CONF and
cfg.CONF.dhcp_agents_per_network <= 0):
msg = _("dhcp_agents_per_network must be >= 1. '%s' "
"is invalid.") % cfg.CONF.dhcp_agents_per_network
return msg
def validate_pre_plugin_load():
"""Checks if the configuration variables are valid.
@ -135,10 +122,6 @@ class NeutronManager(object):
plugin = self._get_plugin_instance(CORE_PLUGINS_NAMESPACE,
plugin_provider)
directory.add_plugin(lib_const.CORE, plugin)
msg = validate_post_plugin_load()
if msg:
LOG.critical(msg)
raise Exception(msg)
# load services from the core plugin first
self._load_services_from_core_plugin(plugin)

15
neutron/tests/unit/test_manager.py

@ -217,17 +217,10 @@ class NeutronManagerTestCase(base.BaseTestCase):
svc_plugins = directory.get_plugins()
self.assertIn(dummy_plugin.DUMMY_SERVICE_TYPE, svc_plugins)
def test_post_plugin_validation(self):
cfg.CONF.import_opt('dhcp_agents_per_network',
'neutron.db.agentschedulers_db')
self.assertIsNone(manager.validate_post_plugin_load())
cfg.CONF.set_override('dhcp_agents_per_network', 2)
self.assertIsNone(manager.validate_post_plugin_load())
cfg.CONF.set_override('dhcp_agents_per_network', 0)
self.assertIsNotNone(manager.validate_post_plugin_load())
cfg.CONF.set_override('dhcp_agents_per_network', -1)
self.assertIsNotNone(manager.validate_post_plugin_load())
def test_dhcp_agents_per_network_min(self):
# Ensures dhcp_agents_per_network must be at least 1.
self.assertRaises(ValueError, cfg.CONF.set_override,
'dhcp_agents_per_network', 0)
def test_pre_plugin_validation(self):
self.assertIsNotNone(manager.validate_pre_plugin_load())

Loading…
Cancel
Save