in scripts/comparison.py [0:0]
def check(src, dst):
#
# check metadata
#
srcDbNames = src.conn.database_names()
dstDbNames = dst.conn.database_names()
srcDbNames = [db for db in srcDbNames if db not in configure[EXCLUDE_DBS]]
dstDbNames = [db for db in dstDbNames if db not in configure[EXCLUDE_DBS]]
if len(srcDbNames) != len(dstDbNames):
log_error("DIFF => database count not equals src[%s] != dst[%s].\nsrc: %s\ndst: %s" % (len(srcDbNames),
len(dstDbNames),
srcDbNames,
dstDbNames))
return False
else:
log_info("EQUL => database count equals")
# check database names and collections
for db in srcDbNames:
if db in configure[EXCLUDE_DBS]:
log_info("IGNR => ignore database [%s]" % db)
continue
if dstDbNames.count(db) == 0:
log_error("DIFF => database [%s] only in srcDb" % (db))
return False
# db.stats() comparison
srcDb = src.conn[db]
dstDb = dst.conn[db]
# srcStats = srcDb.command("dbstats")
# dstStats = dstDb.command("dbstats")
#
# srcStats = filter_check(srcStats)
# dstStats = filter_check(dstStats)
#
# if srcStats != dstStats:
# log_error("DIFF => database [%s] stats not equals src[%s], dst[%s]" % (db, srcStats, dstStats))
# return False
# else:
# log_info("EQUL => database [%s] stats equals" % db)
# for collections in db
srcColls = srcDb.collection_names()
dstColls = dstDb.collection_names()
srcColls = [coll for coll in srcColls if coll not in configure[EXCLUDE_COLLS] and srcColls.count(coll) > 0]
dstColls = [coll for coll in dstColls if coll not in configure[EXCLUDE_COLLS] and dstColls.count(coll) > 0]
if len(srcColls) != len(dstColls):
log_error("DIFF => database [%s] collections count not equals, src[%s], dst[%s]" % (db, srcColls, dstColls))
return False
else:
log_info("EQUL => database [%s] collections count equals" % (db))
for coll in srcColls:
if coll in configure[EXCLUDE_COLLS]:
log_info("IGNR => ignore collection [%s]" % coll)
continue
if dstColls.count(coll) == 0:
log_error("DIFF => collection only in source [%s]" % (coll))
return False
srcColl = srcDb[coll]
dstColl = dstDb[coll]
# comparison collection records number
if srcColl.count() != dstColl.count():
log_error("DIFF => collection [%s] record count not equals" % (coll))
return False
else:
log_info("EQUL => collection [%s] record count equals" % (coll))
# comparison collection index number
src_index_length = len(srcColl.index_information())
dst_index_length = len(dstColl.index_information())
if src_index_length != dst_index_length:
log_error("DIFF => collection [%s] index number not equals: src[%r], dst[%r]" % (coll, src_index_length, dst_index_length))
return False
else:
log_info("EQUL => collection [%s] index number equals" % (coll))
# check sample data
if not data_comparison(srcColl, dstColl, configure[COMPARISION_MODE]):
log_error("DIFF => collection [%s] data comparison not equals" % (coll))
return False
else:
log_info("EQUL => collection [%s] data data comparison exactly eauals" % (coll))
return True