Skip to content

Commit

Permalink
PBM-1114 (#45)
Browse files Browse the repository at this point in the history
* PBM tests with ratelimiter

* PBM-1114 simulate failure on uploading metadata files

* PBM-1114 added test
  • Loading branch information
olexandr-havryliak authored Sep 19, 2024
1 parent 72f5b0c commit 5e1dbce
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pbm-functional/pytest/Dockerfile-nginx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM nginx:stable-alpine
COPY conf/nginx.conf /etc/nginx/nginx.conf
EXPOSE 21114
72 changes: 72 additions & 0 deletions pbm-functional/pytest/conf/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
user nginx;
worker_processes auto;

error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
keepalive_timeout 65;
limit_req_zone $limit zone=one:10m rate=10r/m;

map $request_method $limit {
default "";
PUT $binary_remote_addr;
POST $binary_remote_addr;
}

server {
listen 21114;
server_name minio-nginx;

ignore_invalid_headers off;
client_max_body_size 0;
proxy_buffering off;
proxy_request_buffering off;

location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

proxy_connect_timeout 300;
proxy_http_version 1.1;
proxy_set_header Connection "";
chunked_transfer_encoding off;

proxy_pass http://minio:9000/;
}
location ~* metadata\.json {
if ($request_method = PUT) {
return 444;
}
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

proxy_connect_timeout 300;
proxy_http_version 1.1;
proxy_set_header Connection "";
chunked_transfer_encoding off;

proxy_pass http://minio:9000$request_uri;
}
}
}
11 changes: 11 additions & 0 deletions pbm-functional/pytest/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ services:
- "MINIO_SECRET_KEY=minio1234"
command: server /backups --console-address ":9001"

nginx-minio:
build:
dockerfile: ./Dockerfile-nginx
context: .
container_name: nginx-minio
hostname: nginx-minio
networks:
- test
depends_on:
- minio

createbucket:
container_name: createbucket
image: minio/mc
Expand Down
56 changes: 56 additions & 0 deletions pbm-functional/pytest/test_PBM-1114.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import pytest
import pymongo
import bson
import testinfra
import time
import os
import docker
import threading

from datetime import datetime
from cluster import Cluster

documents = [{"a": 1}, {"b": 2}, {"c": 3}, {"d": 4}]

@pytest.fixture(scope="package")
def docker_client():
return docker.from_env()

@pytest.fixture(scope="package")
def config():
return {"mongos": "mongos",
"configserver":
{"_id": "rscfg", "members": [{"host": "rscfg01"}]},
"shards": [
{"_id": "rs1", "members": [{"host": "rs101"}]},
{"_id": "rs2", "members": [{"host": "rs201"}]}
]}

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

@pytest.fixture(scope="function")
def start_cluster(cluster, request):
try:
cluster.destroy()
cluster.create()
cluster.setup_pbm()
result = cluster.exec_pbm_cli("config --set storage.s3.endpointUrl=http://nginx-minio:21114")
Cluster.log("Setup PBM with nginx proxy:\n" + result.stdout)
assert result.rc == 0
client = pymongo.MongoClient(cluster.connection)
client.admin.command("enableSharding", "test")
client.admin.command("shardCollection", "test.test", key={"_id": "hashed"})
yield True
finally:
if request.config.getoption("--verbose"):
cluster.get_logs()
cluster.destroy()

@pytest.mark.timeout(300, func_only=True)
def test_logical_PBM_T266(start_cluster, cluster):
cluster.check_pbm_status()
pymongo.MongoClient(cluster.connection)["test"]["test"].insert_many(documents)
result = cluster.exec_pbm_cli("backup --wait")
assert result.rc != 0, result.stdout + result.stderr

0 comments on commit 5e1dbce

Please sign in to comment.