diff --git a/mlink/example_cluster.py b/mlink/example_cluster.py new file mode 100644 index 00000000..f640da85 --- /dev/null +++ b/mlink/example_cluster.py @@ -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") + diff --git a/pbm-functional/pytest/Dockerfile-pykmip b/pbm-functional/pytest/Dockerfile-pykmip index 0a74c43c..2aa8a4cd 100644 --- a/pbm-functional/pytest/Dockerfile-pykmip +++ b/pbm-functional/pytest/Dockerfile-pykmip @@ -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 && \