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
This commit is contained in:
Matthew Treinish 2016-04-08 17:03:11 -04:00
parent 00d769e8f0
commit 6b7f8820b9
No known key found for this signature in database
GPG Key ID: FD12A0F214C9E177

View File

@ -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}