def _get_redis_role(redis_container: str, authenticate: bool = False, tls: bool = False) -> str: args = ['redis-cli', '-p'] if tls: args.extend([ '46379', '--tls', '--cert', '/usr/local/etc/redis/tls/redis.crt', '--key', '/usr/local/etc/redis/tls/redis.key', '--cacert', '/usr/local/etc/redis/tls/ca.crt', ]) else: args.append('6379') if authenticate: args.extend([ '--user', 'healthcheck', '--pass', 'KUbMBRRnWxCxLfU4qTaBASCZs467uzxB', '--no-auth-warning' ]) args.append('ROLE') output = call_command_in_container(redis_container, args) return output.split('\n')[0].strip()
def _kill_master(master_container: str) -> None: try: # It's weird. Sometimes this command exits 137 to indicate success, sometimes it just returns no output. Either # result, apparently, is indicative of success. output = call_command_in_container(master_container, ['redis-cli', '-p', '6379', 'SHUTDOWN', 'NOSAVE']) assert not output except AssertionError as e: assert 'Call to docker-compose failed with exit code 137' in e.args[0]
def _initiate_master_failover(sentinel_container: str) -> None: output = call_command_in_container( sentinel_container, [ 'redis-cli', '-p', '26379', 'SENTINEL', 'FAILOVER', 'functional_tests' ], ) assert output == 'OK'
def _get_master_ip(sentinel_container: str) -> str: output = call_command_in_container( sentinel_container, ['redis-cli', '-p', '26379', 'SENTINEL', 'MASTER', 'functional_tests'], ) next_is_master_ip = False for line in output.split('\n'): line = line.strip() if not line: continue if next_is_master_ip: return line if line == 'ip': next_is_master_ip = True raise AssertionError('Failed parsing master output:\n{}'.format(output))
def _get_redis_role(redis_container: str) -> str: output = call_command_in_container( redis_container, ['redis-cli', '-p', '6379', 'ROLE'], ) return output.split('\n')[0].strip()