]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Do not initialize anything during import phase
authorClint Byrum <clint@fewbar.com>
Tue, 23 Apr 2013 22:51:57 +0000 (15:51 -0700)
committerClint Byrum <clint@fewbar.com>
Wed, 24 Apr 2013 17:03:06 +0000 (10:03 -0700)
The structure of the program is compromised by doing too much logic in
the import phase. We can read the code more cleanly if we can see where
the intended initialization code is called. This may make tests slightly
more tedious to write, but that should be handled by writing generic
fixtures which can be reused for exactly this purpose.

Change-Id: I1d221e2f90d1f6e89717a37d2128caabd077d30a

16 files changed:
heat/db/__init__.py
heat/db/api.py
heat/engine/__init__.py
heat/engine/parser.py
heat/engine/resources/__init__.py
heat/engine/service.py
heat/tests/test_engine_service.py
heat/tests/test_event.py
heat/tests/test_loadbalancer.py
heat/tests/test_parser.py
heat/tests/test_rpc_client.py
heat/tests/test_security_group.py
heat/tests/test_user.py
heat/tests/test_validate.py
heat/tests/test_waitcondition.py
heat/tests/test_watch.py

index c43bd22c83c56b2cbfe63e7164905c3973c30c81..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
@@ -1,22 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-#
-#    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.
-
-'''Database abstraction for Heat.'''
-
-from heat.common import config
-
-config.register_db_opts()
-
-from heat.db.api import *
index be9713b1f1303ed47426af235acd9b1d288d4868..3835c14631bf5744159397bda6580924bac6e1f9 100644 (file)
@@ -28,6 +28,7 @@ supported backend.
 
 from oslo.config import cfg
 
+from heat.common import config
 from heat.db import utils
 
 SQL_CONNECTION = 'sqlite://'
@@ -44,6 +45,7 @@ IMPL = utils.LazyPluggable('db_backend',
 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 7675cc57c19b5c93c15fd2b78c6d043f896e59d4..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
@@ -1,19 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
-#    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.
-
-from heat.common import config
-
-config.register_engine_opts()
-
-from heat import db  # pyflakes_bypass register DB options
index 203c5bc8649164cd822c51df9aca34fdfee73fd5..c925f0272795d3eb15d0a8090198d9cd09def42a 100644 (file)
@@ -21,6 +21,7 @@ from heat.common import exception
 from heat.engine import dependencies
 from heat.common import identifier
 from heat.engine import resource
+from heat.engine import resources
 from heat.engine import template
 from heat.engine import timestamp
 from heat.engine.parameters import Parameters
@@ -84,6 +85,8 @@ class Stack(object):
         self.timeout_mins = timeout_mins
         self.disable_rollback = disable_rollback
 
+        resources.initialise()
+
         if parameters is None:
             parameters = Parameters(self.name, self.t)
         self.parameters = parameters
index 356c2f052740fb6c59d40fffb4188c205b08988d..1e117455967d6a1b3053709f270738d4a3bbd0e6 100644 (file)
@@ -42,10 +42,19 @@ def _register_modules(modules):
     _register_resources(itertools.chain.from_iterable(resource_lists))
 
 
-def _initialise():
+_initialized = False
+
+
+def initialise():
+    global _initialized
+    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
@@ -53,6 +62,4 @@ def _initialise():
     plugin_pkg = plugin_loader.create_subpackage(cfg.CONF.plugin_dirs,
                                                  'heat.engine')
     _register_modules(plugin_loader.load_modules(plugin_pkg, True))
-
-
-_initialise()
+    _initialized = True
index efd962c1ac115c51a58d160e50c5d618fe8a5414..df34da6160823189360cb89523dac56da3b1ad5d 100644 (file)
@@ -19,6 +19,7 @@ import json
 from oslo.config import cfg
 import webob
 
+from heat.common import config
 from heat.common import context
 from heat.db import api as db_api
 from heat.engine import api
@@ -65,6 +66,7 @@ class EngineService(service.Service):
         super(EngineService, self).__init__(host, topic)
         # stg == "Stack Thread Groups"
         self.stg = {}
+        config.register_engine_opts()
 
     def _start_in_thread(self, stack_id, func, *args, **kwargs):
         if stack_id not in self.stg:
index e5ed9679e450a73a7e5be330d6b7fc3692e989e9..b61942729c49ffd501cec4642d815283d3117248 100644 (file)
@@ -25,7 +25,7 @@ from heat.common import context
 from heat.common import exception
 from heat.tests.v1_1 import fakes
 import heat.engine.api as engine_api
-import heat.db as db_api
+import heat.db.api as db_api
 from heat.common import identifier
 from heat.common import template_format
 from heat.engine import parser
index cd50cdfabe3b179cb54f74d3d9810c50f50b14f7..580af8339ac17edc2736c11fb1cfd3ee489fcae1 100644 (file)
@@ -18,7 +18,7 @@ import mox
 import unittest
 
 from heat.common import context
-import heat.db as db_api
+import heat.db.api as db_api
 from heat.engine import parser
 from heat.engine import resource
 from heat.engine import template
index 1cc916acd05e0933ce96ed2cee7462e74e561986..170210156e3a849a2b259e8c230033a86aac4fe7 100644 (file)
@@ -23,6 +23,7 @@ from nose.plugins.attrib import attr
 
 from oslo.config import cfg
 from heat.common import exception
+from heat.common import config
 from heat.common import context
 from heat.common import template_format
 from heat.engine import parser
@@ -49,6 +50,7 @@ def create_context(mocks, user='lb_test_user',
 @attr(speed='fast')
 class LoadBalancerTest(unittest.TestCase):
     def setUp(self):
+        config.register_engine_opts()
         self.m = mox.Mox()
         self.fc = fakes.FakeClient()
         self.m.StubOutWithMock(lb.LoadBalancer, 'nova')
index 8a349edd1bafbc7067550e23e809e1dc0552b172..968aaf5089ec853ca1f82e39333df0f86d333874 100644 (file)
@@ -29,7 +29,7 @@ from heat.engine import template
 from heat.tests.utils import stack_delete_after
 from heat.tests import generic_resource as generic_rsrc
 
-import heat.db as db_api
+import heat.db.api as db_api
 
 
 def join(raw):
index 11c5627f343cf311961c058d7cae51eb2ca8c7ea..d250c2f7d33f55b3c329be106e0099311b70e136 100644 (file)
@@ -24,6 +24,7 @@ from oslo.config import cfg
 import stubout
 import unittest
 
+from heat.common import config
 from heat.common import context
 from heat.common import identifier
 from heat.rpc import client as rpc_client
@@ -34,6 +35,7 @@ from heat.openstack.common import rpc
 class EngineRpcAPITestCase(unittest.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 bfa30dd4ac8aa84975d340db632c3cb42c8acbb3..ab8051bd44ef249f3db68e700519d480224e414b 100644 (file)
@@ -28,7 +28,6 @@ from heat.tests.v1_1 import fakes
 from novaclient.v1_1 import security_groups as nova_sg
 from novaclient.v1_1 import security_group_rules as nova_sgr
 
-
 NovaSG = collections.namedtuple('NovaSG',
                                 ' '.join([
                                     'name',
index 52fc616364df62c6d4349935a05d0e5f47928154..6c2495c026d646e5f251c34c001a930d128caf48 100644 (file)
@@ -20,6 +20,7 @@ import mox
 from nose.plugins.attrib import attr
 from oslo.config import cfg
 
+from heat.common import config
 from heat.common import context
 from heat.common import exception
 from heat.common import template_format
@@ -34,6 +35,7 @@ import keystoneclient.exceptions
 @attr(speed='fast')
 class UserTest(unittest.TestCase):
     def setUp(self):
+        config.register_engine_opts()
         self.m = mox.Mox()
         self.fc = fakes.FakeKeystoneClient(username='test_stack.CfnUser')
         cfg.CONF.set_default('heat_stack_user_role', 'stack_user_role')
@@ -225,6 +227,7 @@ class UserTest(unittest.TestCase):
 @attr(speed='fast')
 class AccessKeyTest(unittest.TestCase):
     def setUp(self):
+        config.register_engine_opts()
         self.m = mox.Mox()
         self.fc = fakes.FakeKeystoneClient(username='test_stack.CfnUser')
         cfg.CONF.set_default('heat_stack_user_role', 'stack_user_role')
index 689b828aa94def3d86b71656294d6f81aa8a9bf2..8c9a51b63208cc674850775c7145a4ec3327c39f 100644 (file)
@@ -23,7 +23,7 @@ from heat.common import exception
 from heat.common import template_format
 from heat.engine.resources import instance as instances
 from heat.engine import service
-import heat.db as db_api
+import heat.db.api as db_api
 from heat.engine import parser
 
 test_template_volumeattach = '''
index 2977d2179d0c5f2539c752227615d43df9c818a6..c211df0736139ea82fa2965e2c5f88aeb9b692db 100644 (file)
@@ -26,11 +26,12 @@ import unittest
 from heat.tests import fakes
 from heat.tests.utils import stack_delete_after
 
-import heat.db as db_api
+import heat.db.api as db_api
 from heat.common import template_format
 from heat.common import identifier
 from heat.engine import parser
 from heat.engine.resources import wait_condition as wc
+from heat.common import config
 from heat.common import context
 
 test_template_waitcondition = '''
@@ -79,6 +80,7 @@ test_template_wc_count = '''
 @attr(speed='slow')
 class WaitConditionTest(unittest.TestCase):
     def setUp(self):
+        config.register_engine_opts()
         self.m = mox.Mox()
         self.m.StubOutWithMock(wc.WaitConditionHandle,
                                'get_status')
@@ -381,6 +383,7 @@ class WaitConditionTest(unittest.TestCase):
 @attr(speed='fast')
 class WaitConditionHandleTest(unittest.TestCase):
     def setUp(self):
+        config.register_engine_opts()
         self.m = mox.Mox()
         cfg.CONF.set_default('heat_waitcondition_server_url',
                              'http://127.0.0.1:8000/v1/waitcondition')
index b2d0b4c9ee8ddf798db172b851703b0cb95f0ce7..7a0162d4a4c2d759485df2a535058e7066c5c49b 100644 (file)
@@ -18,7 +18,7 @@ import mox
 from nose.plugins.attrib import attr
 import unittest
 from heat.common import context
-import heat.db as db_api
+import heat.db.api as db_api
 
 from heat.openstack.common import timeutils
 from heat.engine import watchrule