'Initialize the cluster:
Clean out the databases used by the tests
Make connections to mongos, mongods
Create and shard test collections
Create OplogThreads'

def set_up_sharded_cluster(self, sharded_cluster_type):

    self.cluster = sharded_cluster_type().start()
    self.mongos_conn = self.cluster.client()
    self.shard1_conn = self.cluster.shards[0].client()
    self.shard2_conn = self.cluster.shards[1].client()
    self.mongos_conn['test']['mcsharded'].drop()
    self.mongos_conn.config.settings.update_one({'_id': 'balancer'}, {'$set': {'stopped': True}}, upsert=True)
    self.mongos_conn['test']['mcsharded'].create_index('i')
    self.mongos_conn.admin.command('enableSharding', 'test')
    self.mongos_conn.admin.command('shardCollection', 'test.mcsharded', key={'i': 1})
    self.mongos_conn.admin.command(bson.SON([('split', 'test.mcsharded'), ('middle', {'i': 1000})]))
    try:
        self.mongos_conn['admin'].command('moveChunk', 'test.mcsharded', find={'i': 1}, to='demo-set-0')
    except pymongo.errors.OperationFailure:
        pass
    try:
        self.mongos_conn['admin'].command('moveChunk', 'test.mcsharded', find={'i': 1000}, to='demo-set-1')
    except pymongo.errors.OperationFailure:
        pass
    self.mongos_conn['test']['mcsharded'].insert_one({'i': 1})
    self.mongos_conn['test']['mcsharded'].insert_one({'i': 1000})
    def chunks_moved():
        doc1 = self.shard1_conn.test.mcsharded.find_one()
        doc2 = self.shard2_conn.test.mcsharded.find_one()
        if (None in (doc1, doc2)):
            return False
        return ((doc1['i'] == 1) and (doc2['i'] == 1000))
    assert_soon(chunks_moved, max_tries=120, message=('chunks    not    moved?    doc1=%r,    doc2=%r' % (self.shard1_conn.test.mcsharded.find_one(), self.shard2_conn.test.mcsharded.find_one())))
    self.mongos_conn.test.mcsharded.delete_many({})
    try:
        os.unlink('oplog.timestamp')
    except OSError:
        pass
    open('oplog.timestamp', 'w').close()
    doc_manager = DocManager()
    oplog_progress = LockingDict()
    namespace_config = NamespaceConfig(namespace_set=['test.mcsharded', 'test.mcunsharded'])
    self.opman1 = OplogThread(primary_client=self.shard1_conn, doc_managers=(doc_manager,), oplog_progress_dict=oplog_progress, namespace_config=namespace_config, mongos_client=self.mongos_conn)
    self.opman2 = OplogThread(primary_client=self.shard2_conn, doc_managers=(doc_manager,), oplog_progress_dict=oplog_progress, namespace_config=namespace_config, mongos_client=self.mongos_conn)
