def test_options_defaults_override(self):
     opts.set_defaults(self.conf_fixture.conf, enabled=True, trace_sqlalchemy=True, hmac_keys="MY_KEY")
     self.assertTrue(self.conf_fixture.conf.profiler.enabled)
     self.assertTrue(self.conf_fixture.conf.profiler.trace_sqlalchemy)
     self.assertEqual("MY_KEY", self.conf_fixture.conf.profiler.hmac_keys)
     self.assertTrue(opts.is_trace_enabled(self.conf_fixture.conf))
     self.assertTrue(opts.is_db_trace_enabled(self.conf_fixture.conf))
Esempio n. 2
0
def set_external_opts_defaults():
    """Update default configuration options for oslo.middleware."""
    # CORS Defaults
    # TODO(krotscheck): Update with https://review.openstack.org/#/c/285368/
    cfg.set_defaults(cors.CORS_OPTS,
                     allow_headers=[
                         'X-Auth-Token', 'X-Openstack-Request-Id',
                         'X-Subject-Token', 'X-Project-Id', 'X-Project-Name',
                         'X-Project-Domain-Id', 'X-Project-Domain-Name',
                         'X-Domain-Id', 'X-Domain-Name'
                     ],
                     expose_headers=[
                         'X-Auth-Token', 'X-Openstack-Request-Id',
                         'X-Subject-Token'
                     ],
                     allow_methods=['GET', 'PUT', 'POST', 'DELETE', 'PATCH'])

    # configure OSprofiler options
    profiler.set_defaults(CONF, enabled=False, trace_sqlalchemy=False)

    # Oslo.cache is always enabled by default for request-local caching
    # TODO(morganfainberg): Fix this to not use internal interface when
    # oslo.cache has proper interface to set defaults added. This is
    # just a bad way to do this.
    opts = cache._opts.list_opts()
    for opt_list in opts:
        if opt_list[0] == 'cache':
            for o in opt_list[1]:
                if o.name == 'enabled':
                    o.default = True
Esempio n. 3
0
    def test_all_public_methods_are_traced(self):
        profiler_opts.set_defaults(conf.CONF)
        self.config(enabled=True,
                    group='profiler')

        classes = [
            'magnum.conductor.api.API',
            'magnum.conductor.api.ListenerAPI',
            'magnum.conductor.handlers.ca_conductor.Handler',
            'magnum.conductor.handlers.cluster_conductor.Handler',
            'magnum.conductor.handlers.conductor_listener.Handler',
            'magnum.conductor.handlers.indirection_api.Handler',
            'magnum.service.periodic.MagnumPeriodicTasks',
        ]
        for clsname in classes:
            # give the metaclass and trace_cls() decorator a chance to patch
            # methods of the classes above
            six.reload_module(
                importutils.import_module(clsname.rsplit('.', 1)[0]))
            cls = importutils.import_class(clsname)

            for attr, obj in cls.__dict__.items():
                # only public methods are traced
                if attr.startswith('_'):
                    continue
                # only checks callables
                if not (inspect.ismethod(obj) or inspect.isfunction(obj)):
                    continue
                # osprofiler skips static methods
                if isinstance(obj, staticmethod):
                    continue

                self.assertTrue(getattr(obj, '__traced__', False), obj)
Esempio n. 4
0
    def __init__(self, argv):
        args = self._get_base_parser().parse_args(argv)
        opts.set_defaults(cfg.CONF)

        if not (args.os_auth_token and args.ceilometer_url):
            if not args.os_username:
                raise exc.CommandError(
                    "You must provide a username via either --os-username or "
                    "via env[OS_USERNAME]")

            if not args.os_password:
                raise exc.CommandError(
                    "You must provide a password via either --os-password or "
                    "via env[OS_PASSWORD]")

            if self._no_project_and_domain_set(args):
                # steer users towards Keystone V3 API
                raise exc.CommandError(
                    "You must provide a project_id via either --os-project-id "
                    "or via env[OS_PROJECT_ID] and a domain_name via either "
                    "--os-user-domain-name or via env[OS_USER_DOMAIN_NAME] or "
                    "a domain_id via either --os-user-domain-id or via "
                    "env[OS_USER_DOMAIN_ID]")

            if not args.os_auth_url:
                raise exc.CommandError(
                    "You must provide an auth url via either --os-auth-url or "
                    "via env[OS_AUTH_URL]")

        args.func(args)
Esempio n. 5
0
def prepare_service(args=None, conf=None, config_files=None):
    set_defaults()
    if conf is None:
        conf = cfg.ConfigOpts()
    log.register_options(conf)
    policy_opts.set_defaults(conf)
    osprofiler_opts.set_defaults(conf)
    db_options.set_defaults(conf)

    for group, options in opts.list_opts():
        conf.register_opts(list(options),
                           group=None if group == 'DEFAULT' else group)

    conf(args,
         project='vitrage',
         validate_default_values=True,
         default_config_files=config_files)

    if conf.profiler.enabled:
        osprofiler_initializer.init_from_conf(conf=conf,
                                              context=None,
                                              project="vitrage",
                                              service="api",
                                              host=conf.api.host)

    for datasource in conf.datasources.types:
        register_opts(conf, datasource, conf.datasources.path)

    keystone_client.register_keystoneauth_opts(conf)

    log.setup(conf, 'vitrage')
    conf.log_opt_values(LOG, log.DEBUG)
    messaging.setup()

    return conf
Esempio n. 6
0
    def test_all_public_methods_are_traced(self):
        profiler_opts.set_defaults(conf.CONF)
        self.config(enabled=True, group='profiler')

        classes = [
            'zun.compute.api.API',
            'zun.compute.rpcapi.API',
        ]
        for clsname in classes:
            # give the metaclass and trace_cls() decorator a chance to patch
            # methods of the classes above
            imp.reload(importutils.import_module(clsname.rsplit('.', 1)[0]))
            cls = importutils.import_class(clsname)

            for attr, obj in cls.__dict__.items():
                # only public methods are traced
                if attr.startswith('_'):
                    continue
                # only checks callables
                if not (inspect.ismethod(obj) or inspect.isfunction(obj)):
                    continue
                # osprofiler skips static methods
                if isinstance(obj, staticmethod):
                    continue

                self.assertTrue(getattr(obj, '__traced__', False), obj)
Esempio n. 7
0
    def test_all_public_methods_are_traced(self):
        profiler_opts.set_defaults(conf.CONF)
        self.config(enabled=True, group='profiler')

        classes = [
            'magnum.conductor.api.API',
            'magnum.conductor.api.ListenerAPI',
            'magnum.conductor.handlers.ca_conductor.Handler',
            'magnum.conductor.handlers.cluster_conductor.Handler',
            'magnum.conductor.handlers.conductor_listener.Handler',
            'magnum.conductor.handlers.indirection_api.Handler',
            'magnum.service.periodic.MagnumPeriodicTasks',
        ]
        for clsname in classes:
            # give the metaclass and trace_cls() decorator a chance to patch
            # methods of the classes above
            six.reload_module(
                importutils.import_module(clsname.rsplit('.', 1)[0]))
            cls = importutils.import_class(clsname)

            for attr, obj in cls.__dict__.items():
                # only public methods are traced
                if attr.startswith('_'):
                    continue
                # only checks callables
                if not (inspect.ismethod(obj) or inspect.isfunction(obj)):
                    continue
                # osprofiler skips static methods
                if isinstance(obj, staticmethod):
                    continue

                self.assertTrue(getattr(obj, '__traced__', False), obj)
Esempio n. 8
0
def parse_config(args, default_config_files=None):
    set_defaults()
    log.register_options(CONF)
    policy_opts.set_defaults(CONF)
    osprofiler_opts.set_defaults(CONF)
    db_options.set_defaults(CONF)

    for group, options in opts.list_opts():
        CONF.register_opts(list(options),
                           group=None if group == 'DEFAULT' else group)

    CONF(args[1:],
         project='vitrage',
         validate_default_values=True,
         default_config_files=default_config_files)

    if CONF.profiler.enabled:
        osprofiler_initializer.init_from_conf(conf=CONF,
                                              context=None,
                                              project='vitrage',
                                              service='api',
                                              host=CONF.api.host)

    for datasource in CONF.datasources.types:
        opts.register_opts(datasource, CONF.datasources.path)

    keystone_client.register_keystoneauth_opts()
    log.setup(CONF, 'vitrage')
    CONF.log_opt_values(LOG, log.DEBUG)
    messaging.setup()
Esempio n. 9
0
def initialize():
    """Initialize the module."""
    db_options.set_defaults(
        CONF,
        connection="sqlite:///keystone.db")
    # Configure OSprofiler options
    profiler.set_defaults(CONF, enabled=False, trace_sqlalchemy=False)
Esempio n. 10
0
 def test_web_trace_enabled(self, mock_disable, mock_enable):
     opts.set_defaults(self.conf_fixture.conf, enabled=True,
                       hmac_keys="MY_KEY")
     opts.enable_web_trace(self.conf_fixture.conf)
     opts.disable_web_trace(self.conf_fixture.conf)
     mock_enable.assert_called_once_with("MY_KEY")
     mock_disable.assert_called_once_with()
Esempio n. 11
0
 def setUp(self):
     super(DriverTestCase, self).setUp()
     CONF(["--config-file", os.path.dirname(__file__) + "/config.cfg"])
     opts.set_defaults(CONF,
                       enabled=True,
                       trace_sqlalchemy=False,
                       hmac_keys="SECRET_KEY")
 def test_options_defaults(self):
     opts.set_defaults(self.conf_fixture.conf)
     self.assertFalse(self.conf_fixture.conf.profiler.enabled)
     self.assertFalse(self.conf_fixture.conf.profiler.trace_sqlalchemy)
     self.assertEqual("SECRET_KEY", self.conf_fixture.conf.profiler.hmac_keys)
     self.assertFalse(opts.is_trace_enabled(self.conf_fixture.conf))
     self.assertFalse(opts.is_db_trace_enabled(self.conf_fixture.conf))
Esempio n. 13
0
 def setUp(self):
     super(DriverTestCase, self).setUp()
     CONF(["--config-file", os.path.dirname(__file__) + "/config.cfg"])
     opts.set_defaults(CONF,
                       enabled=True,
                       trace_sqlalchemy=False,
                       hmac_keys="SECRET_KEY")
Esempio n. 14
0
File: core.py Progetto: Boye-Z/123
def initialize():
    """Initialize the module."""
    db_options.set_defaults(
        CONF,
        connection="sqlite:///keystone.db")
    # Configure OSprofiler options
    profiler.set_defaults(CONF, enabled=False, trace_sqlalchemy=False)
Esempio n. 15
0
def set_external_opts_defaults():
    """Update default configuration options for oslo.middleware."""
    cors.set_defaults(allow_headers=[
        'X-Auth-Token', 'X-Openstack-Request-Id', 'X-Subject-Token',
        'X-Project-Id', 'X-Project-Name', 'X-Project-Domain-Id',
        'X-Project-Domain-Name', 'X-Domain-Id', 'X-Domain-Name',
        'Openstack-Auth-Receipt'
    ],
                      expose_headers=[
                          'X-Auth-Token', 'X-Openstack-Request-Id',
                          'X-Subject-Token', 'Openstack-Auth-Receipt'
                      ],
                      allow_methods=['GET', 'PUT', 'POST', 'DELETE', 'PATCH'])

    # configure OSprofiler options
    profiler.set_defaults(CONF, enabled=False, trace_sqlalchemy=False)

    # TODO(gmann): Remove setting the default value of config policy_file
    # once oslo_policy change the default value to 'policy.yaml'.
    # https://github.com/openstack/oslo.policy/blob/a626ad12fe5a3abd49d70e3e5b95589d279ab578/oslo_policy/opts.py#L49
    DEFAULT_POLICY_FILE = 'policy.yaml'
    policy_opts.set_defaults(cfg.CONF, DEFAULT_POLICY_FILE)

    # Oslo.cache is always enabled by default for request-local caching
    # TODO(morganfainberg): Fix this to not use internal interface when
    # oslo.cache has proper interface to set defaults added. This is
    # just a bad way to do this.
    opts = cache._opts.list_opts()
    for opt_list in opts:
        if opt_list[0] == 'cache':
            for o in opt_list[1]:
                if o.name == 'enabled':
                    o.default = True
Esempio n. 16
0
def set_external_opts_defaults():
    """Update default configuration options for oslo.middleware."""
    cors.set_defaults(
        allow_headers=['X-Auth-Token',
                       'X-Openstack-Request-Id',
                       'X-Subject-Token',
                       'X-Project-Id',
                       'X-Project-Name',
                       'X-Project-Domain-Id',
                       'X-Project-Domain-Name',
                       'X-Domain-Id',
                       'X-Domain-Name'],
        expose_headers=['X-Auth-Token',
                        'X-Openstack-Request-Id',
                        'X-Subject-Token'],
        allow_methods=['GET',
                       'PUT',
                       'POST',
                       'DELETE',
                       'PATCH']
    )

    # configure OSprofiler options
    profiler.set_defaults(CONF, enabled=False, trace_sqlalchemy=False)

    # Oslo.cache is always enabled by default for request-local caching
    # TODO(morganfainberg): Fix this to not use internal interface when
    # oslo.cache has proper interface to set defaults added. This is
    # just a bad way to do this.
    opts = cache._opts.list_opts()
    for opt_list in opts:
        if opt_list[0] == 'cache':
            for o in opt_list[1]:
                if o.name == 'enabled':
                    o.default = True
Esempio n. 17
0
    def setUp(self):
        super(TestBase, self).setUp()

        self.useFixture(fixtures.FakeLogger('zaqar'))

        if os.environ.get('OS_STDOUT_CAPTURE') is not None:
            stdout = self.useFixture(fixtures.StringStream('stdout')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout))
        if os.environ.get('OS_STDERR_CAPTURE') is not None:
            stderr = self.useFixture(fixtures.StringStream('stderr')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))

        if self.config_file:
            self.config_file = helpers.override_mongo_conf(
                self.config_file, self)
            self.conf = self.load_conf(self.config_file)
        else:
            self.conf = cfg.ConfigOpts()

        self.conf.register_opts(default.ALL_OPTS)
        self.conf.register_opts(drivers.ALL_OPTS, group=drivers.GROUP_NAME)
        self.conf.register_opts(notification.ALL_OPTS,
                                group=notification.GROUP_NAME)
        self.conf.register_opts(signed_url.ALL_OPTS,
                                group=signed_url.GROUP_NAME)
        opts.set_defaults(self.conf)
        self.conf.register_opts(profiler.ALL_OPTS, group=profiler.GROUP_NAME)
        self.redis_url = os.environ.get('ZAQAR_TEST_REDIS_URL',
                                        'redis://127.0.0.1:6379')
        self.mongodb_url = os.environ.get('ZAQAR_TEST_MONGODB_URL',
                                          'mongodb://127.0.0.1:27017')
Esempio n. 18
0
    def setUp(self):
        super(TestBase, self).setUp()

        self.useFixture(fixtures.FakeLogger('zaqar'))

        if os.environ.get('OS_STDOUT_CAPTURE') is not None:
            stdout = self.useFixture(fixtures.StringStream('stdout')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout))
        if os.environ.get('OS_STDERR_CAPTURE') is not None:
            stderr = self.useFixture(fixtures.StringStream('stderr')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))

        if self.config_file:
            self.config_file = helpers.override_mongo_conf(
                self.config_file, self)
            self.conf = self.load_conf(self.config_file)
        else:
            self.conf = cfg.ConfigOpts()

        self.conf.register_opts(configs._GENERAL_OPTIONS)
        self.conf.register_opts(configs._DRIVER_OPTIONS,
                                group=configs._DRIVER_GROUP)
        self.conf.register_opts(configs._NOTIFICATION_OPTIONS,
                                group=configs._NOTIFICATION_GROUP)
        self.conf.register_opts(configs._NOTIFICATION_OPTIONS,
                                group=configs._NOTIFICATION_GROUP)
        self.conf.register_opts(configs._SIGNED_URL_OPTIONS,
                                group=configs._SIGNED_URL_GROUP)
        opts.set_defaults(self.conf)
        self.conf.register_opts(configs._PROFILER_OPTIONS,
                                group=configs._PROFILER_GROUP)
        self.redis_url = os.environ.get('ZAQAR_TEST_REDIS_URL',
                                        'redis://127.0.0.1:6379')
        self.mongodb_url = os.environ.get('ZAQAR_TEST_MONGODB_URL',
                                          'mongodb://127.0.0.1:27017')
Esempio n. 19
0
 def test_web_trace_enabled(self, mock_disable, mock_enable):
     opts.set_defaults(self.conf_fixture.conf,
                       enabled=True,
                       hmac_keys="MY_KEY")
     opts.enable_web_trace(self.conf_fixture.conf)
     opts.disable_web_trace(self.conf_fixture.conf)
     mock_enable.assert_called_once_with("MY_KEY")
     mock_disable.assert_called_once_with()
Esempio n. 20
0
 def setUp(self):
     super(DriverTestCase, self).setUp()
     CONF([])
     opts.set_defaults(CONF,
                       connection_string="redis://localhost:6379",
                       enabled=True,
                       trace_sqlalchemy=False,
                       hmac_keys="SECRET_KEY")
Esempio n. 21
0
 def setUp(self):
     super(DriverTestCase, self).setUp()
     CONF([])
     opts.set_defaults(CONF,
                       connection_string="redis://localhost:6379",
                       enabled=True,
                       trace_sqlalchemy=False,
                       hmac_keys="SECRET_KEY")
Esempio n. 22
0
 def test_options_defaults(self):
     opts.set_defaults(self.conf_fixture.conf)
     self.assertFalse(self.conf_fixture.conf.profiler.enabled)
     self.assertFalse(self.conf_fixture.conf.profiler.trace_sqlalchemy)
     self.assertEqual("SECRET_KEY",
                      self.conf_fixture.conf.profiler.hmac_keys)
     self.assertFalse(opts.is_trace_enabled(self.conf_fixture.conf))
     self.assertFalse(opts.is_db_trace_enabled(self.conf_fixture.conf))
Esempio n. 23
0
def parse_args(argv, default_config_files=None):
    rpc.set_defaults(control_exchange='ironic')
    cfg.CONF(argv[1:],
             project='ironic',
             version=version.version_info.release_string(),
             default_config_files=default_config_files)
    rpc.init(cfg.CONF)
    profiler_opts.set_defaults(cfg.CONF)
Esempio n. 24
0
def parse_args(argv, default_config_files=None):
    rpc.set_defaults(control_exchange='ironic')
    cfg.CONF(argv[1:],
             project='ironic',
             version=version.version_info.release_string(),
             default_config_files=default_config_files)
    rpc.init(cfg.CONF)
    profiler_opts.set_defaults(cfg.CONF)
Esempio n. 25
0
 def test_options_defaults_override(self):
     opts.set_defaults(self.conf_fixture.conf,
                       enabled=True,
                       trace_sqlalchemy=True,
                       hmac_keys="MY_KEY")
     self.assertTrue(self.conf_fixture.conf.profiler.enabled)
     self.assertTrue(self.conf_fixture.conf.profiler.trace_sqlalchemy)
     self.assertEqual("MY_KEY", self.conf_fixture.conf.profiler.hmac_keys)
     self.assertTrue(opts.is_trace_enabled(self.conf_fixture.conf))
     self.assertTrue(opts.is_db_trace_enabled(self.conf_fixture.conf))
Esempio n. 26
0
    def test_all_public_methods_are_traced(self):
        # NOTE(rpodolyaka): osprofiler only wraps class methods when option
        # CONF.profiler.enabled is set to True and the default value is False,
        # which means in our usual test run we use original, not patched
        # classes. In order to test, that we actually properly wrap methods
        # we are interested in, this test case sets CONF.profiler.enabled to
        # True and reloads all the affected Python modules (application of
        # decorators and metaclasses is performed at module import time).
        # Unfortunately, this leads to subtle failures of other test cases
        # (e.g. super() is performed on a "new" version of a class instance
        # created after a module reload while the class name is a reference to
        # an "old" version of the class). Thus, this test is run in isolation.
        if not os.getenv('TEST_OSPROFILER', False):
            self.skipTest('TEST_OSPROFILER env variable is not set. '
                          'Skipping osprofiler tests...')

        # reinitialize the metaclass after enabling osprofiler
        profiler.set_defaults(conf.CONF)
        self.flags(enabled=True, group='profiler')
        six.reload_module(importutils.import_module('nova.manager'))

        classes = [
            'nova.compute.api.API',
            'nova.compute.manager.ComputeManager',
            'nova.compute.rpcapi.ComputeAPI',
            'nova.conductor.manager.ComputeTaskManager',
            'nova.conductor.manager.ConductorManager',
            'nova.conductor.rpcapi.ComputeTaskAPI',
            'nova.conductor.rpcapi.ConductorAPI',
            'nova.image.api.API',
            'nova.network.neutron.ClientWrapper',
            'nova.scheduler.manager.SchedulerManager',
            'nova.scheduler.rpcapi.SchedulerAPI',
            'nova.virt.libvirt.vif.LibvirtGenericVIFDriver',
            'nova.virt.libvirt.volume.volume.LibvirtBaseVolumeDriver',
        ]
        for clsname in classes:
            # give the metaclass and trace_cls() decorator a chance to patch
            # methods of the classes above
            six.reload_module(
                importutils.import_module(clsname.rsplit('.', 1)[0]))
            cls = importutils.import_class(clsname)

            for attr, obj in cls.__dict__.items():
                # only public methods are traced
                if attr.startswith('_'):
                    continue
                # only checks callables
                if not (inspect.ismethod(obj) or inspect.isfunction(obj)):
                    continue
                # osprofiler skips static methods
                if isinstance(obj, staticmethod):
                    continue

                self.assertTrue(getattr(obj, '__traced__', False), obj)
Esempio n. 27
0
    def __init__(self, conf):
        self.conf = conf

        for group, opts in opts_tool.list_opts_by_group():
            self.conf.register_opts(opts, group=group)
        profiler_opts.set_defaults(self.conf)

        # TODO(wangxiyuan): Now the OSprofiler feature in Zaqar only support
        # wsgi. Websocket part will be added in the future.
        profile.setup(self.conf, 'Zaqar-server', socket.gethostname())

        self.driver_conf = self.conf[driver_opts.GROUP_NAME]
Esempio n. 28
0
    def __init__(self, conf):
        self.conf = conf

        for group, opts in opts_tool.list_opts_by_group():
            self.conf.register_opts(opts, group=group)
        profiler_opts.set_defaults(self.conf)

        # TODO(wangxiyuan): Now the OSprofiler feature in Zaqar only support
        # wsgi. Websocket part will be added in the future.
        profile.setup(self.conf, 'Zaqar-server', socket.gethostname())

        self.driver_conf = self.conf[driver_opts.GROUP_NAME]
Esempio n. 29
0
 def test_web_trace_disabled(self, mock_disable, mock_enable):
     opts.set_defaults(self.conf_fixture.conf, hmac_keys="MY_KEY")
     opts.enable_web_trace(self.conf_fixture.conf)
     opts.disable_web_trace(self.conf_fixture.conf)
     self.assertEqual(0, mock_enable.call_count)
     self.assertEqual(0, mock_disable.call_count)
Esempio n. 30
0
    for client in ('nova', 'swift', 'neutron', 'cinder',
                   'ceilometer', 'keystone', 'heat', 'glance', 'trove',
                   'sahara'):
        client_specific_group = 'clients_' + client
        yield client_specific_group, clients_opts

    yield 'clients_heat', heat_client_opts
    yield 'clients_keystone', keystone_client_opts
    yield 'clients_nova', client_http_log_debug_opts
    yield 'clients_cinder', client_http_log_debug_opts


cfg.CONF.register_group(paste_deploy_group)
cfg.CONF.register_group(auth_password_group)
cfg.CONF.register_group(revision_group)
profiler.set_defaults(cfg.CONF)

for group, opts in list_opts():
    cfg.CONF.register_opts(opts, group=group)


def _get_deployment_flavor():
    """Retrieves the paste_deploy.flavor config item.

    Item formatted appropriately for appending to the application name.
    """
    flavor = cfg.CONF.paste_deploy.flavor
    return '' if not flavor else ('-' + flavor)


def _get_deployment_config_file():
Esempio n. 31
0
#    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_config import cfg
from oslo_log import log as logging
import osprofiler.initializer
from osprofiler import opts as profiler_opts
import osprofiler.web

from neutron._i18n import _LI
from neutron import context


CONF = cfg.CONF
profiler_opts.set_defaults(CONF)
LOG = logging.getLogger(__name__)


def setup(name, host='0.0.0.0'):  # nosec
    """Setup OSprofiler notifier and enable profiling.

    :param name: name of the service, that will be profiled
    :param host: host (either host name or host address) the service will be
                 running on. By default host will be set to 0.0.0.0, but more
                 specified host name / address usage is highly recommended.
    """
    if CONF.profiler.enabled:
        osprofiler.initializer.init_from_conf(
            conf=CONF,
            context=context.get_admin_context(),
Esempio n. 32
0
    def test_all_public_methods_are_traced(self):
        # NOTE(rpodolyaka): osprofiler only wraps class methods when option
        # CONF.profiler.enabled is set to True and the default value is False,
        # which means in our usual test run we use original, not patched
        # classes. In order to test, that we actually properly wrap methods
        # we are interested in, this test case sets CONF.profiler.enabled to
        # True and reloads all the affected Python modules (application of
        # decorators and metaclasses is performed at module import time).
        # Unfortunately, this leads to subtle failures of other test cases
        # (e.g. super() is performed on a "new" version of a class instance
        # created after a module reload while the class name is a reference to
        # an "old" version of the class). Thus, this test is run in isolation.
        if not os.getenv('TEST_OSPROFILER', False):
            self.skipTest('TEST_OSPROFILER env variable is not set. '
                          'Skipping osprofiler tests...')

        # reinitialize the metaclass after enabling osprofiler
        profiler.set_defaults(conf.CONF)
        self.flags(enabled=True, group='profiler')
        six.reload_module(importutils.import_module('nova.manager'))

        classes = [
            'nova.api.manager.MetadataManager',
            'nova.cells.manager.CellsManager',
            'nova.cells.rpcapi.CellsAPI',
            'nova.cert.manager.CertManager',
            'nova.cert.rpcapi.CertAPI',
            'nova.compute.api.API',
            'nova.compute.manager.ComputeManager',
            'nova.compute.rpcapi.ComputeAPI',
            'nova.conductor.manager.ComputeTaskManager',
            'nova.conductor.manager.ConductorManager',
            'nova.conductor.rpcapi.ComputeTaskAPI',
            'nova.conductor.rpcapi.ConductorAPI',
            'nova.console.manager.ConsoleProxyManager',
            'nova.console.rpcapi.ConsoleAPI',
            'nova.consoleauth.manager.ConsoleAuthManager',
            'nova.consoleauth.rpcapi.ConsoleAuthAPI',
            'nova.image.api.API',
            'nova.network.api.API',
            'nova.network.manager.FlatDHCPManager',
            'nova.network.manager.FlatManager',
            'nova.network.manager.VlanManager',
            'nova.network.neutronv2.api.ClientWrapper',
            'nova.network.rpcapi.NetworkAPI',
            'nova.scheduler.manager.SchedulerManager',
            'nova.scheduler.rpcapi.SchedulerAPI',
            'nova.virt.libvirt.vif.LibvirtGenericVIFDriver',
            'nova.virt.libvirt.volume.volume.LibvirtBaseVolumeDriver',
        ]
        for clsname in classes:
            # give the metaclass and trace_cls() decorator a chance to patch
            # methods of the classes above
            six.reload_module(
                importutils.import_module(clsname.rsplit('.', 1)[0]))
            cls = importutils.import_class(clsname)

            for attr, obj in cls.__dict__.items():
                # only public methods are traced
                if attr.startswith('_'):
                    continue
                # only checks callables
                if not (inspect.ismethod(obj) or inspect.isfunction(obj)):
                    continue
                # osprofiler skips static methods
                if isinstance(obj, staticmethod):
                    continue

                self.assertTrue(getattr(obj, '__traced__', False), obj)
Esempio n. 33
0
 def test_web_trace_disabled(self, mock_disable, mock_enable):
     opts.set_defaults(self.conf_fixture.conf, hmac_keys="MY_KEY")
     opts.enable_web_trace(self.conf_fixture.conf)
     opts.disable_web_trace(self.conf_fixture.conf)
     self.assertEqual(0, mock_enable.call_count)
     self.assertEqual(0, mock_disable.call_count)
Esempio n. 34
0
               deprecated_reason=_('Use the http_proxy_to_wsgi middleware '
                                   'instead.'),
               help=_('The HTTP header used to determine the scheme for the '
                      'original request, even if it was removed by an SSL '
                      'terminating proxy. Typical value is '
                      '"HTTP_X_FORWARDED_PROTO".')),
]

LOG = logging.getLogger(__name__)

CONF = cfg.CONF
CONF.register_opts(bind_opts)
CONF.register_opts(socket_opts)
CONF.register_opts(eventlet_opts)
CONF.register_opts(wsgi_opts)
profiler_opts.set_defaults(CONF)

ASYNC_EVENTLET_THREAD_POOL_LIST = []

# Detect if we're running under the uwsgi server
try:
    import uwsgi
    LOG.debug('Detected running under uwsgi')
except ImportError:
    LOG.debug('Detected not running under uwsgi')
    uwsgi = None


def get_num_workers():
    """Return the configured number of workers."""
    if CONF.workers is None:
Esempio n. 35
0
from neutron.objects import exceptions as obj_exc


def set_hook(engine):
    if (profiler_opts.is_trace_enabled()
            and profiler_opts.is_db_trace_enabled()):
        osprofiler.sqlalchemy.add_tracing(sqlalchemy, engine, 'neutron.db')


context_manager = api.get_context_manager()

# TODO(ihrachys) the hook assumes options defined by osprofiler, and the only
# public function that is provided by osprofiler that will register them is
# set_defaults, that's why we call it here even though we don't need to change
# defaults
profiler_opts.set_defaults(cfg.CONF)
context_manager.append_on_engine_create(set_hook)

MAX_RETRIES = 10
LOG = logging.getLogger(__name__)


def is_retriable(e):
    if getattr(e, '_RETRY_EXCEEDED', False):
        return False
    if _is_nested_instance(
            e, (db_exc.DBDeadlock, exc.StaleDataError,
                db_exc.DBConnectionError, db_exc.DBDuplicateEntry,
                db_exc.RetryRequest, obj_exc.NeutronDbObjectDuplicateEntry)):
        return True
    # looking savepoints mangled by deadlocks. see bug/1590298 for details.
Esempio n. 36
0
                   'glance', 'heat', 'keystone', 'magnum', 'manila', 'mistral',
                   'monasca', 'neutron', 'nova', 'sahara', 'senlin', 'swift',
                   'trove', 'zaqar'):
        client_specific_group = 'clients_' + client
        yield client_specific_group, clients_opts

    yield 'clients_heat', heat_client_opts
    yield 'clients_keystone', keystone_client_opts
    yield 'clients_nova', client_http_log_debug_opts
    yield 'clients_cinder', client_http_log_debug_opts


cfg.CONF.register_group(paste_deploy_group)
cfg.CONF.register_group(auth_password_group)
cfg.CONF.register_group(revision_group)
profiler.set_defaults(cfg.CONF)

for group, opts in list_opts():
    cfg.CONF.register_opts(opts, group=group)


def _get_deployment_flavor():
    """Retrieves the paste_deploy.flavor config item.

    Item formatted appropriately for appending to the application name.
    """
    flavor = cfg.CONF.paste_deploy.flavor
    return '' if not flavor else ('-' + flavor)


def _get_deployment_config_file():
Esempio n. 37
0
    def __init__(self, argv):
        args = self._get_base_parser().parse_args(argv)
        opts.set_defaults(cfg.CONF)

        args.func(args)
Esempio n. 38
0
    def __init__(self, argv):
        args = self._get_base_parser().parse_args(argv)
        opts.set_defaults(cfg.CONF)

        args.func(args)
Esempio n. 39
0
from sqlalchemy.orm import exc


def set_hook(engine):
    if (profiler_opts.is_trace_enabled() and
            profiler_opts.is_db_trace_enabled()):
        osprofiler.sqlalchemy.add_tracing(sqlalchemy, engine, 'neutron.db')


context_manager = api.get_context_manager()

# TODO(ihrachys) the hook assumes options defined by osprofiler, and the only
# public function that is provided by osprofiler that will register them is
# set_defaults, that's why we call it here even though we don't need to change
# defaults
profiler_opts.set_defaults(cfg.CONF)
context_manager.append_on_engine_create(set_hook)


MAX_RETRIES = 10
LOG = logging.getLogger(__name__)


def is_retriable(e):
    if getattr(e, '_RETRY_EXCEEDED', False):
        return False
    if _is_nested_instance(e, (db_exc.DBDeadlock, exc.StaleDataError,
                               db_exc.DBConnectionError,
                               db_exc.DBDuplicateEntry, db_exc.RetryRequest,
                               obj_exc.NeutronDbObjectDuplicateEntry)):
        return True