From ab2cfc1d6442df15a7c2a84fd1b961fcd6041f97 Mon Sep 17 00:00:00 2001 From: Vladimir Kozhukalov 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/Chart.yaml | 2 +- helm-toolkit/templates/scripts/_db-drop.py.tpl | 5 +++-- helm-toolkit/templates/scripts/_db-init.py.tpl | 9 +++++---- releasenotes/notes/helm-toolkit.yaml | 1 + 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/helm-toolkit/Chart.yaml b/helm-toolkit/Chart.yaml index e8ccd617a..f7b0034eb 100644 --- a/helm-toolkit/Chart.yaml +++ b/helm-toolkit/Chart.yaml @@ -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: diff --git a/helm-toolkit/templates/scripts/_db-drop.py.tpl b/helm-toolkit/templates/scripts/_db-drop.py.tpl index 1e28da9ca..c6a7521d2 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 110cd98eb..1917f78b4 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: diff --git a/releasenotes/notes/helm-toolkit.yaml b/releasenotes/notes/helm-toolkit.yaml index f2cb15f5d..dbcf87e6b 100644 --- a/releasenotes/notes/helm-toolkit.yaml +++ b/releasenotes/notes/helm-toolkit.yaml @@ -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 ...