← Back to team overview

yahoo-eng-team team mailing list archive

[Bug 1482416] [NEW] bug blocks DB migration that changes column type

 

Public bug reported:

I'm trying to make the following change as a DB migration

+    # Table instances, modify field 'vcpus_used' to Float
+    compute_nodes = Table('compute_nodes', meta, autoload=True)
+    vcpus_used = getattr(compute_nodes.c, 'vcpus_used')
+    vcpus_used.alter(type=Float)


This works at runtime (using PostgreSQL) but when running the unit tests (using sqlite) I get the following:


nova.tests.unit.db.test_migrations.TestNovaMigrationsSQLite.test_models_sync
----------------------------------------------------------------------------

Captured traceback:
~~~~~~~~~~~~~~~~~~~
    Traceback (most recent call last):
      File "/home/cfriesen/devel/wrlinux-x/addons/wr-cgcs/layers/cgcs/git/nova/.tox/py27/lib/python2.7/site-packages/oslo_db/sqlalchemy/test_migrations.py", line 588, in test_models_sync
        "Models and migration scripts aren't in sync:\n%s" % msg)
      File "/home/cfriesen/devel/wrlinux-x/addons/wr-cgcs/layers/cgcs/git/nova/.tox/py27/lib/python2.7/site-packages/unittest2/case.py", line 690, in fail
        raise self.failureException(msg)
    AssertionError: Models and migration scripts aren't in sync:
    [ ( 'add_constraint',
        UniqueConstraint(Column('host', String(length=255), table=<compute_nodes>), Column('hypervisor_hostname', String(length=255), table=<compute_nodes>), Column('deleted', Integer(), table=<compute_nodes>, default=ColumnDefault(0))))]
    


This appears to be an interaction between two things, the change I made to alter the vcpus_used column, and a previous change (commit 2db4a1ac, migration version 279) to add the uniq_compute_nodes0host0hypervisor_hostname constraint.  sqlite doesn't support altering columns, so there's a workaround that makes a new column, copies the contents over, and deletes the old one...this seems to be running into problems with the modified constraint.

I suspect that this means that anyone wanting to change the type of a
column in the "compute_nodes" table will run into a similar problem.

** Affects: nova
     Importance: Undecided
         Status: New


** Tags: compute db

-- 
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to OpenStack Compute (nova).
https://bugs.launchpad.net/bugs/1482416

Title:
  bug blocks DB migration that changes column type

Status in OpenStack Compute (nova):
  New

Bug description:
  I'm trying to make the following change as a DB migration

  +    # Table instances, modify field 'vcpus_used' to Float
  +    compute_nodes = Table('compute_nodes', meta, autoload=True)
  +    vcpus_used = getattr(compute_nodes.c, 'vcpus_used')
  +    vcpus_used.alter(type=Float)

  
  This works at runtime (using PostgreSQL) but when running the unit tests (using sqlite) I get the following:

  
  nova.tests.unit.db.test_migrations.TestNovaMigrationsSQLite.test_models_sync
  ----------------------------------------------------------------------------

  Captured traceback:
  ~~~~~~~~~~~~~~~~~~~
      Traceback (most recent call last):
        File "/home/cfriesen/devel/wrlinux-x/addons/wr-cgcs/layers/cgcs/git/nova/.tox/py27/lib/python2.7/site-packages/oslo_db/sqlalchemy/test_migrations.py", line 588, in test_models_sync
          "Models and migration scripts aren't in sync:\n%s" % msg)
        File "/home/cfriesen/devel/wrlinux-x/addons/wr-cgcs/layers/cgcs/git/nova/.tox/py27/lib/python2.7/site-packages/unittest2/case.py", line 690, in fail
          raise self.failureException(msg)
      AssertionError: Models and migration scripts aren't in sync:
      [ ( 'add_constraint',
          UniqueConstraint(Column('host', String(length=255), table=<compute_nodes>), Column('hypervisor_hostname', String(length=255), table=<compute_nodes>), Column('deleted', Integer(), table=<compute_nodes>, default=ColumnDefault(0))))]
      

  
  This appears to be an interaction between two things, the change I made to alter the vcpus_used column, and a previous change (commit 2db4a1ac, migration version 279) to add the uniq_compute_nodes0host0hypervisor_hostname constraint.  sqlite doesn't support altering columns, so there's a workaround that makes a new column, copies the contents over, and deletes the old one...this seems to be running into problems with the modified constraint.

  I suspect that this means that anyone wanting to change the type of a
  column in the "compute_nodes" table will run into a similar problem.

To manage notifications about this bug go to:
https://bugs.launchpad.net/nova/+bug/1482416/+subscriptions


Follow ups