Do not initialize anything during import phase
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
This commit is contained in:
parent
f3be3d90b3
commit
a60f6d4569
@ -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 *
|
|
@ -28,6 +28,7 @@ supported backend.
|
|||||||
|
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
|
|
||||||
|
from heat.common import config
|
||||||
from heat.db import utils
|
from heat.db import utils
|
||||||
|
|
||||||
SQL_CONNECTION = 'sqlite://'
|
SQL_CONNECTION = 'sqlite://'
|
||||||
@ -44,6 +45,7 @@ IMPL = utils.LazyPluggable('db_backend',
|
|||||||
def configure():
|
def configure():
|
||||||
global SQL_CONNECTION
|
global SQL_CONNECTION
|
||||||
global SQL_IDLE_TIMEOUT
|
global SQL_IDLE_TIMEOUT
|
||||||
|
config.register_db_opts()
|
||||||
SQL_CONNECTION = cfg.CONF.sql_connection
|
SQL_CONNECTION = cfg.CONF.sql_connection
|
||||||
SQL_IDLE_TIMEOUT = cfg.CONF.sql_idle_timeout
|
SQL_IDLE_TIMEOUT = cfg.CONF.sql_idle_timeout
|
||||||
|
|
||||||
|
@ -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
|
|
@ -21,6 +21,7 @@ from heat.common import exception
|
|||||||
from heat.engine import dependencies
|
from heat.engine import dependencies
|
||||||
from heat.common import identifier
|
from heat.common import identifier
|
||||||
from heat.engine import resource
|
from heat.engine import resource
|
||||||
|
from heat.engine import resources
|
||||||
from heat.engine import template
|
from heat.engine import template
|
||||||
from heat.engine import timestamp
|
from heat.engine import timestamp
|
||||||
from heat.engine.parameters import Parameters
|
from heat.engine.parameters import Parameters
|
||||||
@ -84,6 +85,8 @@ class Stack(object):
|
|||||||
self.timeout_mins = timeout_mins
|
self.timeout_mins = timeout_mins
|
||||||
self.disable_rollback = disable_rollback
|
self.disable_rollback = disable_rollback
|
||||||
|
|
||||||
|
resources.initialise()
|
||||||
|
|
||||||
if parameters is None:
|
if parameters is None:
|
||||||
parameters = Parameters(self.name, self.t)
|
parameters = Parameters(self.name, self.t)
|
||||||
self.parameters = parameters
|
self.parameters = parameters
|
||||||
|
@ -42,10 +42,19 @@ def _register_modules(modules):
|
|||||||
_register_resources(itertools.chain.from_iterable(resource_lists))
|
_register_resources(itertools.chain.from_iterable(resource_lists))
|
||||||
|
|
||||||
|
|
||||||
def _initialise():
|
_initialized = False
|
||||||
|
|
||||||
|
|
||||||
|
def initialise():
|
||||||
|
global _initialized
|
||||||
|
if _initialized:
|
||||||
|
return
|
||||||
import sys
|
import sys
|
||||||
|
from heat.common import config
|
||||||
from heat.common import plugin_loader
|
from heat.common import plugin_loader
|
||||||
|
|
||||||
|
config.register_engine_opts()
|
||||||
|
|
||||||
_register_modules(plugin_loader.load_modules(sys.modules[__name__]))
|
_register_modules(plugin_loader.load_modules(sys.modules[__name__]))
|
||||||
|
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
@ -53,6 +62,4 @@ def _initialise():
|
|||||||
plugin_pkg = plugin_loader.create_subpackage(cfg.CONF.plugin_dirs,
|
plugin_pkg = plugin_loader.create_subpackage(cfg.CONF.plugin_dirs,
|
||||||
'heat.engine')
|
'heat.engine')
|
||||||
_register_modules(plugin_loader.load_modules(plugin_pkg, True))
|
_register_modules(plugin_loader.load_modules(plugin_pkg, True))
|
||||||
|
_initialized = True
|
||||||
|
|
||||||
_initialise()
|
|
||||||
|
@ -19,6 +19,7 @@ import json
|
|||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
import webob
|
import webob
|
||||||
|
|
||||||
|
from heat.common import config
|
||||||
from heat.common import context
|
from heat.common import context
|
||||||
from heat.db import api as db_api
|
from heat.db import api as db_api
|
||||||
from heat.engine import api
|
from heat.engine import api
|
||||||
@ -65,6 +66,7 @@ class EngineService(service.Service):
|
|||||||
super(EngineService, self).__init__(host, topic)
|
super(EngineService, self).__init__(host, topic)
|
||||||
# stg == "Stack Thread Groups"
|
# stg == "Stack Thread Groups"
|
||||||
self.stg = {}
|
self.stg = {}
|
||||||
|
config.register_engine_opts()
|
||||||
|
|
||||||
def _start_in_thread(self, stack_id, func, *args, **kwargs):
|
def _start_in_thread(self, stack_id, func, *args, **kwargs):
|
||||||
if stack_id not in self.stg:
|
if stack_id not in self.stg:
|
||||||
|
@ -25,7 +25,7 @@ from heat.common import context
|
|||||||
from heat.common import exception
|
from heat.common import exception
|
||||||
from heat.tests.v1_1 import fakes
|
from heat.tests.v1_1 import fakes
|
||||||
import heat.engine.api as engine_api
|
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 identifier
|
||||||
from heat.common import template_format
|
from heat.common import template_format
|
||||||
from heat.engine import parser
|
from heat.engine import parser
|
||||||
|
@ -18,7 +18,7 @@ import mox
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from heat.common import context
|
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 parser
|
||||||
from heat.engine import resource
|
from heat.engine import resource
|
||||||
from heat.engine import template
|
from heat.engine import template
|
||||||
|
@ -23,6 +23,7 @@ from nose.plugins.attrib import attr
|
|||||||
|
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
from heat.common import exception
|
from heat.common import exception
|
||||||
|
from heat.common import config
|
||||||
from heat.common import context
|
from heat.common import context
|
||||||
from heat.common import template_format
|
from heat.common import template_format
|
||||||
from heat.engine import parser
|
from heat.engine import parser
|
||||||
@ -49,6 +50,7 @@ def create_context(mocks, user='lb_test_user',
|
|||||||
@attr(speed='fast')
|
@attr(speed='fast')
|
||||||
class LoadBalancerTest(unittest.TestCase):
|
class LoadBalancerTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
config.register_engine_opts()
|
||||||
self.m = mox.Mox()
|
self.m = mox.Mox()
|
||||||
self.fc = fakes.FakeClient()
|
self.fc = fakes.FakeClient()
|
||||||
self.m.StubOutWithMock(lb.LoadBalancer, 'nova')
|
self.m.StubOutWithMock(lb.LoadBalancer, 'nova')
|
||||||
|
@ -29,7 +29,7 @@ from heat.engine import template
|
|||||||
from heat.tests.utils import stack_delete_after
|
from heat.tests.utils import stack_delete_after
|
||||||
from heat.tests import generic_resource as generic_rsrc
|
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):
|
def join(raw):
|
||||||
|
@ -24,6 +24,7 @@ from oslo.config import cfg
|
|||||||
import stubout
|
import stubout
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
from heat.common import config
|
||||||
from heat.common import context
|
from heat.common import context
|
||||||
from heat.common import identifier
|
from heat.common import identifier
|
||||||
from heat.rpc import client as rpc_client
|
from heat.rpc import client as rpc_client
|
||||||
@ -34,6 +35,7 @@ from heat.openstack.common import rpc
|
|||||||
class EngineRpcAPITestCase(unittest.TestCase):
|
class EngineRpcAPITestCase(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
config.register_engine_opts()
|
||||||
self.context = context.get_admin_context()
|
self.context = context.get_admin_context()
|
||||||
cfg.CONF.set_default('rpc_backend',
|
cfg.CONF.set_default('rpc_backend',
|
||||||
'heat.openstack.common.rpc.impl_fake')
|
'heat.openstack.common.rpc.impl_fake')
|
||||||
|
@ -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_groups as nova_sg
|
||||||
from novaclient.v1_1 import security_group_rules as nova_sgr
|
from novaclient.v1_1 import security_group_rules as nova_sgr
|
||||||
|
|
||||||
|
|
||||||
NovaSG = collections.namedtuple('NovaSG',
|
NovaSG = collections.namedtuple('NovaSG',
|
||||||
' '.join([
|
' '.join([
|
||||||
'name',
|
'name',
|
||||||
|
@ -20,6 +20,7 @@ import mox
|
|||||||
from nose.plugins.attrib import attr
|
from nose.plugins.attrib import attr
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
|
|
||||||
|
from heat.common import config
|
||||||
from heat.common import context
|
from heat.common import context
|
||||||
from heat.common import exception
|
from heat.common import exception
|
||||||
from heat.common import template_format
|
from heat.common import template_format
|
||||||
@ -34,6 +35,7 @@ import keystoneclient.exceptions
|
|||||||
@attr(speed='fast')
|
@attr(speed='fast')
|
||||||
class UserTest(unittest.TestCase):
|
class UserTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
config.register_engine_opts()
|
||||||
self.m = mox.Mox()
|
self.m = mox.Mox()
|
||||||
self.fc = fakes.FakeKeystoneClient(username='test_stack.CfnUser')
|
self.fc = fakes.FakeKeystoneClient(username='test_stack.CfnUser')
|
||||||
cfg.CONF.set_default('heat_stack_user_role', 'stack_user_role')
|
cfg.CONF.set_default('heat_stack_user_role', 'stack_user_role')
|
||||||
@ -225,6 +227,7 @@ class UserTest(unittest.TestCase):
|
|||||||
@attr(speed='fast')
|
@attr(speed='fast')
|
||||||
class AccessKeyTest(unittest.TestCase):
|
class AccessKeyTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
config.register_engine_opts()
|
||||||
self.m = mox.Mox()
|
self.m = mox.Mox()
|
||||||
self.fc = fakes.FakeKeystoneClient(username='test_stack.CfnUser')
|
self.fc = fakes.FakeKeystoneClient(username='test_stack.CfnUser')
|
||||||
cfg.CONF.set_default('heat_stack_user_role', 'stack_user_role')
|
cfg.CONF.set_default('heat_stack_user_role', 'stack_user_role')
|
||||||
|
@ -23,7 +23,7 @@ from heat.common import exception
|
|||||||
from heat.common import template_format
|
from heat.common import template_format
|
||||||
from heat.engine.resources import instance as instances
|
from heat.engine.resources import instance as instances
|
||||||
from heat.engine import service
|
from heat.engine import service
|
||||||
import heat.db as db_api
|
import heat.db.api as db_api
|
||||||
from heat.engine import parser
|
from heat.engine import parser
|
||||||
|
|
||||||
test_template_volumeattach = '''
|
test_template_volumeattach = '''
|
||||||
|
@ -26,11 +26,12 @@ import unittest
|
|||||||
from heat.tests import fakes
|
from heat.tests import fakes
|
||||||
from heat.tests.utils import stack_delete_after
|
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 template_format
|
||||||
from heat.common import identifier
|
from heat.common import identifier
|
||||||
from heat.engine import parser
|
from heat.engine import parser
|
||||||
from heat.engine.resources import wait_condition as wc
|
from heat.engine.resources import wait_condition as wc
|
||||||
|
from heat.common import config
|
||||||
from heat.common import context
|
from heat.common import context
|
||||||
|
|
||||||
test_template_waitcondition = '''
|
test_template_waitcondition = '''
|
||||||
@ -79,6 +80,7 @@ test_template_wc_count = '''
|
|||||||
@attr(speed='slow')
|
@attr(speed='slow')
|
||||||
class WaitConditionTest(unittest.TestCase):
|
class WaitConditionTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
config.register_engine_opts()
|
||||||
self.m = mox.Mox()
|
self.m = mox.Mox()
|
||||||
self.m.StubOutWithMock(wc.WaitConditionHandle,
|
self.m.StubOutWithMock(wc.WaitConditionHandle,
|
||||||
'get_status')
|
'get_status')
|
||||||
@ -381,6 +383,7 @@ class WaitConditionTest(unittest.TestCase):
|
|||||||
@attr(speed='fast')
|
@attr(speed='fast')
|
||||||
class WaitConditionHandleTest(unittest.TestCase):
|
class WaitConditionHandleTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
config.register_engine_opts()
|
||||||
self.m = mox.Mox()
|
self.m = mox.Mox()
|
||||||
cfg.CONF.set_default('heat_waitcondition_server_url',
|
cfg.CONF.set_default('heat_waitcondition_server_url',
|
||||||
'http://127.0.0.1:8000/v1/waitcondition')
|
'http://127.0.0.1:8000/v1/waitcondition')
|
||||||
|
@ -18,7 +18,7 @@ import mox
|
|||||||
from nose.plugins.attrib import attr
|
from nose.plugins.attrib import attr
|
||||||
import unittest
|
import unittest
|
||||||
from heat.common import context
|
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.openstack.common import timeutils
|
||||||
from heat.engine import watchrule
|
from heat.engine import watchrule
|
||||||
|
Loading…
Reference in New Issue
Block a user