# You must have the 6 mongo servers running in Replicatikon_setup.txt and Replication_setup2.txt. # The replication in the replica set must be setup. # Make sure pymongo is installed. # https://docs.mongodb.com/manual/installation/ echo '#!/usr/bin/python # Submit port to the this script as './pymongo.py 3001' for exmaple. import sys try: port = int(sys.argv[1]) except: port = 3001 try: slaveOk = sys.argv[2] except: slaveOk = None import pymongo if slaveOk is not None: client = pymongo.MongoClient("localhost:" + str(port), readPreference="secondaryPreferred") else: client = pymongo.MongoClient("localhost:" + str(port)) db = client.test count = db.no.count() hi = db.command("hostInfo") print "count :", count, ": port :", port, ": hostname :", hi["system"]["hostname"] ' > mongo/pymongo_test.py chmod 755 mongo/pymongo_test.py rm -rf mongo/pymongo mkdir -p mongo/pymongo mongo/logs # Connect to primary and verify we have data. # All of these should have 1000 as the result if you did Replication_setup and Replication_setup2. # These should all fail, but for me it, worked, weird, except for 5 the arbiter. # I am upset because all but 1 should fail, but isn't. # Might be a default setting I need to get rid of for pymongo, not sure. ./mongo/pymongo_test.py 3001 ./mongo/pymongo_test.py 3002 ./mongo/pymongo_test.py 3003 ./mongo/pymongo_test.py 3004 ./mongo/pymongo_test.py 3005 ./mongo/pymongo_test.py 3006 # Now add slaveok, and only 5 should fail. ./mongo/pymongo_test.py 3001 1 ./mongo/pymongo_test.py 3002 1 ./mongo/pymongo_test.py 3003 1 ./mongo/pymongo_test.py 3004 1 ./mongo/pymongo_test.py 3005 1 ./mongo/pymongo_test.py 3006 1 # These mongo shell commands will fail but primary mongo --quiet --port 3001 --eval "db.no.count()" test mongo --quiet --port 3002 --eval "db.no.count()" test mongo --quiet --port 3003 --eval "db.no.count()" test mongo --quiet --port 3004 --eval "db.no.count()" test mongo --quiet --port 3005 --eval "db.no.count()" test mongo --quiet --port 3006 --eval "db.no.count()" test #Only 5 should fail. mongo --quiet --port 3001 --eval "rs.slaveOk(); db.no.count()" test mongo --quiet --port 3002 --eval "rs.slaveOk(); db.no.count()" test mongo --quiet --port 3003 --eval "rs.slaveOk(); db.no.count()" test mongo --quiet --port 3004 --eval "rs.slaveOk(); db.no.count()" test mongo --quiet --port 3005 --eval "rs.slaveOk(); db.no.count()" test mongo --quiet --port 3006 --eval "rs.slaveOk(); db.no.count()" test