def test_manage_pgbouncer_users(): ansible_vars = load_ansible_vars() pgbouncer_user = ansible_vars['pgbouncer_auth_user_list'][0]['username'] pgbouncer_password = ansible_vars['pgbouncer_auth_user_list'][0][ 'password'] pgbouncer_port = ansible_vars['pgbouncer_listen_port'] pg_user = '******' pg_group = 'postgres' if get_pg_type() == 'EPAS': pg_user = '******' pg_group = 'enterprisedb' pgbouncer_address = get_pgbouncer()[0] address = str(pgbouncer_address).strip("<>").split('//')[1] host = get_primary() with host.sudo(pg_user): query = "SHOW users" cmd = host.run( 'PGPASSWORD=%s psql -At -U %s -h %s -p %s -c "%s" pgbouncer | grep %s' % (pgbouncer_password, pgbouncer_user, address, pgbouncer_port, query, 'pgbouncer')) result = cmd.stdout.strip() result = result.split('\n') assert len(result) == 2, \ "pgbouncer users have not been successfully created."
def test_manage_pgbouncer_auth_file(): ansible_vars = load_ansible_vars() pgbouncer_user = ansible_vars['pgbouncer_auth_user_list'][0]['username'] pgbouncer_password = ansible_vars['pgbouncer_auth_user_list'][0][ 'password'] pgbouncer_port = ansible_vars['pgbouncer_listen_port'] pgbouncer_auth_file = ansible_vars['pgbouncer_auth_file'] pg_user = '******' pg_group = 'postgres' if get_pg_type() == 'EPAS': pg_user = '******' pg_group = 'enterprisedb' pgbouncer_address = get_pgbouncer()[0] address = str(pgbouncer_address).strip("<>").split('//')[1] host = get_primary() with host.sudo(pg_user): query = "SHOW config" cmd = host.run( 'PGPASSWORD=%s psql -At -U %s -h %s -p %s -c "%s" pgbouncer | grep %s' % (pgbouncer_password, pgbouncer_user, address, pgbouncer_port, query, 'auth_file')) result = cmd.stdout.strip() assert pgbouncer_auth_file in result, \ "pgbouncer auth file was not configured properly."
def test_setup_pgbouncer_packages(): host = get_pgbouncer()[0] packages = ['pgbouncer'] for package in packages: assert host.package(package).is_installed, \ "Package %s not installed" % packages
def test_setup_pgbouncer_service(): host = get_pgbouncer()[0] service = 'pgbouncer' assert host.service(service).is_running, \ "pgbouncer service not running" assert host.service(service).is_enabled, \ "pgbouncer service not enabled"