Merge "Fix "create database" failed for postgress"

This commit is contained in:
Zuul 2023-06-26 04:15:26 +00:00 committed by Gerrit Code Review
commit 5c12f72fc5
2 changed files with 13 additions and 2 deletions

View File

@ -0,0 +1,8 @@
---
fixes:
- |
Fix guest-agent failed to start postgres container due to execution
of the "CREATE DATABASE" statement within the context manager of
psycopg library. See the following for details
`Stroy 2010761 <https://storyboard.openstack.org/#!/story/2010761>`__

View File

@ -770,12 +770,15 @@ class PostgresConnection(object):
def _execute_stmt(self, statement, identifiers, data_values, fetch,
autocommit=False):
cmd = self._bind(statement, identifiers)
with psycopg2.connect(self.connect_str) as connection:
connection.autocommit = autocommit
connection = psycopg2.connect(self.connect_str)
connection.autocommit = autocommit
try:
with connection.cursor() as cursor:
cursor.execute(cmd, data_values)
if fetch:
return cursor.fetchall()
finally:
connection.close()
def _bind(self, statement, identifiers):
if identifiers: