Bug 1350302 - beaker-init --check on an empty database creates alembic_version table, database cannot be populated
Summary: beaker-init --check on an empty database creates alembic_version table, datab...
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Beaker
Classification: Retired
Component: general
Version: 23
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: 23.3
Assignee: Jon Orris
QA Contact: tools-bugs
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-06-27 05:21 UTC by Dan Callaghan
Modified: 2016-11-07 06:44 UTC (History)
5 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2016-11-07 06:44:34 UTC
Embargoed:


Attachments (Terms of Use)

Description Dan Callaghan 2016-06-27 05:21:04 UTC
Description of problem:
In our Ansible playbooks we are doing a four-step process for db migrations, like this:

beaker-init --check
(if check indicates changes are needed)
beaker-init --user... --background
wait for pid file to disappear
beaker-init --check

This works well for migrating existing databases. But for deploying a fresh environment from scratch, it will fail on the final check step.

Version-Release number of selected component (if applicable):
beaker-server-23.0-0.git.248.ede6acc

How reproducible:
easily, with a fresh environment (empty db)

Steps to Reproduce:
1. Configure /etc/beaker/server.cfg to point at a new, empty database containing no tables
2. Run beaker-init --check
3. Run beaker-init --user admin --password '' --email something

Actual results:
Fails with an exception:
Traceback (most recent call last):
  File "/usr/bin/beaker-init", line 9, in <module>
    load_entry_point('bkr.server==23.0.git.248.ede6acc', 'console_scripts', 'beaker-init')()
  File "/usr/lib/python2.6/site-packages/bkr/server/tools/init.py", line 378, in main
    return doit(opts)
  File "/usr/lib/python2.6/site-packages/bkr/server/util.py", line 178, in decorated
    return func(*args, **kwargs)
  File "/usr/lib/python2.6/site-packages/bkr/server/tools/init.py", line 413, in doit
    upgrade_db(metadata)
  File "/usr/lib/python2.6/site-packages/bkr/server/tools/init.py", line 265, in upgrade_db
    run_alembic_operation(metadata, upgrade)
  File "/usr/lib/python2.6/site-packages/bkr/server/tools/init.py", line 317, in run_alembic_operation
    env_context.run_migrations()
[...]
sqlalchemy.exc.NoSuchTableError: `recipe_task`

Expected results:
Initial beaker-init --check should report that the database needs upgrading.
Subsequent beaker-init should then populate it correctly, not die with an exception.

Additional info:
The exception occurs because the initial beaker-init --check seems to silently create an alembic_version table (with no rows). This means the subsequent beaker-init invocation thinks the database is *not* empty and instead tries to follow the pre-0.19 inspection logic to determine the version, which then fails as above. In fact the database is just empty and should be populated from scratch.

So we either need to make beaker-init ignore the presence of alembic_version when considering whether the database is empty, or we need to make beaker-init --check not silently create the alembic_version table.

I would prefer the latter since beaker-init --check promises to make no changes to the database, although we are clearly violating that promise right now.

Comment 1 Jon Orris 2016-08-25 19:39:55 UTC
(In reply to Dan Callaghan from comment #0)
> So we either need to make beaker-init ignore the presence of alembic_version
> when considering whether the database is empty, or we need to make
> beaker-init --check not silently create the alembic_version table.
> 
> I would prefer the latter since beaker-init --check promises to make no
> changes to the database, although we are clearly violating that promise
> right now.

Unfortunately the second option is not possible, as alembic itself auto-creates this table as soon as you call get_current_revision(). This is, however, fixed in newer versions of alembic, so it will be possible to remove this workaround if and when alembic is upgraded.

https://gerrit.beaker-project.org/#/c/5161/

Comment 2 Dan Callaghan 2016-09-30 00:58:14 UTC
This bug fix is included in beaker-server-23.3-0.git.10.a898f12 which is currently available for download here:

https://beaker-project.org/nightlies/release-23/

Comment 4 Dan Callaghan 2016-11-07 06:44:34 UTC
Beaker 23.3 has been released.


Note You need to log in before you can comment on or make changes to this bug.