Fix client recreation in Redis root-disable test

In the Redis root-disable scenario test, when the root user is disabled,
a check for ensuring the old password is not valid for connecting to
Redis sever fails because connected Redis clients are not affected by
the change of the 'requirepass' parameter, they can still issue commands
like 'PING'. So when a password is provided, a new client should always
be created.

Change-Id: I4e948a20f2b67e49c36bac5c20f411d0b84969ef
This commit is contained in:
Zhao Chao 2018-03-02 20:40:40 +08:00
parent d597bb4714
commit 36ad74c058
1 changed files with 13 additions and 3 deletions

View File

@ -51,12 +51,22 @@ class RedisHelper(TestHelper):
# created.
recreate_client = True
if host in self._ds_client_cache:
new_password = kwargs.get('password')
# NOTE(zhaochao): Another problem about caching clients is, when
# the 'requirepass' paramter of Redis server is changed, already
# connected client can still issue commands. If we want to make sure
# old passwords cannot be used to connect to the server, cached
# clients shouldn't be used, a new one should be created instead.
# We cannot easily tell whether the 'requirepass' paramter is changed.
# So we have to always recreate a client when a password is explicitly
# specified. The cached client is only used when no password
# specified(i.e. we're going to use the default password) and the
# cached password is same as the default one.
if (host in self._ds_client_cache and 'password' not in kwargs):
default_password = self.get_helper_credentials()['password']
cached_password = (self._ds_client_cache[host]
.connection_pool
.connection_kwargs.get('password'))
if new_password == cached_password:
if cached_password == default_password:
recreate_client = False
if recreate_client: