def test_mapped_tacker_error_localized(self, mock_translation): oslo_i18n.install('blaa') msg_translation = 'Translated error' mock_translation.return_value = msg_translation msg = _('Unmapped error') class TestException(n_exc.TackerException): message = msg controller = mock.MagicMock() controller.test.side_effect = TestException() faults = {TestException: exc.HTTPGatewayTimeout} resource = webtest.TestApp( wsgi_resource.Resource(controller, faults=faults)) environ = { 'wsgiorg.routing_args': (None, { 'action': 'test', 'format': 'json' }) } res = resource.get('', extra_environ=environ, expect_errors=True) self.assertEqual(exc.HTTPGatewayTimeout.code, res.status_int) self.assertIn(msg_translation, str(wsgi.JSONDeserializer().deserialize(res.body)))
def initialize_wsgi_app(argv=sys.argv): i18n.install('ironic') service.prepare_service(argv) LOG.debug("Configuration:") CONF.log_opt_values(LOG, log.DEBUG) return app.VersionSelectorApplication()
def init_application(): CONF = cfg.CONF i18n.install('cyborg') service.prepare_service(sys.argv) LOG = log.getLogger(__name__) LOG.debug("Configuration:") CONF.log_opt_values(LOG, log.DEBUG) return app.app_factory(CONF)
def initialize_wsgi_app(show_deprecated=False): i18n.install('ironic') service.prepare_service(sys.argv) LOG.debug("Configuration:") CONF.log_opt_values(LOG, log.DEBUG) if show_deprecated: LOG.warning("Using ironic/api/app.wsgi is deprecated and it will " "be removed in Rocky release. Please use automatically " "generated ironic-api-wsgi instead.") return app.VersionSelectorApplication()
def init_application(): CONF = cfg.CONF # NOTE(hberaud): Call reset to ensure the ConfigOpts object doesn't # already contain registered options if the app is reloaded. CONF.reset() i18n.install('cyborg') service.prepare_service(sys.argv) LOG = log.getLogger(__name__) LOG.debug("Configuration:") CONF.log_opt_values(LOG, log.DEBUG) return app.load_app()
def test_unmapped_tacker_error_localized(self, mock_translation): oslo_i18n.install('blaa') msg_translation = 'Translated error' mock_translation.return_value = msg_translation msg = _('Unmapped error') class TestException(n_exc.TackerException): message = msg controller = mock.MagicMock() controller.test.side_effect = TestException() resource = webtest.TestApp(wsgi_resource.Resource(controller)) environ = {'wsgiorg.routing_args': (None, {'action': 'test', 'format': 'json'})} res = resource.get('', extra_environ=environ, expect_errors=True) self.assertEqual(exc.HTTPInternalServerError.code, res.status_int) self.assertIn(msg_translation, str(wsgi.JSONDeserializer().deserialize(res.body)))
def test_install(self): with mock.patch('six.moves.builtins'): oslo_i18n.install('domain')
# 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. import os os.environ['EVENTLET_NO_GREENDNS'] = 'yes' import eventlet import oslo_i18n as i18n eventlet.monkey_patch(os=False) i18n.install('kongming')
# Copyright (c) 2013 Hewlett-Packard Development Company, L.P. # All Rights Reserved. # # 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. # NOTE(yuriyz): Do eventlet monkey patching here, instead of in # ironic/__init__.py. This allows the API service to run without monkey # patching under Apache (which uses its own concurrency model). Mixing # concurrency models can cause undefined behavior and potentially API timeouts. import os os.environ['EVENTLET_NO_GREENDNS'] = 'yes' # noqa E402 import eventlet eventlet.monkey_patch(os=False) import oslo_i18n as i18n # noqa for I202 due to 'import eventlet' above i18n.install('ironic')
import argparse import imp import os import re import socket import sys import textwrap from oslo_config import cfg import oslo_i18n from oslo_utils import importutils import six import stevedore.named oslo_i18n.install('ironic') STROPT = "StrOpt" BOOLOPT = "BoolOpt" INTOPT = "IntOpt" FLOATOPT = "FloatOpt" LISTOPT = "ListOpt" DICTOPT = "DictOpt" MULTISTROPT = "MultiStrOpt" PORTOPT = "PortOpt" OPT_TYPES = { STROPT: 'string value', BOOLOPT: 'boolean value', INTOPT: 'integer value', FLOATOPT: 'floating point value',
# Copyright (c) 2013 Hewlett-Packard Development Company, L.P. # All Rights Reserved. # # 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. import oslo_i18n as i18n i18n.install("ironic")
# -*- coding: utf-8 -*- # 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. import oslo_i18n import pbr.version oslo_i18n.install('cisco_ironic_contrib') __version__ = pbr.version.VersionInfo( 'cisco_ironic_contrib').version_string()
# If ../tacker/__init__.py exists, add ../ to Python search path, so that # it will override what happens to be installed in /usr/(local/)lib/python... import sys from oslo_config import cfg import oslo_i18n from oslo_service import service as common_service from tacker.common import config from tacker import objects from tacker import service oslo_i18n.install("tacker") def main(): # the configuration will be read into the cfg.CONF global data structure config.init(sys.argv[1:]) objects.register_all() if not cfg.CONF.config_file: sys.exit(_("ERROR: Unable to find configuration file via the default" " search paths (~/.tacker/, ~/, /etc/tacker/, /etc/) and" " the '--config-file' option!")) try: tacker_api = service.serve_wsgi(service.TackerApiService) launcher = common_service.launch(cfg.CONF, tacker_api, workers=cfg.CONF.api_workers or None,
# All Rights Reserved. # # 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. # # Copyright (c) 2018 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # import os os.environ['EVENTLET_NO_GREENDNS'] = 'yes' # noqa E402 import eventlet eventlet.monkey_patch(os=False) import oslo_i18n as i18n # noqa I202 i18n.install('inventory')
# Copyright 2017 Huawei Technologies Co.,LTD. # All Rights Reserved. # # 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. import oslo_i18n as i18n i18n.install('cyborg')
def import_modules(repo_location, package_name, verbose=0): """Import modules. Loops through the repository, importing module by module to populate the configuration object (cfg.CONF) created from Oslo. """ # If the project uses oslo.i18n, make sure that it is initialized so that # the builtins contain the _ function. requirements = os.path.join(repo_location, 'requirements.txt') with open(requirements) as fd: with_i18n = False for line in fd: if line.startswith('oslo.i18n'): i18n.enable_lazy() i18n.install(package_name) with_i18n = True break if not with_i18n: # NOTE(gpocentek): projects didn't use oslo.i18n on havana, and # some imports fail because _ is not yet registered in the # builtins. We try to import and setup the translation tools # manually. try: modname = "%s.openstack.common.gettextutils" % package_name module = importlib.import_module(modname) module.install(package_name) except Exception: pass pkg_location = os.path.join(repo_location, package_name) for root, dirs, files in os.walk(pkg_location): skipdir = False for excludedir in ('tests', 'locale', os.path.join('db', 'migration'), 'transfer'): if ((os.path.sep + excludedir + os.path.sep) in root or ( root.endswith(os.path.sep + excludedir))): skipdir = True break if skipdir: continue for pyfile in files: if pyfile.endswith('.py'): abs_path = os.path.join(root, pyfile) modfile = abs_path.split(repo_location, 1)[1] modname = os.path.splitext(modfile)[0].split(os.path.sep) modname = [m for m in modname if m != ''] modname = '.'.join(modname) if modname.endswith('.__init__'): modname = modname[:modname.rfind(".")] if modname in IGNORE: continue try: module = importlib.import_module(modname) if verbose >= 1: print("imported %s" % modname) except ImportError as e: """ work around modules that don't like being imported in this way FIXME This could probably be better, but does not affect the configuration options found at this stage """ if verbose >= 2: print("Failed to import: %s (%s)" % (modname, e)) continue except cfg.DuplicateOptError as e: """ oslo.cfg doesn't allow redefinition of a config option, but we don't mind. Don't fail if this happens. """ if verbose >= 2: print(e) continue except cfg.NoSuchGroupError as e: """ If a group doesn't exist, we ignore the import. """ if verbose >= 2: print(e) continue _register_runtime_opts(module, abs_path, verbose) _run_hook(modname) # All the components provide keystone token authentication, usually using a # pipeline. Since the auth_token options can only be discovered at runtime # in this configuration, we force their discovery by importing the module. try: import keystonemiddleware.auth_token # noqa except cfg.DuplicateOptError: pass
# it will override what happens to be installed in # /usr/(local/)tosca_lib/python... import sys from oslo_config import cfg import oslo_i18n from oslo_service import service as common_service from apmec import _i18n _i18n.enable_lazy() from apmec.common import config from apmec import service oslo_i18n.install("apmec") def main(): # the configuration will be read into the cfg.CONF global data structure config.init(sys.argv[1:]) if not cfg.CONF.config_file: sys.exit(_("ERROR: Unable to find configuration file via the default" " search paths (~/.apmec/, ~/, /etc/apmec/, /etc/) and" " the '--config-file' option!")) try: apmec_api = service.serve_wsgi(service.ApmecApiService) launcher = common_service.launch(cfg.CONF, apmec_api, workers=cfg.CONF.api_workers or None) launcher.wait()
import argparse import imp import os import re import socket import sys import textwrap from oslo_config import cfg import oslo_i18n from oslo_utils import importutils import six import stevedore.named oslo_i18n.install('iotronic') STROPT = "StrOpt" BOOLOPT = "BoolOpt" INTOPT = "IntOpt" FLOATOPT = "FloatOpt" LISTOPT = "ListOpt" DICTOPT = "DictOpt" MULTISTROPT = "MultiStrOpt" OPT_TYPES = { STROPT: 'string value', BOOLOPT: 'boolean value', INTOPT: 'integer value', FLOATOPT: 'floating point value', LISTOPT: 'list value',
# Copyright (c) 2013 Hewlett-Packard Development Company, L.P. # All Rights Reserved. # # 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. # NOTE(yuriyz): Do eventlet monkey patching here, instead of in # ironic/__init__.py. This allows the API service to run without monkey # patching under Apache (which uses its own concurrency model). Mixing # concurrency models can cause undefined behavior and potentially API timeouts. import os os.environ['EVENTLET_NO_GREENDNS'] = 'yes' import eventlet eventlet.monkey_patch(os=False) import oslo_i18n as i18n # noqa for I202 due to 'import eventlet' above i18n.install('ironic')
# If ../tacker/__init__.py exists, add ../ to Python search path, so that # it will override what happens to be installed in /usr/(local/)lib/python... import sys from oslo_config import cfg import oslo_i18n from oslo_service import service as common_service from tacker import _i18n _i18n.enable_lazy() from tacker.common import config from tacker import service oslo_i18n.install("tacker") def main(): # the configuration will be read into the cfg.CONF global data structure config.init(sys.argv[1:]) if not cfg.CONF.config_file: sys.exit( _("ERROR: Unable to find configuration file via the default" " search paths (~/.tacker/, ~/, /etc/tacker/, /etc/) and" " the '--config-file' option!")) try: tacker_api = service.serve_wsgi(service.TackerApiService) launcher = common_service.launch(cfg.CONF, tacker_api,
# Copyright 2016 Huawei Technologies Co.,LTD. # All Rights Reserved. # # 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. import os os.environ['EVENTLET_NO_GREENDNS'] = 'yes' import eventlet import oslo_i18n as i18n eventlet.monkey_patch(os=False) i18n.install('mogan')