|
| 1 | +import pytest |
| 2 | +import pymongo |
| 3 | +import time |
| 4 | +import os |
| 5 | + |
| 6 | +from cluster import Cluster |
| 7 | + |
| 8 | +@pytest.fixture(scope="package") |
| 9 | +def config(): |
| 10 | + return { "mongos": "mongos", |
| 11 | + "configserver": |
| 12 | + {"_id": "rscfg", "members": [{"host":"rscfg01"}]}, |
| 13 | + "shards":[ |
| 14 | + {"_id": "rs1", "members": [{"host":"rs101"}]}, |
| 15 | + {"_id": "rs2", "members": [{"host":"rs201"}]} |
| 16 | + ]} |
| 17 | + |
| 18 | +@pytest.fixture(scope="package") |
| 19 | +def cluster(config): |
| 20 | + return Cluster(config) |
| 21 | + |
| 22 | +@pytest.fixture(scope="function") |
| 23 | +def start_cluster(cluster,request): |
| 24 | + try: |
| 25 | + cluster.destroy() |
| 26 | + os.chmod("/backups",0o777) |
| 27 | + os.system("rm -rf /backups/*") |
| 28 | + cluster.create() |
| 29 | + cluster.setup_pbm() |
| 30 | + profile=cluster.exec_pbm_cli("profile add worm /etc/minio-worm.conf --wait") |
| 31 | + assert profile.rc==0, profile.stderr |
| 32 | + assert "OK" in profile.stdout, profile.stdout |
| 33 | + client=pymongo.MongoClient(cluster.connection) |
| 34 | + client.admin.command("enableSharding", "test") |
| 35 | + client.admin.command("shardCollection", "test.test", key={"_id": "hashed"}) |
| 36 | + yield True |
| 37 | + |
| 38 | + finally: |
| 39 | + if request.config.getoption("--verbose"): |
| 40 | + cluster.get_logs() |
| 41 | + cluster.destroy(cleanup_backups=True) |
| 42 | + |
| 43 | +@pytest.mark.timeout(300,func_only=True) |
| 44 | +@pytest.mark.parametrize('backup_type',['logical','physical']) |
| 45 | +def test_worm_profile(start_cluster,cluster,backup_type): |
| 46 | + client=pymongo.MongoClient(cluster.connection) |
| 47 | + for i in range(300): |
| 48 | + client['test']['test'].insert_one({"doc":i}) |
| 49 | + |
| 50 | + backup=cluster.make_backup(backup_type + " --profile worm") |
| 51 | + pymongo.MongoClient(cluster.connection).drop_database('test') |
| 52 | + Cluster.log("Attempt restore " + backup_type + " backup from the worm storage") |
| 53 | + if backup_type == 'logical': |
| 54 | + cluster.make_restore(backup, check_pbm_status=True) |
| 55 | + else: |
| 56 | + cluster.make_restore(backup, restart_cluster=True, check_pbm_status=True) |
| 57 | + time.sleep(5) |
| 58 | + assert pymongo.MongoClient(cluster.connection)["test"]["test"].count_documents({}) == 300 |
| 59 | + assert pymongo.MongoClient(cluster.connection)["test"].command("collstats", "test").get("sharded", False) |
0 commit comments