Exemple #1
0
    def test_db_instance(self):
        self.config(unreliable=True)
        cache = oslo_cache.get_cache(self.conf)
        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))
Exemple #2
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)
Exemple #3
0
    def test_db_instance(self):
        self.config(unreliable=True)
        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))
Exemple #4
0
    def test_using_mongos(self):
        cache = oslo_cache.get_cache(self.conf)

        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))
Exemple #5
0
    def test_using_replset(self):
        cache = oslo_cache.get_cache(self.conf)

        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))
Exemple #6
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)
Exemple #7
0
    def test_version_match(self):
        self.config(unreliable=True)
        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')
Exemple #8
0
    def test_write_concern_is_set(self):
        cache = oslo_cache.get_cache(self.conf)

        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('majority', wc.document['w'])
                self.assertFalse(wc.document['j'])
Exemple #9
0
    def test_write_concern_check_works(self):
        cache = oslo_cache.get_cache(self.conf)

        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=1)
                wc.__get__ = mock.Mock(return_value=write_concern)
                self.assertRaises(RuntimeError, mongodb.DataDriver,
                                  self.conf, cache,
                                  mongodb.ControlDriver(self.conf, cache))

                write_concern = pymongo.WriteConcern(w=2)
                wc.__get__ = mock.Mock(return_value=write_concern)
                mongodb.DataDriver(self.conf, cache,
                                   mongodb.ControlDriver(self.conf, cache))
Exemple #10
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)
Exemple #11
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)