From cefe51327bfef95d2415ea536ede742040e166a3 Mon Sep 17 00:00:00 2001 From: Vladimir Kozhukalov Date: Thu, 10 Oct 2024 12:05:59 -0500 Subject: [PATCH] [keystone] Align db scripts with Sqlalchemy 2 Depends-On: I52db7dd4563639a55c12850147cf256cec8b1ee4 Change-Id: Iebf6575d140efb16201fb8c05d16e1e9516d4691 --- keystone/Chart.yaml | 2 +- keystone/templates/bin/_cred-clean.py.tpl | 3 +- .../templates/bin/_endpoint-update.py.tpl | 35 ++++++++++--------- releasenotes/notes/keystone.yaml | 1 + 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/keystone/Chart.yaml b/keystone/Chart.yaml index 77e5d3de7c..00be49a300 100644 --- a/keystone/Chart.yaml +++ b/keystone/Chart.yaml @@ -14,7 +14,7 @@ apiVersion: v1 appVersion: v1.0.0 description: OpenStack-Helm Keystone name: keystone -version: 0.3.15 +version: 0.3.16 home: https://docs.openstack.org/keystone/latest/ icon: https://www.openstack.org/themes/openstack/images/project-mascots/Keystone/OpenStack_Project_Keystone_vertical.png sources: diff --git a/keystone/templates/bin/_cred-clean.py.tpl b/keystone/templates/bin/_cred-clean.py.tpl index d95ed27377..a7cbe6ba49 100644 --- a/keystone/templates/bin/_cred-clean.py.tpl +++ b/keystone/templates/bin/_cred-clean.py.tpl @@ -30,6 +30,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') @@ -127,7 +128,7 @@ except: # Delete all entries from credential table try: - cmd = "DELETE FROM credential" + cmd = text("DELETE FROM credential") with user_engine.connect() as connection: connection.execute(cmd) try: diff --git a/keystone/templates/bin/_endpoint-update.py.tpl b/keystone/templates/bin/_endpoint-update.py.tpl index 1433af21ae..a3e64e9346 100644 --- a/keystone/templates/bin/_endpoint-update.py.tpl +++ b/keystone/templates/bin/_endpoint-update.py.tpl @@ -4,6 +4,7 @@ import logging import sys from sqlalchemy import create_engine +from sqlalchemy import text try: import ConfigParser @@ -69,12 +70,12 @@ except: try: endpoint_url = os.environ['OS_BOOTSTRAP_INTERNAL_URL'] region_id = os.environ['OS_REGION_NAME'] - cmd = ("update endpoint set url = %s where interface ='internal' and " - "service_id = (select id from service where " - "service.type = 'identity') and " - "region_id = %s") + cmd = text("update endpoint set url = :endpoint_url where interface ='internal' and " + "service_id = (select id from service where " + "service.type = 'identity') and " + "region_id = :region_id") with user_engine.connect() as connection: - connection.execute(cmd, (endpoint_url,region_id)) + connection.execute(cmd, {"endpoint_url": endpoint_url, "region_id": region_id}) try: connection.commit() except AttributeError: @@ -87,12 +88,12 @@ except: try: endpoint_url = os.environ['OS_BOOTSTRAP_ADMIN_URL'] region_id = os.environ['OS_REGION_NAME'] - cmd = ("update endpoint set url = %s where interface ='admin' " - "and service_id = (select id from service where " - "service.type = 'identity') " - "and region_id = %s") + cmd = text("update endpoint set url = :endpoint_url where interface ='admin' " + "and service_id = (select id from service where " + "service.type = 'identity') " + "and region_id = :region_id") with user_engine.connect() as connection: - connection.execute(cmd, (endpoint_url,region_id)) + connection.execute(cmd, {"endpoint_url": endpoint_url, "region_id": region_id}) try: connection.commit() except AttributeError: @@ -105,12 +106,12 @@ except: try: endpoint_url = os.environ['OS_BOOTSTRAP_PUBLIC_URL'] region_id = os.environ['OS_REGION_NAME'] - cmd = ("update endpoint set url = %s where interface ='public' " - "and service_id = (select id from service where " - "service.type = 'identity') " - "and region_id = %s") + cmd = text("update endpoint set url = :endpoint_url where interface ='public' " + "and service_id = (select id from service where " + "service.type = 'identity') " + "and region_id = :region_id") with user_engine.connect() as connection: - connection.execute(cmd, (endpoint_url,region_id)) + connection.execute(cmd, {"endpoint_url": endpoint_url, "region_id": region_id}) try: connection.commit() except AttributeError: @@ -123,8 +124,8 @@ except: try: with user_engine.connect() as connection: endpoints = connection.execute( - ("select interface, url from endpoint where service_id = " - "(select id from service where service.type = 'identity')") + text("select interface, url from endpoint where service_id = " + "(select id from service where service.type = 'identity')") ).fetchall() for row in endpoints: logger.info("endpoint ({0}): {1}".format(row[0], row[1])) diff --git a/releasenotes/notes/keystone.yaml b/releasenotes/notes/keystone.yaml index ae0f507331..bd4e438394 100644 --- a/releasenotes/notes/keystone.yaml +++ b/releasenotes/notes/keystone.yaml @@ -62,4 +62,5 @@ keystone: - 0.3.13 Update images used by default - 0.3.14 Align db scripts with sqlalchemy 2.0 - 0.3.15 Use quay.io/airshipit/kubernetes-entrypoint:latest-ubuntu_focal by default + - 0.3.16 Align db scripts with Sqlalchemy 2 ...