Example #1
0
 def setUp(self):
     super(LogLevelTestCase, self).setUp()
     self.CONF = self.useFixture(config.Config()).conf
     levels = self.CONF.default_log_levels
     levels.append("nova-test=AUDIT")
     self.config = self.useFixture(config.Config()).config
     self.config(default_log_levels=levels, verbose=True)
     log.setup('testing')
     self.log = log.getLogger('nova-test')
Example #2
0
 def setUp(self):
     super(NotifierTestCase, self).setUp()
     notification_driver = ['openstack.common.notifier.no_op_notifier']
     self.stubs = self.useFixture(moxstubout.MoxStubout()).stubs
     self.config = self.useFixture(config.Config()).config
     self.CONF = self.useFixture(config.Config()).conf
     self.config(notification_driver=notification_driver)
     self.config(default_publisher_id='publisher')
     self.addCleanup(notifier_api._reset_drivers)
Example #3
0
    def setUp(self):
        super(MultiNotifierTestCase, self).setUp()
        self.config = self.useFixture(config.Config()).config
        self.stubs = self.useFixture(moxstubout.MoxStubout()).stubs

        # Mock log to add one to exception_count when log.exception is called

        def mock_exception(cls, *args):
            self.exception_count += 1

        self.exception_count = 0

        notifier_log = log.getLogger('openstack.common.notifier.api')
        self.stubs.Set(notifier_log, "exception", mock_exception)

        # Mock no_op notifier to add one to notify_count when called.
        def mock_notify(cls, *args):
            self.notify_count += 1

        self.notify_count = 0
        self.stubs.Set(no_op_notifier, 'notify', mock_notify)

        # Mock log_notifier to raise RuntimeError when called.

        def mock_notify2(cls, *args):
            raise RuntimeError("Bad notifier.")

        self.stubs.Set(log_notifier, 'notify', mock_notify2)
        self.addCleanup(notifier_api._reset_drivers)
Example #4
0
 def setUp(self):
     super(RpcKombuHATestCase, self).setUp()
     configfixture = self.useFixture(config.Config())
     self.config = configfixture.config
     self.FLAGS = configfixture.conf
     self.stubs = self.useFixture(moxstubout.MoxStubout()).stubs
     self.useFixture(KombuStubs(self))
    def setUp(self):
        super(MatchMakerRedisLookupTestCase, self).setUp()
        self.config = self.useFixture(config.Config()).config
        if not redis:
            self.skipTest("Redis required for test.")

        self.config(matchmaker_heartbeat_ttl=1)

        self.topic = "test"
        self.hosts = map(lambda x: 'mockhost-' + str(x), range(1, 10))

        try:
            self.driver = matchmaker.MatchMakerRedis()
            self.driver.redis.connection_pool.connection_kwargs[
                'socket_timeout'] = 1
            # Test the connection
            self.driver.redis.ping()
        except redis.exceptions.ConnectionError:
            raise self.skipTest("Redis server not available.")

        # Wipe all entries...
        for host in self.hosts:
            self.driver.unregister(self.topic, host)

        for h in self.hosts:
            self.driver.register(self.topic, h)

        self.driver.start_heartbeat()
Example #6
0
 def setUp(self):
     super(LogConfigTestCase, self).setUp()
     self.config = self.useFixture(config.Config()).config
     self.log_config_append = \
         fileutils.write_to_tempfile(content=self.minimal_config,
                                     prefix='logging',
                                     suffix='.conf'
                                     )
Example #7
0
 def setUp(self):
     super(RpcServiceManagerTestCase, self).setUp()
     self.config = self.useFixture(config.Config()).config
     self.config(fake_rabbit=True)
     self.config(rpc_backend='openstack.common.rpc.impl_fake')
     self.config(verbose=True)
     self.config(rpc_response_timeout=5)
     self.config(rpc_cast_timeout=5)
Example #8
0
    def setUp(self):
        super(DBAPITestCase, self).setUp()
        config_fixture = self.useFixture(config.Config())
        self.conf = config_fixture.conf
        self.config = config_fixture.config

        mox_fixture = self.useFixture(moxstubout.MoxStubout())
        self.write_to_tempfile = fileutils.write_to_tempfile
        self.stubs = mox_fixture.stubs
Example #9
0
    def setUp(self):
        self.stubs = self.useFixture(moxstubout.MoxStubout()).stubs
        self.CONF = self.useFixture(config.Config()).conf
        self.sample_resources = {
            'r1': quota.BaseResource('r1'),
            'r2': quota.BaseResource('r2')
        }

        dbapi = mock.Mock()
        dbapi.quota_usage_get_all_by_project_and_user = mock.Mock(
            return_value={
                'project_id': 'p1',
                'user_id': 'u1',
                'r1': {
                    'reserved': 1,
                    'in_use': 2
                },
                'r2': {
                    'reserved': 2,
                    'in_use': 3
                }
            })
        dbapi.quota_get_all_by_project_and_user = mock.Mock(return_value={
            'project_id': 'p1',
            'user_id': 'u1',
            'r1': 5,
            'r2': 6
        })
        dbapi.quota_get = mock.Mock(return_value='quota_get')
        dbapi.quota_reserve = mock.Mock(return_value='quota_reserve')
        dbapi.quota_class_get = mock.Mock(return_value='quota_class_get')
        dbapi.quota_class_reserve = mock.Mock(
            return_value='quota_class_reserve')
        dbapi.quota_class_get_default = mock.Mock(return_value={
            'r1': 1,
            'r2': 2
        })
        dbapi.quota_class_get_all_by_name = mock.Mock(return_value={'r1': 9})
        dbapi.quota_get_all_by_project = mock.Mock(
            return_value=dict([('r%d' % i, i) for i in range(3)]))
        dbapi.quota_get_all = mock.Mock(return_value=[{
            'resource': 'r1',
            'hard_limit': 3
        }, {
            'resource': 'r2',
            'hard_limit': 4
        }])
        dbapi.quota_usage_get_all_by_project = mock.Mock(
            return_value=dict([('r%d' % i, {
                'in_use': i,
                'reserved': i + 1
            }) for i in range(3)]))
        self.dbapi = dbapi
        self.driver = quota.DbQuotaDriver(dbapi)
        self.ctxt = FakeContext()
        return super(DbQuotaDriverTestCase, self).setUp()
Example #10
0
    def setUp(self):
        super(CommonLoggerTestsMixIn, self).setUp()
        self.config = self.useFixture(config.Config()).config

        # common context has different fields to the defaults in log.py
        self.config(logging_context_format_string='%(asctime)s %(levelname)s '
                    '%(name)s [%(request_id)s '
                    '%(user)s %(tenant)s] '
                    '%(message)s')
        self.log = None
Example #11
0
 def setUp(self):
     super(ServiceTestBase, self).setUp()
     self.CONF = self.useFixture(config.Config()).conf
     # FIXME(markmc): Ugly hack to workaround bug #1073732
     self.CONF.unregister_opts(notifier_api.notifier_opts)
     # NOTE(markmc): ConfigOpts.log_opt_values() uses CONF.config-file
     self.CONF(args=[], default_config_files=[])
     self.addCleanup(self.CONF.reset)
     self.addCleanup(self.CONF.register_opts, notifier_api.notifier_opts)
     self.addCleanup(self._reap_pid)
Example #12
0
    def setUp(self):
        super(SqliteInMemoryFixture, self).setUp()
        config_fixture = self.useFixture(config.Config())
        self.conf = config_fixture.conf
        self.conf.import_opt('connection',
                             'openstack.common.db.sqlalchemy.session',
                             group='database')

        self.conf.set_default('connection', "sqlite://", group='database')
        self.addCleanup(session.cleanup)
Example #13
0
    def setUp(self):
        if kombu is None:
            self.skipTest("Test requires kombu")
        configfixture = self.useFixture(config.Config())
        self.config = configfixture.config
        self.FLAGS = configfixture.conf
        self.stubs = self.useFixture(moxstubout.MoxStubout()).stubs
        self.useFixture(KombuStubs(self))

        super(RpcKombuTestCase, self).setUp()
Example #14
0
    def setUp(self):
        super(TestRequestBodySizeLimiter, self).setUp()
        self.MAX_REQUEST_BODY_SIZE = \
            self.useFixture(config.Config()).conf.max_request_body_size

        @webob.dec.wsgify()
        def fake_app(req):
            return webob.Response(req.body)

        self.middleware = sizelimit.RequestBodySizeLimiter(fake_app)
        self.request = webob.Request.blank('/', method='POST')
Example #15
0
    def setUp(self):
        super(KombuStubs, self).setUp()

        test = self.test()
        if kombu:
            test.conf = self.useFixture(config.Config()).conf
            test.config(fake_rabbit=True)
            test.config(rpc_response_timeout=5)
            test.rpc = impl_kombu
            self.addCleanup(impl_kombu.cleanup)
        else:
            test.rpc = None
Example #16
0
 def setUp(self):
     super(RpcKombuSslBadVersionTestCase, self).setUp()
     if kombu is None:
         self.skipTest("Test requires kombu")
     configfixture = self.useFixture(config.Config())
     self.config = configfixture.config
     self.FLAGS = configfixture.conf
     self.config(kombu_ssl_keyfile=SSL_KEYFILE,
                 kombu_ssl_ca_certs=SSL_CA_CERT,
                 kombu_ssl_certfile=SSL_CERT,
                 kombu_ssl_version="SSLv24",
                 rabbit_use_ssl=True,
                 fake_rabbit=True)
Example #17
0
 def setUp(self,
           supports_timeouts=True,
           topic='test',
           topic_nested='nested'):
     super(BaseRpcTestCase, self).setUp()
     self.topic = topic or self.topic
     self.topic_nested = topic_nested or self.topic_nested
     self.supports_timeouts = supports_timeouts
     self.context = rpc_common.CommonRpcContext(user='******',
                                                pw='fake_pw')
     self.FLAGS = self.useFixture(config.Config()).conf
     if self.rpc:
         receiver = TestReceiver()
         self.conn = self._create_consumer(receiver, self.topic)
         self.addCleanup(self.conn.close)
Example #18
0
    def setUp(self):
        super(DeprecatedConfigTestCase, self).setUp()
        self.stubs = self.useFixture(moxstubout.MoxStubout()).stubs
        self.config = self.useFixture(config.Config()).config

        self.warnbuffer = ""
        self.critbuffer = ""

        def warn_log(msg):
            self.warnbuffer = msg

        def critical_log(msg):
            self.critbuffer = msg

        self.stubs.Set(LOG, 'warn', warn_log)
        self.stubs.Set(LOG, 'critical', critical_log)
Example #19
0
 def setUp(self):
     super(ContextFormatterTestCase, self).setUp()
     self.config = self.useFixture(config.Config()).config
     self.config(logging_context_format_string="HAS CONTEXT "
                 "[%(request_id)s]: "
                 "%(message)s",
                 logging_default_format_string="NOCTXT: %(message)s",
                 logging_debug_format_suffix="--DBG")
     self.log = log.getLogger()
     self.stream = six.StringIO()
     self.handler = logging.StreamHandler(self.stream)
     self.handler.setFormatter(log.ContextFormatter())
     self.log.logger.addHandler(self.handler)
     self.addCleanup(self.log.logger.removeHandler, self.handler)
     self.level = self.log.logger.getEffectiveLevel()
     self.log.logger.setLevel(logging.DEBUG)
     self.addCleanup(self.log.logger.setLevel, self.level)
Example #20
0
    def setUp(self):
        super(FancyRecordTestCase, self).setUp()
        self.config = self.useFixture(config.Config()).config
        # NOTE(sdague): use the different formatters to demonstrate format
        # string with valid fancy keys and without. Slightly hacky, but given
        # the way log objects layer up seemed to be most concise approach
        self.config(logging_context_format_string="%(color)s "
                    "[%(request_id)s]: "
                    "%(message)s",
                    logging_default_format_string="%(missing)s: %(message)s")
        self.stream = six.StringIO()

        self.colorhandler = log.ColorHandler(self.stream)
        self.colorhandler.setFormatter(log.ContextFormatter())

        self.colorlog = log.getLogger()
        self.colorlog.logger.addHandler(self.colorhandler)
        self.level = self.colorlog.logger.getEffectiveLevel()
        self.colorlog.logger.setLevel(logging.DEBUG)
Example #21
0
    def setUp(self, topic='test', topic_nested='nested'):
        if not impl_zmq:
            self.skipTest("ZeroMQ library required")

        self.reactor = None
        self.rpc = impl_zmq
        self.stubs = self.useFixture(moxstubout.MoxStubout()).stubs
        configfixture = self.useFixture(config.Config())
        self.config = configfixture.config
        self.FLAGS = configfixture.conf
        self.conf = self.FLAGS
        self.config(rpc_zmq_bind_address='127.0.0.1')
        self.config(rpc_zmq_host='127.0.0.1')
        self.config(rpc_response_timeout=5)
        self.rpc._get_matchmaker(host='127.0.0.1')

        # We'll change this if we detect no daemon running.
        ipc_dir = self.FLAGS.rpc_zmq_ipc_dir

        # Only launch the router if it isn't running.
        if not os.path.exists(os.path.join(ipc_dir, "zmq_topic_zmq_replies")):
            # NOTE(ewindisch): rpc_zmq_port and internal_ipc_dir must
            #                  increment to avoid async socket
            #                  closing/wait delays causing races
            #                  between tearDown() and setUp()
            # TODO(mordred): replace this with testresources once we're on
            #                testr
            self.config(rpc_zmq_port=get_unused_port())
            internal_ipc_dir = self.useFixture(fixtures.TempDir()).path
            self.config(rpc_zmq_ipc_dir=internal_ipc_dir)

            LOG.info(_("Running internal zmq receiver."))
            reactor = impl_zmq.ZmqProxy(self.FLAGS)
            self.addCleanup(self._close_reactor)
            reactor.consume_in_thread()
        else:
            LOG.warning(_("Detected zmq-receiver socket."))
            LOG.warning(_("Assuming oslo-rpc-zmq-receiver is running."))
            LOG.warning(_("Using system zmq receiver deamon."))
        super(_RpcZmqBaseTestCase, self).setUp(topic=topic,
                                               topic_nested=topic_nested)
Example #22
0
    def setUp(self):
        super(RpcQpidTestCase, self).setUp()

        if qpid is None:
            self.skipTest("Test required qpid")

        self.mock_connection = None
        self.mock_session = None
        self.mock_sender = None
        self.mock_receiver = None

        self.orig_connection = qpid.messaging.Connection
        self.orig_session = qpid.messaging.Session
        self.orig_sender = qpid.messaging.Sender
        self.orig_receiver = qpid.messaging.Receiver

        self.useFixture(
            fixtures.MonkeyPatch('qpid.messaging.Connection',
                                 lambda *_x, **_y: self.mock_connection))
        self.useFixture(
            fixtures.MonkeyPatch('qpid.messaging.Session',
                                 lambda *_x, **_y: self.mock_session))
        self.useFixture(
            fixtures.MonkeyPatch('qpid.messaging.Sender',
                                 lambda *_x, **_y: self.mock_sender))
        self.useFixture(
            fixtures.MonkeyPatch('qpid.messaging.Receiver',
                                 lambda *_x, **_y: self.mock_receiver))

        self.uuid4 = uuid.uuid4()
        self.useFixture(fixtures.MonkeyPatch('uuid.uuid4', self.mock_uuid4))

        configfixture = self.useFixture(config.Config())
        self.config = configfixture.config
        self.FLAGS = configfixture.conf

        moxfixture = self.useFixture(moxstubout.MoxStubout())
        self.stubs = moxfixture.stubs
        self.mox = moxfixture.mox
 def setUp(self):
     super(BackdoorPortTest, self).setUp()
     self.mox = self.useFixture(moxstubout.MoxStubout()).mox
     self.config = self.useFixture(config.Config()).config
Example #24
0
 def setUp(self):
     super(RpcProxyTestCase, self).setUp()
     self.config = self.useFixture(config.Config()).config
     moxfixture = self.useFixture(moxstubout.MoxStubout())
     self.mox = moxfixture.mox
     self.stubs = moxfixture.stubs
Example #25
0
 def setUp(self):
     super(PolicyBaseTestCase, self).setUp()
     self.CONF = self.useFixture(config.Config()).conf
     self.CONF(args=['--config-dir', TEST_VAR_DIR])
     self.enforcer = ENFORCER
Example #26
0
 def setUp(self):
     super(SessionParametersTestCase, self).setUp()
     config_fixture = self.useFixture(config.Config())
     self.conf = config_fixture.conf
     self.write_to_tempfile = fileutils.write_to_tempfile
Example #27
0
 def setUp(self):
     super(LogConfigOptsTestCase, self).setUp()
     self.CONF = self.useFixture(config.Config()).conf
Example #28
0
 def setUp(self):
     super(LauncherTest, self).setUp()
     self.mox = self.useFixture(moxstubout.MoxStubout()).mox
     self.config = self.useFixture(config.Config()).config
 def setUp(self):
     super(RpcCryptoTestCase, self).setUp()
     self.CONF = self.useFixture(config.Config()).conf
Example #30
0
 def setUp(self):
     super(LockTestCase, self).setUp()
     self.config = self.useFixture(config.Config()).config