[openstack-dev] [neutron] how to create initial db migration script to sub-project

Henry Gessau HenryG at gessau.net
Sun Jul 24 18:21:26 UTC 2016


Hi Moshe,

It has been a while since a neutron sub-project initialized new alembic
migrations, so the devref is out of date, sorry. Let me help you get this
sorted out and then I can update the devref with the latest info.

First you need to create the initial migration for each branch (expand and
contract). This is done by submitting a patch -- the contents of which used to
be crafted by copying a similar patch from another sub-project. The patches to
copy from are now out of date, so I have created a patch [2] for you and we
can use this as the new "template patch for initial alembic migrations."

Some more comments inline ...

Moshe Levi <moshele at mellanox.com> wrote:
> Hi,
> 
> I am trying to create initial db for the networking-mlnx project. 
> I am following this neutron alembic documentation [1].
> I added a entrypoint to networking-mlnx setup.cfg
> neutron.db.alembic_migrations =
>     networking-mlnx = networking_mlnx.db.migration:alembic_migrations
> I added model.py file to networking-mlnx/networking_mlnx/db
> And I run python setup.py develop to regenerate the entrypoint 
> 
> I am running the following commands:
> 1. mysql -e "drop database neutron; create database neutron;"
> 2. neutron-db-manage --subproject=neutron  upgrade heads

So far so good.

> 3. neutron-db-manage --subproject=networking-mlnx  revision -m "test" --autogenerate

Because we now require split (expand and contract) branches, you must now
specify --expand or --contract *instead of* --autogenerate. I will update the
devref about this.

> I am getting the following errors:
> INFO  [alembic.runtime.migration] Context impl MySQLImpl.                                                           
> INFO  [alembic.runtime.migration] Will assume non-transactional DDL.                                                
> INFO  [alembic.autogenerate.compare] Detected removed table u'alembic_version'                                      
> INFO  [alembic.autogenerate.compare] Detected removed index 'idx_autoinc_vr_id' on 'ha_router_vrid_allocations'     
>   Generating /.autodirect/mtrswgwork/moshele/openstack/networking-mlnx/networking_mlnx/db/migration/alembic_migrations/versions/120e7e350bb1_test.py ... done
>   OK                                                                                                                                                         
> Traceback (most recent call last):                                                                                                                           
>   File "/usr/bin/neutron-db-manage", line 10, in <module>                                                                                                    
>     sys.exit(main())                                                                                                                                         
>   File "/.autodirect/mtrswgwork/moshele/openstack/neutron/neutron/db/migration/cli.py", line 689, in main                                                    
>     return_val |= bool(CONF.command.func(config, CONF.command.name))                                                                                         
>   File "/.autodirect/mtrswgwork/moshele/openstack/neutron/neutron/db/migration/cli.py", line 275, in do_revision                                             
>     update_head_files(config)                                                                                                                                
>   File "/.autodirect/mtrswgwork/moshele/openstack/neutron/neutron/db/migration/cli.py", line 398, in update_head_files                                       
>     f.write(head_map[CONTRACT_BRANCH] + '\n')                                                                                                                
> KeyError: 'contract'
> 
> 
> And the migration script just dropping unrelated tables 

This should be fixed by env.py in [2].

> [moshele at r-dcs84 networking-mlnx]$ cat /.autodirect/mtrswgwork/moshele/openstack/networking-mlnx/networking_mlnx/db/migration/alembic_migrations/versions/120e7e350bb1_test.py
> # revision identifiers, used by Alembic.
> revision = '120e7e350bb1'
> down_revision = None
> 
> from alembic import op
> import sqlalchemy as sa
> from sqlalchemy.dialects import mysql
> 
> def upgrade():
>     ### commands auto generated by Alembic - please adjust! ###
>     op.drop_table('alembic_version')
>     op.drop_index('idx_autoinc_vr_id', table_name='ha_router_vrid_allocations')
>     ### end Alembic commands ###
> 
> 
> 
> It seem that the neutron alembic migration documentation [1] is out of date
> ( I don't see the --core_plugin flag in the neutron-db-manage man, but I do
> see the --subproject flag)
> 
> Does anyone know how to make it works? 

Yes, --core_plugin is defunct and I will remove it from the devref.

If you rebase on top of my patch [2] and run the revision command with
--expand you should get a clean new migration.

> 
> [1] - http://docs.openstack.org/developer/neutron/devref/alembic_migrations.html


[2] https://review.openstack.org/346538




More information about the OpenStack-dev mailing list