Bug 1301410 - beaker-init tries (and fails) to populate the database on downgrade
Summary: beaker-init tries (and fails) to populate the database on downgrade
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Beaker
Classification: Retired
Component: general
Version: 22
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: 22.2
Assignee: Dan Callaghan
QA Contact: tools-bugs
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-01-24 22:51 UTC by Dan Callaghan
Modified: 2016-03-15 01:51 UTC (History)
4 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2016-03-15 01:51:30 UTC
Embargoed:


Attachments (Terms of Use)

Description Dan Callaghan 2016-01-24 22:51:02 UTC
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>
    main()
  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 05:41:18 UTC
http://gerrit.beaker-project.org/4654

Comment 2 Dan Callaghan 2016-02-03 05:43:11 UTC
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-15 01:51:30 UTC
Beaker 22.2 has been released.


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