Properly init config in unit tests
upcoming policy-related changes need a properly initialized global oslo_config's CONF instance, which inspector's unit tests currently lack. As a side effect of implementing this, the 'dbsync' module was changed to not register it's CLI options right on its import. Also, setting default log levels was moved to a function which is already registered as the one providing defaults to options in oslo_config's entrypoints. Config sample is updated accordingly. Change-Id: I20bc537605062900d00fcc0343172774c1cd1363
This commit is contained in:
parent
7625ed68c8
commit
a65a2ee5d2
@ -146,7 +146,7 @@
|
||||
|
||||
# List of package logging levels in logger=LEVEL pairs. This option is
|
||||
# ignored if log_config_append is set. (list value)
|
||||
#default_log_levels = amqp=WARN,amqplib=WARN,boto=WARN,qpid=WARN,sqlalchemy=WARN,suds=INFO,oslo.messaging=INFO,oslo_messaging=INFO,iso8601=WARN,requests.packages.urllib3.connectionpool=WARN,urllib3.connectionpool=WARN,websocket=WARN,requests.packages.urllib3.util.retry=WARN,urllib3.util.retry=WARN,keystonemiddleware=WARN,routes.middleware=WARN,stevedore=WARN,taskflow=WARN,keystoneauth=WARN,oslo.cache=INFO,dogpile.core.dogpile=INFO
|
||||
#default_log_levels = sqlalchemy=WARNING,iso8601=WARNING,requests=WARNING,urllib3.connectionpool=WARNING,keystonemiddleware=WARNING,swiftclient=WARNING,keystoneauth=WARNING,ironicclient=WARNING
|
||||
|
||||
# Enables or disables publication of error events. (boolean value)
|
||||
#publish_errors = false
|
||||
|
@ -10,25 +10,19 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
|
||||
from ironic_inspector import conf
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
CONF = cfg.CONF
|
||||
CONF = conf.cfg.CONF
|
||||
|
||||
|
||||
def prepare_service(args):
|
||||
def prepare_service(args=None):
|
||||
args = [] if args is None else args
|
||||
log.register_options(CONF)
|
||||
log.set_defaults(default_log_levels=['sqlalchemy=WARNING',
|
||||
'iso8601=WARNING',
|
||||
'requests=WARNING',
|
||||
'urllib3.connectionpool=WARNING',
|
||||
'keystonemiddleware=WARNING',
|
||||
'swiftclient=WARNING',
|
||||
'keystoneauth=WARNING',
|
||||
'ironicclient=WARNING'])
|
||||
CONF(args, project='ironic-inspector')
|
||||
conf.set_config_defaults()
|
||||
conf.parse_args(args)
|
||||
log.setup(CONF, 'ironic_inspector')
|
||||
|
||||
LOG.debug("Configuration:")
|
||||
|
@ -12,9 +12,11 @@
|
||||
# limitations under the License.
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
from oslo_middleware import cors
|
||||
|
||||
from ironic_inspector.common.i18n import _
|
||||
from ironic_inspector import version
|
||||
|
||||
|
||||
MIN_VERSION_HEADER = 'X-OpenStack-Ironic-Inspector-API-Minimum-Version'
|
||||
@ -214,6 +216,14 @@ def list_opts():
|
||||
|
||||
def set_config_defaults():
|
||||
"""This method updates all configuration default values."""
|
||||
log.set_defaults(default_log_levels=['sqlalchemy=WARNING',
|
||||
'iso8601=WARNING',
|
||||
'requests=WARNING',
|
||||
'urllib3.connectionpool=WARNING',
|
||||
'keystonemiddleware=WARNING',
|
||||
'swiftclient=WARNING',
|
||||
'keystoneauth=WARNING',
|
||||
'ironicclient=WARNING'])
|
||||
set_cors_middleware_defaults()
|
||||
|
||||
|
||||
@ -229,3 +239,10 @@ def set_cors_middleware_defaults():
|
||||
allow_methods=['GET', 'POST', 'PUT', 'HEAD',
|
||||
'PATCH', 'DELETE', 'OPTIONS']
|
||||
)
|
||||
|
||||
|
||||
def parse_args(args, default_config_files=None):
|
||||
cfg.CONF(args,
|
||||
project='ironic-inspector',
|
||||
version=version.version_info.release_string(),
|
||||
default_config_files=default_config_files)
|
||||
|
@ -59,8 +59,6 @@ command_opt = cfg.SubCommandOpt('command',
|
||||
help='Available commands',
|
||||
handler=add_command_parsers)
|
||||
|
||||
CONF.register_cli_opt(command_opt)
|
||||
|
||||
|
||||
def _get_alembic_config():
|
||||
return alembic_config.Config(os.path.join(os.path.dirname(__file__),
|
||||
@ -86,6 +84,7 @@ def do_alembic_command(config, cmd, *args, **kwargs):
|
||||
|
||||
def main(args=sys.argv[1:]):
|
||||
log.register_options(CONF)
|
||||
CONF.register_cli_opt(command_opt)
|
||||
CONF(args, project='ironic-inspector')
|
||||
config = _get_alembic_config()
|
||||
config.set_main_option('script_location', "ironic_inspector:migrations")
|
||||
|
@ -18,7 +18,6 @@ import fixtures
|
||||
import futurist
|
||||
import mock
|
||||
from oslo_concurrency import lockutils
|
||||
from oslo_config import cfg
|
||||
from oslo_config import fixture as config_fixture
|
||||
from oslo_log import log
|
||||
from oslo_utils import units
|
||||
@ -26,15 +25,14 @@ from oslo_utils import uuidutils
|
||||
from oslotest import base as test_base
|
||||
|
||||
from ironic_inspector.common import i18n
|
||||
# Import configuration options
|
||||
from ironic_inspector import conf # noqa
|
||||
from ironic_inspector import conf
|
||||
from ironic_inspector import db
|
||||
from ironic_inspector import introspection_state as istate
|
||||
from ironic_inspector import node_cache
|
||||
from ironic_inspector.plugins import base as plugins_base
|
||||
from ironic_inspector import utils
|
||||
|
||||
CONF = cfg.CONF
|
||||
CONF = conf.cfg.CONF
|
||||
|
||||
|
||||
class BaseTest(test_base.BaseTestCase):
|
||||
@ -65,6 +63,7 @@ class BaseTest(test_base.BaseTestCase):
|
||||
self.cfg.set_default('connection', "sqlite:///", group='database')
|
||||
self.cfg.set_default('slave_connection', None, group='database')
|
||||
self.cfg.set_default('max_retries', 10, group='database')
|
||||
conf.parse_args([], default_config_files=[])
|
||||
|
||||
def assertPatchEqual(self, expected, actual):
|
||||
expected = sorted(expected, key=lambda p: p['path'])
|
||||
|
Loading…
Reference in New Issue
Block a user