[helm-toolkit] Fix db-init and db-drop scripts

Wrap queries into sqlalchemy.text before executing them.

Change-Id: I783bd05bdd529c73825311515e1390f3cc077c4f
This commit is contained in:
Vladimir Kozhukalov 2024-10-02 15:13:15 -05:00
parent 5d81f0f5a4
commit ab2cfc1d64
4 changed files with 10 additions and 7 deletions

View File

@ -15,7 +15,7 @@ apiVersion: v1
appVersion: v1.0.0
description: OpenStack-Helm Helm-Toolkit
name: helm-toolkit
version: 0.2.77
version: 0.2.78
home: https://docs.openstack.org/openstack-helm
icon: https://www.openstack.org/themes/openstack/images/project-mascots/OpenStack-Helm/OpenStack_Project_OpenStackHelm_vertical.png
sources:

View File

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

View File

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

View File

@ -84,4 +84,5 @@ helm-toolkit:
- 0.2.75 Add daemonset_overrides_root util
- 0.2.76 update tookit to support fqdn alias
- 0.2.77 Add recommended kubernetes name label to pods definition
- 0.2.78 Fix db-init and db-drop scripts to make them work with sqlalchemy >2.0
...