Python oslo_config.cfg.ConfigFilesNotFoundError() Examples
The following are 23
code examples of oslo_config.cfg.ConfigFilesNotFoundError().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
oslo_config.cfg
, or try the search function
.
Example #1
Source File: config.py From openstack-omni with Apache License 2.0 | 6 votes |
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
Example #2
Source File: app.py From aodh with Apache License 2.0 | 6 votes |
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})
Example #3
Source File: test_manage.py From manila with Apache License 2.0 | 6 votes |
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)
Example #4
Source File: policy.py From oslo.policy with Apache License 2.0 | 6 votes |
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,))
Example #5
Source File: config.py From syntribos with Apache License 2.0 | 6 votes |
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)
Example #6
Source File: app.py From vitrage with Apache License 2.0 | 6 votes |
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})
Example #7
Source File: config.py From tacker with Apache License 2.0 | 6 votes |
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
Example #8
Source File: manage.py From karbor with Apache License 2.0 | 5 votes |
def main(): """Parse options and call the appropriate class/method.""" objects.register_all() CONF.register_cli_opt(category_opt) script_name = sys.argv[0] if len(sys.argv) < 2: print(_("\nOpenStack Karbor 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='karbor', version=version.version_string()) logging.setup(CONF, "karbor") except cfg.ConfigDirNotFoundError as details: print(_("Invalid directory: %s") % details) sys.exit(2) except cfg.ConfigFilesNotFoundError: cfgfile = CONF.config_file[-1] if CONF.config_file else None if cfgfile and not os.access(cfgfile, os.R_OK): st = os.stat(cfgfile) print(_("Could not read %s, Please try running this" "command again as root/Administrator privilege" "using sudo.") % cfgfile) try: os.execvp('sudo', ['sudo', '-u', '#%s' % st.st_uid] + sys.argv) except Exception: print(_('sudo failed, continuing as if nothing happened')) print(_('Please re-run karbor-manage as root.')) sys.exit(2) fn = CONF.category.action_fn fn_args = fetch_func_args(fn) fn(*fn_args)
Example #9
Source File: app.py From zun with Apache License 2.0 | 5 votes |
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)
Example #10
Source File: test_app.py From aodh with Apache License 2.0 | 5 votes |
def test_api_paste_file_not_exist(self): self.CONF.set_override('paste_config', 'non-existent-file', "api") with mock.patch.object(self.CONF, 'find_file') as ff: ff.return_value = None self.assertRaises(cfg.ConfigFilesNotFoundError, app.load_app, self.CONF)
Example #11
Source File: app.py From cyborg with Apache License 2.0 | 5 votes |
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)
Example #12
Source File: test_policy.py From oslo.policy with Apache License 2.0 | 5 votes |
def test_get_policy_path_raises_exc(self): enforcer = policy.Enforcer(self.conf, policy_file='raise_error.json') e = self.assertRaises(cfg.ConfigFilesNotFoundError, enforcer._get_policy_path, enforcer.policy_file) self.assertEqual(('raise_error.json', ), e.config_files)
Example #13
Source File: test_service_setup.py From st2 with Apache License 2.0 | 5 votes |
def test_service_setup_default_st2_conf_config_is_used(self): st2common_config.get_logging_config_path = mock_get_logging_config_path cfg.CONF.reset() # 1. DEFAULT_CONFIG_FILE_PATH config path should be used by default (/etc/st2/st2.conf) expected_msg = 'Failed to find some config files: %s' % (MOCK_DEFAULT_CONFIG_FILE_PATH) self.assertRaisesRegexp(ConfigFilesNotFoundError, expected_msg, service_setup.setup, service='api', config=st2common_config, config_args=['--debug'], setup_db=False, register_mq_exchanges=False, register_signal_handlers=False, register_internal_trigger_types=False, run_migrations=False) cfg.CONF.reset() # 2. --config-file should still override default config file path option config_file_path = '/etc/st2/config.override.test' expected_msg = 'Failed to find some config files: %s' % (config_file_path) self.assertRaisesRegexp(ConfigFilesNotFoundError, expected_msg, service_setup.setup, service='api', config=st2common_config, config_args=['--config-file', config_file_path], setup_db=False, register_mq_exchanges=False, register_signal_handlers=False, register_internal_trigger_types=False, run_migrations=False)
Example #14
Source File: test_config.py From tacker with Apache License 2.0 | 5 votes |
def test_load_paste_app_not_found(self): self.config(api_paste_config='no_such_file.conf') with mock.patch.object(cfg.CONF, 'find_file', return_value=None) as ff: e = self.assertRaises(cfg.ConfigFilesNotFoundError, config.load_paste_app, 'app') ff.assert_called_once_with('no_such_file.conf') self.assertEqual(['no_such_file.conf'], e.config_files)
Example #15
Source File: app.py From cloudkitty with Apache License 2.0 | 5 votes |
def load_app(): cfg_file = None cfg_path = cfg.CONF.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([cfg.CONF.api_paste_config]) LOG.info("Full WSGI config used: %s", cfg_file) appname = "cloudkitty+{}".format(cfg.CONF.auth_strategy) LOG.info("Cloudkitty API with '%s' auth type will be loaded.", cfg.CONF.auth_strategy) return deploy.loadapp("config:" + cfg_file, name=appname)
Example #16
Source File: service.py From yabmp with Apache License 2.0 | 5 votes |
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)
Example #17
Source File: manage.py From masakari with Apache License 2.0 | 5 votes |
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)
Example #18
Source File: manage.py From manila with Apache License 2.0 | 5 votes |
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)
Example #19
Source File: test_root.py From magnum with Apache License 2.0 | 5 votes |
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)
Example #20
Source File: test_root.py From magnum with Apache License 2.0 | 5 votes |
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)
Example #21
Source File: app.py From magnum with Apache License 2.0 | 5 votes |
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)
Example #22
Source File: service_policies.py From searchlight with Apache License 2.0 | 5 votes |
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
Example #23
Source File: __init__.py From yabgp with Apache License 2.0 | 5 votes |
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)