Skip to content

Commit

Permalink
PBM-1389 disallow performing selective backup
Browse files Browse the repository at this point in the history
  • Loading branch information
olexandr-havryliak committed Sep 19, 2024
1 parent 5e1dbce commit bc27086
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/PBM-FULL.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
strategy:
fail-fast: false
matrix:
psmdb: ["5.0", "6.0", "7.0"]
psmdb: ["5.0", "6.0", "7.0", "8.0"]
test: [logical, physical, incremental, external]
env:
PBM_BRANCH: ${{ github.event.inputs.pbm_branch || 'dev' }}
Expand All @@ -32,7 +32,7 @@ jobs:
- uses: actions/checkout@v4
- name: Setup environment with PSMDB ${{ matrix.psmdb }} and PBM branch ${{ env.PBM_BRANCH }}
run: |
PSMDB=percona/percona-server-mongodb:${{ matrix.psmdb }} docker compose build
PSMDB=perconalab/percona-server-mongodb:${{ matrix.psmdb }} docker compose build
docker compose up -d
working-directory: ./pbm-functional/pytest
- name: Test ${{ matrix.test }} backup/restore on PSMDB ${{ matrix.psmdb }} and PBM branch ${{ env.PBM_BRANCH }}
Expand Down
19 changes: 12 additions & 7 deletions pbm-functional/pytest/test_PBM-1355.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_general_PBM_T257(start_cluster,cluster,backup_type,restore_type):
for i in range(600):
client['test']['test'].insert_one({"doc":i})
time.sleep(0.1)
time.sleep(10)
time.sleep(60)
pitr = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S")
Cluster.log("Time for PITR is: " + pitr)
pitr_backup="--time=" + pitr
Expand Down Expand Up @@ -144,10 +144,20 @@ def test_incremental_PBM_T258(start_cluster,cluster):
assert pymongo.MongoClient(cluster.connection)["test"]["test"].count_documents({}) == 1200
assert pymongo.MongoClient(cluster.connection)["test"].command("collstats", "test").get("sharded", False)

@pytest.mark.parametrize('command',['config --force-resync','backup'])
def test_logical_cli_PBM_T260(start_cluster,cluster,command):
cluster.check_pbm_status()
result = cluster.exec_pbm_cli(command + ' --wait')
assert result.rc == 0, result.stderr
Cluster.log(result.stdout)


"""
@pytest.mark.timeout(900,func_only=True)
@pytest.mark.parametrize('restore_ns',['sharded','unsharded'])
@pytest.mark.parametrize('restore_type',['base','pitr'])
def test_logical_selective_PBM_T259(start_cluster,cluster,restore_ns,restore_type):
pytest.skip("Not implemented")
cluster.check_pbm_status()
client=pymongo.MongoClient(cluster.connection)
for i in range(600):
Expand Down Expand Up @@ -186,9 +196,4 @@ def test_logical_selective_PBM_T259(start_cluster,cluster,restore_ns,restore_typ
cluster.make_restore(backup,restart_cluster=False,check_pbm_status=True,make_resync=False)
assert pymongo.MongoClient(cluster.connection)["test"][collection].count_documents({}) == 1200
assert pymongo.MongoClient(cluster.connection)["test"][empty_collection].count_documents({}) == 0

@pytest.mark.parametrize('command',['config --force-resync','backup'])
def test_logical_cli_PBM_T260(start_cluster,cluster,command):
result = cluster.exec_pbm_cli(command + ' --wait')
assert result.rc == 0, result.stderr
Cluster.log(result.stdout)
"""
70 changes: 70 additions & 0 deletions pbm-functional/pytest/test_PBM-1389.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import pytest
import pymongo
import bson
import testinfra
import time
import os
import docker

from datetime import datetime
from cluster import Cluster
from packaging import version


@pytest.fixture(scope="package")
def mongod_version():
return docker.from_env().containers.run(
image='replica_member/local',
remove=True,
command='bash -c \'mongod --version | head -n1 | sed "s/db version v//"\''
).decode("utf-8", errors="replace")

@pytest.fixture(scope="package")
def config(mongod_version):
if version.parse(mongod_version) < version.parse("8.0.0"):
pytest.skip("Unsupported version for config shards")
else:
return { "mongos": "mongos",
"configserver":
{"_id": "rscfg", "members": [{"host":"rscfg01"},{"host": "rscfg02"},{"host": "rscfg03" }]},
"shards":[
{"_id": "rs1", "members": [{"host":"rs101"},{"host": "rs102"},{"host": "rs103" }]}
]}

@pytest.fixture(scope="package")
def cluster(config):
return Cluster(config)

@pytest.fixture(scope="function")
def start_cluster(cluster,request):
try:
cluster.destroy()
os.chmod("/backups",0o777)
os.system("rm -rf /backups/*")
cluster.create()
client=pymongo.MongoClient(cluster.connection)
Cluster.log(client.admin.command({'transitionFromDedicatedConfigServer': 1}))
client.admin.command("enableSharding", "test")
client.admin.command("shardCollection", "test.test", key={"_id": "hashed"})
cluster.setup_pbm()
result = cluster.exec_pbm_cli("config --set storage.type=filesystem --set storage.filesystem.path=/backups --set backup.compression=none")
assert result.rc == 0
Cluster.log("Setup PBM with fs storage:\n" + result.stdout)
yield True
finally:
if request.config.getoption("--verbose"):
cluster.get_logs()
cluster.destroy()

@pytest.mark.timeout(300,func_only=True)
def test_logical_selective_PBM_T267(start_cluster,cluster):
cluster.check_pbm_status()
client=pymongo.MongoClient(cluster.connection)
for i in range(100):
client['test']['test'].insert_one({"doc":i})
client['test']['test1'].insert_one({"doc":i})

result = cluster.exec_pbm_cli("logical --ns=test.test --wait")
assert result.rc != 0, result.stdout + result.stderr
result = cluster.exec_pbm_cli("logical --ns=test.test1 --wait")
assert result.rc != 0, result.stdout + result.stderr

0 comments on commit bc27086

Please sign in to comment.