-
Couldn't load subscription status.
- Fork 1
PBM use pytest shard for parallelization #442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
eae175c
PBM use pytest shard for parallelization
olexandr-havryliak 0454f18
Fix linting error
olexandr-havryliak 7e3299f
Explicitly disable the tests marked as jenkins and skipped, add the r…
olexandr-havryliak 86a2a1e
PBM. Re-design T299 test to work with parallel execution (#444)
sandraromanchenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| [tool.pytest.ini_options] | ||
| addopts = "-p no:cacheprovider" | ||
| markers = ["jenkins: mark test to run only in Jenkins or with --jenkins flag"] | ||
| markers = ["jenkins: mark test to run only in Jenkins or with --jenkins flag"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,3 @@ | ||
| import os | ||
|
|
||
| import docker | ||
| import pymongo | ||
| import pytest | ||
|
|
@@ -19,97 +17,88 @@ def docker_client(): | |
| def pbm_mongodb_uri(): | ||
| return 'mongodb://pbm:[email protected]:27017/?authSource=admin&serverSelectionTimeoutMS=10000' | ||
|
|
||
| @pytest.fixture | ||
| def rs_encrypted_same_key(pbm_mongodb_uri): | ||
| config = { | ||
| "_id": "rs1", | ||
| "members": [{"host": "rs101"}, {"host": "rs102"}, {"host": "rs103"}]} | ||
| return Cluster(config, pbm_mongodb_uri=pbm_mongodb_uri, mongod_extra_args="--enableEncryption --encryptionKeyFile=/etc/mongodb-keyfile") | ||
|
|
||
| @pytest.fixture | ||
| def rs_encrypted_mixed_key(pbm_mongodb_uri): | ||
| config = { | ||
| "_id": "rs1", | ||
| "members": [ | ||
| {"host": "rs101"},{"host": "rs102"}, | ||
| {"host": "rs101", "mongod_extra_args": "--enableEncryption --encryptionKeyFile=/etc/mongodb-keyfile"}, | ||
| {"host": "rs102", "mongod_extra_args": "--enableEncryption --encryptionKeyFile=/etc/mongodb-keyfile-new"}, | ||
| {"host": "rs103", "mongod_extra_args": "--enableEncryption --encryptionKeyFile=/etc/mongodb-keyfile-new"}]} | ||
| return Cluster(config, pbm_mongodb_uri=pbm_mongodb_uri, mongod_extra_args="--enableEncryption --encryptionKeyFile=/etc/mongodb-keyfile") | ||
| return Cluster(config, pbm_mongodb_uri=pbm_mongodb_uri) | ||
|
|
||
| @pytest.fixture | ||
| def rs_encrypted_new_key(pbm_mongodb_uri): | ||
| config = { | ||
| "_id": "rs1", | ||
| "members": [{"host": "rs101"}, {"host": "rs102"}, {"host": "rs103"}]} | ||
| return Cluster(config, pbm_mongodb_uri=pbm_mongodb_uri, mongod_extra_args="--enableEncryption --encryptionKeyFile=/etc/mongodb-keyfile-new") | ||
| return Cluster(config, pbm_mongodb_uri=pbm_mongodb_uri, mongod_extra_args="--enableEncryption --encryptionKeyFile=/etc/mongodb-keyfile") | ||
|
|
||
| @pytest.fixture | ||
| def start_cluster(request): | ||
| cluster_name, allow_partly_done, cleanup_backups = request.param | ||
| cluster = request.getfixturevalue(cluster_name) | ||
| def start_cluster(rs_encrypted_mixed_key, request): | ||
| cluster = rs_encrypted_mixed_key | ||
| try: | ||
| cluster.destroy() | ||
| cluster.create() | ||
| os.chmod("/backups", 0o777) | ||
| os.system("rm -rf /backups/*") | ||
| cluster.setup_pbm() | ||
| yield cluster, allow_partly_done, cluster_name | ||
| yield cluster | ||
| finally: | ||
| if request.config.getoption("--verbose"): | ||
| cluster.get_logs() | ||
| cluster.destroy(cleanup_backups=cleanup_backups) | ||
| cluster.destroy(cleanup_backups=True) | ||
|
|
||
| @pytest.mark.timeout(800, func_only=True) | ||
| # RS type, allow_partly_done, cleanup_backups | ||
| @pytest.mark.parametrize("start_cluster", | ||
| [("rs_encrypted_same_key", False, False), | ||
| ("rs_encrypted_mixed_key", True, False), | ||
| ("rs_encrypted_mixed_key", False, False), | ||
| ("rs_encrypted_new_key", False, True)], | ||
| ids=["same_key","mixed_key","mixed_key_fb","new_key_fb"],indirect=True) | ||
| @pytest.mark.parametrize('backup_type',['physical','incremental']) | ||
| def test_general_PBM_T299(start_cluster, docker_client, backup_type): | ||
| @pytest.mark.parametrize( | ||
| "allow_partly_done, start_new_cluster", | ||
| [(True, False), (False, False), (False, True)], | ||
| ids=["mixed_key_no_fb","mixed_key_fb","new_key_fb"]) | ||
| @pytest.mark.parametrize('backup_type', ['physical', 'incremental']) | ||
| def test_general_PBM_T299(start_cluster, docker_client, allow_partly_done, start_new_cluster, rs_encrypted_new_key, backup_type): | ||
| """ | ||
| Test fallback feature functionality during PBM physical restore. Due to configurations | ||
| where database encryption keys differ between backup and running DB, restore may | ||
| partially or fully fail, triggering fallback mechanism. | ||
| Behavior: | ||
| - Creates backup only during first test run | ||
| - For 'rs_encrypted_mixed_key' (with allow_partly_done=False) and 'rs_encrypted_new_key': | ||
| - Creates backup | ||
| - For mixed_key_fb and new_key_fb: | ||
| Pre-restore data is expected to persist due to fallback on restore failure | ||
| - For 'rs_encrypted_mixed_key' (with allow_partly_done=True) and 'rs_encrypted_same_key': | ||
| - For mixed_key_no_fb: | ||
| Only backup data should be present after restore (no fallback triggered) | ||
| - Verifies that .fallbacksync directory is cleaned up after restore on all nodes | ||
| """ | ||
| cluster, allow_partly_done, cluster_name = start_cluster | ||
| fallback_expected = (cluster_name == "rs_encrypted_new_key" or | ||
| (cluster_name == "rs_encrypted_mixed_key" and allow_partly_done is False)) | ||
| cluster = start_cluster | ||
| fallback_expected = (allow_partly_done is False) | ||
| cluster.check_pbm_status() | ||
| collection = pymongo.MongoClient(cluster.connection)["test"]["test"] | ||
| cache_entry = backup_cache.get(backup_type) | ||
| if not cache_entry: | ||
| inserted_docs = [] | ||
| collection.insert_many(documents) | ||
| inserted_docs.extend(documents) | ||
| if backup_type == "physical": | ||
| backup = cluster.make_backup("physical") | ||
| elif backup_type == "incremental": | ||
| cluster.make_backup("incremental --base") | ||
| collection.insert_many(incr_docs) | ||
| inserted_docs.extend(incr_docs) | ||
| backup = cluster.make_backup("incremental") | ||
| backup_cache[backup_type] = { | ||
| "backup": backup, | ||
| "inserted_docs": inserted_docs | ||
| } | ||
| assert collection.delete_many({}).deleted_count == len(inserted_docs), "Document deletion failed" | ||
| inserted_docs = [] | ||
| collection.insert_many(documents) | ||
| inserted_docs.extend(documents) | ||
| if backup_type == "physical": | ||
| backup = cluster.make_backup("physical") | ||
| elif backup_type == "incremental": | ||
| cluster.make_backup("incremental --base") | ||
| collection.insert_many(incr_docs) | ||
| inserted_docs.extend(incr_docs) | ||
| backup = cluster.make_backup("incremental") | ||
| assert collection.delete_many({}).deleted_count == len(inserted_docs), "Document deletion failed" | ||
|
|
||
| if start_new_cluster: | ||
| cluster.destroy() | ||
| rs_encrypted_new_key.create() | ||
| rs_encrypted_new_key.setup_pbm() | ||
| rs_encrypted_new_key.check_pbm_status() | ||
| pre_restore_docs = [{"_id": 100 + i, "name": f"pre_{i}", "value": i} for i in range(10)] | ||
| collection.insert_many(pre_restore_docs) | ||
| rs_encrypted_new_key.make_restore(backup, timeout=500, | ||
| restart_cluster=True, check_pbm_status=True, | ||
| restore_opts=["--fallback-enabled=true", "--allow-partly-done=" + str(allow_partly_done).lower()]) | ||
| else: | ||
| backup = cache_entry["backup"] | ||
| inserted_docs = cache_entry["inserted_docs"] | ||
| Cluster.log(f"Using existing backup: {backup}") | ||
| pre_restore_docs = [{"_id": 100 + i, "name": f"pre_{i}", "value": i} for i in range(10)] | ||
| collection.insert_many(pre_restore_docs) | ||
| cluster.make_restore(backup, timeout=500, restart_cluster=True, check_pbm_status=True, | ||
| pre_restore_docs = [{"_id": 100 + i, "name": f"pre_{i}", "value": i} for i in range(10)] | ||
| collection.insert_many(pre_restore_docs) | ||
| cluster.make_restore(backup, timeout=500, | ||
| restart_cluster=True, check_pbm_status=True, | ||
| restore_opts=["--fallback-enabled=true", "--allow-partly-done=" + str(allow_partly_done).lower()]) | ||
|
|
||
| expected_docs = pre_restore_docs if fallback_expected else inserted_docs | ||
| restored_count = collection.count_documents({}) | ||
| assert restored_count == len(expected_docs), f"Expected {len(expected_docs)} documents, found {restored_count}" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.