Skip to content

Commit

Permalink
Add some tests to verify Redis DB configuration (#12877)
Browse files Browse the repository at this point in the history
* Add test to verify that the redis DB is not being saved to disk

Add a test script to check that the redis config for the save setting is
correct. This can be extended to check for other config options.


Signed-off-by: Saikrishna Arcot <sarcot@microsoft.com>
  • Loading branch information
saiarcot895 authored May 30, 2024
1 parent 95d5707 commit 9684620
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions .azure-pipelines/pr_test_scripts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ t0:
- console/test_console_udevrule.py
- container_checker/test_container_checker.py
- container_hardening/test_container_hardening.py
- database/test_db_config.py
- database/test_db_scripts.py
- dhcp_relay/test_dhcp_pkt_recv.py
- dhcp_relay/test_dhcp_relay.py
Expand Down
50 changes: 50 additions & 0 deletions tests/database/test_db_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""
Test the database config
"""
import logging
import pytest
import json

from tests.common.helpers.assertions import pytest_assert

logger = logging.getLogger(__name__)

pytestmark = [
pytest.mark.topology('any')
]


def test_redis_save_disabled(duthosts, rand_one_dut_hostname):
"""
@summary: Test that the database isn't being saved to disk
"""
duthost = duthosts[rand_one_dut_hostname]

save_config_json = duthost.command(argv=["redis-cli", "--json", "CONFIG", "GET", "save"])["stdout"]
save_config = json.loads(save_config_json)
pytest_assert(save_config["save"] == "", "Redis should not be persisting contents to disk, save config is {}"
.format(save_config["save"]))


def test_redis_database_count(duthosts, rand_one_dut_hostname):
"""
@summary: Test that redis is configured to support 100 databases
"""
duthost = duthosts[rand_one_dut_hostname]

database_config_json = duthost.command(argv=["redis-cli", "--json", "CONFIG", "GET", "databases"])["stdout"]
database_config = json.loads(database_config_json)
pytest_assert(database_config["databases"] == "100", "Redis is configured to support {} instead of 100 databases"
.format(database_config["databases"]))


def test_redis_unix_socket(duthosts, rand_one_dut_hostname):
"""
@summary: Test that redis has the unix socket option enabled
"""
duthost = duthosts[rand_one_dut_hostname]

unixsocket_config_json = duthost.command(argv=["redis-cli", "--json", "CONFIG", "GET", "unixsocket"])["stdout"]
unixsocket_config = json.loads(unixsocket_config_json)
pytest_assert(unixsocket_config["unixsocket"] == "/var/run/redis/redis.sock",
"Redis unixsocket is not configured correctly")
1 change: 1 addition & 0 deletions tests/kvmtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ test_t0() {
show_techsupport/test_techsupport_no_secret.py \
system_health/test_system_status.py \
radv/test_radv_ipv6_ra.py \
database/test_db_config.py \
database/test_db_scripts.py"

pushd $SONIC_MGMT_DIR/tests
Expand Down

0 comments on commit 9684620

Please sign in to comment.