def setUp(self):
        super(PoolCatalogTest, self).setUp()

        cache = oslo_cache.get_cache()
        control = utils.load_storage_driver(self.conf, cache,
                                            control_mode=True)

        self.pools_ctrl = control.pools_controller
        self.flavors_ctrl = control.flavors_controller
        self.catalogue_ctrl = control.catalogue_controller

        # NOTE(cpp-cabrera): populate catalogue
        self.pool = str(uuid.uuid1())
        self.pool2 = str(uuid.uuid1())
        self.pool_group = 'pool-group'
        self.queue = str(uuid.uuid1())
        self.flavor = str(uuid.uuid1())
        self.project = str(uuid.uuid1())

        self.pools_ctrl.create(self.pool, 100, 'mongodb://localhost:27017')
        self.pools_ctrl.create(self.pool2, 100,
                               'mongodb://127.0.0.1:27017',
                               group=self.pool_group)
        self.catalogue_ctrl.insert(self.project, self.queue, self.pool)
        self.catalog = pooling.Catalog(self.conf, cache, control)
        self.flavors_ctrl.create(self.flavor, self.pool_group,
                                 project=self.project)
    def test_using_replset(self):
        cache = oslo_cache.get_cache()

        with mock.patch('pymongo.MongoClient.nodes') as nodes:
            nodes.__get__ = mock.Mock(return_value=['node1', 'node2'])
            mongodb.DataDriver(self.conf, cache,
                               mongodb.ControlDriver(self.conf, cache))
示例#3
0
    def test_db_instance(self):
        cache = oslo_cache.get_cache()
        redis_driver = driver.DataDriver(self.conf, cache,
                                         driver.ControlDriver
                                         (self.conf, cache))

        self.assertTrue(isinstance(redis_driver.connection, redis.StrictRedis))
    def test_using_mongos(self):
        cache = oslo_cache.get_cache()

        with mock.patch('pymongo.MongoClient.is_mongos') as is_mongos:
            is_mongos.__get__ = mock.Mock(return_value=True)
            mongodb.DataDriver(self.conf, cache,
                               mongodb.ControlDriver(self.conf, cache))
示例#5
0
    def setUp(self):
        super(PoolCatalogTest, self).setUp()

        self.conf.register_opts([cfg.StrOpt('storage')],
                                group='drivers')
        cache = oslo_cache.get_cache()
        control = utils.load_storage_driver(self.conf, cache,
                                            control_mode=True)

        self.pools_ctrl = control.pools_controller
        self.flavors_ctrl = control.flavors_controller
        self.catalogue_ctrl = control.catalogue_controller

        # NOTE(cpp-cabrera): populate catalogue
        self.pool = str(uuid.uuid1())
        self.pool2 = str(uuid.uuid1())
        self.pool_group = 'pool-group'
        self.queue = str(uuid.uuid1())
        self.flavor = str(uuid.uuid1())
        self.project = str(uuid.uuid1())

        self.pools_ctrl.create(self.pool, 100, 'sqlite://:memory:')
        self.pools_ctrl.create(self.pool2, 100,
                               'sqlite://:memory:',
                               group=self.pool_group)
        self.catalogue_ctrl.insert(self.project, self.queue, self.pool)
        self.catalog = pooling.Catalog(self.conf, cache, control)
        self.flavors_ctrl.create(self.flavor, self.pool_group,
                                 project=self.project)
    def test_db_instance(self):
        cache = oslo_cache.get_cache()
        redis_driver = driver.DataDriver(self.conf, cache,
                                         driver.ControlDriver
                                         (self.conf, cache))

        self.assertTrue(isinstance(redis_driver.connection, redis.StrictRedis))
示例#7
0
    def setUp(self):
        super(PoolCatalogTest, self).setUp()

        cache = oslo_cache.get_cache()
        control = utils.load_storage_driver(self.conf, cache,
                                            control_mode=True)

        self.pools_ctrl = control.pools_controller
        self.flavors_ctrl = control.flavors_controller
        self.catalogue_ctrl = control.catalogue_controller

        # NOTE(cpp-cabrera): populate catalogue
        self.pool = str(uuid.uuid1())
        self.pool2 = str(uuid.uuid1())
        self.pool_group = 'pool-group'
        self.queue = str(uuid.uuid1())
        self.flavor = str(uuid.uuid1())
        self.project = str(uuid.uuid1())

        self.pools_ctrl.create(self.pool, 100, 'sqlite://:memory:')
        self.pools_ctrl.create(self.pool2, 100,
                               'sqlite://:memory:',
                               group=self.pool_group)
        self.catalogue_ctrl.insert(self.project, self.queue, self.pool)
        self.catalog = pooling.Catalog(self.conf, cache, control)
        self.flavors_ctrl.create(self.flavor, self.pool_group,
                                 project=self.project)
示例#8
0
    def test_replicaset_or_mongos_needed(self):
        cache = oslo_cache.get_cache()

        with mock.patch('pymongo.MongoClient.nodes') as nodes:
            nodes.__get__ = mock.Mock(return_value=[])
            with mock.patch('pymongo.MongoClient.is_mongos') as is_mongos:
                is_mongos.__get__ = mock.Mock(return_value=False)
                self.assertRaises(RuntimeError, mongodb.DataDriver,
                                  self.conf, cache)
示例#9
0
    def test_write_concern_is_set(self):
        cache = oslo_cache.get_cache()

        with mock.patch('pymongo.MongoClient.is_mongos') as is_mongos:
            is_mongos.__get__ = mock.Mock(return_value=True)
            driver = mongodb.DataDriver(self.conf, cache)
            wc = driver.connection.write_concern
            self.assertEqual(wc['w'], 'majority')
            self.assertEqual(wc['j'], False)
示例#10
0
    def test_db_instance(self):
        self.config(unreliable=True)
        cache = oslo_cache.get_cache()
        control = mongodb.ControlDriver(self.conf, cache)
        data = mongodb.DataDriver(self.conf, cache, control)

        for db in data.message_databases:
            self.assertThat(db.name, matchers.StartsWith(
                data.mongodb_conf.database))
示例#11
0
    def test_write_concern_is_set(self):
        cache = oslo_cache.get_cache()

        with mock.patch('pymongo.MongoClient.is_mongos') as is_mongos:
            is_mongos.__get__ = mock.Mock(return_value=True)
            driver = mongodb.DataDriver(self.conf, cache)
            wc = driver.connection.write_concern
            self.assertEqual(wc['w'], 'majority')
            self.assertEqual(wc['j'], False)
示例#12
0
    def test_db_instance(self):
        cache = oslo_cache.get_cache()
        driver = mongodb.DataDriver(self.conf, cache)

        databases = (driver.message_databases + [driver.queues_database])

        for db in databases:
            self.assertThat(db.name,
                            matchers.StartsWith(driver.mongodb_conf.database))
    def test_db_instance(self):
        self.config(unreliable=True)
        cache = oslo_cache.get_cache()
        control = mongodb.ControlDriver(self.conf, cache)
        data = mongodb.DataDriver(self.conf, cache, control)

        for db in data.message_databases:
            self.assertThat(db.name, matchers.StartsWith(
                data.mongodb_conf.database))
示例#14
0
 def cache(self):
     LOG.debug(u'Loading proxy cache driver')
     try:
         oslo_cache.register_oslo_configs(self.conf)
         mgr = oslo_cache.get_cache(self.conf.cache_url)
         return mgr
     except RuntimeError as exc:
         LOG.exception(exc)
         raise errors.InvalidDriver(exc)
示例#15
0
    def test_replicaset_or_mongos_needed(self):
        cache = oslo_cache.get_cache()

        with mock.patch('pymongo.MongoClient.nodes') as nodes:
            nodes.__get__ = mock.Mock(return_value=[])
            with mock.patch('pymongo.MongoClient.is_mongos') as is_mongos:
                is_mongos.__get__ = mock.Mock(return_value=False)
                self.assertRaises(RuntimeError, mongodb.DataDriver,
                                  self.conf, cache)
示例#16
0
    def test_cached(self):
        conf = cfg.ConfigOpts()
        oslo_cache.register_oslo_configs(conf)
        cache = oslo_cache.get_cache(conf.cache_url)

        sample_project = {
            u'name': u'Cats Abound',
            u'bits': b'\x80\x81\x82\x83\x84',
            b'key': u'Value. \x80',
        }

        def create_key(user, project=None):
            return user + ':' + str(project)

        class TestClass(object):

            def __init__(self, cache):
                self._cache = cache
                self.project_gets = 0
                self.project_dels = 0

            @decorators.caches(create_key, 60)
            def get_project(self, user, project=None):
                self.project_gets += 1
                return sample_project

            @get_project.purges
            def del_project(self, user, project=None):
                self.project_dels += 1

        instance = TestClass(cache)

        args = ('23', 'cats')

        project = instance.get_project(*args)
        self.assertEqual(project, sample_project)
        self.assertEqual(instance.project_gets, 1)

        # Should be in the cache now.
        project = msgpack.unpackb(cache.get(create_key(*args)),
                                  encoding='utf-8')
        self.assertEqual(project, sample_project)

        # Should read from the cache this time (counter will not
        # be incremented).
        project = instance.get_project(*args)
        self.assertEqual(project, sample_project)
        self.assertEqual(instance.project_gets, 1)

        # Use kwargs this time
        instance.del_project('23', project='cats')
        self.assertEqual(instance.project_dels, 1)

        # Should be a cache miss since we purged (above)
        project = instance.get_project(*args)
        self.assertEqual(instance.project_gets, 2)
示例#17
0
    def test_db_instance(self):
        cache = oslo_cache.get_cache()
        driver = mongodb.DataDriver(self.conf, cache)

        databases = (driver.message_databases +
                     [driver.queues_database])

        for db in databases:
            self.assertThat(db.name, matchers.StartsWith(
                driver.mongodb_conf.database))
示例#18
0
    def test_cached(self):
        conf = cfg.ConfigOpts()
        oslo_cache.register_oslo_configs(conf)
        cache = oslo_cache.get_cache(conf.cache_url)

        sample_project = {
            u'name': u'Cats Abound',
            u'bits': b'\x80\x81\x82\x83\x84',
            b'key': u'Value. \x80',
        }

        def create_key(user, project=None):
            return user + ':' + str(project)

        class TestClass(object):
            def __init__(self, cache):
                self._cache = cache
                self.project_gets = 0
                self.project_dels = 0

            @decorators.caches(create_key, 60)
            def get_project(self, user, project=None):
                self.project_gets += 1
                return sample_project

            @get_project.purges
            def del_project(self, user, project=None):
                self.project_dels += 1

        instance = TestClass(cache)

        args = ('23', 'cats')

        project = instance.get_project(*args)
        self.assertEqual(project, sample_project)
        self.assertEqual(instance.project_gets, 1)

        # Should be in the cache now.
        project = msgpack.unpackb(cache.get(create_key(*args)),
                                  encoding='utf-8')
        self.assertEqual(project, sample_project)

        # Should read from the cache this time (counter will not
        # be incremented).
        project = instance.get_project(*args)
        self.assertEqual(project, sample_project)
        self.assertEqual(instance.project_gets, 1)

        # Use kwargs this time
        instance.del_project('23', project='cats')
        self.assertEqual(instance.project_dels, 1)

        # Should be a cache miss since we purged (above)
        project = instance.get_project(*args)
        self.assertEqual(instance.project_gets, 2)
示例#19
0
    def test_using_mongos(self):
        cache = oslo_cache.get_cache()

        with mock.patch('pymongo.MongoClient.is_mongos') as is_mongos:
            is_mongos.__get__ = mock.Mock(return_value=True)

            with mock.patch('pymongo.MongoClient.write_concern') as wc:
                write_concern = pymongo.WriteConcern(w=2)
                wc.__get__ = mock.Mock(return_value=write_concern)
                mongodb.DataDriver(self.conf, cache,
                                   mongodb.ControlDriver(self.conf, cache))
示例#20
0
    def test_using_replset(self):
        cache = oslo_cache.get_cache()

        with mock.patch('pymongo.MongoClient.nodes') as nodes:
            nodes.__get__ = mock.Mock(return_value=['node1', 'node2'])

            with mock.patch('pymongo.MongoClient.write_concern') as wc:
                write_concern = pymongo.WriteConcern(w=2)
                wc.__get__ = mock.Mock(return_value=write_concern)
                mongodb.DataDriver(self.conf, cache,
                                   mongodb.ControlDriver(self.conf, cache))
示例#21
0
    def test_write_concern_check_works(self):
        cache = oslo_cache.get_cache()

        with mock.patch('pymongo.MongoClient.is_mongos') as is_mongos:
            is_mongos.__get__ = mock.Mock(return_value=True)

            with mock.patch('pymongo.MongoClient.write_concern') as wc:
                wc.__get__ = mock.Mock(return_value={'w': 1})
                self.assertRaises(RuntimeError, mongodb.DataDriver,
                                  self.conf, cache)

                wc.__get__ = mock.Mock(return_value={'w': 2})
                mongodb.DataDriver(self.conf, cache)
示例#22
0
    def test_write_concern_check_works(self):
        cache = oslo_cache.get_cache()

        with mock.patch('pymongo.MongoClient.is_mongos') as is_mongos:
            is_mongos.__get__ = mock.Mock(return_value=True)

            with mock.patch('pymongo.MongoClient.write_concern') as wc:
                wc.__get__ = mock.Mock(return_value={'w': 1})
                self.assertRaises(RuntimeError, mongodb.DataDriver,
                                  self.conf, cache)

                wc.__get__ = mock.Mock(return_value={'w': 2})
                mongodb.DataDriver(self.conf, cache)
示例#23
0
    def test_version_match(self):
        cache = oslo_cache.get_cache()

        with mock.patch('redis.StrictRedis.info') as info:
            info.return_value = {'redis_version': '2.4.6'}
            self.assertRaises(RuntimeError, driver.DataDriver,
                              self.conf, cache)

            info.return_value = {'redis_version': '2.11'}

            try:
                driver.DataDriver(self.conf, cache)
            except RuntimeError:
                self.fail('version match failed')
示例#24
0
    def test_version_match(self):
        cache = oslo_cache.get_cache()

        with mock.patch('pymongo.MongoClient.server_info') as info:
            info.return_value = {'version': '2.1'}
            self.assertRaises(RuntimeError, mongodb.DataDriver, self.conf,
                              cache)

            info.return_value = {'version': '2.11'}

            try:
                mongodb.DataDriver(self.conf, cache)
            except RuntimeError:
                self.fail('version match failed')
示例#25
0
    def test_version_match(self):
        cache = oslo_cache.get_cache()

        with mock.patch('redis.StrictRedis.info') as info:
            info.return_value = {'redis_version': '2.4.6'}
            self.assertRaises(RuntimeError, driver.DataDriver, self.conf,
                              cache)

            info.return_value = {'redis_version': '2.11'}

            try:
                driver.DataDriver(self.conf, cache)
            except RuntimeError:
                self.fail('version match failed')
示例#26
0
    def test_version_match(self):
        cache = oslo_cache.get_cache()

        with mock.patch('pymongo.MongoClient.server_info') as info:
            info.return_value = {'version': '2.1'}
            self.assertRaises(RuntimeError, mongodb.DataDriver,
                              self.conf, cache)

            info.return_value = {'version': '2.11'}

            try:
                mongodb.DataDriver(self.conf, cache)
            except RuntimeError:
                self.fail('version match failed')
示例#27
0
    def setUp(self):
        super(PoolQueuesTest, self).setUp()

        cache = oslo_cache.get_cache()
        control = utils.load_storage_driver(self.conf,
                                            cache,
                                            control_mode=True)
        self.pools_ctrl = control.pools_controller
        self.driver = pooling.DataDriver(self.conf, cache, control)
        self.controller = self.driver.queue_controller

        # fake two pools
        for _ in six.moves.xrange(2):
            self.pools_ctrl.create(str(uuid.uuid1()), 100, 'sqlite://:memory:')
示例#28
0
    def test_write_concern_is_set(self):
        cache = oslo_cache.get_cache()

        with mock.patch('pymongo.MongoClient.is_mongos') as is_mongos:
            is_mongos.__get__ = mock.Mock(return_value=True)
            self.config(unreliable=True)
            driver = mongodb.DataDriver(
                self.conf, cache, mongodb.ControlDriver(self.conf, cache))

            driver.server_version = (2, 6)

            for db in driver.message_databases:
                wc = db.write_concern

                self.assertEqual(wc.document['w'], 'majority')
                self.assertEqual(wc.document['j'], False)
示例#29
0
    def setUp(self):
        super(PoolQueuesTest, self).setUp()
        conf = self.load_conf('wsgi_mongodb_pooled.conf')

        conf.register_opts([cfg.StrOpt('storage')],
                           group='drivers')

        cache = oslo_cache.get_cache()
        control = utils.load_storage_driver(conf, cache, control_mode=True)
        self.pools_ctrl = control.pools_controller
        self.driver = pooling.DataDriver(conf, cache, control)
        self.controller = self.driver.queue_controller

        # fake two pools
        for _ in six.moves.xrange(2):
            self.pools_ctrl.create(str(uuid.uuid1()), 100,
                                   'sqlite://:memory:')
示例#30
0
    def test_write_concern_is_set(self):
        cache = oslo_cache.get_cache()

        with mock.patch('pymongo.MongoClient.is_mongos') as is_mongos:
            is_mongos.__get__ = mock.Mock(return_value=True)
            self.config(unreliable=True)
            driver = mongodb.DataDriver(self.conf, cache,
                                        mongodb.ControlDriver
                                        (self.conf, cache))

            driver.server_version = (2, 6)

            for db in driver.message_databases:
                wc = db.write_concern

                self.assertEqual(wc.document['w'], 'majority')
                self.assertEqual(wc.document['j'], False)
示例#31
0
    def setUp(self):
        super(PoolCatalogTest, self).setUp()

        self.conf.register_opts([cfg.StrOpt('storage')], group='drivers')
        cache = oslo_cache.get_cache()
        control = utils.load_storage_driver(self.conf,
                                            cache,
                                            control_mode=True)

        self.catalogue_ctrl = control.catalogue_controller
        self.pools_ctrl = control.pools_controller

        # NOTE(cpp-cabrera): populate catalogue
        self.pool = str(uuid.uuid1())
        self.queue = str(uuid.uuid1())
        self.project = str(uuid.uuid1())
        self.pools_ctrl.create(self.pool, 100, 'sqlite://:memory:')
        self.catalogue_ctrl.insert(self.project, self.queue, self.pool)
        self.catalog = pooling.Catalog(self.conf, cache, control)
示例#32
0
    def test_cached_with_cond(self):
        conf = cfg.ConfigOpts()
        oslo_cache.register_oslo_configs(conf)
        cache = oslo_cache.get_cache(conf.cache_url)

        class TestClass(object):

            def __init__(self, cache):
                self._cache = cache
                self.user_gets = 0

            @decorators.caches(lambda x: x, 60, lambda v: v != 'kgriffs')
            def get_user(self, name):
                self.user_gets += 1
                return name

        instance = TestClass(cache)

        name = 'malini'

        user = instance.get_user(name)
        self.assertEqual(user, name)
        self.assertEqual(instance.user_gets, 1)

        # Should be in the cache now.
        user = msgpack.unpackb(cache.get(name), encoding='utf-8')
        self.assertEqual(user, name)

        # Should read from the cache this time (counter will not
        # be incremented).
        user = instance.get_user(name)
        self.assertEqual(user, name)
        self.assertEqual(instance.user_gets, 1)

        # Won't go into the cache because of cond
        name = 'kgriffs'
        for i in range(3):
            user = instance.get_user(name)

            self.assertEqual(cache.get(name), None)

            self.assertEqual(user, name)
            self.assertEqual(instance.user_gets, 2 + i)
示例#33
0
    def test_cached_with_cond(self):
        conf = cfg.ConfigOpts()
        oslo_cache.register_oslo_configs(conf)
        cache = oslo_cache.get_cache(conf.cache_url)

        class TestClass(object):
            def __init__(self, cache):
                self._cache = cache
                self.user_gets = 0

            @decorators.caches(lambda x: x, 60, lambda v: v != 'kgriffs')
            def get_user(self, name):
                self.user_gets += 1
                return name

        instance = TestClass(cache)

        name = 'malini'

        user = instance.get_user(name)
        self.assertEqual(user, name)
        self.assertEqual(instance.user_gets, 1)

        # Should be in the cache now.
        user = msgpack.unpackb(cache.get(name), encoding='utf-8')
        self.assertEqual(user, name)

        # Should read from the cache this time (counter will not
        # be incremented).
        user = instance.get_user(name)
        self.assertEqual(user, name)
        self.assertEqual(instance.user_gets, 1)

        # Won't go into the cache because of cond
        name = 'kgriffs'
        for i in range(3):
            user = instance.get_user(name)

            self.assertEqual(cache.get(name), None)

            self.assertEqual(user, name)
            self.assertEqual(instance.user_gets, 2 + i)
示例#34
0
    def setUp(self):
        super(ControllerBaseTest, self).setUp()

        if not self.driver_class:
            self.skipTest('No driver class specified')

        if not issubclass(self.controller_class, self.controller_base_class):
            self.skipTest('{0} is not an instance of {1}. '
                          'Tests not supported'.format(
                              self.controller_class,
                              self.controller_base_class))

        oslo_cache.register_oslo_configs(self.conf)
        cache = oslo_cache.get_cache(self.conf.cache_url)

        self.conf.register_opts(bootstrap._GENERAL_OPTIONS)
        pooling = 'pooling' in self.conf and self.conf.pooling
        if pooling and not self.control_driver_class:
            self.skipTest("Pooling is enabled, "
                          "but control driver class is not specified")

        if not pooling:
            self.driver = self.driver_class(self.conf, cache)
        else:
            control = self.control_driver_class(self.conf, cache)
            uri = "sqlite:///:memory:"
            for i in range(4):
                control.pools_controller.create(six.text_type(i), 100, uri)
            self.driver = self.driver_class(self.conf, cache, control)

        self._prepare_conf()

        self.addCleanup(self._purge_databases)

        if not pooling:
            self.controller = self.controller_class(self.driver)
        else:
            self.controller = self.controller_class(self.driver._pool_catalog)
示例#35
0
    def setUp(self):
        super(ControllerBaseTest, self).setUp()

        if not self.driver_class:
            self.skipTest('No driver class specified')

        if not issubclass(self.controller_class, self.controller_base_class):
            self.skipTest('{0} is not an instance of {1}. '
                          'Tests not supported'.format(
                              self.controller_class,
                              self.controller_base_class))

        oslo_cache.register_oslo_configs(self.conf)
        cache = oslo_cache.get_cache(self.conf.cache_url)

        self.conf.register_opts(bootstrap._GENERAL_OPTIONS)
        pooling = 'pooling' in self.conf and self.conf.pooling
        if pooling and not self.control_driver_class:
            self.skipTest("Pooling is enabled, "
                          "but control driver class is not specified")

        if not pooling:
            self.driver = self.driver_class(self.conf, cache)
        else:
            control = self.control_driver_class(self.conf, cache)
            uri = "sqlite:///:memory:"
            for i in range(4):
                control.pools_controller.create(six.text_type(i), 100, uri)
            self.driver = self.driver_class(self.conf, cache, control)

        self._prepare_conf()

        self.addCleanup(self._purge_databases)

        if not pooling:
            self.controller = self.controller_class(self.driver)
        else:
            self.controller = self.controller_class(self.driver._pool_catalog)
示例#36
0
    def test_using_replset(self):
        cache = oslo_cache.get_cache()

        with mock.patch('pymongo.MongoClient.nodes') as nodes:
            nodes.__get__ = mock.Mock(return_value=['node1', 'node2'])
            mongodb.DataDriver(self.conf, cache)
示例#37
0
    def test_using_mongos(self):
        cache = oslo_cache.get_cache()

        with mock.patch('pymongo.MongoClient.is_mongos') as is_mongos:
            is_mongos.__get__ = mock.Mock(return_value=True)
            mongodb.DataDriver(self.conf, cache)