Fix "create database" failed for postgress
This PR stops using the psycopg2’s connections context manager because "CREATE DATABASE" command must be run outside any transaction[1]. [1]: https://www.psycopg.org/docs/usage.html#transactions-control Co-Authored-By: hungnt1 <sudo.nguyenhung@gmail.com> Co-Authored-By: Hirotaka Wakabayashi <hiwkby@yahoo.com> Story: 2010761 Task: 48059 Change-Id: I73ec6c659d8ad7216460055077737429c878df33
This commit is contained in:
parent
09fd606163
commit
cd11d7677e
@ -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>`__
|
||||||
|
|
@ -770,12 +770,15 @@ class PostgresConnection(object):
|
|||||||
def _execute_stmt(self, statement, identifiers, data_values, fetch,
|
def _execute_stmt(self, statement, identifiers, data_values, fetch,
|
||||||
autocommit=False):
|
autocommit=False):
|
||||||
cmd = self._bind(statement, identifiers)
|
cmd = self._bind(statement, identifiers)
|
||||||
with psycopg2.connect(self.connect_str) as connection:
|
connection = psycopg2.connect(self.connect_str)
|
||||||
connection.autocommit = autocommit
|
connection.autocommit = autocommit
|
||||||
|
try:
|
||||||
with connection.cursor() as cursor:
|
with connection.cursor() as cursor:
|
||||||
cursor.execute(cmd, data_values)
|
cursor.execute(cmd, data_values)
|
||||||
if fetch:
|
if fetch:
|
||||||
return cursor.fetchall()
|
return cursor.fetchall()
|
||||||
|
finally:
|
||||||
|
connection.close()
|
||||||
|
|
||||||
def _bind(self, statement, identifiers):
|
def _bind(self, statement, identifiers):
|
||||||
if identifiers:
|
if identifiers:
|
||||||
|
Loading…
Reference in New Issue
Block a user