Coverage for nova/db/api/api.py: 82%
18 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-04-17 15:08 +0000
« prev ^ index » next coverage.py v7.6.12, created at 2025-04-17 15:08 +0000
1# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
13from oslo_db.sqlalchemy import enginefacade
14from oslo_utils import importutils
15import sqlalchemy as sa
17import nova.conf
19profiler_sqlalchemy = importutils.try_import('osprofiler.sqlalchemy')
21CONF = nova.conf.CONF
23context_manager = enginefacade.transaction_context()
25# NOTE(stephenfin): We don't need equivalents of the 'get_context_manager' or
26# 'create_context_manager' APIs found in 'nova.db.main.api' since we don't need
27# to be cell-aware here
30def _get_db_conf(conf_group, connection=None):
31 kw = dict(conf_group.items())
32 if connection is not None: 32 ↛ 33line 32 didn't jump to line 33 because the condition on line 32 was never true
33 kw['connection'] = connection
34 return kw
37def configure(conf):
38 context_manager.configure(**_get_db_conf(conf.api_database))
40 if ( 40 ↛ 45line 40 didn't jump to line 45 because the condition on line 40 was never true
41 profiler_sqlalchemy and
42 CONF.profiler.enabled and
43 CONF.profiler.trace_sqlalchemy
44 ):
45 context_manager.append_on_engine_create(
46 lambda eng: profiler_sqlalchemy.add_tracing(sa, eng, "db"))
49def get_engine():
50 return context_manager.writer.get_engine()