From 6b7f8820b9a5f571f3ff0a4c49a436353d5d899f Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Fri, 8 Apr 2016 17:03:11 -0400 Subject: [PATCH] Remove DB existence check from open session termination This commit removes an if check from the block to close any open sessions. It turns out this isn't actually needed. If the table doesn't exist the query will just return 0 hits (because there can't be any open sessions on a nonexistent table) Change-Id: I3e52413bc244a0b06c2045f81c9accac55be7f88 --- subunit2sql/tests/subunit2sql_fixtures.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/subunit2sql/tests/subunit2sql_fixtures.py b/subunit2sql/tests/subunit2sql_fixtures.py index 9d73944..2840ab5 100644 --- a/subunit2sql/tests/subunit2sql_fixtures.py +++ b/subunit2sql/tests/subunit2sql_fixtures.py @@ -120,19 +120,15 @@ class PostgresConfFixture(config_fixture.Config): sqlcmd = ('psql -w -U %(user)s -h %(host)s -c' ' "%(sql)s" -d template1') - sql = "\list" - databases = execute_cmd(sqlcmd % {'user': user, 'host': host, - 'sql': sql}) - if database in databases.decode('UTF-8'): - # NOTE(masayukig): We terminate sessions because some closed - # sessions are remaining until here - sql = ("select pg_terminate_backend(pg_stat_activity.pid) " - "from pg_stat_activity " - "where pg_stat_activity.datname = '%(database)s';") - sql = sql % {'database': database} - term_session = sqlcmd % {'user': user, 'host': host, - 'sql': sql} - execute_cmd(term_session) + # NOTE(masayukig): We terminate sessions because some closed + # sessions are remaining until here + sql = ("select pg_terminate_backend(pg_stat_activity.pid) " + "from pg_stat_activity " + "where pg_stat_activity.datname = '%(database)s';") + sql = sql % {'database': database} + term_session = sqlcmd % {'user': user, 'host': host, + 'sql': sql} + execute_cmd(term_session) sql = ("drop database if exists %(database)s;") sql = sql % {'database': database}