Skip to content

Commit

Permalink
Merge "SQLAlchemy 2.0 Support"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and openstack-gerrit committed Jan 4, 2023
2 parents 1069a7f + 3fe42b5 commit c0f9602
Show file tree
Hide file tree
Showing 41 changed files with 1,479 additions and 763 deletions.
4 changes: 2 additions & 2 deletions ironic_inspector/cmd/dbsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def add_command_parsers(subparsers):

def _get_alembic_config():
base_path = os.path.split(os.path.dirname(__file__))[0]
return alembic_config.Config(os.path.join(base_path, 'alembic.ini'))
return alembic_config.Config(os.path.join(base_path, 'db/alembic.ini'))


def do_revision(config, cmd, *args, **kwargs):
Expand All @@ -85,7 +85,7 @@ def main(args=sys.argv[1:]):
CONF.register_cli_opt(command_opt)
CONF(args, project='ironic-inspector')
config = _get_alembic_config()
config.set_main_option('script_location', "ironic_inspector:migrations")
config.set_main_option('script_location', "ironic_inspector.db:migrations")
config.ironic_inspector_config = CONF

CONF.command.func(config, CONF.command.name)
8 changes: 6 additions & 2 deletions ironic_inspector/conductor/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from ironic_inspector.common.i18n import _
from ironic_inspector.common import ironic as ir_utils
from ironic_inspector.common import keystone
from ironic_inspector import db
from ironic_inspector.db import api as dbapi
from ironic_inspector import introspect
from ironic_inspector import node_cache
from ironic_inspector.plugins import base as plugins_base
Expand All @@ -52,6 +52,7 @@ def __init__(self):
self._zeroconf = None
self._shutting_down = semaphore.Semaphore()
self.coordinator = None
self.dbapi = None

def init_host(self):
"""Initialize Worker host
Expand All @@ -69,7 +70,8 @@ def init_host(self):
LOG.info('Introspection data will be stored in the %s backend',
CONF.processing.store_data)

db.init()
if not self.dbapi:
self.dbapi = dbapi.init()

self.coordinator = None
try:
Expand Down Expand Up @@ -169,6 +171,8 @@ def del_host(self):
self._zeroconf.close()
self._zeroconf = None

self.dbapi = None

self._shutting_down.release()

LOG.info('Shut down successfully')
Expand Down
19 changes: 19 additions & 0 deletions ironic_inspector/db/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

from oslo_db.sqlalchemy import enginefacade

# TODO(aarefiev): enable foreign keys for SQLite once all unit
# tests with failed constraint will be fixed.
# FIXME(stephenfin): we need to remove reliance on autocommit semantics ASAP
# since it's not compatible with SQLAlchemy 2.0
enginefacade.configure(sqlite_fk=False)
File renamed without changes.
Loading

0 comments on commit c0f9602

Please sign in to comment.