]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Update oslo.notifier and always register options
authorJulien Danjou <julien@danjou.info>
Wed, 10 Jul 2013 15:27:52 +0000 (17:27 +0200)
committerJulien Danjou <julien@danjou.info>
Thu, 11 Jul 2013 13:45:52 +0000 (15:45 +0200)
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 <julien@danjou.info>
15 files changed:
bin/heat-engine
heat/api/__init__.py
heat/common/config.py
heat/common/wsgi.py
heat/db/api.py
heat/engine/resources/__init__.py
heat/openstack/common/notifier/api.py
heat/openstack/common/notifier/rpc_notifier.py
heat/openstack/common/notifier/rpc_notifier2.py
heat/tests/test_engine_service.py
heat/tests/test_heatclient.py
heat/tests/test_loadbalancer.py
heat/tests/test_rpc_client.py
heat/tests/test_user.py
heat/tests/test_waitcondition.py

index 3e0167a4425e1e7055d0ccf79101164d487a2133..14e6f185148fa470e58ff28976d5149adf2a8846 100755 (executable)
@@ -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()
index de94140f3086dbea6b95d6f84ad69766177c4304..e8e403594152912bed8c5a341795ba08bf925d34 100644 (file)
@@ -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()
index 02ae986c462a5a964c6b6aec5c64a323513d85c8..d32025a656fedeb2ac99aa302065d8f47ba0bb41 100644 (file)
@@ -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:
index a355f355667814e7e98fc0040cdd3a04af1d3437..7282ca6527a3c228559d9cf1e8753265ca1a83ba 100644 (file)
@@ -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')
 
index 23cc8b9bdfdc71a5e743d5afabad5c946bb98fff..941bbfe26faa3443c68f1fd8413a83c1396fa700 100644 (file)
@@ -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
 
index 28bdc4004fb1061ec0fb1df97af50177bd4fea06..924114bea43f9819e1c7891583e0bff95537b817 100644 (file)
@@ -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))
index d5d2b36a271578a7183674dd1adf4e740e520a32..428e5068c1d333d7075f700ecefea0990d41a395 100644 (file)
 #    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)
 
 
index 1b3c2597caca70de2b2856e34589c03fc167f9d2..ffe8fdcc484315d2db9b07fd08f8908688b9afa3 100644 (file)
@@ -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
 
index 3688484c9f9dd6067a6abfb5a216c5488e6b3182..53cf6c9e6a33806a177f6ac04e2068df8f17a747 100644 (file)
@@ -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
 
index d2b63b7a2f096b7a4b2de02ff6cf465493da4229..9e5b3cb9c406ba28579cdd3c4246d6c067fa965b 100644 (file)
@@ -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'
 
index 362a926db5b0c19d7beca038bf198fa61a52e5d8..d04aa9dcddaab51d8d8edb925720ebb37d14fc2d 100644 (file)
@@ -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(
index aeab875a16d70651d206ad72d09235367648ceec..2136c82a66e5d8c5fe5173af6b9bf5d17612eaeb 100644 (file)
@@ -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')
index c09e7669c042841e41f76e911316b19c3a270e16..41f47e4d2a4b7aaab5802d1725b49f471e4d07f8 100644 (file)
@@ -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')
index 280629ec013005be9732af2704038a883276e032..052eb85b43e1eb9334ec59e2fb24e8113ed374eb 100644 (file)
@@ -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')
index e508ef5c910704c6e4f35a13fe4b522640436fd8..24a09b413fd0f915583ca8584d006ff38c4b5338 100644 (file)
@@ -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')