diff --git a/helm-toolkit/Chart.yaml b/helm-toolkit/Chart.yaml index 082112450..e00dd5a3e 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.65 +version: 0.2.66 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 03884fa18..1e28da9ca 100644 --- a/helm-toolkit/templates/scripts/_db-drop.py.tpl +++ b/helm-toolkit/templates/scripts/_db-drop.py.tpl @@ -124,7 +124,12 @@ except: # Delete DB try: - root_engine.execute("DROP DATABASE IF EXISTS {0}".format(database)) + with root_engine.connect() as connection: + connection.execute("DROP DATABASE IF EXISTS {0}".format(database)) + try: + connection.commit() + except AttributeError: + pass logger.info("Deleted database {0}".format(database)) except: logger.critical("Could not drop database {0}".format(database)) @@ -132,7 +137,12 @@ except: # Delete DB User try: - root_engine.execute("DROP USER IF EXISTS {0}".format(user)) + with root_engine.connect() as connection: + connection.execute("DROP USER IF EXISTS {0}".format(user)) + try: + connection.commit() + except AttributeError: + pass logger.info("Deleted user {0}".format(user)) except: logger.critical("Could not delete user {0}".format(user)) diff --git a/helm-toolkit/templates/scripts/_db-init.py.tpl b/helm-toolkit/templates/scripts/_db-init.py.tpl index 6027b9515..110cd98eb 100644 --- a/helm-toolkit/templates/scripts/_db-init.py.tpl +++ b/helm-toolkit/templates/scripts/_db-init.py.tpl @@ -124,7 +124,12 @@ except: # Create DB try: - root_engine.execute("CREATE DATABASE IF NOT EXISTS {0}".format(database)) + with root_engine.connect() as connection: + connection.execute("CREATE DATABASE IF NOT EXISTS {0}".format(database)) + try: + connection.commit() + except AttributeError: + pass logger.info("Created database {0}".format(database)) except: logger.critical("Could not create database {0}".format(database)) @@ -132,11 +137,16 @@ except: # Create DB User try: - root_engine.execute( - "CREATE USER IF NOT EXISTS \'{0}\'@\'%%\' IDENTIFIED BY \'{1}\' {2}".format( - user, password, mysql_x509)) - root_engine.execute( - "GRANT ALL ON `{0}`.* TO \'{1}\'@\'%%\'".format(database, user)) + with root_engine.connect() as connection: + connection.execute( + "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)) + try: + connection.commit() + except AttributeError: + pass logger.info("Created user {0} for {1}".format(user, database)) except: logger.critical("Could not create user {0} for {1}".format(user, database)) diff --git a/releasenotes/notes/helm-toolkit.yaml b/releasenotes/notes/helm-toolkit.yaml index 3bbd2eb27..c72606ac9 100644 --- a/releasenotes/notes/helm-toolkit.yaml +++ b/releasenotes/notes/helm-toolkit.yaml @@ -72,4 +72,5 @@ helm-toolkit: - 0.2.63 Add custom job annotations snippet and wire it into job templates - 0.2.64 Use custom secret annotations snippet in other secret templates - 0.2.65 Escape special characters in password for DB connection + - 0.2.66 Align db scripts with sqlalchemy 2.0 ...