From: Julien Danjou Date: Wed, 10 Jul 2013 15:27:52 +0000 (+0200) Subject: Update oslo.notifier and always register options X-Git-Tag: 2014.1~355^2 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=f2ef092d8ca73ee4cae8745f5985d5c0f108dac8;p=openstack-build%2Fheat-build.git Update oslo.notifier and always register options This avoids registering multiple times the option if the registering functions are called multiple path by different code paths. It's necessary for the default configuration sample generator to have options only registered once. The update of oslo.notifier is needed to avoid it using the inexistant $host option. Change-Id: If31974d7ef7fdbf85a88e950ff06c60ccbd6c31d Signed-off-by: Julien Danjou --- diff --git a/bin/heat-engine b/bin/heat-engine index 3e0167a4..14e6f185 100755 --- a/bin/heat-engine +++ b/bin/heat-engine @@ -43,7 +43,6 @@ from oslo.config import cfg from heat.openstack.common import log as logging from heat.openstack.common import service -from heat.common import config from heat.db import api as db_api from heat.rpc import api as rpc_api @@ -64,7 +63,6 @@ if __name__ == '__main__': from heat.engine import service as engine db_api.configure() - config.register_engine_opts() srv = engine.EngineService(cfg.CONF.host, rpc_api.ENGINE_TOPIC) launcher = service.launch(srv) launcher.wait() diff --git a/heat/api/__init__.py b/heat/api/__init__.py index de94140f..e8e40359 100644 --- a/heat/api/__init__.py +++ b/heat/api/__init__.py @@ -12,7 +12,3 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. - -from heat.common import config - -config.register_api_opts() diff --git a/heat/common/config.py b/heat/common/config.py index 02ae986c..d32025a6 100644 --- a/heat/common/config.py +++ b/heat/common/config.py @@ -38,10 +38,6 @@ paste_deploy_opts = [ help="The API paste config file to use")] -bind_opts = [ - cfg.IntOpt('bind_port', default=8000), - cfg.StrOpt('bind_host', default='127.0.0.1')] - service_opts = [ cfg.IntOpt('report_interval', default=10, @@ -113,38 +109,23 @@ rpc_opts = [ 'This can be an opaque identifier.' 'It is not necessarily a hostname, FQDN, or IP address.')] - -def register_api_opts(): - cfg.CONF.register_opts(bind_opts) - cfg.CONF.register_opts(rpc_opts) - rpc.set_defaults(control_exchange='heat') - - -def register_db_opts(): - cfg.CONF.register_opts(db_opts) +cfg.CONF.register_opts(db_opts) +cfg.CONF.register_opts(engine_opts) +cfg.CONF.register_opts(service_opts) +cfg.CONF.register_opts(rpc_opts) +cfg.CONF.register_group(paste_deploy_group) +cfg.CONF.register_opts(paste_deploy_opts, group=paste_deploy_group) -def register_engine_opts(): - cfg.CONF.register_opts(engine_opts) - cfg.CONF.register_opts(service_opts) - cfg.CONF.register_opts(rpc_opts) +def rpc_set_default(): rpc.set_defaults(control_exchange='heat') -def _register_paste_deploy_opts(): - """ - Idempotent registration of paste_deploy option group - """ - cfg.CONF.register_group(paste_deploy_group) - cfg.CONF.register_opts(paste_deploy_opts, group=paste_deploy_group) - - def _get_deployment_flavor(): """ Retrieve the paste_deploy.flavor config item, formatted appropriately for appending to the application name. """ - _register_paste_deploy_opts() flavor = cfg.CONF.paste_deploy.flavor return '' if not flavor else ('-' + flavor) @@ -154,7 +135,6 @@ def _get_deployment_config_file(): Retrieve the deployment_config_file config item, formatted as an absolute pathname. """ - _register_paste_deploy_opts() config_path = cfg.CONF.find_file( cfg.CONF.paste_deploy['api_paste_config']) if config_path is None: diff --git a/heat/common/wsgi.py b/heat/common/wsgi.py index a355f355..7282ca65 100644 --- a/heat/common/wsgi.py +++ b/heat/common/wsgi.py @@ -58,13 +58,19 @@ bind_opts = [ cfg.IntOpt('bind_port'), ] +cfg.CONF.register_opts(bind_opts) + socket_opts = [ cfg.IntOpt('backlog', default=4096), cfg.StrOpt('cert_file'), cfg.StrOpt('key_file'), ] -workers_opt = cfg.IntOpt('workers', default=0) +cfg.CONF.register_opts(socket_opts) + +workers_opts = cfg.IntOpt('workers', default=0) + +cfg.CONF.register_opt(workers_opts) class WritableLogger(object): @@ -178,7 +184,6 @@ class Server(object): self.application = application self.sock = get_socket(conf, default_port) - conf.register_opt(workers_opt) self.logger = logging.getLogger('eventlet.wsgi.server') diff --git a/heat/db/api.py b/heat/db/api.py index 23cc8b9b..941bbfe2 100644 --- a/heat/db/api.py +++ b/heat/db/api.py @@ -28,7 +28,6 @@ supported backend. from oslo.config import cfg -from heat.common import config from heat.db import utils SQL_CONNECTION = 'sqlite://' @@ -38,14 +37,19 @@ db_opts = [ default='sqlalchemy', help='The backend to use for db')] +cfg.CONF.register_opts(db_opts) + IMPL = utils.LazyPluggable('db_backend', sqlalchemy='heat.db.sqlalchemy.api') +cfg.CONF.import_opt('sql_connection', 'heat.common.config') +cfg.CONF.import_opt('sql_idle_timeout', 'heat.common.config') + + def configure(): global SQL_CONNECTION global SQL_IDLE_TIMEOUT - config.register_db_opts() SQL_CONNECTION = cfg.CONF.sql_connection SQL_IDLE_TIMEOUT = cfg.CONF.sql_idle_timeout diff --git a/heat/engine/resources/__init__.py b/heat/engine/resources/__init__.py index 28bdc400..924114be 100644 --- a/heat/engine/resources/__init__.py +++ b/heat/engine/resources/__init__.py @@ -51,15 +51,14 @@ def initialise(): if _initialized: return import sys - from heat.common import config from heat.common import plugin_loader - config.register_engine_opts() - _register_modules(plugin_loader.load_modules(sys.modules[__name__])) from oslo.config import cfg + cfg.CONF.import_opt('plugin_dirs', 'heat.common.config') + plugin_pkg = plugin_loader.create_subpackage(cfg.CONF.plugin_dirs, 'heat.engine') _register_modules(plugin_loader.load_modules(plugin_pkg, True)) diff --git a/heat/openstack/common/notifier/api.py b/heat/openstack/common/notifier/api.py index d5d2b36a..428e5068 100644 --- a/heat/openstack/common/notifier/api.py +++ b/heat/openstack/common/notifier/api.py @@ -13,12 +13,13 @@ # License for the specific language governing permissions and limitations # under the License. +import socket import uuid from oslo.config import cfg from heat.openstack.common import context -from heat.openstack.common.gettextutils import _ +from heat.openstack.common.gettextutils import _ # noqa from heat.openstack.common import importutils from heat.openstack.common import jsonutils from heat.openstack.common import log as logging @@ -35,7 +36,7 @@ notifier_opts = [ default='INFO', help='Default notification level for outgoing notifications'), cfg.StrOpt('default_publisher_id', - default='$host', + default=None, help='Default publisher_id for outgoing notifications'), ] @@ -74,7 +75,7 @@ def notify_decorator(name, fn): ctxt = context.get_context_from_function_and_args(fn, args, kwarg) notify(ctxt, - CONF.default_publisher_id, + CONF.default_publisher_id or socket.gethostname(), name, CONF.default_notification_level, body) @@ -84,7 +85,10 @@ def notify_decorator(name, fn): def publisher_id(service, host=None): if not host: - host = CONF.host + try: + host = CONF.host + except AttributeError: + host = CONF.default_publisher_id or socket.gethostname() return "%s.%s" % (service, host) diff --git a/heat/openstack/common/notifier/rpc_notifier.py b/heat/openstack/common/notifier/rpc_notifier.py index 1b3c2597..ffe8fdcc 100644 --- a/heat/openstack/common/notifier/rpc_notifier.py +++ b/heat/openstack/common/notifier/rpc_notifier.py @@ -16,7 +16,7 @@ from oslo.config import cfg from heat.openstack.common import context as req_context -from heat.openstack.common.gettextutils import _ +from heat.openstack.common.gettextutils import _ # noqa from heat.openstack.common import log as logging from heat.openstack.common import rpc diff --git a/heat/openstack/common/notifier/rpc_notifier2.py b/heat/openstack/common/notifier/rpc_notifier2.py index 3688484c..53cf6c9e 100644 --- a/heat/openstack/common/notifier/rpc_notifier2.py +++ b/heat/openstack/common/notifier/rpc_notifier2.py @@ -18,7 +18,7 @@ from oslo.config import cfg from heat.openstack.common import context as req_context -from heat.openstack.common.gettextutils import _ +from heat.openstack.common.gettextutils import _ # noqa from heat.openstack.common import log as logging from heat.openstack.common import rpc diff --git a/heat/tests/test_engine_service.py b/heat/tests/test_engine_service.py index d2b63b7a..9e5b3cb9 100644 --- a/heat/tests/test_engine_service.py +++ b/heat/tests/test_engine_service.py @@ -20,7 +20,6 @@ import sys import mox from oslo.config import cfg -from heat.common import config from heat.common import context from heat.engine import environment from heat.common import exception @@ -574,7 +573,6 @@ class stackServiceTest(HeatTestCase): def setUp(self): super(stackServiceTest, self).setUp() - config.register_engine_opts() self.username = 'stack_service_test_user' self.tenant = 'stack_service_test_tenant' diff --git a/heat/tests/test_heatclient.py b/heat/tests/test_heatclient.py index 362a926d..d04aa9dc 100644 --- a/heat/tests/test_heatclient.py +++ b/heat/tests/test_heatclient.py @@ -14,7 +14,6 @@ import mox -from heat.common import config from heat.common import context from heat.common import heat_keystoneclient from heat.tests.common import HeatTestCase @@ -26,7 +25,6 @@ class KeystoneClientTest(HeatTestCase): def setUp(self): super(KeystoneClientTest, self).setUp() # load config so role checking doesn't barf - config.register_engine_opts() # mock the internal keystone client and its authentication self.m.StubOutClassWithMocks(heat_keystoneclient.kc, "Client") self.mock_ks_client = heat_keystoneclient.kc.Client( diff --git a/heat/tests/test_loadbalancer.py b/heat/tests/test_loadbalancer.py index aeab875a..2136c82a 100644 --- a/heat/tests/test_loadbalancer.py +++ b/heat/tests/test_loadbalancer.py @@ -18,7 +18,6 @@ import re from oslo.config import cfg from heat.common import exception -from heat.common import config from heat.common import template_format from heat.engine import clients from heat.engine import scheduler @@ -76,7 +75,6 @@ lb_template = ''' class LoadBalancerTest(HeatTestCase): def setUp(self): super(LoadBalancerTest, self).setUp() - config.register_engine_opts() self.fc = fakes.FakeClient() self.m.StubOutWithMock(clients.OpenStackClients, 'nova') self.m.StubOutWithMock(self.fc.servers, 'create') diff --git a/heat/tests/test_rpc_client.py b/heat/tests/test_rpc_client.py index c09e7669..41f47e4d 100644 --- a/heat/tests/test_rpc_client.py +++ b/heat/tests/test_rpc_client.py @@ -23,7 +23,6 @@ from oslo.config import cfg import stubout import testtools -from heat.common import config from heat.common import context from heat.common import identifier from heat.rpc import api as rpc_api @@ -34,7 +33,6 @@ from heat.openstack.common import rpc class EngineRpcAPITestCase(testtools.TestCase): def setUp(self): - config.register_engine_opts() self.context = context.get_admin_context() cfg.CONF.set_default('rpc_backend', 'heat.openstack.common.rpc.impl_fake') diff --git a/heat/tests/test_user.py b/heat/tests/test_user.py index 280629ec..052eb85b 100644 --- a/heat/tests/test_user.py +++ b/heat/tests/test_user.py @@ -15,7 +15,6 @@ from oslo.config import cfg -from heat.common import config from heat.common import exception from heat.common import template_format from heat.engine import resource @@ -92,7 +91,6 @@ user_policy_template = ''' class UserPolicyTestCase(HeatTestCase): def setUp(self): super(UserPolicyTestCase, self).setUp() - config.register_engine_opts() username = utils.PhysName('test_stack', 'CfnUser') self.fc = fakes.FakeKeystoneClient(username=username) cfg.CONF.set_default('heat_stack_user_role', 'stack_user_role') diff --git a/heat/tests/test_waitcondition.py b/heat/tests/test_waitcondition.py index e508ef5c..24a09b41 100644 --- a/heat/tests/test_waitcondition.py +++ b/heat/tests/test_waitcondition.py @@ -34,7 +34,6 @@ from heat.engine import parser from heat.engine import resource from heat.engine import scheduler from heat.engine.resources import wait_condition as wc -from heat.common import config from heat.common import context test_template_waitcondition = ''' @@ -96,7 +95,6 @@ class WaitConditionTest(HeatTestCase): def setUp(self): super(WaitConditionTest, self).setUp() - config.register_engine_opts() setup_dummy_db() self.m.StubOutWithMock(wc.WaitConditionHandle, 'get_status') @@ -389,7 +387,6 @@ class WaitConditionTest(HeatTestCase): class WaitConditionHandleTest(HeatTestCase): def setUp(self): super(WaitConditionHandleTest, self).setUp() - config.register_engine_opts() cfg.CONF.set_default('heat_waitcondition_server_url', 'http://127.0.0.1:8000/v1/waitcondition')