openstack-helm-infra/redis/templates/test/_python_redis_tests.py.tpl
Nikos Mimigiannis 7afe5189a0 Create Helm test for redis chart
Task: 21711
Story: 2002201

This patch creates Helm test for redis chart

Change-Id: Ifac407b5544484f2626ba7ffdbd2e96fca6e51ef
Signed-off-by: Nikos Mimigiannis <nmimi@intracom-telecom.com>
2019-02-15 07:55:07 -05:00

55 lines
1.9 KiB
Smarty

import os
import redis
class RedisTest(object):
def __init__(self):
host = os.environ.get('REDIS_HOST', 'redis')
port = os.environ.get('REDIS_PORT', 6379)
db = os.environ.get('REDIS_DB', 0)
self.redis_conn = redis.Redis(host, port, db)
def test_connection(self):
ping = self.redis_conn.ping()
assert ping, "No connection to database"
print("Successfully connected to database")
def database_info(self):
ip_port = []
for client in self.redis_conn.client_list():
ip_port.append(client["addr"])
print(ip_port)
assert self.redis_conn.client_list(), "Database client's list is null"
return ip_port
def test_insert_delete_data(self):
key = "test"
value = "it's working"
result_set = self.redis_conn.set(key, value)
assert result_set, "Error: SET command failed"
print("Successfully SET keyvalue pair")
result_get = self.redis_conn.get(key)
assert result_get, "Error: GET command failed"
print("Successfully GET keyvalue pair")
db_size = self.redis_conn.dbsize()
assert db_size > 0, "Database size not valid"
result_delete = self.redis_conn.delete(key)
assert result_delete == 1, "Error: Delete command failed"
print("Successfully DELETED keyvalue pair")
def test_client_kill(self, client_ip_port_list):
for client_ip_port in client_ip_port_list:
result = self.redis_conn.client_kill(client_ip_port)
print(result)
assert result, "Client failed to be removed"
print("Successfully DELETED client")
client_ip_port = []
redis_client = RedisTest()
redis_client.test_connection()
client_ip_port = redis_client.database_info()
redis_client.test_insert_delete_data()
redis_client.test_client_kill(client_ip_port)