From 582f862d12f8bcefb2aaf9f2e59707e11125bd2e Mon Sep 17 00:00:00 2001 From: pulkitvajpayee07 Date: Wed, 6 Mar 2024 08:56:09 +0000 Subject: [PATCH] fix_db_migration Deployment was failing,loosing connection with database while db_migration and not able to create tables, revert few changes. Once we have complete support for SQLAlchemy2.0 needs to fix this issue. Change-Id: I78d7d327be9d4f95490eeee62f3300cdc2b07a85 --- .../drivers/apic_aim/data_migrations.py | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/gbpservice/neutron/plugins/ml2plus/drivers/apic_aim/data_migrations.py b/gbpservice/neutron/plugins/ml2plus/drivers/apic_aim/data_migrations.py index bca7446a8..041f00882 100644 --- a/gbpservice/neutron/plugins/ml2plus/drivers/apic_aim/data_migrations.py +++ b/gbpservice/neutron/plugins/ml2plus/drivers/apic_aim/data_migrations.py @@ -31,7 +31,6 @@ from aim.api import resource as aim_resource from aim import context as aim_context from aim import utils as aim_utils from alembic import util as alembic_util -from gbpservice.neutron.db import api as db_api from neutron.db.migration.cli import CONF from neutron.db.models import address_scope as as_db from neutron.db.models import securitygroup as sg_models @@ -138,7 +137,9 @@ def do_apic_aim_persist_migration(session): aim_ctx = aim_context.AimContext(session) mapper = apic_mapper.APICNameMapper() - with db_api.CONTEXT_WRITER.using(session): + # REVISIT: needs to add support for context_reader/ + # context_writer + with session.begin(subtransactions=True): # Migrate address scopes. scope_dbs = (session.query(as_db.AddressScope) .options(lazyload('*')).all()) @@ -274,7 +275,9 @@ def do_ap_name_change(session, conf=None): aim_ctx = aim_context.AimContext(session) system_id = cfg.apic_system_id alembic_util.msg("APIC System ID: %s" % system_id) - with db_api.CONTEXT_WRITER.using(session): + # REVISIT: needs to add support for context_reader/ + # context_writer + with session.begin(subtransactions=True): net_dbs = session.query(models_v2.Network).options(lazyload('*')).all() for net_db in net_dbs: ext_db = _get_network_extn_db(session, net_db.id) @@ -366,7 +369,9 @@ def do_apic_aim_security_group_migration(session): aim = aim_manager.AimManager() aim_ctx = aim_context.AimContext(session) mapper = apic_mapper.APICNameMapper() - with db_api.CONTEXT_WRITER.using(session): + # REVISIT: needs to add support for context_reader/ + # context_writer + with session.begin(subtransactions=True): # Migrate SG. sg_dbs = (session.query(sg_models.SecurityGroup). options(lazyload('*')).all()) @@ -438,7 +443,9 @@ def do_sg_rule_remote_group_id_insertion(session): aim = aim_manager.AimManager() aim_ctx = aim_context.AimContext(session) mapper = apic_mapper.APICNameMapper() - with db_api.CONTEXT_WRITER.using(session): + # REVISIT: needs to add support for context_reader/ + # context_writer + with session.begin(subtransactions=True): sg_rule_dbs = (session.query(sg_models.SecurityGroupRule). options(lazyload('*')).all()) for sg_rule_db in sg_rule_dbs: @@ -468,7 +475,9 @@ def do_ha_ip_duplicate_entries_removal(session): haip_ip = HAIPAddressToPortAssociation.c.ha_ip_address haip_port_id = HAIPAddressToPortAssociation.c.port_id - with db_api.CONTEXT_WRITER.using(session): + # REVISIT: needs to add support for context_reader/ + # context_writer + with session.begin(subtransactions=True): port_and_haip_dbs = (session.query(models_v2.Port, HAIPAddressToPortAssociation).join( HAIPAddressToPortAssociation, @@ -500,7 +509,9 @@ def do_ha_ip_network_id_insertion(session): haip_ip = HAIPAddressToPortAssociation.c.ha_ip_address haip_port_id = HAIPAddressToPortAssociation.c.port_id - with db_api.CONTEXT_WRITER.using(session): + # REVISIT: needs to add support for context_reader/ + # context_writer + with session.begin(subtransactions=True): port_and_haip_dbs = (session.query(models_v2.Port, HAIPAddressToPortAssociation).join( @@ -522,6 +533,8 @@ def do_hpp_insertion(session): alembic_util.msg( "Starting hpp normalized value insertion for HPP table.") + # REVISIT: needs to add support for context_reader/ + # context_writer with session.begin(subtransactions=True): session.execute(HPPDB.insert().values(hpp_normalized=False))