[grafana] Adjust scripts for SQLAlchemy 2.0 compatibility
* wrap statements with `text()` where appropriate * add commit handling for explicit transactions * replace deprecated .execute() usage with SQLAlchemy 2.0 syntax Change-Id: If528ed9240ede4478aba53249f0bfe2be41d8769 Signed-off-by: Arina Stebenkova <astebenkova@mirantis.com>
This commit is contained in:
@@ -11,7 +11,7 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine, text
|
||||||
|
|
||||||
# Create logger, console handler and formatter
|
# Create logger, console handler and formatter
|
||||||
logger = logging.getLogger('OpenStack-Helm DB Init')
|
logger = logging.getLogger('OpenStack-Helm DB Init')
|
||||||
@@ -58,13 +58,18 @@ except:
|
|||||||
|
|
||||||
# Create Table
|
# Create Table
|
||||||
try:
|
try:
|
||||||
user_engine.execute('''CREATE TABLE IF NOT EXISTS `session` (
|
with user_engine.connect() as conn:
|
||||||
`key`CHAR(16) NOT NULL,
|
conn.execute(text('''CREATE TABLE IF NOT EXISTS `session` (
|
||||||
`data` BLOB,
|
`key` CHAR(16) NOT NULL,
|
||||||
`expiry` INT(11) UNSIGNED NOT NULL,
|
`data` BLOB,
|
||||||
PRIMARY KEY (`key`)
|
`expiry` INT(11) UNSIGNED NOT NULL,
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;''')
|
PRIMARY KEY (`key`)
|
||||||
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;'''))
|
||||||
|
try:
|
||||||
|
conn.commit()
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
logger.info('Created table for session cache')
|
logger.info('Created table for session cache')
|
||||||
except:
|
except Exception as e:
|
||||||
logger.critical('Could not create table for session cache')
|
logger.critical(f'Could not create table for session cache: {e}')
|
||||||
raise
|
raise
|
||||||
|
|||||||
4
releasenotes/notes/grafana-b3fac6a311d115a6.yaml
Normal file
4
releasenotes/notes/grafana-b3fac6a311d115a6.yaml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
grafana:
|
||||||
|
- Adjust Python code for SQLAlchemy 2.0 compatibility
|
||||||
|
...
|
||||||
Reference in New Issue
Block a user