blob: d23cd9e1dc43a5c5c40e1239d274c2cac7552ae7 [file] [log] [blame]
From ab2cfc1d6442df15a7c2a84fd1b961fcd6041f97 Mon Sep 17 00:00:00 2001
From: Vladimir Kozhukalov <kozhukalov@gmail.com>
Date: Wed, 2 Oct 2024 15:13:15 -0500
Subject: [PATCH] [helm-toolkit] Fix db-init and db-drop scripts
Wrap queries into sqlalchemy.text before executing them.
Change-Id: I783bd05bdd529c73825311515e1390f3cc077c4f
---
helm-toolkit/templates/scripts/_db-drop.py.tpl | 5 +++--
helm-toolkit/templates/scripts/_db-init.py.tpl | 9 +++++----
4 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/helm-toolkit/templates/scripts/_db-drop.py.tpl b/helm-toolkit/templates/scripts/_db-drop.py.tpl
index 1e28da9c..c6a7521d 100644
--- a/helm-toolkit/templates/scripts/_db-drop.py.tpl
+++ b/helm-toolkit/templates/scripts/_db-drop.py.tpl
@@ -33,6 +33,7 @@ except ImportError:
PARSER_OPTS = {"strict": False}
import logging
from sqlalchemy import create_engine
+from sqlalchemy import text
# Create logger, console handler and formatter
logger = logging.getLogger('OpenStack-Helm DB Drop')
@@ -125,7 +126,7 @@ except:
# Delete DB
try:
with root_engine.connect() as connection:
- connection.execute("DROP DATABASE IF EXISTS {0}".format(database))
+ connection.execute(text("DROP DATABASE IF EXISTS {0}".format(database)))
try:
connection.commit()
except AttributeError:
@@ -138,7 +139,7 @@ except:
# Delete DB User
try:
with root_engine.connect() as connection:
- connection.execute("DROP USER IF EXISTS {0}".format(user))
+ connection.execute(text("DROP USER IF EXISTS {0}".format(user)))
try:
connection.commit()
except AttributeError:
diff --git a/helm-toolkit/templates/scripts/_db-init.py.tpl b/helm-toolkit/templates/scripts/_db-init.py.tpl
index 110cd98e..1917f78b 100644
--- a/helm-toolkit/templates/scripts/_db-init.py.tpl
+++ b/helm-toolkit/templates/scripts/_db-init.py.tpl
@@ -33,6 +33,7 @@ except ImportError:
PARSER_OPTS = {"strict": False}
import logging
from sqlalchemy import create_engine
+from sqlalchemy import text
# Create logger, console handler and formatter
logger = logging.getLogger('OpenStack-Helm DB Init')
@@ -125,7 +126,7 @@ except:
# Create DB
try:
with root_engine.connect() as connection:
- connection.execute("CREATE DATABASE IF NOT EXISTS {0}".format(database))
+ connection.execute(text("CREATE DATABASE IF NOT EXISTS {0}".format(database)))
try:
connection.commit()
except AttributeError:
@@ -139,10 +140,10 @@ except:
try:
with root_engine.connect() as connection:
connection.execute(
- "CREATE USER IF NOT EXISTS \'{0}\'@\'%%\' IDENTIFIED BY \'{1}\' {2}".format(
- user, password, mysql_x509))
+ text("CREATE USER IF NOT EXISTS \'{0}\'@\'%%\' IDENTIFIED BY \'{1}\' {2}".format(
+ user, password, mysql_x509)))
connection.execute(
- "GRANT ALL ON `{0}`.* TO \'{1}\'@\'%%\'".format(database, user))
+ text("GRANT ALL ON `{0}`.* TO \'{1}\'@\'%%\'".format(database, user)))
try:
connection.commit()
except AttributeError:
...
--
2.25.1