Configure agents using neutron.common.config.init (formerly .parse)

After oslo.messaging port is done, we'll need to initialize RPC layer
from all RPC agents. We'll put initialization into init() function, so
the first step for migration is to make agents use it.

The function is renamed to be explicit about the fact that we don't just
parse configuration by calling it, but also do other common
initializations, like setting RPC layer.

blueprint oslo-messaging

Change-Id: I71c62f270ac7a1ff1426a3f49a32133b65580e35
changes/05/97505/13
Ihar Hrachyshka 8 years ago
parent 5c3b67a025
commit c0db9c23e3
  1. 4
      neutron/agent/dhcp_agent.py
  2. 5
      neutron/agent/l3_agent.py
  3. 3
      neutron/agent/metadata/agent.py
  4. 2
      neutron/cmd/sanity_check.py
  5. 4
      neutron/cmd/usage_audit.py
  6. 2
      neutron/common/config.py
  7. 2
      neutron/plugins/bigswitch/agent/restproxy_agent.py
  8. 7
      neutron/plugins/hyperv/agent/hyperv_neutron_agent.py
  9. 7
      neutron/plugins/ibm/agent/sdnve_neutron_agent.py
  10. 6
      neutron/plugins/linuxbridge/agent/linuxbridge_neutron_agent.py
  11. 6
      neutron/plugins/mlnx/agent/eswitch_neutron_agent.py
  12. 7
      neutron/plugins/nec/agent/nec_neutron_agent.py
  13. 7
      neutron/plugins/oneconvergence/agent/nvsd_neutron_agent.py
  14. 6
      neutron/plugins/openvswitch/agent/ovs_neutron_agent.py
  15. 6
      neutron/plugins/ryu/agent/ryu_neutron_agent.py
  16. 2
      neutron/plugins/vmware/check_nsx_config.py
  17. 2
      neutron/server/__init__.py
  18. 5
      neutron/services/firewall/agents/varmour/varmour_router.py
  19. 5
      neutron/services/loadbalancer/agent/agent.py
  20. 4
      neutron/services/metering/agents/metering_agent.py
  21. 2
      neutron/tests/base.py
  22. 3
      neutron/tests/unit/bigswitch/test_restproxy_agent.py
  23. 15
      neutron/tests/unit/hyperv/test_hyperv_neutron_agent.py
  24. 2
      neutron/tests/unit/ml2/drivers/cisco/apic/test_cisco_apic_common.py
  25. 6
      neutron/tests/unit/nec/test_nec_agent.py
  26. 6
      neutron/tests/unit/oneconvergence/test_nvsd_agent.py
  27. 6
      neutron/tests/unit/ryu/test_ryu_agent.py
  28. 3
      neutron/tests/unit/test_debug_commands.py
  29. 3
      neutron/tests/unit/test_dhcp_agent.py

@ -16,6 +16,7 @@
# under the License.
import os
import sys
import eventlet
eventlet.monkey_patch()
@ -29,6 +30,7 @@ from neutron.agent.linux import external_process
from neutron.agent.linux import interface
from neutron.agent.linux import ovs_lib # noqa
from neutron.agent import rpc as agent_rpc
from neutron.common import config as common_config
from neutron.common import constants
from neutron.common import exceptions
from neutron.common import rpc_compat
@ -610,7 +612,7 @@ def register_options():
def main():
register_options()
cfg.CONF(project='neutron')
common_config.init(sys.argv[1:])
config.setup_logging(cfg.CONF)
server = neutron_service.Service.create(
binary='neutron-dhcp-agent',

@ -13,6 +13,8 @@
# under the License.
#
import sys
import eventlet
eventlet.monkey_patch()
@ -26,6 +28,7 @@ from neutron.agent.linux import ip_lib
from neutron.agent.linux import iptables_manager
from neutron.agent.linux import ovs_lib # noqa
from neutron.agent import rpc as agent_rpc
from neutron.common import config as common_config
from neutron.common import constants as l3_constants
from neutron.common import rpc_compat
from neutron.common import topics
@ -977,7 +980,7 @@ def main(manager='neutron.agent.l3_agent.L3NATAgentWithStateReport'):
config.register_root_helper(conf)
conf.register_opts(interface.OPTS)
conf.register_opts(external_process.OPTS)
conf(project='neutron')
common_config.init(sys.argv[1:])
config.setup_logging(conf)
server = neutron_service.Service.create(
binary='neutron-l3-agent',

@ -20,6 +20,7 @@ import hashlib
import hmac
import os
import socket
import sys
import eventlet
eventlet.monkey_patch()
@ -384,7 +385,7 @@ def main():
cache.register_oslo_configs(cfg.CONF)
cfg.CONF.set_default(name='cache_url', default='memory://?default_ttl=5')
agent_conf.register_agent_state_opts_helper(cfg.CONF)
cfg.CONF(project='neutron')
config.init(sys.argv[1:])
config.setup_logging(cfg.CONF)
utils.log_opt_values(LOG)
proxy = UnixDomainMetadataProxy(cfg.CONF)

@ -85,7 +85,7 @@ def main():
cfg.CONF.register_cli_opts(OPTS)
cfg.CONF.set_override('use_stderr', True)
config.setup_logging(cfg.CONF)
config.parse(sys.argv[1:], default_config_files=[])
config.init(sys.argv[1:], default_config_files=[])
if cfg.CONF.config_file:
enable_tests_from_config()

@ -21,6 +21,8 @@ subnets.
"""
import sys
from oslo.config import cfg
from neutron.common import config
@ -30,7 +32,7 @@ from neutron.openstack.common.notifier import api as notifier_api
def main():
cfg.CONF(project='neutron')
config.init(sys.argv[1:])
config.setup_logging(cfg.CONF)
cxt = context.get_admin_context()

@ -134,7 +134,7 @@ db_options.set_defaults(sql_connection=_SQL_CONNECTION_DEFAULT,
max_overflow=20, pool_timeout=10)
def parse(args, **kwargs):
def init(args, **kwargs):
cfg.CONF(args=args, project='neutron',
version='%%prog %s' % version.version_info.release_string(),
**kwargs)

@ -166,7 +166,7 @@ class RestProxyAgent(rpc_compat.RpcCallback,
def main():
cfg.CONF(project='neutron')
config.init(sys.argv[1:])
config.setup_logging(cfg.CONF)
pl_config.register_config()

@ -20,6 +20,7 @@
import platform
import re
import sys
import time
import eventlet
@ -30,7 +31,7 @@ from oslo.config import cfg
from neutron.agent.common import config
from neutron.agent import rpc as agent_rpc
from neutron.agent import securitygroups_rpc as sg_rpc
from neutron.common import config as logging_config
from neutron.common import config as common_config
from neutron.common import constants as n_const
from neutron.common import rpc_compat
from neutron.common import topics
@ -472,8 +473,8 @@ class HyperVNeutronAgent(rpc_compat.RpcCallback):
def main():
cfg.CONF(project='neutron')
logging_config.setup_logging(cfg.CONF)
common_config.init(sys.argv[1:])
common_config.setup_logging(cfg.CONF)
plugin = HyperVNeutronAgent()

@ -18,6 +18,7 @@
import socket
import sys
import time
import eventlet
@ -28,7 +29,7 @@ from oslo.config import cfg
from neutron.agent.linux import ip_lib
from neutron.agent.linux import ovs_lib
from neutron.agent import rpc as agent_rpc
from neutron.common import config as logging_config
from neutron.common import config as common_config
from neutron.common import constants as n_const
from neutron.common import rpc_compat
from neutron.common import topics
@ -257,8 +258,8 @@ def create_agent_config_map(config):
def main():
cfg.CONF.register_opts(ip_lib.OPTS)
cfg.CONF(project='neutron')
logging_config.setup_logging(cfg.CONF)
common_config.init(sys.argv[1:])
common_config.setup_logging(cfg.CONF)
try:
agent_config = create_agent_config_map(cfg.CONF)

@ -36,7 +36,7 @@ from neutron.agent.linux import ip_lib
from neutron.agent.linux import utils
from neutron.agent import rpc as agent_rpc
from neutron.agent import securitygroups_rpc as sg_rpc
from neutron.common import config as logging_config
from neutron.common import config as common_config
from neutron.common import constants
from neutron.common import exceptions
from neutron.common import rpc_compat
@ -1029,9 +1029,9 @@ class LinuxBridgeNeutronAgentRPC(sg_rpc.SecurityGroupAgentRpcMixin):
def main():
cfg.CONF(project='neutron')
common_config.init(sys.argv[1:])
logging_config.setup_logging(cfg.CONF)
common_config.setup_logging(cfg.CONF)
try:
interface_mappings = q_utils.parse_mappings(
cfg.CONF.LINUX_BRIDGE.physical_interface_mappings)

@ -27,7 +27,7 @@ from oslo.config import cfg
from neutron.agent import rpc as agent_rpc
from neutron.agent import securitygroups_rpc as sg_rpc
from neutron.common import config as logging_config
from neutron.common import config as common_config
from neutron.common import constants as q_constants
from neutron.common import rpc_compat
from neutron.common import topics
@ -421,8 +421,8 @@ class MlnxEswitchNeutronAgent(sg_rpc.SecurityGroupAgentRpcMixin):
def main():
cfg.CONF(project='neutron')
logging_config.setup_logging(cfg.CONF)
common_config.init(sys.argv[1:])
common_config.setup_logging(cfg.CONF)
try:
interface_mappings = q_utils.parse_mappings(

@ -21,6 +21,7 @@
# @author: Akihiro MOTOKI
import socket
import sys
import time
import eventlet
@ -29,7 +30,7 @@ eventlet.monkey_patch()
from neutron.agent.linux import ovs_lib
from neutron.agent import rpc as agent_rpc
from neutron.agent import securitygroups_rpc as sg_rpc
from neutron.common import config as logging_config
from neutron.common import config as common_config
from neutron.common import constants as q_const
from neutron.common import rpc_compat
from neutron.common import topics
@ -234,9 +235,9 @@ class NECNeutronAgent(object):
def main():
config.CONF(project='neutron')
common_config.init(sys.argv[1:])
logging_config.setup_logging(config.CONF)
common_config.setup_logging(config.CONF)
# Determine which agent type to use.
integ_br = config.OVS.integration_bridge

@ -17,6 +17,7 @@
"""NVSD agent code for security group events."""
import socket
import sys
import time
import eventlet
@ -25,7 +26,7 @@ eventlet.monkey_patch()
from neutron.agent.linux import ovs_lib
from neutron.agent import rpc as agent_rpc
from neutron.agent import securitygroups_rpc as sg_rpc
from neutron.common import config as logging_config
from neutron.common import config as common_config
from neutron.common import rpc_compat
from neutron.common import topics
from neutron import context as n_context
@ -164,8 +165,8 @@ class NVSDNeutronAgent(rpc_compat.RpcCallback):
def main():
config.CONF(project='neutron')
logging_config.setup_logging(config.CONF)
common_config.init(sys.argv[1:])
common_config.setup_logging(config.CONF)
integ_br = config.AGENT.integration_bridge
root_helper = config.AGENT.root_helper

@ -33,7 +33,7 @@ from neutron.agent.linux import polling
from neutron.agent.linux import utils
from neutron.agent import rpc as agent_rpc
from neutron.agent import securitygroups_rpc as sg_rpc
from neutron.common import config as logging_config
from neutron.common import config as common_config
from neutron.common import constants as q_const
from neutron.common import rpc_compat
from neutron.common import topics
@ -1502,8 +1502,8 @@ def create_agent_config_map(config):
def main():
cfg.CONF.register_opts(ip_lib.OPTS)
cfg.CONF(project='neutron')
logging_config.setup_logging(cfg.CONF)
common_config.init(sys.argv[1:])
common_config.setup_logging(cfg.CONF)
q_utils.log_opt_values(LOG)
try:

@ -35,7 +35,7 @@ from neutron.agent.linux import ip_lib
from neutron.agent.linux import ovs_lib
from neutron.agent import rpc as agent_rpc
from neutron.agent import securitygroups_rpc as sg_rpc
from neutron.common import config as logging_config
from neutron.common import config as common_config
from neutron.common import exceptions as n_exc
from neutron.common import rpc_compat
from neutron.common import topics
@ -286,9 +286,9 @@ class OVSNeutronOFPRyuAgent(rpc_compat.RpcCallback,
def main():
cfg.CONF(project='neutron')
common_config.init(sys.argv[1:])
logging_config.setup_logging(cfg.CONF)
common_config.setup_logging(cfg.CONF)
integ_br = cfg.CONF.OVS.integration_bridge
polling_interval = cfg.CONF.AGENT.polling_interval

@ -90,7 +90,7 @@ def main():
help(sys.argv[0])
args = ['--config-file']
args.append(sys.argv[1])
config.parse(args)
config.init(args)
print("----------------------- Database Options -----------------------")
print("\tconnection: %s" % cfg.CONF.database.connection)
print("\tretry_interval: %d" % cfg.CONF.database.retry_interval)

@ -37,7 +37,7 @@ LOG = logging.getLogger(__name__)
def main():
# the configuration will be read into the cfg.CONF global data structure
config.parse(sys.argv[1:])
config.init(sys.argv[1:])
if not cfg.CONF.config_file:
sys.exit(_("ERROR: Unable to find configuration file via the default"
" search paths (~/.neutron/, ~/, /etc/neutron/, /etc/) and"

@ -18,6 +18,8 @@
# @author: Gary Duan, vArmour Networks Inc.
#
import sys
import eventlet
eventlet.monkey_patch()
@ -29,6 +31,7 @@ from neutron.agent import l3_agent
from neutron.agent.linux import external_process
from neutron.agent.linux import interface
from neutron.agent.linux import ip_lib
from neutron.common import config as common_config
from neutron.common import constants as l3_constants
from neutron.common import topics
from neutron.openstack.common import log as logging
@ -337,7 +340,7 @@ def main():
config.register_root_helper(conf)
conf.register_opts(interface.OPTS)
conf.register_opts(external_process.OPTS)
conf(project='neutron')
common_config.init(sys.argv[1:])
config.setup_logging(conf)
server = neutron_service.Service.create(
binary='neutron-l3-agent',

@ -16,6 +16,8 @@
#
# @author: Mark McClain, DreamHost
import sys
import eventlet
eventlet.monkey_patch()
@ -23,6 +25,7 @@ from oslo.config import cfg
from neutron.agent.common import config
from neutron.agent.linux import interface
from neutron.common import config as common_config
from neutron.common import rpc_compat
from neutron.common import topics
from neutron.openstack.common import service
@ -57,7 +60,7 @@ def main():
config.register_agent_state_opts_helper(cfg.CONF)
config.register_root_helper(cfg.CONF)
cfg.CONF(project='neutron')
common_config.init(sys.argv[1:])
config.setup_logging(cfg.CONF)
mgr = manager.LbaasAgentManager(cfg.CONF)

@ -14,6 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import sys
import time
import eventlet
@ -23,6 +24,7 @@ from oslo.config import cfg
from neutron.agent.common import config
from neutron.agent import rpc as agent_rpc
from neutron.common import config as common_config
from neutron.common import constants as constants
from neutron.common import rpc_compat
from neutron.common import topics
@ -287,7 +289,7 @@ def main():
conf.register_opts(MeteringAgent.Opts)
config.register_agent_state_opts_helper(conf)
config.register_root_helper(conf)
conf(project='neutron')
common_config.init(sys.argv[1:])
config.setup_logging(conf)
server = neutron_service.Service.create(
binary='neutron-metering-agent',

@ -109,7 +109,7 @@ class BaseTestCase(testtools.TestCase):
if args is None:
args = ['--config-file', etcdir('neutron.conf.test')]
if conf is None:
config.parse(args=args)
config.init(args=args)
else:
conf(args)

@ -166,9 +166,10 @@ class TestRestProxyAgent(BaseAgentTestCase):
'CONF.AGENT.root_helper': 'helper'}
with contextlib.nested(
mock.patch(AGENTMOD + '.cfg', **cfg_attrs),
mock.patch(AGENTMOD + '.config.init'),
mock.patch(NEUTRONCFG),
mock.patch(PLCONFIG),
) as (mock_conf, mock_log_conf, mock_pluginconf):
) as (mock_conf, mock_init, mock_log_conf, mock_pluginconf):
self.mod_agent.main()
mock_log_conf.assert_has_calls([

@ -212,13 +212,10 @@ class TestHyperVNeutronAgent(base.BaseTestCase):
def test_main(self):
with mock.patch.object(hyperv_neutron_agent,
'HyperVNeutronAgent') as plugin:
with mock.patch.object(hyperv_neutron_agent.cfg, 'CONF') as cfg:
with mock.patch.object(
hyperv_neutron_agent,
'logging_config') as logging_config:
with mock.patch.object(hyperv_neutron_agent,
'common_config') as common_config:
hyperv_neutron_agent.main()
hyperv_neutron_agent.main()
self.assertTrue(cfg.called)
self.assertTrue(logging_config.setup_logging.called)
plugin.assert_has_calls([mock.call().daemon_loop()])
self.assertTrue(common_config.init.called)
self.assertTrue(common_config.setup_logging.called)
plugin.assert_has_calls([mock.call().daemon_loop()])

@ -170,7 +170,7 @@ class ConfigMixin(object):
def set_up_mocks(self):
# Mock the configuration file
args = ['--config-file', base.etcdir('neutron.conf.test')]
neutron_config.parse(args=args)
neutron_config.init(args=args)
# Configure the ML2 mechanism drivers and network types
ml2_opts = {

@ -350,16 +350,16 @@ class TestNecAgentMain(base.BaseTestCase):
def test_main(self):
with contextlib.nested(
mock.patch.object(nec_neutron_agent, 'NECNeutronAgent'),
mock.patch.object(nec_neutron_agent, 'logging_config'),
mock.patch.object(nec_neutron_agent, 'common_config'),
mock.patch.object(nec_neutron_agent, 'config')
) as (agent, logging_config, cfg):
) as (agent, common_config, cfg):
cfg.OVS.integration_bridge = 'br-int-x'
cfg.AGENT.root_helper = 'dummy-helper'
cfg.AGENT.polling_interval = 10
nec_neutron_agent.main()
self.assertTrue(logging_config.setup_logging.called)
self.assertTrue(common_config.setup_logging.called)
agent.assert_has_calls([
mock.call('br-int-x', 'dummy-helper', 10),
mock.call().daemon_loop()

@ -161,16 +161,16 @@ class TestOneConvergenceAgentMain(base.BaseTestCase):
def test_main(self):
with contextlib.nested(
mock.patch.object(nvsd_neutron_agent, 'NVSDNeutronAgent'),
mock.patch.object(nvsd_neutron_agent, 'logging_config'),
mock.patch.object(nvsd_neutron_agent, 'common_config'),
mock.patch.object(nvsd_neutron_agent, 'config')
) as (agent, logging_config, config):
) as (agent, common_config, config):
config.AGENT.integration_bridge = 'br-int-dummy'
config.AGENT.root_helper = 'root-helper'
config.AGENT.polling_interval = 5
nvsd_neutron_agent.main()
self.assertTrue(logging_config.setup_logging.called)
self.assertTrue(common_config.setup_logging.called)
agent.assert_has_calls([
mock.call('br-int-dummy', 'root-helper', 5),
mock.call().daemon_loop()

@ -610,15 +610,15 @@ class TestRyuNeutronAgent(RyuAgentTestCase):
'CONF.AGENT.root_helper': 'helper'}
with contextlib.nested(
mock.patch(self._AGENT_NAME + '.cfg', **cfg_attrs),
mock.patch(self._AGENT_NAME + '.logging_config'),
mock.patch(self._AGENT_NAME + '.common_config'),
mock.patch(self._AGENT_NAME + '._get_tunnel_ip',
return_value='10.0.0.1'),
mock.patch(self._AGENT_NAME + '._get_ovsdb_ip',
return_value='172.16.0.1'),
) as (mock_conf, mock_log_conf, _tun, _ovsdb):
) as (mock_conf, mock_common_conf, _tun, _ovsdb):
self.mod_agent.main()
mock_log_conf.assert_has_calls([
mock_common_conf.assert_has_calls([
mock.call(mock_conf)
])

@ -22,6 +22,7 @@ from oslo.config import cfg
from neutron.agent.common import config
from neutron.agent.linux import interface
from neutron.common import config as common_config
from neutron.debug import commands
from neutron.debug import debug_agent
from neutron.tests import base
@ -37,7 +38,7 @@ class TestDebugCommands(base.BaseTestCase):
super(TestDebugCommands, self).setUp()
cfg.CONF.register_opts(interface.OPTS)
cfg.CONF.register_opts(debug_agent.NeutronDebugAgent.OPTS)
cfg.CONF(args=[], project='neutron')
common_config.init([])
config.register_interface_driver_opts_helper(cfg.CONF)
config.register_use_namespaces_opts_helper(cfg.CONF)
config.register_root_helper(cfg.CONF)

@ -28,6 +28,7 @@ from neutron.agent.common import config
from neutron.agent import dhcp_agent
from neutron.agent.linux import dhcp
from neutron.agent.linux import interface
from neutron.common import config as common_config
from neutron.common import constants as const
from neutron.common import exceptions
from neutron.common import rpc_compat
@ -157,7 +158,7 @@ class TestDhcpAgent(base.BaseTestCase):
config.register_root_helper(cfg.CONF)
cfg.CONF.register_opts(dhcp.OPTS)
cfg.CONF.register_opts(interface.OPTS)
cfg.CONF(project='neutron')
common_config.init(sys.argv[1:])
agent_mgr = dhcp_agent.DhcpAgentWithStateReport(
'testhost')
eventlet.greenthread.sleep(1)

Loading…
Cancel
Save