Tacker - how different db tables are created

Asked by Sridhar Ramaswamy

Tacker db tables are created in two ways. Some using alembic migrations scripts and other are created in other magical ways. We need to understand how this flow works.

Question information

Language:
English Edit question
Status:
Solved
For:
tacker Edit question
Assignee:
No assignee Edit question
Solved by:
Sridhar Ramaswamy
Solved:
Last query:
Last reply:
Revision history for this message
Sridhar Ramaswamy (srics-r) said :
#1

Answering my own question ...

Alembic migration scripts builds device and proxy related tables as coded in.

Steps to run,

1) Create tacker db,

CREATE DATABASE tacker CHARACTER SET utf8;

2) Run tacker-db-manage to run through all the migration scripts

stack@tacker-dev:/opt/stack/devstack$ tacker-db-manage --config-file /etc/tacker/tacker.conf upgrade head
INFO [alembic.runtime.migration] Context impl MySQLImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
INFO [alembic.runtime.migration] Running upgrade -> 1c6b0d82afcd, add tables for servicevm framework
INFO [alembic.runtime.migration] Running upgrade 1c6b0d82afcd -> 81ffa86020d, rpc_proxy
INFO [alembic.runtime.migration] Running upgrade 81ffa86020d -> 4c31092895b8, empty message
INFO [alembic.runtime.migration] Running upgrade 4c31092895b8 -> 13c0e0661015, add descrition to vnf
INFO [alembic.runtime.migration] Running upgrade 13c0e0661015 -> 5958429bcb3c, modify datatype of value

3) Following db tables are created at the end of this step,

mysql> use tacker;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+--------------------------+
| Tables_in_tacker |
+--------------------------+
| alembic_version |
| deviceattributes |
| devices |
| devicetemplateattributes |
| devicetemplates |
| proxymgmtports |
| proxyserviceports |
+--------------------------+
7 rows in set (0.00 sec)

Revision history for this message
Sridhar Ramaswamy (srics-r) said :
#2

However when the tacker server is run there are tables in mysql (marked as **)

mysql> show tables;
+--------------------------+
| Tables_in_tacker |
+--------------------------+
| alembic_version |
| deviceattributes |
| devices |
| deviceservicecontexts | **
| devicetemplateattributes |
| devicetemplates |
| proxymgmtports |
| proxyserviceports |
| servicecontexts | **
| servicedevicebindings | **
| serviceinstances | **
| servicetypes | **
+--------------------------+
12 rows in set (0.00 sec)

These tables are automatically created when tacker-server starts up.

This happens when VNFMPlugin [1] loads initialized the base vm_db class [2] which in turn does a register_models [3]. This last call will call sqlalchemy create_all() call which will create all "TackerBase" classes defined in vm_db.py. See the debug logs with sqlalchemy debugs verbose enabled,

http://paste.openstack.org/show/478397/

[1] https://github.com/openstack/tacker/blob/master/tacker/vm/plugin.py#L169
[2] https://github.com/openstack/tacker/blob/master/tacker/db/vm/vm_db.py#L279
[3] https://github.com/openstack/tacker/blob/master/tacker/db/api.py#L73