From 06ce1329a044b8e7be9db59811d4f4316d0d0743 Mon Sep 17 00:00:00 2001 From: Paul Michali Date: Thu, 24 Jan 2013 08:13:18 -0500 Subject: [PATCH] Reqd. core_plugin for plugin agents & show cfg opts loaded. For the linuxbridge, openvswitch, nec, and ryu plugin agents, require the core_plugin configuration option, and throw an exception, if not present. Note: cannot make this a required option for all agents, as there are agent that include the core config options, but do not require core_plugin. In addition, log (as debug) the configuration options that have been loaded at start-up for these four agents. This will help with diagnosing start-up issues related to the configuraiton settings (or lack of). Tested that exception thrown, when missing core_plugin value in config file(s) included, for these four agents. bug 1059923 Change-Id: I813f0c2a3d0ec01be74a34e56ab085979197a16a --- quantum/agent/common/validate.py | 28 +++++++++++++++++++ .../agent/linuxbridge_quantum_agent.py | 6 ++++ .../plugins/nec/agent/nec_quantum_agent.py | 5 ++++ .../openvswitch/agent/ovs_quantum_agent.py | 5 ++++ .../plugins/ryu/agent/ryu_quantum_agent.py | 5 ++++ quantum/tests/unit/test_agent_config.py | 21 ++++++++++++++ 6 files changed, 70 insertions(+) create mode 100644 quantum/agent/common/validate.py diff --git a/quantum/agent/common/validate.py b/quantum/agent/common/validate.py new file mode 100644 index 000000000..763f84200 --- /dev/null +++ b/quantum/agent/common/validate.py @@ -0,0 +1,28 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 +# Copyright 2013 Cisco Systems, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# @author: Paul Michali, Cisco Systems, Inc. + + +def core_config_options(options): + '''Validate core configuration options. + + Make sure that core configuration options that are needed are present and, + if not, generate warnings/errors, based on the severity. Will be used + only by the agents that require the option(s). + ''' + + if options.core_plugin is None: + raise Exception(_('Quantum core_plugin not configured!')) diff --git a/quantum/plugins/linuxbridge/agent/linuxbridge_quantum_agent.py b/quantum/plugins/linuxbridge/agent/linuxbridge_quantum_agent.py index 56d11ccfd..64ccaaeaf 100755 --- a/quantum/plugins/linuxbridge/agent/linuxbridge_quantum_agent.py +++ b/quantum/plugins/linuxbridge/agent/linuxbridge_quantum_agent.py @@ -27,12 +27,14 @@ import sys import time import eventlet +import logging as std_logging import pyudev from quantum.agent.linux import ip_lib from quantum.agent.linux import utils from quantum.agent import rpc as agent_rpc from quantum.agent import securitygroups_rpc as sg_rpc +from quantum.agent.common import validate from quantum.common import config as logging_config from quantum.common import topics from quantum.common import utils as q_utils @@ -602,6 +604,10 @@ def main(): cfg.CONF(project='quantum') logging_config.setup_logging(cfg.CONF) + + cfg.CONF.log_opt_values(LOG, std_logging.DEBUG) + validate.core_config_options(cfg.CONF) + try: interface_mappings = q_utils.parse_mappings( cfg.CONF.LINUX_BRIDGE.physical_interface_mappings) diff --git a/quantum/plugins/nec/agent/nec_quantum_agent.py b/quantum/plugins/nec/agent/nec_quantum_agent.py index 8c8786b4e..5dc306e9b 100755 --- a/quantum/plugins/nec/agent/nec_quantum_agent.py +++ b/quantum/plugins/nec/agent/nec_quantum_agent.py @@ -24,7 +24,9 @@ import socket import sys import time +import logging as std_logging +from quantum.agent.common import validate from quantum.agent.linux import ovs_lib from quantum.common import config as logging_config from quantum.common import topics @@ -112,6 +114,9 @@ def main(): logging_config.setup_logging(config.CONF) + config.CONF.log_opt_values(LOG, std_logging.DEBUG) + validate.core_config_options(config.CONF) + # Determine which agent type to use. integ_br = config.OVS.integration_bridge root_helper = config.AGENT.root_helper diff --git a/quantum/plugins/openvswitch/agent/ovs_quantum_agent.py b/quantum/plugins/openvswitch/agent/ovs_quantum_agent.py index 042aac5b4..301c1b827 100755 --- a/quantum/plugins/openvswitch/agent/ovs_quantum_agent.py +++ b/quantum/plugins/openvswitch/agent/ovs_quantum_agent.py @@ -24,7 +24,9 @@ import sys import time import eventlet +import logging as std_logging +from quantum.agent.common import validate from quantum.agent.linux import ip_lib from quantum.agent.linux import ovs_lib from quantum.agent.linux import utils @@ -690,6 +692,9 @@ def main(): cfg.CONF(project='quantum') logging_config.setup_logging(cfg.CONF) + cfg.CONF.log_opt_values(LOG, std_logging.DEBUG) + validate.core_config_options(cfg.CONF) + try: agent_config = create_agent_config_map(cfg.CONF) except ValueError as e: diff --git a/quantum/plugins/ryu/agent/ryu_quantum_agent.py b/quantum/plugins/ryu/agent/ryu_quantum_agent.py index e20dba9ca..bc6e5df04 100755 --- a/quantum/plugins/ryu/agent/ryu_quantum_agent.py +++ b/quantum/plugins/ryu/agent/ryu_quantum_agent.py @@ -24,12 +24,14 @@ import httplib import socket import sys +import logging as std_logging import netifaces from ryu.app import client from ryu.app import conf_switch_key from ryu.app import rest_nw_id from sqlalchemy.ext.sqlsoup import SqlSoup +from quantum.agent.common import validate from quantum.agent.linux import ovs_lib from quantum.agent.linux.ovs_lib import VifPort from quantum.common import config as logging_config @@ -210,6 +212,9 @@ def main(): logging_config.setup_logging(cfg.CONF) + cfg.CONF.log_opt_values(LOG, std_logging.DEBUG) + validate.core_config_options(cfg.CONF) + integ_br = cfg.CONF.OVS.integration_bridge root_helper = cfg.CONF.AGENT.root_helper options = {"sql_connection": cfg.CONF.DATABASE.sql_connection} diff --git a/quantum/tests/unit/test_agent_config.py b/quantum/tests/unit/test_agent_config.py index 73e10ed01..8c1e4398c 100644 --- a/quantum/tests/unit/test_agent_config.py +++ b/quantum/tests/unit/test_agent_config.py @@ -15,9 +15,30 @@ # License for the specific language governing permissions and limitations # under the License. +import unittest2 as unittest + from quantum.agent.common import config +from quantum.agent.common import validate +from quantum.openstack.common import cfg def test_setup_conf(): conf = config.setup_conf() assert conf.state_path.endswith('/var/lib/quantum') + + +class TestCoreConfigOptions(unittest.TestCase): + + def setUp(self): + self._saved_core_plugin = cfg.CONF.core_plugin + + def tearDown(self): + cfg.CONF.set_override('core_plugin', self._saved_core_plugin) + + def test_missing_required_core_option(self): + with self.assertRaises(Exception) as ex: + validate.core_config_options(cfg.CONF) + + def test_have_required_core_option(self): + cfg.CONF.set_override('core_plugin', 'some_core_plugin_option') + validate.core_config_options(cfg.CONF) -- 2.45.2