def test_copy_db_auth_concurrent(self): # SERVER-6427, can't copy database via mongos with auth. yield skip_if_mongos(self.cx) n_copies = 2 test_db_names = ['motor_test_%s' % i for i in range(n_copies)] # 1. Drop old test DBs yield self.cx.drop_database('motor_test') yield self.collection.insert({'_id': 1}) yield self.drop_databases(test_db_names) # 2. Copy a test DB N times at once try: # self.cx is logged in as root. yield self.cx.motor_test.add_user('mike', 'password') client = self.get_client() results = yield [ client.copy_database( 'motor_test', test_db_name, username='******', password='******') for test_db_name in test_db_names] self.assertTrue(all(isinstance(i, dict) for i in results)) yield self.check_copydb_results({'_id': 1}, test_db_names) finally: yield remove_all_users(client.motor_test) yield self.drop_databases( test_db_names, authenticated_client=self.cx)
def test_parallel_scan(self): if not (yield version.at_least(self.cx, (2, 5, 5))): raise SkipTest("Requires MongoDB >= 2.5.5") yield skip_if_mongos(self.cx) collection = self.collection # Enough documents that each cursor requires multiple batches. yield collection.remove() yield collection.insert(({'_id': i} for i in range(8000)), w=test.env.w) if test.env.is_replica_set: client = self.motor_rsc() # Test that getMore messages are sent to the right server. client.read_preference = ReadPreference.SECONDARY collection = client.motor_test.test_collection docs = [] @gen.coroutine def f(cursor): self.assertTrue(isinstance(cursor, motor.MotorCommandCursor)) while (yield cursor.fetch_next): docs.append(cursor.next_object()) cursors = yield collection.parallel_scan(3) yield [f(cursor) for cursor in cursors] self.assertEqual(len(docs), (yield collection.count()))
def test_parallel_scan(self): if not (yield version.at_least(self.cx, (2, 5, 5))): raise SkipTest("Requires MongoDB >= 2.5.5") yield skip_if_mongos(self.cx) collection = self.collection # Enough documents that each cursor requires multiple batches. yield collection.remove() yield collection.insert(({ '_id': i } for i in range(8000)), w=test.env.w) if test.env.is_replica_set: client = self.motor_rsc() # Test that getMore messages are sent to the right server. client.read_preference = ReadPreference.SECONDARY collection = client.motor_test.test_collection docs = [] @gen.coroutine def f(cursor): self.assertTrue(isinstance(cursor, motor.MotorCommandCursor)) while (yield cursor.fetch_next): docs.append(cursor.next_object()) cursors = yield collection.parallel_scan(3) yield [f(cursor) for cursor in cursors] self.assertEqual(len(docs), (yield collection.count()))
def test_copy_db_auth(self): # SERVER-6427, can't copy database via mongos with auth. yield skip_if_mongos(self.cx) yield self.collection.insert({'_id': 1}) try: # self.cx is logged in as root. yield self.cx.motor_test.add_user('mike', 'password') client = self.get_client() target_db_name = 'motor_test_2' with assert_raises(pymongo.errors.OperationFailure): yield client.copy_database( 'motor_test', target_db_name, username='******', password='******') with assert_raises(pymongo.errors.OperationFailure): yield client.copy_database( 'motor_test', target_db_name, username='******', password='******') # Copy a database using name and password. yield client.copy_database( 'motor_test', target_db_name, username='******', password='******') self.assertEqual( {'_id': 1}, (yield client[target_db_name].test_collection.find_one())) yield client.drop_database(target_db_name) finally: yield remove_all_users(self.cx.motor_test)
def test_copy_db_auth_concurrent(self): # SERVER-6427, can't copy database via mongos with auth. yield skip_if_mongos(self.cx) n_copies = 2 test_db_names = ['motor_test_%s' % i for i in range(n_copies)] # 1. Drop old test DBs yield self.cx.drop_database('motor_test') yield self.collection.insert({'_id': 1}) yield self.drop_databases(test_db_names) # 2. Copy a test DB N times at once try: # self.cx is logged in as root. yield self.cx.motor_test.add_user('mike', 'password') client = self.get_client() results = yield [ client.copy_database('motor_test', test_db_name, username='******', password='******') for test_db_name in test_db_names ] self.assertTrue(all(isinstance(i, dict) for i in results)) yield self.check_copydb_results({'_id': 1}, test_db_names) finally: yield remove_all_users(client.motor_test) yield self.drop_databases(test_db_names, authenticated_client=self.cx)
def test_copy_db_auth_concurrent(self): cx = self.get_client() yield skip_if_mongos(cx) n_copies = 2 test_db_names = ['motor_test_%s' % i for i in range(n_copies)] # 1. Drop old test DBs yield cx.drop_database('motor_test') yield self.drop_databases(test_db_names) # 2. Copy a test DB N times at once collection = cx.motor_test.test_collection yield collection.remove() yield collection.insert({'_id': 1}) yield cx.admin.add_user('admin', 'password', ) yield cx.admin.authenticate('admin', 'password') try: yield cx.motor_test.add_user('mike', 'password') results = yield [ cx.copy_database( 'motor_test', test_db_name, username='******', password='******') for test_db_name in test_db_names] self.assertTrue(all(isinstance(i, dict) for i in results)) yield self.check_copydb_results({'_id': 1}, test_db_names) finally: yield remove_all_users(cx.motor_test) yield self.drop_databases(test_db_names, authenticated_client=cx) yield cx.admin.remove_user('admin')
def test_copy_db_auth(self): # This will catch any socket leaks. cx = self.get_client(max_pool_size=1, waitQueueTimeoutMS=1) # SERVER-6427, can't copy database via mongos with auth. yield skip_if_mongos(cx) target_db_name = 'motor_test_2' collection = cx.motor_test.test_collection yield collection.remove() yield collection.insert({'_id': 1}) yield cx.admin.add_user('admin', 'password') yield cx.admin.authenticate('admin', 'password') try: yield cx.motor_test.add_user('mike', 'password') with assert_raises(pymongo.errors.OperationFailure): yield cx.copy_database( 'motor_test', target_db_name, username='******', password='******') with assert_raises(pymongo.errors.OperationFailure): yield cx.copy_database( 'motor_test', target_db_name, username='******', password='******') # Copy a database using name and password. yield cx.copy_database( 'motor_test', target_db_name, username='******', password='******') self.assertEqual( {'_id': 1}, (yield cx[target_db_name].test_collection.find_one())) yield cx.drop_database(target_db_name) finally: yield remove_all_users(cx.motor_test) yield cx.admin.remove_user('admin') cx.close() gc.collect()
def test_copy_db_auth(self): # See SERVER-6427. cx = self.get_client() yield skip_if_mongos(cx) target_db_name = 'motor_test_2' collection = cx.motor_test.test_collection yield collection.remove() yield collection.insert({'_id': 1}) yield cx.admin.add_user('admin', 'password') yield cx.admin.authenticate('admin', 'password') try: yield cx.motor_test.add_user('mike', 'password') with assert_raises(pymongo.errors.OperationFailure): yield cx.copy_database('motor_test', target_db_name, username='******', password='******') with assert_raises(pymongo.errors.OperationFailure): yield cx.copy_database('motor_test', target_db_name, username='******', password='******') # Copy a database using name and password. yield cx.copy_database('motor_test', target_db_name, username='******', password='******') self.assertEqual( {'_id': 1}, (yield cx[target_db_name].test_collection.find_one())) yield cx.drop_database(target_db_name) finally: yield remove_all_users(cx.motor_test) yield cx.admin.remove_user('admin')
def test_copy_db_auth_concurrent(self): cx = self.get_client() yield skip_if_mongos(cx) n_copies = 2 test_db_names = ['motor_test_%s' % i for i in range(n_copies)] # 1. Drop old test DBs yield cx.drop_database('motor_test') yield self.drop_databases(test_db_names) # 2. Copy a test DB N times at once collection = cx.motor_test.test_collection yield collection.remove() yield collection.insert({'_id': 1}) yield cx.admin.add_user( 'admin', 'password', ) yield cx.admin.authenticate('admin', 'password') try: yield cx.motor_test.add_user('mike', 'password') results = yield [ cx.copy_database('motor_test', test_db_name, username='******', password='******') for test_db_name in test_db_names ] self.assertTrue(all(isinstance(i, dict) for i in results)) yield self.check_copydb_results({'_id': 1}, test_db_names) finally: yield remove_all_users(cx.motor_test) yield self.drop_databases(test_db_names, authenticated_client=cx) yield cx.admin.remove_user('admin')
def test_copy_db_auth(self): # See SERVER-6427. cx = self.get_client() yield skip_if_mongos(cx) target_db_name = 'motor_test_2' collection = cx.motor_test.test_collection yield collection.remove() yield collection.insert({'_id': 1}) yield cx.admin.add_user('admin', 'password') yield cx.admin.authenticate('admin', 'password') try: yield cx.motor_test.add_user('mike', 'password') with assert_raises(pymongo.errors.OperationFailure): yield cx.copy_database( 'motor_test', target_db_name, username='******', password='******') with assert_raises(pymongo.errors.OperationFailure): yield cx.copy_database( 'motor_test', target_db_name, username='******', password='******') # Copy a database using name and password. yield cx.copy_database( 'motor_test', target_db_name, username='******', password='******') self.assertEqual( {'_id': 1}, (yield cx[target_db_name].test_collection.find_one())) yield cx.drop_database(target_db_name) finally: yield remove_all_users(cx.motor_test) yield cx.admin.remove_user('admin')
def test_copy_db_auth(self): # SERVER-6427, can't copy database via mongos with auth. yield skip_if_mongos(self.cx) yield self.collection.insert({'_id': 1}) try: # self.cx is logged in as root. yield self.cx.motor_test.add_user('mike', 'password') # This will catch any socket leaks. client = self.get_client(max_pool_size=1, waitQueueTimeoutMS=1) target_db_name = 'motor_test_2' with assert_raises(pymongo.errors.OperationFailure): yield client.copy_database('motor_test', target_db_name, username='******', password='******') with assert_raises(pymongo.errors.OperationFailure): yield client.copy_database('motor_test', target_db_name, username='******', password='******') # Copy a database using name and password. yield client.copy_database('motor_test', target_db_name, username='******', password='******') self.assertEqual( {'_id': 1}, (yield client[target_db_name].test_collection.find_one())) yield client.drop_database(target_db_name) finally: yield remove_all_users(self.cx.motor_test)