From 1cfb025d73d3d347e6f6465fcb249c41aef90572 Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Tue, 28 Aug 2012 13:03:07 -0700 Subject: [PATCH] Remove db auto-creation magic from glance-manage This removes the reliance of glance-manage db_sync on configure_db calling register_models. Fixes bug 1042925 Change-Id: Id93283905256247bdd2663b799d41a7925804542 --- bin/glance-manage | 5 ----- glance/db/sqlalchemy/api.py | 1 + glance/db/sqlalchemy/migration.py | 5 ++++- glance/tests/functional/test_glance_manage.py | 7 +++++-- glance/tests/unit/test_migrations.py | 2 ++ 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/bin/glance-manage b/bin/glance-manage index 257259a1d8..03a8f938c3 100755 --- a/bin/glance-manage +++ b/bin/glance-manage @@ -81,11 +81,6 @@ def do_db_sync(args): Place a database under migration control and upgrade, creating first if necessary. """ - # override auto-create flag, as complete DB should always - # be created on sync if not already existing - CONF.register_opts(glance.db.sqlalchemy.api.db_opts) - CONF.set_override('db_auto_create', True) - glance.db.sqlalchemy.api.configure_db() version = args.pop(0) if args else None current_version = args.pop(0) if args else None glance.db.sqlalchemy.migration.db_sync(version, current_version) diff --git a/glance/db/sqlalchemy/api.py b/glance/db/sqlalchemy/api.py index 50736b5d8c..aa011adb53 100644 --- a/glance/db/sqlalchemy/api.py +++ b/glance/db/sqlalchemy/api.py @@ -840,5 +840,6 @@ def image_tag_get_all(context, image_id, session=None): tags = session.query(models.ImageTag).\ filter_by(image_id=image_id).\ filter_by(deleted=False).\ + order_by(sqlalchemy.asc(models.ImageTag.created_at)).\ all() return [tag['value'] for tag in tags] diff --git a/glance/db/sqlalchemy/migration.py b/glance/db/sqlalchemy/migration.py index d76a68d435..7264e0986a 100644 --- a/glance/db/sqlalchemy/migration.py +++ b/glance/db/sqlalchemy/migration.py @@ -98,6 +98,9 @@ def version_control(version=None): def _version_control(version): """ Place a database under migration control + + This will only set the specific version of a database, it won't + run any migrations. """ repo_path = get_migrate_repo_path() sql_connection = CONF.sql_connection @@ -114,7 +117,7 @@ def db_sync(version=None, current_version=None): """ sql_connection = CONF.sql_connection try: - _version_control(current_version) + _version_control(current_version or 0) except versioning_exceptions.DatabaseAlreadyControlledError, e: if current_version is not None: msg = (_("database '%(sql_connection)s' is already under " diff --git a/glance/tests/functional/test_glance_manage.py b/glance/tests/functional/test_glance_manage.py index 3bf2ddad53..00054d18ec 100644 --- a/glance/tests/functional/test_glance_manage.py +++ b/glance/tests/functional/test_glance_manage.py @@ -53,8 +53,11 @@ class TestGlanceManage(functional.FunctionalTest): self.assertTrue('CREATE TABLE images' in out) self.assertTrue('CREATE TABLE image_tags' in out) - self.assertTrue('CREATE TABLE image_members' in out) - self.assertTrue('CREATE TABLE image_properties' in out) + + #NOTE(bcwaldon): For some reason we need double-quotes around + # these two table names + self.assertTrue('CREATE TABLE "image_members"' in out) + self.assertTrue('CREATE TABLE "image_properties"' in out) @depends_on_exe('sqlite3') @skip_if_disabled diff --git a/glance/tests/unit/test_migrations.py b/glance/tests/unit/test_migrations.py index 663ac52ce5..66f812141b 100644 --- a/glance/tests/unit/test_migrations.py +++ b/glance/tests/unit/test_migrations.py @@ -35,6 +35,8 @@ from sqlalchemy.pool import NullPool from glance.common import exception import glance.db.sqlalchemy.migration as migration_api +#NOTE(bcwaldon): import this to prevent circular import +from glance.db.sqlalchemy import api from glance.db.sqlalchemy import models from glance.openstack.common import cfg from glance.tests import utils