From 9b9afcaa29572c2e16b2b4ddfa9d70b99de0efb1 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Wed, 19 Jul 2023 10:17:24 +0100 Subject: [PATCH] db: Disable logging by default for alembic We don't want alembic overriding our logging: we can configure it ourselves. This removes a whole lot of noise from our test output. Change-Id: Ic1bc4ab967913a8adaac559482d330d72e47a4b5 Signed-off-by: Stephen Finucane --- .../db/sqlalchemy/alembic_migrations/__init__.py | 8 ++++++-- glance/db/sqlalchemy/alembic_migrations/env.py | 14 +++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/glance/db/sqlalchemy/alembic_migrations/__init__.py b/glance/db/sqlalchemy/alembic_migrations/__init__.py index 8b4f39995a..e5cda3a434 100644 --- a/glance/db/sqlalchemy/alembic_migrations/__init__.py +++ b/glance/db/sqlalchemy/alembic_migrations/__init__.py @@ -27,6 +27,10 @@ def get_alembic_config(engine=None): """Return a valid alembic config object""" ini_path = os.path.join(os.path.dirname(__file__), 'alembic.ini') config = alembic_config.Config(os.path.abspath(ini_path)) + # we don't want to use the logger configuration from the file, which is + # only really intended for the CLI + # https://stackoverflow.com/a/42691781/613428 + config.attributes['configure_logger'] = False if engine is None: engine = db_api.get_engine() # str(sqlalchemy.engine.url.URL) returns a RFC-1738 quoted URL. @@ -61,9 +65,9 @@ def get_current_alembic_heads(): version_num=new).where( alembic_version.c.version_num == old).execute() - if ("pike01" in heads): + if "pike01" in heads: update_alembic_version("pike01", "pike_contract01") - elif ("ocata01" in heads): + elif "ocata01" in heads: update_alembic_version("ocata01", "ocata_contract01") heads = context.get_current_heads() diff --git a/glance/db/sqlalchemy/alembic_migrations/env.py b/glance/db/sqlalchemy/alembic_migrations/env.py index a474009e8a..bb2b46346f 100644 --- a/glance/db/sqlalchemy/alembic_migrations/env.py +++ b/glance/db/sqlalchemy/alembic_migrations/env.py @@ -12,6 +12,7 @@ # 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 logging import config as log_config from alembic import context @@ -26,17 +27,12 @@ from glance.db.sqlalchemy import models_metadef config = context.config CONF = cfg.CONF -# other values from the config, defined by the needs of env.py, -# can be acquired: -# my_important_option = config.get_main_option("my_important_option") -# ... etc. - -# Interpret the config file for Python logging. +# Interpret the config file for Python logging unless we're told not to. # This line sets up loggers basically. -log_config.fileConfig(config.config_file_name) +if config.attributes.get('configure_logger', True): + log_config.fileConfig(config.config_file_name) -# add your model's MetaData object here -# for 'autogenerate' support +# this is the MetaData object for the various models in the database target_metadata = models.BASE.metadata for table in models_metadef.BASE_DICT.metadata.sorted_tables: target_metadata._add_table(table.name, table.schema, table)