Beispiel #1
0
 def setUp(self):
     super(VimTest, self).setUp()
     patcher = mock.patch('suds.client.Client')
     self.addCleanup(patcher.stop)
     self.SudsClientMock = patcher.start()
     back_use_lazy = i18n._lazy.USE_LAZY
     i18n.enable_lazy()
     self.addCleanup(self._restore_use_lazy, back_use_lazy)
Beispiel #2
0
 def setUp(self):
     super(VimTest, self).setUp()
     patcher = mock.patch('suds.client.Client')
     self.addCleanup(patcher.stop)
     self.SudsClientMock = patcher.start()
     back_use_lazy = i18n._lazy.USE_LAZY
     i18n.enable_lazy()
     self.addCleanup(self._restore_use_lazy, back_use_lazy)
Beispiel #3
0
def prepare_service(argv=None):
    i18n.enable_lazy()
    log.set_defaults(_DEFAULT_LOG_LEVELS)
    log.register_options(CONF)
    if argv is None:
        argv = sys.argv
    CONF(argv[1:], project='glance-search')
    log.setup(cfg.CONF, 'glance-search')
    oslo.messaging.set_transport_defaults('glance')
Beispiel #4
0
def prepare_service(argv=None):
    i18n.enable_lazy()
    log.set_defaults(_DEFAULT_LOG_LEVELS)
    log.register_options(CONF)
    if argv is None:
        argv = sys.argv
    CONF(argv[1:], project='glance-search')
    log.setup(cfg.CONF, 'glance-search')
    oslo.messaging.set_transport_defaults('glance')
def prepare_service(argv=None):
    i18n.enable_lazy()
    log_levels = (cfg.CONF.default_log_levels +
                  ['stevedore=INFO', 'keystoneclient=INFO'])
    cfg.set_defaults(log.log_opts, default_log_levels=log_levels)
    if argv is None:
        argv = sys.argv
    cfg.CONF(argv[1:], project='ceilometer', validate_default_values=True)
    log.setup('ceilometer')
    messaging.setup()
Beispiel #6
0
def prepare_service(argv=None):
    i18n.enable_lazy()
    log_levels = (cfg.CONF.default_log_levels +
                  ['stevedore=INFO', 'keystoneclient=INFO'])
    cfg.set_defaults(log.log_opts,
                     default_log_levels=log_levels)
    if argv is None:
        argv = sys.argv
    cfg.CONF(argv[1:], project='ceilometer')
    log.setup('ceilometer')
    messaging.setup()
 def test_toggle_lazy(self):
     original = _lazy.USE_LAZY
     try:
         i18n.enable_lazy(True)
         i18n.enable_lazy(False)
     finally:
         i18n.enable_lazy(original)
 def test_toggle_lazy(self):
     original = _lazy.USE_LAZY
     try:
         i18n.enable_lazy(True)
         i18n.enable_lazy(False)
     finally:
         i18n.enable_lazy(original)
Beispiel #9
0
def enable_lazy(enable=True):
    return i18n.enable_lazy(enable)
Beispiel #10
0
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', 'cmd',
                           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.
    import keystoneclient.middleware.auth_token  # noqa
#    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 logging
import os

from oslo import i18n


# NOTE(dstanek): i18n.enable_lazy() must be called before
# keystone.i18n._() is called to ensure it has the desired lazy lookup
# behavior. This includes cases, like keystone.exceptions, where
# keystone.i18n._() is called at import time.
i18n.enable_lazy()


from keystone import backends
from keystone.common import dependency
from keystone.common import environment
from keystone.common import sql
from keystone import config
from keystone.openstack.common import log
from keystone import service


CONF = config.CONF

config.configure()
sql.initialize()
Beispiel #12
0
def enable_lazy():
    if CONF.i18n_enable_lazy:
        return i18n.enable_lazy()
Beispiel #13
0
def enable_lazy():
    return i18n.enable_lazy()
Beispiel #14
0
def enable_lazy():
    return i18n.enable_lazy()
Beispiel #15
0
def enable_lazy(enable=True):
    return i18n.enable_lazy(enable)
Beispiel #16
0
def enable_lazy():
    if CONF.i18n_enable_lazy:
        return i18n.enable_lazy()
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', 'cmd',
                           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.
    import keystoneclient.middleware.auth_token  # noqa