Glance update for Ubuntu failing

Bug #779311 reported by Graham Hemingway
32
This bug affects 4 people
Affects Status Importance Assigned to Milestone
glance (Ubuntu)
Expired
High
Unassigned

Bug Description

Today I tried upgrading to the current trunk (129 I think) and I get a bit fail on the apt-get upgrade. Here is the error message:

Setting up glance (2011.3~bzr129-0ubuntu0ppa1~maverick2) ...
Traceback (most recent call last):
  File "/usr/bin/glance-manage", line 141, in <module>
    main()
  File "/usr/bin/glance-manage", line 137, in main
    dispatch_cmd(options, args)
  File "/usr/bin/glance-manage", line 109, in dispatch_cmd
    cmd_func(options, args)
  File "/usr/bin/glance-manage", line 97, in do_db_sync
    glance.registry.db.migration.db_sync(options, version=db_version)
  File "/usr/lib/pymodules/python2.6/glance/registry/db/migration.py", line 117, in db_sync
    upgrade(options, version=version)
  File "/usr/lib/pymodules/python2.6/glance/registry/db/migration.py", line 64, in upgrade
    return versioning_api.upgrade(sql_connection, repo_path, version)
  File "/usr/lib/pymodules/python2.6/migrate/versioning/api.py", line 185, in upgrade
    return _migrate(url, repository, version, upgrade=True, err=err, **opts)
  File "<string>", line 2, in _migrate
  File "/usr/lib/pymodules/python2.6/migrate/versioning/util/__init__.py", line 160, in with_engine
    return f(*a, **kw)
  File "/usr/lib/pymodules/python2.6/migrate/versioning/api.py", line 364, in _migrate
    schema.runchange(ver, change, changeset.step)
  File "/usr/lib/pymodules/python2.6/migrate/versioning/schema.py", line 83, in runchange
    change.run(self.engine, step)
  File "/usr/lib/pymodules/python2.6/migrate/versioning/script/py.py", line 140, in run
    script_func(engine)
  File "/usr/lib/pymodules/python2.6/glance/registry/db/migrate_repo/versions/001_add_images_table.py", line 49, in upgrade
    create_tables(tables)
  File "/usr/lib/pymodules/python2.6/glance/registry/db/migrate_repo/schema.py", line 97, in create_tables
    table.create()
  File "/usr/lib/python2.6/dist-packages/sqlalchemy/schema.py", line 439, in create
    bind.create(self, checkfirst=checkfirst)
  File "/usr/lib/python2.6/dist-packages/sqlalchemy/engine/base.py", line 1647, in create
    connection=connection, **kwargs)
  File "/usr/lib/python2.6/dist-packages/sqlalchemy/engine/base.py", line 1682, in _run_visitor
    **kwargs).traverse_single(element)
  File "/usr/lib/python2.6/dist-packages/sqlalchemy/sql/visitors.py", line 77, in traverse_single
    return meth(obj, **kw)
  File "/usr/lib/python2.6/dist-packages/sqlalchemy/engine/ddl.py", line 58, in visit_table
    self.connection.execute(schema.CreateTable(table))
  File "/usr/lib/python2.6/dist-packages/sqlalchemy/engine/base.py", line 1157, in execute
    params)
  File "/usr/lib/python2.6/dist-packages/sqlalchemy/engine/base.py", line 1210, in _execute_ddl
    return self.__execute_context(context)
  File "/usr/lib/python2.6/dist-packages/sqlalchemy/engine/base.py", line 1268, in __execute_context
    context.parameters[0], context=context)
  File "/usr/lib/python2.6/dist-packages/sqlalchemy/engine/base.py", line 1367, in _cursor_execute
    context)
  File "/usr/lib/python2.6/dist-packages/sqlalchemy/engine/base.py", line 1360, in _cursor_execute
    context)
  File "/usr/lib/python2.6/dist-packages/sqlalchemy/engine/default.py", line 288, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.OperationalError: (OperationalError) table images already exists u'\nCREATE TABLE images (\n\tid INTEGER NOT NULL, \n\tname VARCHAR(255), \n\ttype VARCHAR(30), \n\tsize INTEGER, \n\tstatus VARCHAR(30) NOT NULL, \n\tis_public BOOLEAN NOT NULL, \n\tlocation TEXT, \n\tcreated_at DATETIME NOT NULL, \n\tupdated_at DATETIME, \n\tdeleted_at DATETIME, \n\tdeleted BOOLEAN NOT NULL, \n\tPRIMARY KEY (id), \n\tCHECK (is_public IN (0, 1)), \n\tCHECK (deleted IN (0, 1))\n)\n\n' ()
dpkg: error processing glance (--configure):
 subprocess installed post-installation script returned error exit status 1
Setting up python-nova (2011.3~bzr1058-0ubuntu0ppa1~maverick1) ...
Setting up nova-common (2011.3~bzr1058-0ubuntu0ppa1~maverick1) ...
Installing new version of config file /etc/sudoers.d/nova_sudoers ...
Setting up nova-objectstore (2011.3~bzr1058-0ubuntu0ppa1~maverick1) ...
Installing new version of config file /etc/logrotate.d/nova-objectstore ...
nova-objectstore start/running, process 14301
Setting up nova-api (2011.3~bzr1058-0ubuntu0ppa1~maverick1) ...
nova-api start/running, process 14319
Setting up nova-scheduler (2011.3~bzr1058-0ubuntu0ppa1~maverick1) ...
nova-scheduler start/running, process 14335
Setting up nova-network (2011.3~bzr1058-0ubuntu0ppa1~maverick1) ...
nova-network start/running, process 14351
Processing triggers for python-support ...
Errors were encountered while processing:
 glance
E: Sub-process /usr/bin/dpkg returned an error code (1)

It looks like a sqlalchemy call is failing because the table IMAGES already exists (which it does since I have been running glance for a bit already). What should I do?
Thanks,
   Graham

Related branches

Changed in glance:
assignee: nobody → Rick Harris (rconradharris)
Changed in glance:
status: New → In Progress
Revision history for this message
Rick Harris (rconradharris) wrote :

Hi Graham, thanks for the bug report!

It looks like we're trying to erroneously re-migrate your database from the beginning. AFAIK, this only happens when the target DB is missing the `migrate_version` table which keeps track of which version of the database schema we're using.

Out of curiosity:

* Could you paste in what value you have for `sql_connection` in `/etc/glance/glance.conf`?

* Is there a `migrate_version` table present in the `glance` database?

* If the `migrate_version` table is present, can you paste in the results of a `SELECT * FROM migrate_version;`

* How was the `glance` database originally created? Was the database created by installing the glance package, or was glance originally installed from source and `glance-manage db_sync` run?

Thanks,

-Rick

Revision history for this message
Graham Hemingway (graham-hemingway) wrote :

Rick, thanks for getting back to me on this.

My connection string is:
sql_connection = sqlite:////var/lib/glance/glance.sqlite

There is a migrate version table. Here is some info:
sqlite> select * from migrate_version;
Glance Migrations|/usr/lib/pymodules/python2.6/glance/registry/db/migrate_repo|0

So, the database was not created in either of these ways. I ran into a glance bug two weeks ago (see https://answers.launchpad.net/glance/+question/154442). In trying to fix this I deleted the glance.sqlite database. I let glance recreate it on startup (which it seems to do). But I never called db_sync or anything else. I am certain that this is the cause of my issue. Is there a way to fix it?

Thanks,
   Graham

Jay Pipes (jaypipes)
Changed in glance:
milestone: none → diablo-1
Revision history for this message
Soren Hansen (soren) wrote :

003_add_disk_format tries to migrate a "type" column which does not exist. It seems to be created in 001_add_images_table.py, but it's never been mentioned in db/models.py, which is what was used to create db tables in the bad, old days.

Revision history for this message
Soren Hansen (soren) wrote :

Err.. Right, sorry:

The existing schema seems to match version 2 of the migrate_versions, except for the aforementioned "type" column.

...so setting the existing version to 2 almost does the trick except for this.

Revision history for this message
Rick Harris (rconradharris) wrote :

> I let glance recreate it on startup (which it seems to do). But I never called db_sync or anything else. I am certain that this is the cause of my issue.

Yeah that sounds like the root cause. The current code auto-creates the tables if they're not present. This leads to an inconsistent state since the `migrate_version` table isn't present.

I think the solution here is to prevent tables from being created outside of migrations; in other words, the only way to create the schema is via `glance-manage db_sync`. That change is in this branch: https://code.launchpad.net/~rconradharris/glance/lp779311

> Is there a way to fix it?

Probably the best way is to eyeball the schema in the DB and compare that to the migrations present in migrate_repo/versions. By looking at the differences, you should be able to 'guess' the proper version.

For example, if in your schema `image_properties` is using `name` instead of `key`, then your DB version is at 6 (the latest and greatest).

You can then create a migrate_version table and populate it like

Glance Migrations|/usr/lib/pymodules/python2.6/glance/registry/db/migrate_repo|6

Revision history for this message
Soren Hansen (soren) wrote : Re: [Bug 779311] Re: Glance update for Ubuntu failing

2011/5/25 Rick Harris <email address hidden>:
>> Is there a way to fix it?
> Probably the best way is to eyeball the schema in the DB and compare
> that to the migrations present in migrate_repo/versions. By looking at
> the differences, you should be able to 'guess' the proper version.
>
> For example, if in your schema `image_properties` is using `name`
> instead of `key`, then your DB version is at 6 (the latest and
> greatest).
>
> You can then create a migrate_version table and populate it like
>
> Glance
> Migrations|/usr/lib/pymodules/python2.6/glance/registry/db/migrate_repo|6

So you're suggesting we leave this up to users themselves to do this
manually? Is there any particular reason why the approach Nova took
isn't feasible for Glance?

--
Soren Hansen        | http://linux2go.dk/
Ubuntu Developer    | http://www.ubuntu.com/
OpenStack Developer | http://www.openstack.org/

Jay Pipes (jaypipes)
Changed in glance:
importance: Undecided → Medium
Jay Pipes (jaypipes)
Changed in glance:
status: In Progress → Fix Committed
Revision history for this message
Jay Pipes (jaypipes) wrote :

I'm re-opening this based on comments from Soren and from a duplicate bug (symptom) reported from Ant...

Changed in glance:
status: Fix Committed → Confirmed
Revision history for this message
Thierry Carrez (ttx) wrote :

@Rick, are you looking into this ? Or should this be unassigned so that someone else can take it ?

Changed in glance:
milestone: diablo-1 → diablo-4
importance: Medium → High
Revision history for this message
Rick Harris (rconradharris) wrote :

Thierry: Not looking at this at the moment. I'll unassign myself for the time being in case someone else can jump in. I'll try to get back to this once the alpha madness calms down a bit ;)

Changed in glance:
assignee: Rick Harris (rconradharris) → nobody
Dave Walker (davewalker)
Changed in glance (Ubuntu):
status: New → Confirmed
importance: Undecided → High
Jay Pipes (jaypipes)
Changed in glance:
milestone: diablo-4 → diablo-rbp
Thierry Carrez (ttx)
Changed in glance:
milestone: diablo-rbp → 2011.3
Jay Pipes (jaypipes)
Changed in glance:
milestone: 2011.3 → none
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package glance - 2012.1~e1~20111021.1056-0ubuntu1

---------------
glance (2012.1~e1~20111021.1056-0ubuntu1) precise; urgency=low

  * New upstream release.
  * Dropped patches:
    - debian/patches/lp_845788_glance_client_zero_length.patch
    - debian/patches/lp_850425_remote_swift_image_streaming.patch
  * debian/control:
    - Add dependency on python-httplib2. (LP: #779311)
    - Add dependency on python-paste.
  * debian/patches/sql_conn.patch: Updated for update config file.
  * debian/glance.install: Update for new config files.
 -- Chuck Short <email address hidden> Fri, 21 Oct 2011 14:11:04 -0400

Changed in glance (Ubuntu):
status: Confirmed → Fix Released
Revision history for this message
Adam Gandelman (gandelman-a) wrote :

Appears this bug was mistakenly closed in Ubuntu due to the wrong bug # in a changelog. Reopening as there are duplicates popping up again.

Changed in glance (Ubuntu):
status: Fix Released → Confirmed
Jay Pipes (jaypipes)
no longer affects: glance
Revision history for this message
James Page (james-page) wrote :

Wow - this is quite an old bug now; are folks still seeing this issue with the 12.04 packages?

Marking 'Incomplete' pending any responses.

Changed in glance (Ubuntu):
status: Confirmed → Incomplete
Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for glance (Ubuntu) because there has been no activity for 60 days.]

Changed in glance (Ubuntu):
status: Incomplete → Expired
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Related questions

Remote bug watches

Bug watches keep track of this bug in other bug trackers.