Skip to content

PML example setup with failpoint for simulating network errors #310

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 2 commits into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions mlink/example_cluster.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import signal
import pymongo
from cluster import Cluster
from mongolink import Mongolink

"""
docker compose run -ti --rm test python3 -i example_cluster.py
The way to simulate network errors using failpoint 'failCommand'.
To enable failpoint based on appName use connection string with 'appName' parameter
Parameters passed to failpoint command:
'commands' - the array of commands to fail on like ['hello','find']
'mode' - can be either 'alwaysOn' or dictionary with 'skip' and 'times' like {skip: 1, times: 2}
There is the way not to close the connection but return known or unknown error to the client
See the examples in jstests/core/failcommand_failpoint.js
"""

dstRS = Cluster({ "_id": "rs2", "members": [{"host":"rs201"}]},mongod_extra_args='--setParameter enableTestCommands=1')
srcRS = Cluster({ "_id": "rs1", "members": [{"host":"rs101"}]},mongod_extra_args='--setParameter enableTestCommands=1')
mlink = Mongolink('mlink',srcRS.mlink_connection + '&appName=mongolink', dstRS.mlink_connection + '&appName=mongolink')

def configure_failpoint(connection,commands,mode):
client = pymongo.MongoClient(connection)
data = { 'closeConnection': True, 'failCommands': commands, 'appName': 'mongolink'}
result = client.admin.command({'configureFailPoint': 'failCommand', 'mode': mode, 'data': data})
Cluster.log(result)

def handler(signum,frame):
mlink.destroy()
srcRS.destroy()
dstRS.destroy()
exit(0)

srcRS.destroy()
dstRS.destroy()
mlink.destroy()
srcRS.create()
dstRS.create()
mlink.create()
configure_failpoint(srcRS.connection,['find','listIndexes','listDatabases','listCollections'],'alwaysOn')

signal.signal(signal.SIGINT,handler)
print("\nCluster is prepared and ready to use")
print("\nPress CTRL-C to destroy and exit")

2 changes: 2 additions & 0 deletions pbm-functional/pytest/Dockerfile-pykmip
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ RUN apk add --no-cache libffi-dev build-base bash git openssl && cd ~ && \
./easyrsa --batch build-server-full pykmip nopass && \
./easyrsa --batch build-client-full mongod nopass && \
cat pki/issued/mongod.crt pki/private/mongod.key > /etc/mongod.pem && \
pip install --upgrade --no-cache-dir --break-system-packages pip && \
pip install --upgrade --no-cache-dir --break-system-packages setuptools && \
pip install --no-cache-dir --break-system-packages pykmip && cd ~ && \
git clone https://github.com/OpenKMIP/PyKMIP && \
cd PyKMIP && \
Expand Down