From 500e01967db99b67d8fc753b2b80c58a21656877 Mon Sep 17 00:00:00 2001 From: Sandra Romanchenko <53295797+sandraromanchenko@users.noreply.github.com> Date: Thu, 7 Nov 2024 13:08:48 +0200 Subject: [PATCH] PBM-1417. Allow multi-DB backup (#232) --- pbm-functional/pytest/test_replicaset.py | 7 ++++++- pbm-functional/pytest/test_sharded.py | 16 +++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/pbm-functional/pytest/test_replicaset.py b/pbm-functional/pytest/test_replicaset.py index abaf40cd..26b88c83 100644 --- a/pbm-functional/pytest/test_replicaset.py +++ b/pbm-functional/pytest/test_replicaset.py @@ -46,12 +46,17 @@ def test_logical(start_cluster,cluster): cluster.check_pbm_status() pymongo.MongoClient(cluster.connection)["test"]["test"].insert_many(documents) pymongo.MongoClient(cluster.connection)["test"]["test1"].insert_many(documents) - backup_partial=cluster.make_backup("logical --ns=test.test") + pymongo.MongoClient(cluster.connection)["test2"]["test21"].insert_many(documents) + pymongo.MongoClient(cluster.connection)["test2"]["test22"].insert_many(documents) + backup_partial=cluster.make_backup("logical --ns=test.test,test2.*") backup_full=cluster.make_backup("logical") pymongo.MongoClient(cluster.connection).drop_database('test') + pymongo.MongoClient(cluster.connection).drop_database('test2') cluster.make_restore(backup_partial,check_pbm_status=True) assert pymongo.MongoClient(cluster.connection)["test"]["test"].count_documents({}) == len(documents) assert pymongo.MongoClient(cluster.connection)["test"]["test1"].count_documents({}) == 0 + assert pymongo.MongoClient(cluster.connection)["test2"]["test21"].count_documents({}) == len(documents) + assert pymongo.MongoClient(cluster.connection)["test2"]["test22"].count_documents({}) == len(documents) pymongo.MongoClient(cluster.connection).drop_database('test') cluster.make_restore(backup_full,check_pbm_status=True) assert pymongo.MongoClient(cluster.connection)["test"]["test"].count_documents({}) == len(documents) diff --git a/pbm-functional/pytest/test_sharded.py b/pbm-functional/pytest/test_sharded.py index 8709c6f8..e601a2fb 100644 --- a/pbm-functional/pytest/test_sharded.py +++ b/pbm-functional/pytest/test_sharded.py @@ -40,9 +40,11 @@ def start_cluster(cluster,request): cluster.setup_pbm() client=pymongo.MongoClient(cluster.connection) client.admin.command("enableSharding", "test") + client.admin.command("enableSharding", "test2") client.admin.command("shardCollection", "test.test", key={"_id": "hashed"}) client.admin.command("shardCollection", "test.test2", key={"_id": "hashed"}) client.admin.command("shardCollection", "test.test3", key={"_id": "hashed"}) + client.admin.command("shardCollection", "test2.test21", key={"_id": "hashed"}) yield True finally: @@ -55,16 +57,20 @@ def test_logical_PBM_T218(start_cluster,cluster): cluster.check_pbm_status() pymongo.MongoClient(cluster.connection)["test"]["test"].insert_many(documents) pymongo.MongoClient(cluster.connection)["test"]["test1"].insert_many(documents) - backup_partial_sharded=cluster.make_backup("logical --ns=test.test") - backup_partial_unsharded=cluster.make_backup("logical --ns=test.test1") + pymongo.MongoClient(cluster.connection)["test2"]["test21"].insert_many(documents) + pymongo.MongoClient(cluster.connection)["test2"]["test22"].insert_many(documents) + backup_partial=cluster.make_backup("logical --ns=test.test,test2.*") backup_full=cluster.make_backup("logical") pymongo.MongoClient(cluster.connection).drop_database('test') - cluster.make_restore(backup_partial_sharded,check_pbm_status=True) + cluster.make_restore(backup_partial,check_pbm_status=True) assert pymongo.MongoClient(cluster.connection)["test"]["test"].count_documents({}) == len(documents) assert pymongo.MongoClient(cluster.connection)["test"].command("collstats", "test").get("sharded", False) - cluster.make_restore(backup_partial_unsharded,check_pbm_status=True) - assert pymongo.MongoClient(cluster.connection)["test"]["test1"].count_documents({}) == len(documents) + assert pymongo.MongoClient(cluster.connection)["test"]["test1"].count_documents({}) == 0 assert pymongo.MongoClient(cluster.connection)["test"].command("collstats", "test1").get("sharded", True) is False + assert pymongo.MongoClient(cluster.connection)["test2"]["test21"].count_documents({}) == len(documents) + assert pymongo.MongoClient(cluster.connection)["test2"].command("collstats", "test21").get("sharded", False) + assert pymongo.MongoClient(cluster.connection)["test2"]["test22"].count_documents({}) == len(documents) + assert pymongo.MongoClient(cluster.connection)["test2"].command("collstats", "test22").get("sharded", True) is False pymongo.MongoClient(cluster.connection).drop_database('test') cluster.make_restore(backup_full,check_pbm_status=True) assert pymongo.MongoClient(cluster.connection)["test"]["test1"].count_documents({}) == len(documents)