From 4f878ed1021ed2b2d1768b3c97d92627dcced2bb Mon Sep 17 00:00:00 2001 From: Madhu Mohan Nelemane Date: Thu, 26 Jul 2018 15:18:03 +0200 Subject: [PATCH 1/2] Fix for duplicate uniq_agents --- aim/db/agent_model.py | 2 +- .../alembic_migrations/versions/accfe645090a_agent_resource.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/aim/db/agent_model.py b/aim/db/agent_model.py index 8c9bbad0..f3d86414 100644 --- a/aim/db/agent_model.py +++ b/aim/db/agent_model.py @@ -32,7 +32,7 @@ class Agent(model_base.Base, model_base.HasId, model_base.AttributeMixin): __table_args__ = ( sa.UniqueConstraint('agent_type', 'host', - name='uniq_agents0agent_type0host'), + name='aim_agents_uniq_agents0agent_type0host'), model_base.Base.__table_args__ ) diff --git a/aim/db/migration/alembic_migrations/versions/accfe645090a_agent_resource.py b/aim/db/migration/alembic_migrations/versions/accfe645090a_agent_resource.py index 99cafd29..6d1cf602 100644 --- a/aim/db/migration/alembic_migrations/versions/accfe645090a_agent_resource.py +++ b/aim/db/migration/alembic_migrations/versions/accfe645090a_agent_resource.py @@ -48,7 +48,7 @@ def upgrade(): sa.Column('version', sa.String(10)), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('agent_type', 'host', - name='uniq_agents0agent_type0host')) + name='aim_agents_uniq_agents0agent_type0host')) op.create_table( 'aim_agent_to_tree_associations', From 5eeeab4349f16827fe8532d60e3abd2720a93caa Mon Sep 17 00:00:00 2001 From: Madhu Mohan Nelemane Date: Thu, 26 Jul 2018 15:33:39 +0200 Subject: [PATCH 2/2] Fix for #230 to handle nested sessions --- .../versions/aceb1ac13668_vmm_policy.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/aim/db/migration/alembic_migrations/versions/aceb1ac13668_vmm_policy.py b/aim/db/migration/alembic_migrations/versions/aceb1ac13668_vmm_policy.py index 49d1b5a8..b8f2d83b 100644 --- a/aim/db/migration/alembic_migrations/versions/aceb1ac13668_vmm_policy.py +++ b/aim/db/migration/alembic_migrations/versions/aceb1ac13668_vmm_policy.py @@ -36,6 +36,8 @@ from aim import context from aim.db import api +from oslo_db.exception import DBError + def upgrade(): @@ -59,12 +61,16 @@ def upgrade(): new_vmms = [] new_phys = [] with session.begin(subtransactions=True): - for vmm in session.query(old_vmm_table).all(): - new_vmms.append(resource.VMMDomain(type=vmm.type, name=vmm.name, - monitored=True)) - for phys in session.query(old_phys_table).all(): - new_phys.append(resource.PhysicalDomain(name=phys.name, - monitored=True)) + try: + for vmm in session.query(old_vmm_table).all(): + new_vmms.append(resource.VMMDomain(type=vmm.type, name=vmm.name, + monitored=True)) + for phys in session.query(old_phys_table).all(): + new_phys.append(resource.PhysicalDomain(name=phys.name, + monitored=True)) + except DBError: + # We can fail if the tables are not yet there + pass op.drop_table('aim_vmm_domains') op.drop_table('aim_physical_domains')