Exemplo n.º 1
0
def parse_args(argv,
               default_config_files=None,
               configure_db=True,
               init_rpc=True):
    log.register_options(CONF)
    # We use the oslo.log default log levels which includes suds=INFO
    # and add only the extra levels that Nova needs
    if CONF.glance.debug:
        extra_default_log_levels = ['glanceclient=DEBUG']
    else:
        extra_default_log_levels = ['glanceclient=WARN']

    # NOTE(danms): DEBUG logging in privsep will result in some large
    # and potentially sensitive things being logged.
    extra_default_log_levels.append('oslo.privsep.daemon=INFO')

    log.set_defaults(default_log_levels=log.get_default_log_levels() +
                     extra_default_log_levels)
    rpc.set_defaults(control_exchange='nova')
    if profiler:
        profiler.set_defaults(CONF)
    config.set_middleware_defaults()

    CONF(argv[1:],
         project='nova',
         version=version.version_string(),
         default_config_files=default_config_files)

    if init_rpc:
        rpc.init(CONF)

    if configure_db:
        sqlalchemy_api.configure(CONF)
Exemplo n.º 2
0
def parse_args(argv,
               default_config_files=None,
               configure_db=True,
               init_rpc=True):
    log.register_options(CONF)
    # We use the oslo.log default log levels which includes suds=INFO
    # and add only the extra levels that Nova needs
    if CONF.glance.debug:
        extra_default_log_levels = ['glanceclient=DEBUG']
    else:
        extra_default_log_levels = ['glanceclient=WARN']
    log.set_defaults(default_log_levels=log.get_default_log_levels() +
                     extra_default_log_levels)
    rpc.set_defaults(control_exchange='nova')
    config.set_middleware_defaults()

    CONF(argv[1:],
         project='nova',
         version=version.version_string(),
         default_config_files=default_config_files)

    if init_rpc:
        rpc.init(CONF)

    if configure_db:
        sqlalchemy_api.configure(CONF)
Exemplo n.º 3
0
def parse_args(argv, default_config_files=None, configure_db=True,
               init_rpc=True):
    log.register_options(CONF)
    # We use the oslo.log default log levels which includes suds=INFO
    # and add only the extra levels that Nova needs
    if CONF.glance.debug:
        extra_default_log_levels = ['glanceclient=DEBUG']
    else:
        extra_default_log_levels = ['glanceclient=WARN']

    # NOTE(danms): DEBUG logging in privsep will result in some large
    # and potentially sensitive things being logged.
    extra_default_log_levels.append('oslo.privsep.daemon=INFO')

    log.set_defaults(default_log_levels=log.get_default_log_levels() +
                     extra_default_log_levels)
    rpc.set_defaults(control_exchange='nova')
    if profiler:
        profiler.set_defaults(CONF)
    config.set_middleware_defaults()

    CONF(argv[1:],
         project='nova',
         version=version.version_string(),
         default_config_files=default_config_files)

    if init_rpc:
        rpc.init(CONF)

    if configure_db:
        sqlalchemy_api.configure(CONF)
        placement_db.configure(CONF)
Exemplo n.º 4
0
def parse_args(argv,
               default_config_files=None,
               configure_db=True,
               init_rpc=True):
    log.register_options(CONF)

    # NOTE(sean-k-mooney): this filter addresses bug #1825584
    # https://bugs.launchpad.net/nova/+bug/1825584
    # eventlet monkey-patching breaks AMQP heartbeat on uWSGI
    rabbit_logger = logging.getLogger('oslo.messaging._drivers.impl_rabbit')
    rabbit_logger.addFilter(rabbit_heartbeat_filter)

    set_lib_defaults()
    if profiler:
        profiler.set_defaults(CONF)

    CONF(argv[1:],
         project='nova',
         version=version.version_string(),
         default_config_files=default_config_files)

    if init_rpc:
        rpc.init(CONF)

    if configure_db:
        main_db_api.configure(CONF)
        api_db_api.configure(CONF)
Exemplo n.º 5
0
def parse_args(argv,
               default_config_files=None,
               configure_db=True,
               init_rpc=True):
    log.register_options(CONF)
    # We use the oslo.log default log levels which includes suds=INFO
    # and add only the extra levels that Nova needs
    log.set_defaults(default_log_levels=log.get_default_log_levels() +
                     _EXTRA_DEFAULT_LOG_LEVELS)
    options.set_defaults(CONF,
                         connection=_DEFAULT_SQL_CONNECTION,
                         sqlite_db='nova.sqlite')
    rpc.set_defaults(control_exchange='nova')
    cache.configure(CONF)
    debugger.register_cli_opts()
    config.set_middleware_defaults()

    CONF(argv[1:],
         project='nova',
         version=version.version_string(),
         default_config_files=default_config_files)

    if init_rpc:
        rpc.init(CONF)

    if configure_db:
        sqlalchemy_api.configure(CONF)
Exemplo n.º 6
0
def parse_args(argv, default_config_files=None, configure_db=True,
               init_rpc=True):
    log.register_options(CONF)
    # We use the oslo.log default log levels which includes suds=INFO
    # and add only the extra levels that Nova needs
    if CONF.glance.debug:
        extra_default_log_levels = ['glanceclient=DEBUG']
    else:
        extra_default_log_levels = ['glanceclient=WARN']
    log.set_defaults(default_log_levels=log.get_default_log_levels() +
                     extra_default_log_levels)
    rpc.set_defaults(control_exchange='nova')
    if profiler:
        profiler.set_defaults(CONF)
    config.set_middleware_defaults()

    CONF(argv[1:],
         project='nova',
         version=version.version_string(),
         default_config_files=default_config_files)

    if init_rpc:
        rpc.init(CONF)

    if configure_db:
        sqlalchemy_api.configure(CONF)
Exemplo n.º 7
0
    def test_notification_format_affects_notification_driver(self,
                                                             mock_notifier,
                                                             mock_noti_trans,
                                                             mock_transport):
        conf = mock.Mock()

        cases = {
            'unversioned': [
                mock.call(mock.ANY, serializer=mock.ANY),
                mock.call(mock.ANY, serializer=mock.ANY, driver='noop')],
            'both': [
                mock.call(mock.ANY, serializer=mock.ANY),
                mock.call(mock.ANY, serializer=mock.ANY,
                          topics=['versioned_notifications'])],
            'versioned': [
                mock.call(mock.ANY, serializer=mock.ANY, driver='noop'),
                mock.call(mock.ANY, serializer=mock.ANY,
                          topics=['versioned_notifications'])]}

        for config in cases:
            mock_notifier.reset_mock()
            mock_notifier.side_effect = ['first', 'second']
            conf.notification_format = config
            rpc.init(conf)
            self.assertEqual(cases[config], mock_notifier.call_args_list)
            self.assertEqual('first', rpc.LEGACY_NOTIFIER)
            self.assertEqual('second', rpc.NOTIFIER)
Exemplo n.º 8
0
    def test_notification_format_affects_notification_driver(self, mock_notifier, mock_transport):
        conf = mock.Mock()

        cases = {
            "unversioned": [
                mock.call(mock.ANY, serializer=mock.ANY),
                mock.call(mock.ANY, serializer=mock.ANY, driver="noop"),
            ],
            "both": [
                mock.call(mock.ANY, serializer=mock.ANY),
                mock.call(mock.ANY, serializer=mock.ANY, topic="versioned_notifications"),
            ],
            "versioned": [
                mock.call(mock.ANY, serializer=mock.ANY, driver="noop"),
                mock.call(mock.ANY, serializer=mock.ANY, topic="versioned_notifications"),
            ],
        }

        for config in cases:
            mock_notifier.reset_mock()
            mock_notifier.side_effect = ["first", "second"]
            conf.notification_format = config
            rpc.init(conf)
            self.assertEqual(cases[config], mock_notifier.call_args_list)
            self.assertEqual("first", rpc.LEGACY_NOTIFIER)
            self.assertEqual("second", rpc.NOTIFIER)
Exemplo n.º 9
0
def init(args, **kwargs):
    product_name = "hyperagent"
    logging.register_options(cfg.CONF)
    logging.setup(cfg.CONF, product_name)
    cfg.CONF(args=args, project=product_name,
             version='%%(prog)s %s' % version.version_info.release_string(),
             **kwargs)
    from nova import rpc as n_rpc
    n_rpc.init(cfg.CONF)
Exemplo n.º 10
0
 def setUp(self):
     super(RPCFixture, self).setUp()
     self.addCleanup(rpc.cleanup)
     rpc.add_extra_exmods(*self.exmods)
     self.addCleanup(rpc.clear_extra_exmods)
     self.messaging_conf = messaging_conffixture.ConfFixture(CONF)
     self.messaging_conf.transport_driver = 'fake'
     self.useFixture(self.messaging_conf)
     rpc.init(CONF)
Exemplo n.º 11
0
def main():

    lock_filename = '/tmp/locking.lock'
    lock_file = open(lock_filename, 'w')
    try:
        fcntl.lockf(lock_file, fcntl.LOCK_EX | fcntl.LOCK_NB)
    except IOError:
        print('Cannot lock: ' + lock_filename)
        sys.exit(1)

    if len(sys.argv) < 3 or sys.argv[1] != '--config-file':
        usage()
        exit(1)
    detection_only = False
    if '--detection-only' in sys.argv:
        detection_only = True
        sys.argv.remove('--detection-only')

    out, err = utils.execute('which', 'multipath', check_exit_code=False)
    if 'multipath' not in out:
        print('Info: Multipath tools not installed. No cleanup need be done.')
        exit(0)

    multipath_flush_on_last_del = False
    multipath_conf_path = "/etc/multipath.conf"
    if os.path.exists(multipath_conf_path):
        flush_on_last_del_yes = re.compile(r'\s*flush_on_last_del.*yes')
        for line in open(multipath_conf_path, "r"):
            if flush_on_last_del_yes.match(line):
                multipath_flush_on_last_del = True
                break
    if not multipath_flush_on_last_del:
        print("Warning: 'flush_on_last_del yes' is not seen in"
              " /etc/multipath.conf."
              " 'map in use' failure may show up during cleanup.")

    CONF(sys.argv[1:])

    rpc.set_defaults(control_exchange='nova')
    rpc.init(CONF)

    utils.monkey_patch()
    objects.register_all()
    objects_base.NovaObject.indirection_api = \
        conductor_rpcapi.ConductorAPI()

    # connect_volume and disconnect_volume in nova/virt/libvirt/volume.py
    # need be adjusted to take the same 'external=True' lock for
    # synchronization
    @utils.synchronized('connect_volume', external=True)
    def do_cleanup(detection_only):
        cleaner = FaultyDevicesCleaner(detection_only)
        cleaner.cleanup()

    do_cleanup(detection_only)

    os.unlink('/tmp/locking.lock')
 def setUp(self):
     super(RPCFixture, self).setUp()
     self.addCleanup(rpc.cleanup)
     rpc.add_extra_exmods(*self.exmods)
     self.addCleanup(rpc.clear_extra_exmods)
     self.messaging_conf = messaging_conffixture.ConfFixture(CONF)
     self.messaging_conf.transport_driver = 'fake'
     self.useFixture(self.messaging_conf)
     rpc.init(CONF)
Exemplo n.º 13
0
def parse_args(argv, default_config_files=None):
    db_session.set_defaults(sql_connection=_DEFAULT_SQL_CONNECTION,
                            sqlite_db='nova.sqlite')
    rpc.set_defaults(control_exchange='nova')
    cfg.CONF(argv[1:],
             project='nova',
             version=version.version_string(),
             default_config_files=default_config_files)
    rpc.init(cfg.CONF)
Exemplo n.º 14
0
def parse_args(argv, default_config_files=None):
    options.set_defaults(CONF, connection=_DEFAULT_SQL_CONNECTION,
                         sqlite_db='nova.sqlite')
    rpc.set_defaults(control_exchange='nova')
    debugger.register_cli_opts()
    CONF(argv[1:],
         project='nova',
         version=version.version_string(),
         default_config_files=default_config_files)
    rpc.init(CONF)
Exemplo n.º 15
0
def parse_args(argv, default_config_files=None):
    options.set_defaults(CONF, connection=_DEFAULT_SQL_CONNECTION,
                         sqlite_db='nova.sqlite')
    rpc.set_defaults(control_exchange='nova')
    debugger.register_cli_opts()
    CONF(argv[1:],
         project='nova',
         version=version.version_string(),
         default_config_files=default_config_files)
    rpc.init(CONF)
Exemplo n.º 16
0
    def _test_init(self,
                   notification_format,
                   expected_driver_topic_kwargs,
                   mock_notif,
                   mock_noti_trans,
                   mock_ser,
                   mock_exmods,
                   mock_NOTIFIER,
                   mock_LEGACY_NOTIFIER,
                   mock_NOTIFICATION_TRANSPORT,
                   mock_TRANSPORT,
                   versioned_notifications_topics=None):

        if not versioned_notifications_topics:
            versioned_notifications_topics = ['versioned_notifications']

        self.flags(
            notification_format=notification_format,
            versioned_notifications_topics=versioned_notifications_topics,
            group='notifications')

        legacy_notifier = mock.Mock()
        notifier = mock.Mock()
        notif_transport = mock.Mock()
        transport = mock.Mock()
        serializer = mock.Mock()

        mock_exmods.return_value = ['foo']
        mock_noti_trans.return_value = notif_transport
        mock_ser.return_value = serializer
        mock_notif.side_effect = [legacy_notifier, notifier]

        with mock.patch.object(rpc, 'create_transport') as create_transport, \
                mock.patch.object(rpc, 'get_transport_url') as get_url:
            create_transport.return_value = transport
            rpc.init(CONF)
            create_transport.assert_called_once_with(get_url.return_value)

        self.assertTrue(mock_exmods.called)
        self.assertIsNotNone(mock_TRANSPORT)
        self.assertIsNotNone(mock_LEGACY_NOTIFIER)
        self.assertIsNotNone(mock_NOTIFIER)
        self.assertEqual(legacy_notifier, rpc.LEGACY_NOTIFIER)
        self.assertEqual(notifier, rpc.NOTIFIER)

        expected_calls = []
        for kwargs in expected_driver_topic_kwargs:
            expected_kwargs = {'serializer': serializer}
            expected_kwargs.update(kwargs)
            expected_calls.append(((notif_transport, ), expected_kwargs))

        self.assertEqual(
            expected_calls, mock_notif.call_args_list,
            "The calls to messaging.Notifier() did not create "
            "the legacy and versioned notifiers properly.")
Exemplo n.º 17
0
def parse_args(argv, default_config_files=None):
    options.set_defaults(sql_connection=_DEFAULT_SQL_CONNECTION,
                         sqlite_db='nova.sqlite')
    rpc.set_defaults(control_exchange='nova')
    nova_default_log_levels = (log.DEFAULT_LOG_LEVELS +
            ["keystonemiddleware=WARN", "routes.middleware=WARN"])
    log.set_defaults(default_log_levels=nova_default_log_levels)
    debugger.register_cli_opts()
    cfg.CONF(argv[1:],
             project='nova',
             version=version.version_string(),
             default_config_files=default_config_files)
    rpc.init(cfg.CONF)
Exemplo n.º 18
0
def parse_args(argv, default_config_files=None):
    options.set_defaults(sql_connection=_DEFAULT_SQL_CONNECTION,
                         sqlite_db='nova.sqlite')
    rpc.set_defaults(control_exchange='nova')
    nova_default_log_levels = (
        log.DEFAULT_LOG_LEVELS +
        ["keystonemiddleware=WARN", "routes.middleware=WARN"])
    log.set_defaults(default_log_levels=nova_default_log_levels)
    debugger.register_cli_opts()
    cfg.CONF(argv[1:],
             project='nova',
             version=version.version_string(),
             default_config_files=default_config_files)
    rpc.init(cfg.CONF)
Exemplo n.º 19
0
def parse_args(argv, default_config_files=None, configure_db=True):
    log.set_defaults(_DEFAULT_LOGGING_CONTEXT_FORMAT, _DEFAULT_LOG_LEVELS)
    log.register_options(CONF)
    options.set_defaults(CONF, connection=_DEFAULT_SQL_CONNECTION,
                         sqlite_db='nova.sqlite')
    rpc.set_defaults(control_exchange='nova')
    debugger.register_cli_opts()
    CONF(argv[1:],
         project='nova',
         version=version.version_string(),
         default_config_files=default_config_files)
    rpc.init(CONF)

    if configure_db:
        sqlalchemy_api.configure(CONF)
Exemplo n.º 20
0
def parse_args(argv, default_config_files=None, configure_db=True):
    log.set_defaults(_DEFAULT_LOGGING_CONTEXT_FORMAT, _DEFAULT_LOG_LEVELS)
    log.register_options(CONF)
    options.set_defaults(CONF,
                         connection=_DEFAULT_SQL_CONNECTION,
                         sqlite_db='nova.sqlite')
    rpc.set_defaults(control_exchange='nova')
    debugger.register_cli_opts()
    CONF(argv[1:],
         project='nova',
         version=version.version_string(),
         default_config_files=default_config_files)
    rpc.init(CONF)

    if configure_db:
        sqlalchemy_api.configure(CONF)
Exemplo n.º 21
0
    def _test_init(self, notification_format, expected_driver_topic_kwargs,
            mock_notif, mock_noti_trans, mock_ser, mock_exmods,
            mock_NOTIFIER, mock_LEGACY_NOTIFIER, mock_NOTIFICATION_TRANSPORT,
            mock_TRANSPORT,
            versioned_notifications_topics=None):

        if not versioned_notifications_topics:
            versioned_notifications_topics = ['versioned_notifications']

        self.flags(
            notification_format=notification_format,
            versioned_notifications_topics=versioned_notifications_topics,
            group='notifications')

        legacy_notifier = mock.Mock()
        notifier = mock.Mock()
        notif_transport = mock.Mock()
        transport = mock.Mock()
        serializer = mock.Mock()

        mock_exmods.return_value = ['foo']
        mock_noti_trans.return_value = notif_transport
        mock_ser.return_value = serializer
        mock_notif.side_effect = [legacy_notifier, notifier]

        with mock.patch.object(rpc, 'create_transport') as create_transport, \
                mock.patch.object(rpc, 'get_transport_url') as get_url:
            create_transport.return_value = transport
            rpc.init(CONF)
            create_transport.assert_called_once_with(get_url.return_value)

        self.assertTrue(mock_exmods.called)
        self.assertIsNotNone(mock_TRANSPORT)
        self.assertIsNotNone(mock_LEGACY_NOTIFIER)
        self.assertIsNotNone(mock_NOTIFIER)
        self.assertEqual(legacy_notifier, rpc.LEGACY_NOTIFIER)
        self.assertEqual(notifier, rpc.NOTIFIER)

        expected_calls = []
        for kwargs in expected_driver_topic_kwargs:
            expected_kwargs = {'serializer': serializer}
            expected_kwargs.update(kwargs)
            expected_calls.append(((notif_transport,), expected_kwargs))

        self.assertEqual(expected_calls, mock_notif.call_args_list,
                         "The calls to messaging.Notifier() did not create "
                         "the legacy and versioned notifiers properly.")
Exemplo n.º 22
0
 def setUp(self):
     super(RPCFixture, self).setUp()
     self.addCleanup(rpc.cleanup)
     rpc.add_extra_exmods(*self.exmods)
     self.addCleanup(rpc.clear_extra_exmods)
     self.messaging_conf = messaging_conffixture.ConfFixture(CONF)
     self.messaging_conf.transport_driver = 'fake'
     self.useFixture(self.messaging_conf)
     self.useFixture(fixtures.MonkeyPatch(
         'nova.rpc.create_transport', self._fake_create_transport))
     # NOTE(danms): Execute the init with get_transport_url() as None,
     # instead of the parsed TransportURL(None) so that we can cache
     # it as it will be called later if the default is requested by
     # one of our mq-switching methods.
     with mock.patch('nova.rpc.get_transport_url') as mock_gtu:
         mock_gtu.return_value = None
         rpc.init(CONF)
Exemplo n.º 23
0
 def setUp(self):
     super(RPCFixture, self).setUp()
     self.addCleanup(rpc.cleanup)
     rpc.add_extra_exmods(*self.exmods)
     self.addCleanup(rpc.clear_extra_exmods)
     self.messaging_conf = messaging_conffixture.ConfFixture(CONF)
     self.messaging_conf.transport_driver = 'fake'
     self.useFixture(self.messaging_conf)
     self.useFixture(fixtures.MonkeyPatch(
         'nova.rpc.create_transport', self._fake_create_transport))
     # NOTE(danms): Execute the init with get_transport_url() as None,
     # instead of the parsed TransportURL(None) so that we can cache
     # it as it will be called later if the default is requested by
     # one of our mq-switching methods.
     with mock.patch('nova.rpc.get_transport_url') as mock_gtu:
         mock_gtu.return_value = None
         rpc.init(CONF)
Exemplo n.º 24
0
 def setUp(self):
     super(RPCFixture, self).setUp()
     self.addCleanup(rpc.cleanup)
     rpc.add_extra_exmods(*self.exmods)
     self.addCleanup(rpc.clear_extra_exmods)
     self.messaging_conf = messaging_conffixture.ConfFixture(CONF)
     self.messaging_conf.transport_driver = 'fake'
     self.useFixture(self.messaging_conf)
     rpc.init(CONF)
     # NOTE(sdague): the polling behavior in oslo.messaging <=
     # 1.5.1 fake driver is less than optimal, as by default the
     # polling will wait for a full second even if there are no
     # events available. Turning this down speeds up the tests
     # substantially.
     self.useFixture(
         fixtures.MonkeyPatch('oslo.messaging._executors.base.POLL_TIMEOUT',
                              0.001))
Exemplo n.º 25
0
 def setUp(self):
     super(RPCFixture, self).setUp()
     self.addCleanup(rpc.cleanup)
     rpc.add_extra_exmods(*self.exmods)
     self.addCleanup(rpc.clear_extra_exmods)
     self.messaging_conf = messaging_conffixture.ConfFixture(CONF)
     self.messaging_conf.transport_driver = 'fake'
     self.useFixture(self.messaging_conf)
     rpc.init(CONF)
     # NOTE(sdague): the polling behavior in oslo.messaging <=
     # 1.5.1 fake driver is less than optimal, as by default the
     # polling will wait for a full second even if there are no
     # events available. Turning this down speeds up the tests
     # substantially.
     self.useFixture(fixtures.MonkeyPatch(
         'oslo.messaging._executors.base.POLL_TIMEOUT',
         0.001))
def main():
    if len(sys.argv) < 3 or sys.argv[1] != '--config-file':
        usage()
        exit(1)
    detection_only = False
    if '--detection-only' in sys.argv:
        detection_only = True
        sys.argv.remove('--detection-only')

    out, err = utils.execute('which', 'multipath', check_exit_code=False)
    if 'multipath' not in out:
        print('Info: Multipath tools not installed. No cleanup need be done.')
        exit(0)

    multipath_flush_on_last_del = False
    multipath_conf_path = "/etc/multipath.conf"
    if os.path.exists(multipath_conf_path):
        flush_on_last_del_yes = re.compile(r'\s*flush_on_last_del.*yes')
        for line in open(multipath_conf_path, "r"):
            if flush_on_last_del_yes.match(line):
                multipath_flush_on_last_del = True
                break
    if not multipath_flush_on_last_del:
        print("Warning: 'flush_on_last_del yes' is not seen in"
              " /etc/multipath.conf."
              " 'map in use' failure may show up during cleanup.")

    CONF(sys.argv[1:])

    rpc.set_defaults(control_exchange='nova')
    rpc.init(CONF)

    utils.monkey_patch()
    objects.register_all()
    objects_base.NovaObject.indirection_api = \
        conductor_rpcapi.ConductorAPI()

    # connect_volume and disconnect_volume in nova/virt/libvirt/volume.py
    # need be adjusted to take the same 'external=True' lock for
    # synchronization
    @utils.synchronized('connect_volume', external=True)
    def do_cleanup(detection_only):
        cleaner = FaultyDevicesCleaner(detection_only)
        cleaner.cleanup()
    do_cleanup(detection_only)
Exemplo n.º 27
0
def parse_args(argv, default_config_files=None, configure_db=True,
               init_rpc=True):
    log.register_options(CONF)
    # We use the oslo.log default log levels which includes suds=INFO
    # and add only the extra levels that Nova needs
    log.set_defaults(default_log_levels=log.get_default_log_levels() +
                     _EXTRA_DEFAULT_LOG_LEVELS)
    rpc.set_defaults(control_exchange='nova')
    config.set_middleware_defaults()

    CONF(argv[1:],
         project='nova',
         version=version.version_string(),
         default_config_files=default_config_files)

    if init_rpc:
        rpc.init(CONF)

    if configure_db:
        sqlalchemy_api.configure(CONF)
Exemplo n.º 28
0
    def _test_init(self, mock_notif, mock_noti_trans, mock_trans, mock_ser,
                   mock_exmods, notif_format, expected_driver_topic_kwargs):
        legacy_notifier = mock.Mock()
        notifier = mock.Mock()
        notif_transport = mock.Mock()
        transport = mock.Mock()
        serializer = mock.Mock()
        conf = mock.Mock()

        conf.notification_format = notif_format
        mock_exmods.return_value = ['foo']
        mock_trans.return_value = transport
        mock_noti_trans.return_value = notif_transport
        mock_ser.return_value = serializer
        mock_notif.side_effect = [legacy_notifier, notifier]

        rpc.init(conf)

        mock_exmods.assert_called_once_with()
        mock_trans.assert_called_once_with(conf,
                                           allowed_remote_exmods=['foo'],
                                           aliases=rpc.TRANSPORT_ALIASES)
        self.assertIsNotNone(rpc.TRANSPORT)
        self.assertIsNotNone(rpc.LEGACY_NOTIFIER)
        self.assertIsNotNone(rpc.NOTIFIER)
        self.assertEqual(legacy_notifier, rpc.LEGACY_NOTIFIER)
        self.assertEqual(notifier, rpc.NOTIFIER)

        expected_calls = []
        for kwargs in expected_driver_topic_kwargs:
            expected_kwargs = {'serializer': serializer}
            expected_kwargs.update(kwargs)
            expected_calls.append(((notif_transport, ), expected_kwargs))

        self.assertEqual(
            expected_calls, mock_notif.call_args_list,
            "The calls to messaging.Notifier() did not create "
            "the legacy and versioned notifiers properly.")
Exemplo n.º 29
0
def parse_args(argv, default_config_files=None, configure_db=True,
               init_rpc=True):
    log.register_options(CONF)
    # We use the oslo.log default log levels which includes suds=INFO
    # and add only the extra levels that Nova needs
    if CONF.glance.debug:
        extra_default_log_levels = ['glanceclient=DEBUG']
    else:
        extra_default_log_levels = ['glanceclient=WARN']

    # NOTE(sean-k-mooney): this filter addresses bug #1825584
    # https://bugs.launchpad.net/nova/+bug/1825584
    # eventlet monkey-patching breaks AMQP heartbeat on uWSGI
    rabbit_logger = logging.getLogger('oslo.messaging._drivers.impl_rabbit')
    rabbit_logger.addFilter(rabbit_heartbeat_filter)

    # NOTE(danms): DEBUG logging in privsep will result in some large
    # and potentially sensitive things being logged.
    extra_default_log_levels.append('oslo.privsep.daemon=INFO')

    log.set_defaults(default_log_levels=log.get_default_log_levels() +
                     extra_default_log_levels)
    rpc.set_defaults(control_exchange='nova')
    if profiler:
        profiler.set_defaults(CONF)
    middleware.set_defaults()

    CONF(argv[1:],
         project='nova',
         version=version.version_string(),
         default_config_files=default_config_files)

    if init_rpc:
        rpc.init(CONF)

    if configure_db:
        sqlalchemy_api.configure(CONF)
Exemplo n.º 30
0
    def _test_init(self, mock_notif, mock_noti_trans, mock_trans, mock_ser,
                   mock_exmods, notif_format, expected_driver_topic_kwargs):
        legacy_notifier = mock.Mock()
        notifier = mock.Mock()
        notif_transport = mock.Mock()
        transport = mock.Mock()
        serializer = mock.Mock()
        conf = mock.Mock()

        conf.notification_format = notif_format
        mock_exmods.return_value = ['foo']
        mock_trans.return_value = transport
        mock_noti_trans.return_value = notif_transport
        mock_ser.return_value = serializer
        mock_notif.side_effect = [legacy_notifier, notifier]

        rpc.init(conf)

        mock_exmods.assert_called_once_with()
        mock_trans.assert_called_once_with(conf,
                                           allowed_remote_exmods=['foo'],
                                           aliases=rpc.TRANSPORT_ALIASES)
        self.assertIsNotNone(rpc.TRANSPORT)
        self.assertIsNotNone(rpc.LEGACY_NOTIFIER)
        self.assertIsNotNone(rpc.NOTIFIER)
        self.assertEqual(legacy_notifier, rpc.LEGACY_NOTIFIER)
        self.assertEqual(notifier, rpc.NOTIFIER)

        expected_calls = []
        for kwargs in expected_driver_topic_kwargs:
            expected_kwargs = {'serializer': serializer}
            expected_kwargs.update(kwargs)
            expected_calls.append(((notif_transport,), expected_kwargs))

        self.assertEqual(expected_calls, mock_notif.call_args_list,
                         "The calls to messaging.Notifier() did not create "
                         "the legacy and versioned notifiers properly.")
Exemplo n.º 31
0
    def setUp(self):
        """Run before each test method to initialize test environment."""
        super(TestCase, self).setUp()
        self.useFixture(
            nova_fixtures.Timeout(os.environ.get('OS_TEST_TIMEOUT', 0),
                                  self.TIMEOUT_SCALING_FACTOR))

        self.useFixture(fixtures.NestedTempfile())
        self.useFixture(fixtures.TempHomeDir())
        self.useFixture(nova_fixtures.TranslationFixture())
        self.useFixture(log_fixture.get_logging_handle_error_fixture())

        self.useFixture(nova_fixtures.OutputStreamCapture())

        self.useFixture(nova_fixtures.StandardLogging())

        rpc.add_extra_exmods('nova.test')
        self.addCleanup(rpc.clear_extra_exmods)
        self.addCleanup(rpc.cleanup)

        # NOTE(sdague): because of the way we were using the lock
        # wrapper we eneded up with a lot of tests that started
        # relying on global external locking being set up for them. We
        # consider all of these to be *bugs*. Tests should not require
        # global external locking, or if they do, they should
        # explicitly set it up themselves.
        #
        # The following REQUIRES_LOCKING class parameter is provided
        # as a bridge to get us there. No new tests should be added
        # that require it, and existing classes and tests should be
        # fixed to not need it.
        if self.REQUIRES_LOCKING:
            lock_path = self.useFixture(fixtures.TempDir()).path
            self.fixture = self.useFixture(
                config_fixture.Config(lockutils.CONF))
            self.fixture.config(lock_path=lock_path, group='oslo_concurrency')

        self.useFixture(conf_fixture.ConfFixture(CONF))

        self.messaging_conf = messaging_conffixture.ConfFixture(CONF)
        self.messaging_conf.transport_driver = 'fake'
        self.useFixture(self.messaging_conf)

        rpc.init(CONF)

        if self.USES_DB:
            self.useFixture(nova_fixtures.Database())

        # NOTE(danms): Make sure to reset us back to non-remote objects
        # for each test to avoid interactions. Also, backup the object
        # registry.
        objects_base.NovaObject.indirection_api = None
        self._base_test_obj_backup = copy.copy(
            objects_base.NovaObject._obj_classes)
        self.addCleanup(self._restore_obj_registry)

        # NOTE(mnaser): All calls to utils.is_neutron() are cached in
        # nova.utils._IS_NEUTRON.  We set it to None to avoid any
        # caching of that value.
        utils._IS_NEUTRON = None

        mox_fixture = self.useFixture(moxstubout.MoxStubout())
        self.mox = mox_fixture.mox
        self.stubs = mox_fixture.stubs
        self.addCleanup(self._clear_attrs)
        self.useFixture(fixtures.EnvironmentVariable('http_proxy'))
        self.policy = self.useFixture(policy_fixture.PolicyFixture())
Exemplo n.º 32
0
def parse_config(*args, **kwargs):
    rpc.set_defaults(control_exchange='nova')
    common_config.parse_power_config(*args, **kwargs)
    rpc.init(CONF)
Exemplo n.º 33
0
 def _test(get_url, create_transport):
     create_transport.return_value = transport
     rpc.init(conf)
     create_transport.assert_called_once_with(get_url.return_value)
Exemplo n.º 34
0
    def setUp(self):
        """Run before each test method to initialize test environment."""
        super(TestCase, self).setUp()
        test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0)
        try:
            test_timeout = int(test_timeout)
        except ValueError:
            # If timeout value is invalid do not set a timeout.
            test_timeout = 0

        if self.TIMEOUT_SCALING_FACTOR >= 0:
            test_timeout *= self.TIMEOUT_SCALING_FACTOR
        else:
            raise ValueError('TIMEOUT_SCALING_FACTOR value must be >= 0')

        if test_timeout > 0:
            self.useFixture(fixtures.Timeout(test_timeout, gentle=True))
        self.useFixture(fixtures.NestedTempfile())
        self.useFixture(fixtures.TempHomeDir())
        self.useFixture(TranslationFixture())
        self.useFixture(log_fixture.get_logging_handle_error_fixture())

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

        rpc.add_extra_exmods('nova.test')
        self.addCleanup(rpc.clear_extra_exmods)
        self.addCleanup(rpc.cleanup)

        # set root logger to debug
        root = logging.getLogger()
        root.setLevel(logging.DEBUG)

        # supports collecting debug level for local runs
        if os.environ.get('OS_DEBUG') in _TRUE_VALUES:
            level = logging.DEBUG
        else:
            level = logging.INFO

        # Collect logs
        fs = '%(asctime)s %(levelname)s [%(name)s] %(message)s'
        self.useFixture(fixtures.FakeLogger(format=fs, level=None))
        root.handlers[0].setLevel(level)

        if level > logging.DEBUG:
            # Just attempt to format debug level logs, but don't save them
            handler = NullHandler()
            self.useFixture(fixtures.LogHandler(handler, nuke_handlers=False))
            handler.setLevel(logging.DEBUG)

        self.useFixture(conf_fixture.ConfFixture(CONF))

        self.messaging_conf = messaging_conffixture.ConfFixture(CONF)
        self.messaging_conf.transport_driver = 'fake'
        self.useFixture(self.messaging_conf)

        rpc.init(CONF)

        if self.USES_DB:
            global _DB_CACHE
            if not _DB_CACHE:
                _DB_CACHE = Database(session,
                                     migration,
                                     sql_connection=CONF.database.connection,
                                     sqlite_db=CONF.database.sqlite_db,
                                     sqlite_clean_db=CONF.sqlite_clean_db)

            self.useFixture(_DB_CACHE)

        # NOTE(danms): Make sure to reset us back to non-remote objects
        # for each test to avoid interactions. Also, backup the object
        # registry.
        objects_base.NovaObject.indirection_api = None
        self._base_test_obj_backup = copy.copy(
            objects_base.NovaObject._obj_classes)
        self.addCleanup(self._restore_obj_registry)

        # NOTE(mnaser): All calls to utils.is_neutron() are cached in
        # nova.utils._IS_NEUTRON.  We set it to None to avoid any
        # caching of that value.
        utils._IS_NEUTRON = None

        mox_fixture = self.useFixture(moxstubout.MoxStubout())
        self.mox = mox_fixture.mox
        self.stubs = mox_fixture.stubs
        self.addCleanup(self._clear_attrs)
        self.useFixture(fixtures.EnvironmentVariable('http_proxy'))
        self.policy = self.useFixture(policy_fixture.PolicyFixture())
        CONF.set_override('fatal_exception_format_errors', True)
        CONF.set_override('enabled', True, 'osapi_v3')
        CONF.set_override('force_dhcp_release', False)
        CONF.set_override('periodic_enable', False)
Exemplo n.º 35
0
    def setUp(self):
        """Run before each test method to initialize test environment."""
        super(TestCase, self).setUp()
        self.useFixture(nova_fixtures.Timeout(
            os.environ.get('OS_TEST_TIMEOUT', 0),
            self.TIMEOUT_SCALING_FACTOR))

        self.useFixture(fixtures.NestedTempfile())
        self.useFixture(fixtures.TempHomeDir())
        self.useFixture(nova_fixtures.TranslationFixture())
        self.useFixture(log_fixture.get_logging_handle_error_fixture())

        self.useFixture(nova_fixtures.OutputStreamCapture())

        self.useFixture(nova_fixtures.StandardLogging())

        rpc.add_extra_exmods('nova.test')
        self.addCleanup(rpc.clear_extra_exmods)
        self.addCleanup(rpc.cleanup)

        # NOTE(sdague): because of the way we were using the lock
        # wrapper we eneded up with a lot of tests that started
        # relying on global external locking being set up for them. We
        # consider all of these to be *bugs*. Tests should not require
        # global external locking, or if they do, they should
        # explicitly set it up themselves.
        #
        # The following REQUIRES_LOCKING class parameter is provided
        # as a bridge to get us there. No new tests should be added
        # that require it, and existing classes and tests should be
        # fixed to not need it.
        if self.REQUIRES_LOCKING:
            lock_path = self.useFixture(fixtures.TempDir()).path
            self.fixture = self.useFixture(
                config_fixture.Config(lockutils.CONF))
            self.fixture.config(lock_path=lock_path,
                                group='oslo_concurrency')

        self.useFixture(conf_fixture.ConfFixture(CONF))

        self.messaging_conf = messaging_conffixture.ConfFixture(CONF)
        self.messaging_conf.transport_driver = 'fake'
        self.useFixture(self.messaging_conf)

        rpc.init(CONF)

        if self.USES_DB:
            self.useFixture(nova_fixtures.Database())

        # NOTE(danms): Make sure to reset us back to non-remote objects
        # for each test to avoid interactions. Also, backup the object
        # registry.
        objects_base.NovaObject.indirection_api = None
        self._base_test_obj_backup = copy.copy(
            objects_base.NovaObject._obj_classes)
        self.addCleanup(self._restore_obj_registry)

        # NOTE(mnaser): All calls to utils.is_neutron() are cached in
        # nova.utils._IS_NEUTRON.  We set it to None to avoid any
        # caching of that value.
        utils._IS_NEUTRON = None

        mox_fixture = self.useFixture(moxstubout.MoxStubout())
        self.mox = mox_fixture.mox
        self.stubs = mox_fixture.stubs
        self.addCleanup(self._clear_attrs)
        self.useFixture(fixtures.EnvironmentVariable('http_proxy'))
        self.policy = self.useFixture(policy_fixture.PolicyFixture())
Exemplo n.º 36
0
Arquivo: test.py Projeto: EdLeafe/nova
    def setUp(self):
        """Run before each test method to initialize test environment."""
        super(TestCase, self).setUp()
        self._setup_timeouts()

        self.useFixture(fixtures.NestedTempfile())
        self.useFixture(fixtures.TempHomeDir())
        self.useFixture(TranslationFixture())
        self.useFixture(log_fixture.get_logging_handle_error_fixture())

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

        rpc.add_extra_exmods('nova.test')
        self.addCleanup(rpc.clear_extra_exmods)
        self.addCleanup(rpc.cleanup)

        self._setup_logging()

        # NOTE(sdague): because of the way we were using the lock
        # wrapper we eneded up with a lot of tests that started
        # relying on global external locking being set up for them. We
        # consider all of these to be *bugs*. Tests should not require
        # global external locking, or if they do, they should
        # explicitly set it up themselves.
        #
        # The following REQUIRES_LOCKING class parameter is provided
        # as a bridge to get us there. No new tests should be added
        # that require it, and existing classes and tests should be
        # fixed to not need it.
        if self.REQUIRES_LOCKING:
            lock_path = self.useFixture(fixtures.TempDir()).path
            self.fixture = self.useFixture(
                config_fixture.Config(lockutils.CONF))
            self.fixture.config(lock_path=lock_path,
                                group='oslo_concurrency')

        self.useFixture(conf_fixture.ConfFixture(CONF))

        self.messaging_conf = messaging_conffixture.ConfFixture(CONF)
        self.messaging_conf.transport_driver = 'fake'
        self.useFixture(self.messaging_conf)

        rpc.init(CONF)

        if self.USES_DB:
            global _DB_CACHE
            if not _DB_CACHE:
                _DB_CACHE = Database(session, migration,
                        sql_connection=CONF.database.connection,
                        sqlite_db=CONF.database.sqlite_db,
                        sqlite_clean_db=CONF.sqlite_clean_db)

            self.useFixture(_DB_CACHE)

        # NOTE(danms): Make sure to reset us back to non-remote objects
        # for each test to avoid interactions. Also, backup the object
        # registry.
        objects_base.NovaObject.indirection_api = None
        self._base_test_obj_backup = copy.copy(
            objects_base.NovaObject._obj_classes)
        self.addCleanup(self._restore_obj_registry)

        # NOTE(mnaser): All calls to utils.is_neutron() are cached in
        # nova.utils._IS_NEUTRON.  We set it to None to avoid any
        # caching of that value.
        utils._IS_NEUTRON = None

        mox_fixture = self.useFixture(moxstubout.MoxStubout())
        self.mox = mox_fixture.mox
        self.stubs = mox_fixture.stubs
        self.addCleanup(self._clear_attrs)
        self.useFixture(fixtures.EnvironmentVariable('http_proxy'))
        self.policy = self.useFixture(policy_fixture.PolicyFixture())
        CONF.set_override('fatal_exception_format_errors', True)
        CONF.set_override('enabled', True, 'osapi_v3')
        CONF.set_override('force_dhcp_release', False)
        CONF.set_override('periodic_enable', False)
Exemplo n.º 37
0
def _set_up_nova_objects():
    nova_rpc.init(cfg.CONF)
    block_db_access()
    set_up_nova_object_indirection()
    nova_objects.register_all()
Exemplo n.º 38
0
Arquivo: test.py Projeto: CLisa/nova
    def setUp(self):
        """Run before each test method to initialize test environment."""
        super(TestCase, self).setUp()
        test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0)
        try:
            test_timeout = int(test_timeout)
        except ValueError:
            # If timeout value is invalid do not set a timeout.
            test_timeout = 0

        if self.TIMEOUT_SCALING_FACTOR >= 0:
            test_timeout *= self.TIMEOUT_SCALING_FACTOR
        else:
            raise ValueError('TIMEOUT_SCALING_FACTOR value must be >= 0')

        if test_timeout > 0:
            self.useFixture(fixtures.Timeout(test_timeout, gentle=True))
        self.useFixture(fixtures.NestedTempfile())
        self.useFixture(fixtures.TempHomeDir())
        self.useFixture(TranslationFixture())
        self.useFixture(log_fixture.get_logging_handle_error_fixture())

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

        rpc.add_extra_exmods('nova.test')
        self.addCleanup(rpc.clear_extra_exmods)
        self.addCleanup(rpc.cleanup)

        # set root logger to debug
        root = logging.getLogger()
        root.setLevel(logging.DEBUG)

        # supports collecting debug level for local runs
        if os.environ.get('OS_DEBUG') in _TRUE_VALUES:
            level = logging.DEBUG
        else:
            level = logging.INFO

        # Collect logs
        fs = '%(levelname)s [%(name)s] %(message)s'
        self.useFixture(fixtures.FakeLogger(format=fs, level=None))
        root.handlers[0].setLevel(level)

        if level > logging.DEBUG:
            # Just attempt to format debug level logs, but don't save them
            handler = NullHandler()
            self.useFixture(fixtures.LogHandler(handler, nuke_handlers=False))
            handler.setLevel(logging.DEBUG)

        self.useFixture(conf_fixture.ConfFixture(CONF))

        self.messaging_conf = messaging_conffixture.ConfFixture(CONF)
        self.messaging_conf.transport_driver = 'fake'
        self.messaging_conf.response_timeout = 15
        self.useFixture(self.messaging_conf)

        rpc.init(CONF)

        if self.USES_DB:
            global _DB_CACHE
            if not _DB_CACHE:
                _DB_CACHE = Database(session, migration,
                        sql_connection=CONF.database.connection,
                        sqlite_db=CONF.database.sqlite_db,
                        sqlite_clean_db=CONF.sqlite_clean_db)

            self.useFixture(_DB_CACHE)

        # NOTE(danms): Make sure to reset us back to non-remote objects
        # for each test to avoid interactions. Also, backup the object
        # registry.
        objects_base.NovaObject.indirection_api = None
        self._base_test_obj_backup = copy.copy(
            objects_base.NovaObject._obj_classes)
        self.addCleanup(self._restore_obj_registry)

        # NOTE(mnaser): All calls to utils.is_neutron() are cached in
        # nova.utils._IS_NEUTRON.  We set it to None to avoid any
        # caching of that value.
        utils._IS_NEUTRON = None

        mox_fixture = self.useFixture(moxstubout.MoxStubout())
        self.mox = mox_fixture.mox
        self.stubs = mox_fixture.stubs
        self.addCleanup(self._clear_attrs)
        self.useFixture(fixtures.EnvironmentVariable('http_proxy'))
        self.policy = self.useFixture(policy_fixture.PolicyFixture())
        CONF.set_override('fatal_exception_format_errors', True)
        CONF.set_override('enabled', True, 'osapi_v3')
        CONF.set_override('force_dhcp_release', False)
Exemplo n.º 39
0
    def setUp(self):
        """Run before each test method to initialize test environment."""
        super(TestCase, self).setUp()
        test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0)
        try:
            test_timeout = int(test_timeout)
        except ValueError:
            # If timeout value is invalid do not set a timeout.
            test_timeout = 0

        if self.TIMEOUT_SCALING_FACTOR >= 0:
            test_timeout *= self.TIMEOUT_SCALING_FACTOR
        else:
            raise ValueError('TIMEOUT_SCALING_FACTOR value must be >= 0')

        if test_timeout > 0:
            self.useFixture(fixtures.Timeout(test_timeout, gentle=True))
        self.useFixture(fixtures.NestedTempfile())
        self.useFixture(fixtures.TempHomeDir())
        self.useFixture(TranslationFixture())
        self.useFixture(log_fixture.get_logging_handle_error_fixture())

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

        rpc.add_extra_exmods('nova.test')
        self.addCleanup(rpc.clear_extra_exmods)
        self.addCleanup(rpc.cleanup)

        fs = '%(levelname)s [%(name)s] %(message)s'
        self.log_fixture = self.useFixture(fixtures.FakeLogger(format=fs))
        self.useFixture(conf_fixture.ConfFixture(CONF))

        self.messaging_conf = messaging_conffixture.ConfFixture(CONF)
        self.messaging_conf.transport_driver = 'fake'
        self.messaging_conf.response_timeout = 15
        self.useFixture(self.messaging_conf)

        rpc.init(CONF)

        if self.USES_DB:
            global _DB_CACHE
            if not _DB_CACHE:
                _DB_CACHE = Database(session, migration,
                        sql_connection=CONF.database.connection,
                        sqlite_db=CONF.sqlite_db,
                        sqlite_clean_db=CONF.sqlite_clean_db)

            self.useFixture(_DB_CACHE)

        # NOTE(danms): Make sure to reset us back to non-remote objects
        # for each test to avoid interactions. Also, backup the object
        # registry.
        objects_base.NovaObject.indirection_api = None
        self._base_test_obj_backup = copy.copy(
            objects_base.NovaObject._obj_classes)
        self.addCleanup(self._restore_obj_registry)

        mox_fixture = self.useFixture(moxstubout.MoxStubout())
        self.mox = mox_fixture.mox
        self.stubs = mox_fixture.stubs
        self.addCleanup(self._clear_attrs)
        self.useFixture(fixtures.EnvironmentVariable('http_proxy'))
        self.policy = self.useFixture(policy_fixture.PolicyFixture())
        CONF.set_override('fatal_exception_format_errors', True)
        CONF.set_override('enabled', True, 'osapi_v3')
        CONF.set_override('force_dhcp_release', False)
Exemplo n.º 40
0
    def _start_compute_worker(self):
        # All the subprocess should do this re-init job to enable rpc clients
        rpc.init(CONF)

        objects_base.NovaObject.indirection_api =\
        conductor_rpcapi.ConductorAPI()

        self.__init__(self.host,
                      self.binary,
                      self.topic,
                      self.manager_class_name,
                      self.report_interval,
                      self.periodic_enable,
                      self.periodic_fuzzy_delay,
                      self.periodic_interval_max,
                      db_allowed=False)

        driver_class = self.servicegroup_api._driver_name_class_mapping['db']
        self.servicegroup_api._driver = importutils.import_object(
            driver_class, db_allowed=False)

        # Some subprocess only start RPC servers to answer the requests
        if self._is_main_worker() is False:
            LOG.debug("Creating RPC server for service %s", self.topic)

            if self.backdoor_port is not None:
                self.manager.backdoor_port = self.backdoor_port

            target = messaging.Target(topic=self.topic, server=self.host)
            endpoints = [
                self.manager,
                baserpc.BaseRPCAPI(self.manager.service_name,
                                   self.backdoor_port)
            ]
            endpoints.extend(self.manager.additional_endpoints)
            serializer = objects_base.NovaObjectSerializer()
            self.rpcserver = rpc.get_server(target, endpoints, serializer)
            self.rpcserver.start()
            return

        # Main subprocess do the initial and period jobs
        verstr = version.version_string_with_package()
        LOG.audit(_('Starting %(topic)s node (version %(version)s)'), {
            'topic': self.topic,
            'version': verstr
        })
        self.basic_config_check()
        self.manager.init_host()
        self.model_disconnected = False
        ctxt = context.get_admin_context()
        try:
            self.service_ref = self.conductor_api.service_get_by_args(
                ctxt, self.host, self.binary)
            self.service_id = self.service_ref['id']
        except exception.NotFound:
            try:
                self.service_ref = self._create_service_ref(ctxt)
            except (exception.ServiceTopicExists,
                    exception.ServiceBinaryExists):
                # NOTE(danms): If we race to create a record with a sibling
                # worker, don't fail here.
                self.service_ref = self.conductor_api.service_get_by_args(
                    ctxt, self.host, self.binary)

        self.manager.pre_start_hook()
        self.manager.post_start_hook()

        # Add service to the ServiceGroup membership group.
        LOG.debug("Join ServiceGroup membership for this service %s",
                  self.topic)
        self.servicegroup_api.join(self.host, self.topic, self)

        if self.periodic_enable:
            if self.periodic_fuzzy_delay:
                initial_delay = random.randint(0, self.periodic_fuzzy_delay)
            else:
                initial_delay = None

            self.tg.add_dynamic_timer(
                self.periodic_tasks,
                initial_delay=initial_delay,
                periodic_interval_max=self.periodic_interval_max)
Exemplo n.º 41
0
    def setUp(self):
        """Run before each test method to initialize test environment."""
        super(TestCase, self).setUp()
        test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0)
        try:
            test_timeout = int(test_timeout)
        except ValueError:
            # If timeout value is invalid do not set a timeout.
            test_timeout = 0

        if self.TIMEOUT_SCALING_FACTOR >= 0:
            test_timeout *= self.TIMEOUT_SCALING_FACTOR
        else:
            raise ValueError('TIMEOUT_SCALING_FACTOR value must be >= 0')

        if test_timeout > 0:
            self.useFixture(fixtures.Timeout(test_timeout, gentle=True))
        self.useFixture(fixtures.NestedTempfile())
        self.useFixture(fixtures.TempHomeDir())
        self.useFixture(TranslationFixture())
        self.useFixture(log_fixture.get_logging_handle_error_fixture())

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

        rpc.add_extra_exmods('nova.test')
        self.addCleanup(rpc.clear_extra_exmods)
        self.addCleanup(rpc.cleanup)

        fs = '%(levelname)s [%(name)s] %(message)s'
        self.log_fixture = self.useFixture(
            fixtures.FakeLogger(level=logging.DEBUG, format=fs))
        self.useFixture(conf_fixture.ConfFixture(CONF))

        self.messaging_conf = messaging_conffixture.ConfFixture(CONF)
        self.messaging_conf.transport_driver = 'fake'
        self.messaging_conf.response_timeout = 15
        self.useFixture(self.messaging_conf)

        rpc.init(CONF)

        if self.USES_DB:
            global _DB_CACHE
            if not _DB_CACHE:
                _DB_CACHE = Database(session,
                                     migration,
                                     sql_connection=CONF.database.connection,
                                     sqlite_db=CONF.database.sqlite_db,
                                     sqlite_clean_db=CONF.sqlite_clean_db)

            self.useFixture(_DB_CACHE)

        # NOTE(danms): Make sure to reset us back to non-remote objects
        # for each test to avoid interactions. Also, backup the object
        # registry.
        objects_base.NovaObject.indirection_api = None
        self._base_test_obj_backup = copy.copy(
            objects_base.NovaObject._obj_classes)
        self.addCleanup(self._restore_obj_registry)

        mox_fixture = self.useFixture(moxstubout.MoxStubout())
        self.mox = mox_fixture.mox
        self.stubs = mox_fixture.stubs
        self.addCleanup(self._clear_attrs)
        self.useFixture(fixtures.EnvironmentVariable('http_proxy'))
        self.policy = self.useFixture(policy_fixture.PolicyFixture())
        CONF.set_override('fatal_exception_format_errors', True)
        CONF.set_override('enabled', True, 'osapi_v3')
        CONF.set_override('force_dhcp_release', False)
Exemplo n.º 42
0
    def setUp(self):
        """Run before each test method to initialize test environment."""
        super(TestCase, self).setUp()
        test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0)
        try:
            test_timeout = int(test_timeout)
        except ValueError:
            # If timeout value is invalid do not set a timeout.
            test_timeout = 0

        if self.TIMEOUT_SCALING_FACTOR >= 0:
            test_timeout *= self.TIMEOUT_SCALING_FACTOR
        else:
            raise ValueError('TIMEOUT_SCALING_FACTOR value must be >= 0')

        if test_timeout > 0:
            self.useFixture(fixtures.Timeout(test_timeout, gentle=True))
        self.useFixture(fixtures.NestedTempfile())
        self.useFixture(fixtures.TempHomeDir())
        self.useFixture(TranslationFixture())
        self.useFixture(log_fixture.get_logging_handle_error_fixture())

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

        rpc.add_extra_exmods('nova.test')
        self.addCleanup(rpc.clear_extra_exmods)
        self.addCleanup(rpc.cleanup)

        # set root logger to debug
        root = logging.getLogger()
        root.setLevel(logging.DEBUG)

        # supports collecting debug level for local runs
        if os.environ.get('OS_DEBUG') in _TRUE_VALUES:
            level = logging.DEBUG
        else:
            level = logging.INFO

        # Collect logs
        fs = '%(asctime)s %(levelname)s [%(name)s] %(message)s'
        self.useFixture(fixtures.FakeLogger(format=fs, level=None))
        root.handlers[0].setLevel(level)

        if level > logging.DEBUG:
            # Just attempt to format debug level logs, but don't save them
            handler = NullHandler()
            self.useFixture(fixtures.LogHandler(handler, nuke_handlers=False))
            handler.setLevel(logging.DEBUG)

        # Don't log every single DB migration step
        logging.getLogger('migrate.versioning.api').setLevel(logging.WARNING)

        # NOTE(sdague): because of the way we were using the lock
        # wrapper we eneded up with a lot of tests that started
        # relying on global external locking being set up for them. We
        # consider all of these to be *bugs*. Tests should not require
        # global external locking, or if they do, they should
        # explicitly set it up themselves.
        #
        # The following REQUIRES_LOCKING class parameter is provided
        # as a bridge to get us there. No new tests should be added
        # that require it, and existing classes and tests should be
        # fixed to not need it.
        if self.REQUIRES_LOCKING:
            lock_path = self.useFixture(fixtures.TempDir()).path
            self.fixture = self.useFixture(
                config_fixture.Config(lockutils.CONF))
            self.fixture.config(lock_path=lock_path,
                                group='oslo_concurrency')

        self.useFixture(conf_fixture.ConfFixture(CONF))

        self.messaging_conf = messaging_conffixture.ConfFixture(CONF)
        self.messaging_conf.transport_driver = 'fake'
        self.useFixture(self.messaging_conf)

        rpc.init(CONF)

        if self.USES_DB:
            global _DB_CACHE
            if not _DB_CACHE:
                _DB_CACHE = Database(session, migration,
                        sql_connection=CONF.database.connection,
                        sqlite_db=CONF.database.sqlite_db,
                        sqlite_clean_db=CONF.sqlite_clean_db)

            self.useFixture(_DB_CACHE)

        # NOTE(danms): Make sure to reset us back to non-remote objects
        # for each test to avoid interactions. Also, backup the object
        # registry.
        objects_base.NovaObject.indirection_api = None
        self._base_test_obj_backup = copy.copy(
            objects_base.NovaObject._obj_classes)
        self.addCleanup(self._restore_obj_registry)

        # NOTE(mnaser): All calls to utils.is_neutron() are cached in
        # nova.utils._IS_NEUTRON.  We set it to None to avoid any
        # caching of that value.
        utils._IS_NEUTRON = None

        mox_fixture = self.useFixture(moxstubout.MoxStubout())
        self.mox = mox_fixture.mox
        self.stubs = mox_fixture.stubs
        self.addCleanup(self._clear_attrs)
        self.useFixture(fixtures.EnvironmentVariable('http_proxy'))
        self.policy = self.useFixture(policy_fixture.PolicyFixture())
        CONF.set_override('fatal_exception_format_errors', True)
        CONF.set_override('enabled', True, 'osapi_v3')
        CONF.set_override('force_dhcp_release', False)
        CONF.set_override('periodic_enable', False)
Exemplo n.º 43
0
 def _test(get_url, create_transport):
     create_transport.return_value = transport
     rpc.init(conf)
     create_transport.assert_called_once_with(get_url.return_value)
Exemplo n.º 44
0
    def _start_compute_worker(self):
        # All the subprocess should do this re-init job to enable rpc clients
        rpc.init(CONF)

        objects_base.NovaObject.indirection_api =\
        conductor_rpcapi.ConductorAPI()

        self.__init__(self.host, self.binary, self.topic,
            self.manager_class_name, self.report_interval,
            self.periodic_enable, self.periodic_fuzzy_delay,
            self.periodic_interval_max, db_allowed=False)

        driver_class = self.servicegroup_api._driver_name_class_mapping['db']
        self.servicegroup_api._driver = importutils.import_object(driver_class,
            db_allowed=False)

        # Some subprocess only start RPC servers to answer the requests
        if self._is_main_worker() is False:
            LOG.debug("Creating RPC server for service %s", self.topic)

            if self.backdoor_port is not None:
                self.manager.backdoor_port = self.backdoor_port

            target = messaging.Target(topic=self.topic, server=self.host)
            endpoints = [
                self.manager,
                baserpc.BaseRPCAPI(self.manager.service_name, self.backdoor_port)
            ]
            endpoints.extend(self.manager.additional_endpoints)
            serializer = objects_base.NovaObjectSerializer()
            self.rpcserver = rpc.get_server(target, endpoints, serializer)
            self.rpcserver.start()
            return

        # Main subprocess do the initial and period jobs
        verstr = version.version_string_with_package()
        LOG.audit(_('Starting %(topic)s node (version %(version)s)'),
            {'topic': self.topic, 'version': verstr})
        self.basic_config_check()
        self.manager.init_host()
        self.model_disconnected = False
        ctxt = context.get_admin_context()
        try:
            self.service_ref = self.conductor_api.service_get_by_args(ctxt,
                self.host, self.binary)
            self.service_id = self.service_ref['id']
        except exception.NotFound:
            try:
                self.service_ref = self._create_service_ref(ctxt)
            except (exception.ServiceTopicExists,
                    exception.ServiceBinaryExists):
                # NOTE(danms): If we race to create a record with a sibling
                # worker, don't fail here.
                self.service_ref = self.conductor_api.service_get_by_args(
                    ctxt, self.host, self.binary)

        self.manager.pre_start_hook()
        self.manager.post_start_hook()

        # Add service to the ServiceGroup membership group.
        LOG.debug("Join ServiceGroup membership for this service %s",
            self.topic)
        self.servicegroup_api.join(self.host, self.topic, self)

        if self.periodic_enable:
            if self.periodic_fuzzy_delay:
                initial_delay = random.randint(0, self.periodic_fuzzy_delay)
            else:
                initial_delay = None

            self.tg.add_dynamic_timer(self.periodic_tasks,
                initial_delay=initial_delay,
                periodic_interval_max=
                self.periodic_interval_max)