예제 #1
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
예제 #2
0
# Copyright 2013, 2014 IBM Corp.
from oslo import i18n

i18n.install('cinder')
import unittest
import mox
from powervc.volume.manager.manager import PowerVCCinderManager
from powervc.volume.driver.service import PowerVCService

fake_volume_type = {'id': '', 'name': 'fake_volume_type'}

fake_volume = {
    'display_name': 'fake_volume',
    'display_description': 'This is a fake volume',
    'volume_type_id': '',
    'status': '',
    'host': 'powervc',
    'size': 1,
    'availability_zone': 'nova',
    'bootable': 0,
    'snapshot_id': '',
    'source_volid': '',
    'metadata': {},
    'project_id': 'admin',
    'user_id': 'admin',
    'attached_host': 'fake_attached_host',
    'mountpoint': '',
    'instance_uuid': '',
    'attach_status': ''
}
예제 #3
0
# Copyright 2013, 2014 IBM Corp.
import unittest
import mox
from mock import MagicMock
import glanceclient.v1.images as imagesV1
import glanceclient.v1.image_members as membersV1

from oslo import i18n
i18n.install('common-glance-client-ut')

import powervc.common.utils as common_utils

utils = common_utils.import_relative_module('glanceclient', 'tests.utils')
test_images = common_utils.import_relative_module('glanceclient',
                                                  'tests.v1.test_images')
test_image_members = common_utils.import_relative_module(
    'glanceclient',
    'tests.v1.test_image_members')

from powervc.common.client.extensions.glance import Client as PVCGlanceClient


class FakeGlanceClient(object):

    """
        Fake client to populate the pvcglanceclient.Client
    """

    def __init__(self, images, members):
        self.images = images
        self.image_members = members
예제 #4
0
 def test_install(self):
     with mock.patch('six.moves.builtins'):
         i18n.install('domain')
예제 #5
0
#
#    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.

from oslo import i18n


def fake_translate_msgid(msgid, domain, desired_locale=None):
    return msgid

i18n.enable_lazy()
# fixme(elynn): Since install() is deprecated, we should remove it in
# the future
i18n.install('heat')

#To ensure messages don't really get translated while running tests.
#As there are lots of places where matching is expected when comparing
#exception message(translated) with raw message.
i18n._translate_msgid = fake_translate_msgid
예제 #6
0
#    License for the specific language governing permissions and limitations
#    under the License.

from __future__ import print_function

import sys

from oslo.config import cfg
from oslo import i18n

from heat.db import migration
from heat.openstack.common import log as logging

# fixme(elynn): Since install() is deprecated, we should remove it in
# the future
i18n.install('heat')

LOG = logging.getLogger(__name__)

if __name__ == '__main__':
    print('*******************************************', file=sys.stderr)
    print('Deprecated: use heat-manage db_sync instead', file=sys.stderr)
    print('*******************************************', file=sys.stderr)
    cfg.CONF(project='heat', prog='heat-engine')

    try:
        migration.db_sync()
    except Exception as exc:
        print(str(exc), file=sys.stderr)
        sys.exit(1)
예제 #7
0
파일: __init__.py 프로젝트: dagnello/cue
from oslo import i18n

i18n.install('cue')
예제 #8
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
예제 #9
0
# 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.

from oslo import i18n

i18n.install('ironic')
예제 #10
0
# Copyright 2013, 2014 IBM Corp.
from oslo import i18n
i18n.install('cinder')
import unittest
import mox
from powervc.volume.manager.manager import PowerVCCinderManager
from powervc.volume.driver.service import PowerVCService

fake_volume_type = {'id': '',
                    'name': 'fake_volume_type'
                    }


fake_volume = {'display_name': 'fake_volume',
               'display_description': 'This is a fake volume',
               'volume_type_id': '',
               'status': '',
               'host': 'powervc',
               'size': 1,
               'availability_zone': 'nova',
               'bootable': 0,
               'snapshot_id': '',
               'source_volid': '',
               'metadata': {},
               'project_id': 'admin',
               'user_id': 'admin',
               'attached_host': 'fake_attached_host',
               'mountpoint': '',
               'instance_uuid': '',
               'attach_status': ''}
예제 #11
0
# Copyright 2013, 2014 IBM Corp.
import unittest
import mox
from mock import MagicMock
import glanceclient.v1.images as imagesV1
import glanceclient.v1.image_members as membersV1

from oslo import i18n
i18n.install('common-glance-client-ut')

import powervc.common.utils as common_utils

utils = common_utils.import_relative_module('glanceclient', 'tests.utils')
test_images = common_utils.import_relative_module('glanceclient',
                                                  'tests.v1.test_images')
test_image_members = common_utils.import_relative_module(
    'glanceclient', 'tests.v1.test_image_members')

from powervc.common.client.extensions.glance import Client as PVCGlanceClient


class FakeGlanceClient(object):
    """
        Fake client to populate the pvcglanceclient.Client
    """
    def __init__(self, images, members):
        self.images = images
        self.image_members = members
        self.image_tags = MagicMock()

 def test_install(self):
     with mock.patch('six.moves.builtins'):
         i18n.install('domain')