Bug 1301410 - beaker-init tries (and fails) to populate the database on downgrade
beaker-init tries (and fails) to populate the database on downgrade
Product: Beaker
Classification: Community
Component: general (Show other bugs)
Unspecified Unspecified
unspecified Severity unspecified (vote)
: 22.2
: ---
Assigned To: Dan Callaghan
: Patch
Depends On:
  Show dependency treegraph
Reported: 2016-01-24 17:51 EST by Dan Callaghan
Modified: 2016-03-14 21:51 EDT (History)
4 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2016-03-14 21:51:30 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Dan Callaghan 2016-01-24 17:51:02 EST
When upgrading, beaker-init is supposed to perform two functions:

1) create or upgrade the schema
2) "populate" the database with static data, like hypervisor types, key types, admin user account, ...

But beaker-init also has the (essentially unrelated) function of performing schema downgrades too. In that case it should not be trying to populate the database.

However if you invoke beaker-init with --debug, currently it *does* attempt to perform the population step, and most of the time this will fail because the downgraded schema no longer matches what the model code (which is used for populating the db) is expecting.

For example, using 22.0 to downgrade to 21.x schema:

$ beaker-init --downgrade 171c07fb4970
2016-01-25 08:42:27,716 alembic.migration INFO Running downgrade 5ab8960cdb43 -> 171c07fb4970, Delete duplicate rows in osmajor_install_options
Traceback (most recent call last):
  File "bkr/server/tools/init.py", line 310, in <module>
  File "bkr/server/tools/init.py", line 307, in main
    populate_db(opts.user_name, opts.password, opts.display_name, opts.email_address)
  File "bkr/server/tools/init.py", line 53, in populate_db
    admin = Group.by_name(u'admin')
  File "bkr/server/model/identity.py", line 467, in by_name
    return cls.query.filter_by(group_name=name).one()
sqlalchemy.exc.OperationalError: (OperationalError) (1054, "Unknown column 'tg_group.membership_type' in 'field list'") 'SELECT tg_group.root_password AS tg_group_root_password, tg_group.group_id AS tg_group_group_id, tg_group.group_name AS tg_group_group_name, tg_group.display_name AS tg_group_display_name, tg_group.membership_type AS tg_group_membership_type, tg_group.created AS tg_group_created \nFROM tg_group \nWHERE tg_group.group_name = %s' ('admin',)

Looks like it was just an indentation mistake with the populate_db() call on line 307 of init.py (that line should be inside the else: block).
Comment 1 Dan Callaghan 2016-02-03 00:41:18 EST
Comment 2 Dan Callaghan 2016-02-03 00:43:11 EST
Steps to reproduce:
1. On a fully upgraded Beaker 22 environment, try to downgrade to Beaker 21:
$ beaker-init --downgrade 171c07fb4970

Actual results:
Database is downgraded but then a traceback is printed, as per comment 0.

Expected results:
Downgrade completes successfully, no output.
Comment 5 Dan Callaghan 2016-03-14 21:51:30 EDT
Beaker 22.2 has been released.

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