diff --git a/tests/console/redis.pm b/tests/console/redis.pm index 172d29778be6..35f093d51afb 100644 --- a/tests/console/redis.pm +++ b/tests/console/redis.pm @@ -20,45 +20,78 @@ use serial_terminal 'select_serial_terminal'; use utils qw(zypper_call script_retry validate_script_output_retry); use registration qw(add_suseconnect_product get_addon_fullname); -sub run { - my $self = shift; - select_serial_terminal; +sub test_redis { + my (%args) = @_; + $args{port} //= "6379"; + $args{replica_port} //= "6380"; + + my $output = script_output('redis-server --version'); + my $version = "unknown"; + if ($output =~ /v=(.+?)\s/) { + $version = $1; + } + + record_info("Testing " . $version); - # install redis package - zypper_call 'in redis'; - assert_script_run('redis-server --version'); + my $logfile = "/var/log/redis/redis-server_$version_$args{port}.log"; + my $replica_logfile = "/var/log/redis/redis-server_$version_$args{replica_port}.log"; - # start redis server on port 6379 and test that it works - assert_script_run('redis-server --daemonize yes --logfile /var/log/redis/redis-server_6379.log'); - script_retry('redis-cli ping', delay => 5, retry => 12); - validate_script_output_retry('redis-cli ping', sub { m/PONG/ }, delay => 5, retry => 12); - # test some redis cli commands - validate_script_output('redis-cli set foo bar', sub { m/OK/ }); - validate_script_output('redis-cli get foo', sub { m/bar/ }); - validate_script_output('redis-cli pfselftest', sub { m/OK/ }); - validate_script_output('redis-cli flushdb', sub { m/OK/ }); - validate_script_output('redis-cli get foo', sub { !m/bar/ }); + # Start the primary redis server + assert_script_run("redis-server --daemonize yes --port $args{port} --logfile $logfile"); + script_retry("redis-cli -p $args{port} ping", delay => 5, retry => 12); + validate_script_output_retry("redis-cli -p $args{port} ping", sub { m/PONG/ }, delay => 5, retry => 12); + # Perform CRUD operations + validate_script_output("redis-cli -p $args{port} set foo bar", sub { m/OK/ }); + validate_script_output("redis-cli -p $args{port} get foo", sub { m/bar/ }); + validate_script_output("redis-cli -p $args{port} pfselftest", sub { m/OK/ }); + validate_script_output("redis-cli -p $args{port} flushdb", sub { m/OK/ }); + validate_script_output("redis-cli -p $args{port} get foo", sub { !m/bar/ }); + + # Load test DB and validate data assert_script_run 'curl -O ' . data_url('console/movies.redis'); - assert_script_run('redis-cli -h localhost -p 6379 < ./movies.redis'); + assert_script_run("redis-cli -p $args{port} < ./movies.redis"); + validate_script_output("redis-cli -p $args{port} HMGET \"movie:343\" title", sub { m/Spider-Man/ }); + + # Start the replica redis server + assert_script_run("redis-server --daemonize yes --port $args{replica_port} --logfile $replica_logfile"); + validate_script_output_retry("redis-cli -p $args{replica_port} ping", sub { m/PONG/ }, delay => 5, retry => 12); + + # Configure replication + assert_script_run("redis-cli -p $args{replica_port} replicaof localhost $args{port}"); - validate_script_output('redis-cli HMGET "movie:343" title', sub { m/Spider-Man/ }); + # Verify replication status + validate_script_output_retry("redis-cli -p $args{port} info replication", sub { m/connected_slaves:1/ }, delay => 5, retry => 12); + validate_script_output("redis-cli -p $args{replica_port} info replication", sub { m/role:slave/ }); + validate_script_output_retry("redis-cli -p $args{replica_port} info replication", sub { m/master_link_status:up/ }, delay => 5, retry => 12); - # start redis server on port 6380 and test that it works - assert_script_run('redis-server --daemonize yes --port 6380 --logfile /var/log/redis/redis-server_6380.log'); - validate_script_output_retry('redis-cli -p 6380 ping', sub { m/PONG/ }, delay => 5, retry => 12); + # Validate data from the replica + validate_script_output("redis-cli -p $args{replica_port} HMGET \"movie:343\" title", sub { m/Spider-Man/ }); - # make 6380 instance a replica of redis instance running on port 6379 - assert_script_run('redis-cli -p 6380 replicaof localhost 6379'); + # Clean up after testing + assert_script_run("redis-cli -p $args{port} flushall"); + assert_script_run("redis-cli -p $args{replica_port} flushall"); + assert_script_run("killall redis-server"); + assert_script_run("rm -f movies.redis"); + + # Upload logs + upload_logs($logfile) if -e $logfile; + upload_logs($replica_logfile) if -e $replica_logfile; +} + +sub run { + my $self = shift; + select_serial_terminal; - # test master knows about the slave and vice versa - validate_script_output_retry('redis-cli info replication', sub { m/connected_slaves:1/ }, delay => 5, retry => 12); - validate_script_output('redis-cli -p 6380 info replication', sub { m/role:slave/ }); + # Test with redis package (redis6) + zypper_call 'in --force-resolution --solver-focus Update redis'; + test_redis(); - # test that the synchronization finished and the data are reachable from slave - validate_script_output_retry('redis-cli info replication', sub { m/state=online/ }, delay => 5, retry => 12); - validate_script_output('redis-cli -p 6380 HMGET "movie:343" title', sub { m/Spider-Man/ }); + # Switch to redis7 and test + zypper_call 'rm -u redis'; + zypper_call 'in --force-resolution --solver-focus Update redis7'; + test_redis(); } sub post_fail_hook { @@ -74,11 +107,9 @@ sub post_run_hook { } sub cleanup { - upload_logs('/var/log/redis/redis-server_6379.log'); - upload_logs('/var/log/redis/redis-server_6380.log'); - assert_script_run('redis-cli -h localhost flushall'); - assert_script_run('killall redis-server'); - assert_script_run('rm -f movies.redis'); + script_run('redis-cli -h localhost flushall || true'); + script_run('killall redis-server || true'); + script_run('rm -f movies.redis || true'); } 1;