alembic migration from newton to pike fails on postgres

Bug #1737830 reported by Joseph Richard
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
networking-odl
Triaged
Medium
Unassigned

Bug Description

When doing an upgrade from newton(3d560427d776) to pike(6f7dfb241354) on a system using postgres, the 6f7dfb241354_create_opendaylight_preiodic_task_table.py migration will not apply. Manually going through the migrations, I am able to apply each of them until 6f7dfb241354, which will fail to apply.
This failure is because the state type already exists in the database[1][2], and so cannot be created for this migration.
Note, this does not occur when doing `neutron-db-manage upgrade heads` on an empty database(i.e. fresh install).

neutron=# \dT+ state
                                  List of data types
 Schema | Name | Internal name | Size | Elements | Access privileges | Description
--------+-------+---------------+------+------------+-------------------+-------------
 public | state | state | 4 | pending +| |
        | | | | processing+| |
        | | | | failed +| |
        | | | | completed | |
(1 row)

controller-1:/home/wrsroot# psql --version
psql (PostgreSQL) 9.2.23
controller-1:/home/wrsroot# neutron-db-manage --config-file /etc/neutron/neutron-dbsync.conf --subproject networking-odl current
  Running current for networking-odl ...
INFO [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO [alembic.runtime.migration] Will assume transactional DDL.
0472f56ff2fb
fa0c536252a5
  OK
controller-1:/home/wrsroot# neutron-db-manage --config-file /etc/neutron/neutron-dbsync.conf --subproject networking-odl upgrade 6f7dfb241354
INFO [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO [alembic.runtime.migration] Will assume transactional DDL.
  Running upgrade for networking-odl ...
INFO [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO [alembic.runtime.migration] Will assume transactional DDL.
INFO [alembic.runtime.migration] Running upgrade 0472f56ff2fb -> 6f7dfb241354, create opendaylight_preiodic_task table
Traceback (most recent call last):
  File "/usr/bin/neutron-db-manage", line 10, in <module>
    sys.exit(main())
  File "/usr/lib/python2.7/site-packages/neutron/db/migration/cli.py", line 691, in main
    return_val |= bool(CONF.command.func(config, CONF.command.name))
  File "/usr/lib/python2.7/site-packages/neutron/db/migration/cli.py", line 212, in do_upgrade
    desc=branch, sql=CONF.command.sql)
  File "/usr/lib/python2.7/site-packages/neutron/db/migration/cli.py", line 113, in do_alembic_command
    getattr(alembic_command, cmd)(config, *args, **kwargs)
  File "/usr/lib/python2.7/site-packages/alembic/command.py", line 174, in upgrade
    script.run_env()
  File "/usr/lib/python2.7/site-packages/alembic/script/base.py", line 416, in run_env
    util.load_python_file(self.dir, 'env.py')
  File "/usr/lib/python2.7/site-packages/alembic/util/pyfiles.py", line 93, in load_python_file
    module = load_module_py(module_id, path)
  File "/usr/lib/python2.7/site-packages/alembic/util/compat.py", line 79, in load_module_py
    mod = imp.load_source(module_id, path, fp)
  File "/usr/lib/python2.7/site-packages/networking_odl/db/migration/alembic_migrations/env.py", line 99, in <module>
    run_migrations_online()
  File "/usr/lib/python2.7/site-packages/networking_odl/db/migration/alembic_migrations/env.py", line 90, in run_migrations_online
    context.run_migrations()
  File "<string>", line 8, in run_migrations
  File "/usr/lib/python2.7/site-packages/alembic/runtime/environment.py", line 807, in run_migrations
    self.get_context().run_migrations(**kw)
  File "/usr/lib/python2.7/site-packages/alembic/runtime/migration.py", line 321, in run_migrations
    step.migration_fn(**kw)
  File "/usr/lib/python2.7/site-packages/networking_odl/db/migration/alembic_migrations/versions/pike/expand/6f7dfb241354_create_opendaylight_preiodic_task_table.py", line 44, in upgrade
    onupdate=sa.func.now())
  File "<string>", line 8, in create_table
  File "<string>", line 3, in create_table
  File "/usr/lib/python2.7/site-packages/alembic/operations/ops.py", line 1098, in create_table
    return operations.invoke(op)
  File "/usr/lib/python2.7/site-packages/alembic/operations/base.py", line 318, in invoke
    return fn(self, operation)
  File "/usr/lib/python2.7/site-packages/alembic/operations/toimpl.py", line 101, in create_table
    operations.impl.create_table(table)
  File "/usr/lib/python2.7/site-packages/alembic/ddl/impl.py", line 193, in create_table
    _ddl_runner=self)
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/event/attr.py", line 256, in __call__
    fn(*args, **kw)
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/util/langhelpers.py", line 539, in __call__
    return getattr(self.target, self.name)(*arg, **kw)
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/sql/sqltypes.py", line 1035, in _on_table_create
    t._on_table_create(target, bind, **kw)
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.py", line 1371, in _on_table_create
    self.create(bind=bind, checkfirst=checkfirst)
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.py", line 1319, in create
    bind.execute(CreateEnumType(self))
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/base.py", line 914, in execute
    return meth(self, multiparams, params)
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/sql/ddl.py", line 68, in _execute_on_connection
    return connection._execute_ddl(self, multiparams, params)
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/base.py", line 968, in _execute_ddl
    compiled
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/base.py", line 1146, in _execute_context
    context)
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/base.py", line 1337, in _handle_dbapi_exception
    util.raise_from_cause(newraise, exc_info)
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/util/compat.py", line 200, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb)
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/base.py", line 1139, in _execute_context
    context)
  File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/default.py", line 450, in do_execute
    cursor.execute(statement, parameters)
oslo_db.exception.DBError: (psycopg2.ProgrammingError) type "state" already exists
 [SQL: "CREATE TYPE state AS ENUM ('pending', 'processing')"]

[1] https://git.openstack.org/cgit/openstack/networking-odl/commit/?id=0076400bc1823565b5310c8a4527f6e25bf00885
[2] https://bugs.launchpad.net/networking-odl/+bug/1597175

Revision history for this message
Isaku Yamahata (yamahata) wrote :

sounds like valid bug.
thanks for detalied bug report.

Changed in networking-odl:
importance: Undecided → Medium
status: New → Triaged
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.