Skip to content

Commit

Permalink
Fix some tests and made some optimizations in redis tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TheophileDiot committed Jan 17, 2024
1 parent cebcf57 commit 9cce272
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 78 deletions.
58 changes: 4 additions & 54 deletions tests/core/redis/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,67 +119,15 @@ services:
deploy:
replicas: 2

bw-redis-sentinel-1:
bw-redis-sentinel:
image: bitnami/redis-sentinel:7.2
command: /opt/bitnami/scripts/redis-sentinel/run.sh --aclfile /acl/sentinel.acl
volumes:
- ./acl:/acl
- ./tls:/tls
environment:
REDIS_SENTINEL_PORT_NUMBER: "26379"
REDIS_SENTINEL_TLS_PORT_NUMBER: "26379"
REDIS_SENTINEL_TLS_ENABLED: "no"
REDIS_SENTINEL_TLS_CERT_FILE: "/tls/sentinel.pem"
REDIS_SENTINEL_TLS_KEY_FILE: "/tls/sentinel.key"
REDIS_SENTINEL_TLS_CA_FILE: "/tls/sentinel_ca.crt"
REDIS_SENTINEL_TLS_AUTH_CLIENTS: "no"
REDIS_MASTER_HOST: "bw-redis"
REDIS_MASTER_SET: "bw-master"
REDIS_MASTER_PORT_NUMBER: "6379"
REDIS_MASTER_PASSWORD: ""
ALLOW_EMPTY_PASSWORD: "yes"
depends_on:
- bw-redis
- bw-redis-slave
networks:
- bw-services

bw-redis-sentinel-2:
image: bitnami/redis-sentinel:7.2
command: /opt/bitnami/scripts/redis-sentinel/run.sh --aclfile /acl/sentinel.acl
volumes:
- ./acl:/acl
- ./tls:/tls
environment:
REDIS_SENTINEL_PORT_NUMBER: "26379"
REDIS_SENTINEL_TLS_PORT_NUMBER: "26379"
REDIS_SENTINEL_ACLFILE: "/acl/sentinel.acl"
REDIS_SENTINEL_TLS_ENABLED: "no"
REDIS_SENTINEL_TLS_CERT_FILE: "/tls/sentinel.pem"
REDIS_SENTINEL_TLS_KEY_FILE: "/tls/sentinel.key"
REDIS_SENTINEL_TLS_CA_FILE: "/tls/sentinel_ca.crt"
REDIS_SENTINEL_TLS_AUTH_CLIENTS: "no"
REDIS_MASTER_HOST: "bw-redis"
REDIS_MASTER_SET: "bw-master"
REDIS_MASTER_PORT_NUMBER: "6379"
REDIS_MASTER_PASSWORD: ""
ALLOW_EMPTY_PASSWORD: "yes"
depends_on:
- bw-redis
- bw-redis-slave
networks:
- bw-services

bw-redis-sentinel-3:
image: bitnami/redis-sentinel:7.2
command: /opt/bitnami/scripts/redis-sentinel/run.sh --aclfile /acl/sentinel.acl
volumes:
- ./acl:/acl
- ./tls:/tls
environment:
REDIS_SENTINEL_PORT_NUMBER: "26379"
REDIS_SENTINEL_TLS_PORT_NUMBER: "26379"
REDIS_SENTINEL_ACLFILE: "/acl/sentinel.acl"
REDIS_SENTINEL_TLS_PORT_NUMBER: "0"
REDIS_SENTINEL_TLS_ENABLED: "no"
REDIS_SENTINEL_TLS_CERT_FILE: "/tls/sentinel.pem"
REDIS_SENTINEL_TLS_KEY_FILE: "/tls/sentinel.key"
Expand All @@ -195,6 +143,8 @@ services:
- bw-redis-slave
networks:
- bw-services
deploy:
replicas: 3

networks:
bw-universe:
Expand Down
5 changes: 1 addition & 4 deletions tests/core/redis/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@
f"ℹ️ Trying to connect to Redis Sentinel with the following parameters:\nhosts: {sentinel_hosts}\nmaster: {sentinel_master}\nssl: {redis_ssl}\nusername: {sentinel_username}\npassword: {sentinel_password}",
flush=True,
)
sentinel = Sentinel(sentinel_hosts, username=sentinel_username, password=sentinel_password, ssl=redis_ssl, socket_timeout=1)
sentinel.discover_slaves(sentinel_master)
sentinel = Sentinel(sentinel_hosts, username=sentinel_username, password=sentinel_password, ssl=redis_ssl, socket_timeout=1, ssl_cert_reqs="none")

print(
f"ℹ️ Trying to get a Redis Sentinel slave for master {sentinel_master} with the following parameters:\n"
Expand All @@ -89,7 +88,6 @@
db=redis_db,
username=getenv("REDIS_USERNAME", None) or None,
password=getenv("REDIS_PASSWORD", None) or None,
socket_timeout=1,
)
else:
print(
Expand All @@ -106,7 +104,6 @@
password=getenv("REDIS_PASSWORD", None) or None,
ssl=redis_ssl,
socket_timeout=1,
ssl_cert_reqs="none",
)

if not redis_client.ping():
Expand Down
40 changes: 20 additions & 20 deletions tests/core/redis/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ cleanup_stack () {
find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_TLS_ENABLED: "yes"@REDIS_TLS_ENABLED: "no"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_SENTINEL_TLS_ENABLED: "yes"@REDIS_SENTINEL_TLS_ENABLED: "no"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_TLS_PORT_NUMBER: "[0-9]*"@REDIS_TLS_PORT_NUMBER: "6379"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_SENTINEL_TLS_PORT_NUMBER: "[0-9]*"@REDIS_SENTINEL_TLS_PORT_NUMBER: "26379"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_TLS_AUTH_CLIENTS: "no"@REDIS_TLS_AUTH_CLIENTS: "yes"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_PASSWORD: ".*"@REDIS_PASSWORD: ""@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_SENTINEL_PASSWORD: ".*"@REDIS_SENTINEL_PASSWORD: ""@' {} \;
Expand Down Expand Up @@ -304,7 +303,7 @@ do
find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_TLS_PORT_NUMBER: "[0-9]*"@REDIS_TLS_PORT_NUMBER: "6379"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_TLS_AUTH_CLIENTS: "no"@REDIS_TLS_AUTH_CLIENTS: "yes"@' {} \;

find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_SENTINEL_HOSTS: ".*"@REDIS_SENTINEL_HOSTS: "bw-redis-sentinel-1:26379 bw-redis-sentinel-2:26379 bw-redis-sentinel-3:26379"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_SENTINEL_HOSTS: ".*"@REDIS_SENTINEL_HOSTS: "redis-bw-redis-sentinel-1:26379 redis-bw-redis-sentinel-2:26379 redis-bw-redis-sentinel-3:26379"@' {} \;
elif [ "$test" = "sentinel_tweaked" ] ; then
echo "🧰 Running tests with redis' in sentinel mode with tweaked settings ..."
find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_PORT: "[0-9]*"@REDIS_PORT: "6380"@' {} \;
Expand All @@ -316,24 +315,25 @@ do
find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_SENTINEL_PASSWORD: ".*"@REDIS_SENTINEL_PASSWORD: "sentinel_secret"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_USERNAME: ".*"@REDIS_USERNAME: "bunkerweb"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_SENTINEL_USERNAME: ".*"@REDIS_SENTINEL_USERNAME: "bunkerweb_sentinel"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_SENTINEL_HOSTS: ".*"@REDIS_SENTINEL_HOSTS: "bw-redis-sentinel-1:26380 bw-redis-sentinel-2:26380 bw-redis-sentinel-3:26380"@' {} \;
# elif [ "$test" = "sentinel_ssl" ] ; then # TODO
# echo "🧰 Running tests with redis' in sentinel mode with ssl activated ..."
# find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_PORT: "[0-9]*"@REDIS_PORT: "6379"@' {} \;
# find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_PORT_NUMBER: "[0-9]*"@REDIS_PORT_NUMBER: "6379"@' {} \;
# find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_MASTER_PORT_NUMBER: "[0-9]*"@REDIS_MASTER_PORT_NUMBER: "6379"@' {} \;
# find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_SSL: "no"@REDIS_SSL: "yes"@' {} \;
# find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_DATABASE: "1"@REDIS_DATABASE: "0"@' {} \;
# find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_PASSWORD: ".*"@REDIS_PASSWORD: ""@' {} \;
# find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_USERNAME: ".*"@REDIS_USERNAME: ""@' {} \;

# find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_SSL: "no"@REDIS_SSL: "yes"@' {} \;
# find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_TLS_ENABLED: "no"@REDIS_TLS_ENABLED: "yes"@' {} \;
# find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_SENTINEL_TLS_ENABLED: "no"@REDIS_SENTINEL_TLS_ENABLED: "yes"@' {} \;
# find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_TLS_PORT_NUMBER: "[0-9]*"@REDIS_TLS_PORT_NUMBER: "6380"@' {} \;
# find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_SENTINEL_TLS_PORT_NUMBER: "[0-9]*"@REDIS_SENTINEL_TLS_PORT_NUMBER: "26380"@' {} \;
# find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_TLS_AUTH_CLIENTS: "yes"@REDIS_TLS_AUTH_CLIENTS: "no"@' {} \;
# find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_SENTINEL_TLS_AUTH_CLIENTS: "yes"@REDIS_SENTINEL_TLS_AUTH_CLIENTS: "no"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_SENTINEL_HOSTS: ".*"@REDIS_SENTINEL_HOSTS: "redis-bw-redis-sentinel-1:26380 redis-bw-redis-sentinel-2:26380 redis-bw-redis-sentinel-3:26380"@' {} \;
elif [ "$test" = "sentinel_ssl" ] ; then
echo "🧰 Running tests with redis' in sentinel mode with ssl activated ..."
find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_PORT: "[0-9]*"@REDIS_PORT: "6379"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_PORT_NUMBER: "[0-9]*"@REDIS_PORT_NUMBER: "6379"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_MASTER_PORT_NUMBER: "[0-9]*"@REDIS_MASTER_PORT_NUMBER: "6379"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_SSL: "no"@REDIS_SSL: "yes"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_DATABASE: "1"@REDIS_DATABASE: "0"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_PASSWORD: ".*"@REDIS_PASSWORD: ""@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_USERNAME: ".*"@REDIS_USERNAME: ""@' {} \;

find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_SSL: "no"@REDIS_SSL: "yes"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_TLS_ENABLED: "no"@REDIS_TLS_ENABLED: "yes"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_TLS_PORT_NUMBER: "[0-9]*"@REDIS_TLS_PORT_NUMBER: "6380"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_SENTINEL_TLS_ENABLED: "no"@REDIS_SENTINEL_TLS_ENABLED: "yes"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_SENTINEL_PORT_NUMBER: "[0-9]*"@REDIS_SENTINEL_PORT_NUMBER: "26379"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_TLS_AUTH_CLIENTS: "yes"@REDIS_TLS_AUTH_CLIENTS: "no"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_SENTINEL_TLS_AUTH_CLIENTS: "yes"@REDIS_SENTINEL_TLS_AUTH_CLIENTS: "no"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@REDIS_SENTINEL_HOSTS: ".*"@REDIS_SENTINEL_HOSTS: "redis-bw-redis-sentinel-1:26379 redis-bw-redis-sentinel-2:26379 redis-bw-redis-sentinel-3:26379"@' {} \;
fi

echo "🧰 Starting stack ..."
Expand Down

0 comments on commit 9cce272

Please sign in to comment.