[keystone] Align db scripts with Sqlalchemy 2

Depends-On: I52db7dd4563639a55c12850147cf256cec8b1ee4
Change-Id: Iebf6575d140efb16201fb8c05d16e1e9516d4691
This commit is contained in:
Vladimir Kozhukalov
2024-10-10 12:05:59 -05:00
parent fe2633dab2
commit cefe51327b
4 changed files with 22 additions and 19 deletions

View File

@@ -14,7 +14,7 @@ apiVersion: v1
appVersion: v1.0.0 appVersion: v1.0.0
description: OpenStack-Helm Keystone description: OpenStack-Helm Keystone
name: keystone name: keystone
version: 0.3.15 version: 0.3.16
home: https://docs.openstack.org/keystone/latest/ home: https://docs.openstack.org/keystone/latest/
icon: https://www.openstack.org/themes/openstack/images/project-mascots/Keystone/OpenStack_Project_Keystone_vertical.png icon: https://www.openstack.org/themes/openstack/images/project-mascots/Keystone/OpenStack_Project_Keystone_vertical.png
sources: sources:

View File

@@ -30,6 +30,7 @@ except ImportError:
PARSER_OPTS = {"strict": False} PARSER_OPTS = {"strict": False}
import logging import logging
from sqlalchemy import create_engine from sqlalchemy import create_engine
from sqlalchemy import text
# Create logger, console handler and formatter # Create logger, console handler and formatter
logger = logging.getLogger('OpenStack-Helm DB Drop') logger = logging.getLogger('OpenStack-Helm DB Drop')
@@ -127,7 +128,7 @@ except:
# Delete all entries from credential table # Delete all entries from credential table
try: try:
cmd = "DELETE FROM credential" cmd = text("DELETE FROM credential")
with user_engine.connect() as connection: with user_engine.connect() as connection:
connection.execute(cmd) connection.execute(cmd)
try: try:

View File

@@ -4,6 +4,7 @@ import logging
import sys import sys
from sqlalchemy import create_engine from sqlalchemy import create_engine
from sqlalchemy import text
try: try:
import ConfigParser import ConfigParser
@@ -69,12 +70,12 @@ except:
try: try:
endpoint_url = os.environ['OS_BOOTSTRAP_INTERNAL_URL'] endpoint_url = os.environ['OS_BOOTSTRAP_INTERNAL_URL']
region_id = os.environ['OS_REGION_NAME'] region_id = os.environ['OS_REGION_NAME']
cmd = ("update endpoint set url = %s where interface ='internal' and " cmd = text("update endpoint set url = :endpoint_url where interface ='internal' and "
"service_id = (select id from service where " "service_id = (select id from service where "
"service.type = 'identity') and " "service.type = 'identity') and "
"region_id = %s") "region_id = :region_id")
with user_engine.connect() as connection: 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: try:
connection.commit() connection.commit()
except AttributeError: except AttributeError:
@@ -87,12 +88,12 @@ except:
try: try:
endpoint_url = os.environ['OS_BOOTSTRAP_ADMIN_URL'] endpoint_url = os.environ['OS_BOOTSTRAP_ADMIN_URL']
region_id = os.environ['OS_REGION_NAME'] region_id = os.environ['OS_REGION_NAME']
cmd = ("update endpoint set url = %s where interface ='admin' " cmd = text("update endpoint set url = :endpoint_url where interface ='admin' "
"and service_id = (select id from service where " "and service_id = (select id from service where "
"service.type = 'identity') " "service.type = 'identity') "
"and region_id = %s") "and region_id = :region_id")
with user_engine.connect() as connection: 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: try:
connection.commit() connection.commit()
except AttributeError: except AttributeError:
@@ -105,12 +106,12 @@ except:
try: try:
endpoint_url = os.environ['OS_BOOTSTRAP_PUBLIC_URL'] endpoint_url = os.environ['OS_BOOTSTRAP_PUBLIC_URL']
region_id = os.environ['OS_REGION_NAME'] region_id = os.environ['OS_REGION_NAME']
cmd = ("update endpoint set url = %s where interface ='public' " cmd = text("update endpoint set url = :endpoint_url where interface ='public' "
"and service_id = (select id from service where " "and service_id = (select id from service where "
"service.type = 'identity') " "service.type = 'identity') "
"and region_id = %s") "and region_id = :region_id")
with user_engine.connect() as connection: 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: try:
connection.commit() connection.commit()
except AttributeError: except AttributeError:
@@ -123,8 +124,8 @@ except:
try: try:
with user_engine.connect() as connection: with user_engine.connect() as connection:
endpoints = connection.execute( endpoints = connection.execute(
("select interface, url from endpoint where service_id = " text("select interface, url from endpoint where service_id = "
"(select id from service where service.type = 'identity')") "(select id from service where service.type = 'identity')")
).fetchall() ).fetchall()
for row in endpoints: for row in endpoints:
logger.info("endpoint ({0}): {1}".format(row[0], row[1])) logger.info("endpoint ({0}): {1}".format(row[0], row[1]))

View File

@@ -62,4 +62,5 @@ keystone:
- 0.3.13 Update images used by default - 0.3.13 Update images used by default
- 0.3.14 Align db scripts with sqlalchemy 2.0 - 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.15 Use quay.io/airshipit/kubernetes-entrypoint:latest-ubuntu_focal by default
- 0.3.16 Align db scripts with Sqlalchemy 2
... ...