本文整理汇总了Python中oslo_config.cfg.ConfigFilesNotFoundError方法的典型用法代码示例。如果您正苦于以下问题:Python cfg.ConfigFilesNotFoundError方法的具体用法?Python cfg.ConfigFilesNotFoundError怎么用?Python cfg.ConfigFilesNotFoundError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oslo_config.cfg
的用法示例。
在下文中一共展示了cfg.ConfigFilesNotFoundError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_paste_app
# 需要导入模块: from oslo_config import cfg [as 别名]
# 或者: from oslo_config.cfg import ConfigFilesNotFoundError [as 别名]
def load_paste_app(app_name):
"""Builds and returns a WSGI app from a paste config file.
:param app_name: Name of the application to load
:raises ConfigFilesNotFoundError when config file cannot be located
:raises RuntimeError when application cannot be loaded from config file
"""
config_path = cfg.CONF.find_file(cfg.CONF.api_paste_config)
if not config_path:
raise cfg.ConfigFilesNotFoundError(
config_files=[cfg.CONF.api_paste_config])
config_path = os.path.abspath(config_path)
LOG.info(_LI("Config paste file: %s"), config_path)
try:
app = deploy.loadapp("config:%s" % config_path, name=app_name)
except (LookupError, ImportError):
msg = (_("Unable to load %(app_name)s from "
"configuration file %(config_path)s.") %
{'app_name': app_name,
'config_path': config_path})
LOG.exception(msg)
raise RuntimeError(msg)
return app
示例2: test_main_sudo_failed
# 需要导入模块: from oslo_config import cfg [as 别名]
# 或者: from oslo_config.cfg import ConfigFilesNotFoundError [as 别名]
def test_main_sudo_failed(self, register_cli_opt, log_setup,
register_log_opts, config_opts_call):
script_name = 'manila-manage'
sys.argv = [script_name, 'fake_category', 'fake_action']
config_opts_call.side_effect = cfg.ConfigFilesNotFoundError(
mock.sentinel._namespace)
exit = self.assertRaises(SystemExit, manila_manage.main)
self.assertTrue(register_cli_opt.called)
register_log_opts.assert_called_once_with(CONF)
config_opts_call.assert_called_once_with(
sys.argv[1:], project='manila',
version=version.version_string())
self.assertFalse(log_setup.called)
self.assertEqual(2, exit.code)
示例3: handle_config_exception
# 需要导入模块: from oslo_config import cfg [as 别名]
# 或者: from oslo_config.cfg import ConfigFilesNotFoundError [as 别名]
def handle_config_exception(exc):
msg = ""
if not any(LOG.handlers):
logging.basicConfig(level=logging.DEBUG)
if isinstance(exc, cfg.RequiredOptError):
msg = "Missing option '{opt}'".format(opt=exc.opt_name)
if exc.group:
msg += " in group '{}'".format(exc.group)
CONF.print_help()
elif isinstance(exc, cfg.ConfigFilesNotFoundError):
if CONF._args[0] == "init":
return
msg = (_("Configuration file specified ('%s') wasn't "
"found or was unreadable.") % ",".join(
CONF.config_file))
if msg:
LOG.warning(msg)
print(syntribos.SEP)
else:
LOG.exception(exc)
示例4: load_app
# 需要导入模块: from oslo_config import cfg [as 别名]
# 或者: from oslo_config.cfg import ConfigFilesNotFoundError [as 别名]
def load_app():
global APPCONFIGS
# Build the WSGI app
cfg_path = CONF.api.paste_config
if not os.path.isabs(cfg_path):
cfg_path = CONF.find_file(cfg_path)
if cfg_path is None or not os.path.exists(cfg_path):
raise cfg.ConfigFilesNotFoundError([CONF.api.paste_config])
config = dict(conf=CONF)
configkey = uuidutils.generate_uuid()
APPCONFIGS[configkey] = config
LOG.info('Full WSGI config used: %s', cfg_path)
appname = "vitrage+" + CONF.api.auth_mode
return deploy.loadapp("config:" + cfg_path, name=appname,
global_conf={'configkey': configkey})
示例5: load_paste_app
# 需要导入模块: from oslo_config import cfg [as 别名]
# 或者: from oslo_config.cfg import ConfigFilesNotFoundError [as 别名]
def load_paste_app(app_name):
"""Builds and returns a WSGI app from a paste config file.
:param app_name: Name of the application to load
:raises ConfigFilesNotFoundError: when config file cannot be located
:raises RuntimeError: when application cannot be loaded from config file
"""
config_path = cfg.CONF.find_file(cfg.CONF.api_paste_config)
if not config_path:
raise cfg.ConfigFilesNotFoundError(
config_files=[cfg.CONF.api_paste_config])
config_path = os.path.abspath(config_path)
LOG.info("Config paste file: %s", config_path)
try:
app = deploy.loadapp("config:%s" % config_path, name=app_name)
except (LookupError, ImportError):
msg = (_("Unable to load %(app_name)s from "
"configuration file %(config_path)s.") %
{'app_name': app_name,
'config_path': config_path})
LOG.exception(msg)
raise RuntimeError(msg)
return app
示例6: _get_policy_path
# 需要导入模块: from oslo_config import cfg [as 别名]
# 或者: from oslo_config.cfg import ConfigFilesNotFoundError [as 别名]
def _get_policy_path(self, path):
"""Locate the policy YAML/JSON data file/path.
:param path: It's value can be a full path or related path. When
full path specified, this function just returns the full
path. When related path specified, this function will
search configuration directories to find one that exists.
:returns: The policy path
:raises: ConfigFilesNotFoundError if the file/path couldn't
be located.
"""
policy_path = self.conf.find_file(path)
if policy_path:
return policy_path
raise cfg.ConfigFilesNotFoundError((path,))
示例7: load_app
# 需要导入模块: from oslo_config import cfg [as 别名]
# 或者: from oslo_config.cfg import ConfigFilesNotFoundError [as 别名]
def load_app(conf):
global APPCONFIGS
# Build the WSGI app
cfg_path = conf.api.paste_config
if not os.path.isabs(cfg_path):
cfg_path = conf.find_file(cfg_path)
if cfg_path is None or not os.path.exists(cfg_path):
raise cfg.ConfigFilesNotFoundError([conf.api.paste_config])
config = dict(conf=conf)
configkey = str(uuid.uuid4())
APPCONFIGS[configkey] = config
LOG.info("WSGI config used: %s", cfg_path)
return deploy.loadapp("config:" + cfg_path,
name="aodh+" + (
conf.api.auth_mode
if conf.api.auth_mode else "noauth"
),
global_conf={'configkey': configkey})
示例8: load_app
# 需要导入模块: from oslo_config import cfg [as 别名]
# 或者: from oslo_config.cfg import ConfigFilesNotFoundError [as 别名]
def load_app():
cfg_file = None
cfg_path = CONF.api.api_paste_config
if not os.path.isabs(cfg_path):
cfg_file = CONF.find_file(cfg_path)
elif os.path.exists(cfg_path):
cfg_file = cfg_path
if not cfg_file:
raise cfg.ConfigFilesNotFoundError([CONF.api.api_paste_config])
LOG.info("Full WSGI config used: %s", cfg_file)
return deploy.loadapp("config:" + cfg_file)
示例9: prepare_service
# 需要导入模块: from oslo_config import cfg [as 别名]
# 或者: from oslo_config.cfg import ConfigFilesNotFoundError [as 别名]
def prepare_service(args=None, handler=None, api_hander=None, reactor_thread_size=100):
"""prepare all services
"""
try:
CONF(args=args, project='yabgp', version=version,
default_config_files=['/etc/yabgp/yabgp.ini'])
except cfg.ConfigFilesNotFoundError:
CONF(args=args, project='yabgp', version=version)
log.init_log()
LOG.info('Log (Re)opened.')
LOG.info("Configuration:")
cfg.CONF.log_opt_values(LOG, logging.INFO)
try:
if not handler:
LOG.info('No handler provided, init default handler')
handler = DefaultHandler()
get_bgp_config()
check_msg_config()
except Exception as e:
LOG.error(e)
LOG.debug(traceback.format_exc())
sys.exit()
# prepare api handler
if api_hander:
register_api_handler(api_hander)
LOG.info('Starting server in PID %s', os.getpid())
prepare_twisted_service(handler, reactor_thread_size)
示例10: _get_enforcers
# 需要导入模块: from oslo_config import cfg [as 别名]
# 或者: from oslo_config.cfg import ConfigFilesNotFoundError [as 别名]
def _get_enforcers():
global _ENFORCERS
if not _ENFORCERS:
_ENFORCERS = {}
pol_files = cfg.CONF.service_policies.service_policy_files
for service, pol_file in pol_files.items():
base_path = str(cfg.CONF.service_policies.service_policy_path)
service_policy_path = os.path.join(base_path,
pol_file)
enforcer = policy.Enforcer(cfg.CONF, service_policy_path)
missing_config_file = False
# oslo.policy's approach to locating these files seems to be
# changing; current master doesn't raise an exception
try:
enforcer.load_rules()
enforcer.register_defaults(policies.list_rules())
if not enforcer.policy_path:
missing_config_file = True
except cfg.ConfigFilesNotFoundError:
missing_config_file = True
if missing_config_file:
LOG.error("Policy file for service %(service)s not found"
" in %(policy_file)s (base path %(base)s)" %
{"service": service, "policy_file": pol_file,
"base": service_policy_path})
raise MissingPolicyFile(
"Could not find policy file %(pol_file)s for service "
"type %(service)s" % {'pol_file': pol_file,
'service': service})
LOG.debug("Adding policy enforcer for %s" % service)
_ENFORCERS[service] = enforcer
return _ENFORCERS
示例11: test_api_paste_file_not_exist
# 需要导入模块: from oslo_config import cfg [as 别名]
# 或者: from oslo_config.cfg import ConfigFilesNotFoundError [as 别名]
def test_api_paste_file_not_exist(self):
cfg.CONF.set_override('api_paste_config', 'non-existent-file',
group='api')
with mock.patch.object(cfg.CONF, 'find_file') as ff:
ff.return_value = None
self.assertRaises(cfg.ConfigFilesNotFoundError, app.load_app)
示例12: test_api_paste_file_not_exist_not_abs
# 需要导入模块: from oslo_config import cfg [as 别名]
# 或者: from oslo_config.cfg import ConfigFilesNotFoundError [as 别名]
def test_api_paste_file_not_exist_not_abs(self, mock_deploy):
path = self.get_path(cfg.CONF['api']['api_paste_config'] + 'test')
cfg.CONF.set_override('api_paste_config', path, group='api')
self.assertRaises(cfg.ConfigFilesNotFoundError, app.load_app)
示例13: main
# 需要导入模块: from oslo_config import cfg [as 别名]
# 或者: from oslo_config.cfg import ConfigFilesNotFoundError [as 别名]
def main():
"""Parse options and call the appropriate class/method."""
CONF.register_cli_opt(category_opt)
script_name = sys.argv[0]
if len(sys.argv) < 2:
print(_("\nOpenStack manila version: %(version)s\n") %
{'version': version.version_string()})
print(script_name + " category action [<args>]")
print(_("Available categories:"))
for category in CATEGORIES:
print("\t%s" % category)
sys.exit(2)
try:
log.register_options(CONF)
CONF(sys.argv[1:], project='manila',
version=version.version_string())
log.setup(CONF, "manila")
except cfg.ConfigFilesNotFoundError as e:
cfg_files = e.config_files
print(_("Failed to read configuration file(s): %s") % cfg_files)
sys.exit(2)
fn = CONF.category.action_fn
fn_args = fetch_func_args(fn)
fn(*fn_args)
示例14: main
# 需要导入模块: from oslo_config import cfg [as 别名]
# 或者: from oslo_config.cfg import ConfigFilesNotFoundError [as 别名]
def main():
"""Parse options and call the appropriate class/method."""
CONF.register_cli_opt(command_opt)
script_name = sys.argv[0]
if len(sys.argv) < 2:
print(_("\nOpenStack masakari version: %(version)s\n") %
{'version': version.version_string()})
print(script_name + " category action [<args>]")
print(_("Available categories:"))
for category in CATEGORIES:
print(_("\t%s") % category)
sys.exit(2)
try:
CONF(sys.argv[1:], project='masakari',
version=version.version_string())
logging.setup(CONF, "masakari")
python_logging.captureWarnings(True)
except cfg.ConfigDirNotFoundError as details:
print(_("Invalid directory: %s") % details)
sys.exit(2)
except cfg.ConfigFilesNotFoundError as e:
cfg_files = ', '.join(e.config_files)
print(_("Failed to read configuration file(s): %s") % cfg_files)
sys.exit(2)
fn = CONF.category.action_fn
fn_args = fetch_func_args(fn)
fn(*fn_args)
示例15: prepare_service
# 需要导入模块: from oslo_config import cfg [as 别名]
# 或者: from oslo_config.cfg import ConfigFilesNotFoundError [as 别名]
def prepare_service(args=None, handler=None):
"""prepare the twisted service
:param hander: handler object
"""
if not handler:
handler = DefaultHandler()
try:
CONF(args=args, project='yabmp', version=version,
default_config_files=['/etc/yabmp/yabmp.ini'])
except cfg.ConfigFilesNotFoundError:
CONF(args=args, project='yabmp', version=version)
log.init_log()
LOG.info('Log (Re)opened.')
LOG.info("Configuration:")
cfg.CONF.log_opt_values(LOG, logging.INFO)
handler.init()
# start bmp server
try:
reactor.listenTCP(
CONF.bind_port,
BMPFactory(handler=handler),
interface=CONF.bind_host)
LOG.info(
"Starting bmpd server listen to port = %s and ip = %s",
CONF.bind_port, CONF.bind_host)
reactor.run()
except Exception as e:
LOG.error(e)