Merge "Use Oslo.db migration"

This commit is contained in:
Jenkins 2014-02-18 14:59:45 +00:00 committed by Gerrit Code Review
commit f077dc695b
14 changed files with 67 additions and 37 deletions
keystone
assignment/backends
catalog/backends
cli.py
contrib
endpoint_filter/backends
federation/backends
oauth1/backends
credential/backends
identity/backends
policy/backends
tests

@ -17,9 +17,10 @@ import six
from keystone import assignment
from keystone import clean
from keystone.common import sql
from keystone.common.sql import migration
from keystone.common.sql import migration_helpers
from keystone import config
from keystone import exception
from keystone.openstack.common.db.sqlalchemy import migration
from keystone.openstack.common.db.sqlalchemy import session as db_session
@ -30,7 +31,8 @@ class Assignment(sql.Base, assignment.Driver):
# Internal interface to manage the database
def db_sync(self, version=None):
migration.db_sync(version=version)
migration.db_sync(
migration_helpers.find_migrate_repo(), version=version)
def _get_project(self, session, project_id):
project_ref = session.query(Project).get(project_id)

@ -18,9 +18,10 @@ import six
from keystone import catalog
from keystone.catalog import core
from keystone.common import sql
from keystone.common.sql import migration
from keystone.common.sql import migration_helpers
from keystone import config
from keystone import exception
from keystone.openstack.common.db.sqlalchemy import migration
from keystone.openstack.common.db.sqlalchemy import session as db_session
@ -78,7 +79,8 @@ class Endpoint(sql.ModelBase, sql.DictBase):
class Catalog(sql.Base, catalog.Driver):
def db_sync(self, version=None):
migration.db_sync(version=version)
migration.db_sync(
migration_helpers.find_migrate_repo(), version=version)
# Regions
def list_regions(self):

@ -23,11 +23,12 @@ import pbr.version
from keystone.common import openssl
from keystone.common import sql
from keystone.common.sql import migration
from keystone.common.sql import migration_helpers
from keystone.common import utils
from keystone import config
from keystone import contrib
from keystone import exception
from keystone.openstack.common.db.sqlalchemy import migration
from keystone.openstack.common import importutils
from keystone import token
@ -70,7 +71,7 @@ class DbSync(BaseApp):
version = CONF.command.version
extension = CONF.command.extension
if not extension:
migration.db_sync(version=version)
abs_path = migration_helpers.find_migrate_repo()
else:
try:
package_name = '.'.join((contrib.__name__, extension))
@ -79,18 +80,18 @@ class DbSync(BaseApp):
raise ImportError(_("%s extension does not exist.")
% package_name)
try:
abs_path = migration_helpers.find_migrate_repo(package)
try:
migration.db_version_control(package=package)
migration.db_version_control(abs_path)
# Register the repo with the version control API
# If it already knows about the repo, it will throw
# an exception that we can safely ignore
except exceptions.DatabaseAlreadyControlledError:
pass
migration.db_sync(version=version, package=package)
except exception.MigrationNotProvided as e:
print(e)
exit(0)
migration.db_sync(abs_path, version=version)
class DbVersion(BaseApp):
@ -117,12 +118,14 @@ class DbVersion(BaseApp):
raise ImportError(_("%s extension does not exist.")
% package_name)
try:
print(migration.db_version(package))
print(migration.db_version(
migration_helpers.find_migrate_repo(package)), 0)
except exception.MigrationNotProvided as e:
print(e)
exit(0)
else:
print(migration.db_version())
print(migration.db_version(
migration_helpers.find_migrate_repo()), 0)
class BaseCertificateSetup(BaseApp):

@ -13,8 +13,10 @@
# under the License.
from keystone.common import sql
from keystone.common.sql import migration
from keystone.common.sql import migration_helpers
from keystone.contrib import endpoint_filter
from keystone import exception
from keystone.openstack.common.db.sqlalchemy import migration
from keystone.openstack.common.db.sqlalchemy import session as db_session
@ -34,7 +36,8 @@ class EndpointFilter(sql.Base):
# Internal interface to manage the database
def db_sync(self, version=None):
migration.db_sync(version=version)
abs_path = migration_helpers.find_migrate_repo(endpoint_filter)
migration.db_sync(abs_path, version=version)
@sql.handle_conflicts(conflict_type='project_endpoint')
def add_endpoint_to_project(self, endpoint_id, project_id):

@ -13,9 +13,11 @@
# under the License.
from keystone.common import sql
from keystone.common.sql import migration
from keystone.common.sql import migration_helpers
from keystone.contrib import federation
from keystone.contrib.federation import core
from keystone import exception
from keystone.openstack.common.db.sqlalchemy import migration
from keystone.openstack.common.db.sqlalchemy import session as db_session
from keystone.openstack.common import jsonutils
@ -89,7 +91,8 @@ class MappingModel(sql.ModelBase, sql.DictBase):
class Federation(sql.Base, core.Driver):
def db_sync(self):
migration.db_sync()
abs_path = migration_helpers.find_migrate_repo(federation)
migration.db_sync(abs_path)
# Identity Provider CRUD
@sql.handle_conflicts(conflict_type='identity_provider')

@ -19,9 +19,11 @@ import uuid
import six
from keystone.common import sql
from keystone.common.sql import migration
from keystone.common.sql import migration_helpers
from keystone.contrib import oauth1
from keystone.contrib.oauth1 import core
from keystone import exception
from keystone.openstack.common.db.sqlalchemy import migration
from keystone.openstack.common.db.sqlalchemy import session as db_session
from keystone.openstack.common import jsonutils
from keystone.openstack.common import timeutils
@ -84,7 +86,7 @@ class AccessToken(sql.ModelBase, sql.DictBase):
class OAuth1(sql.Base):
def db_sync(self):
migration.db_sync()
migration.db_sync(migration_helpers.find_migrate_repo(oauth1))
def _get_consumer(self, session, consumer_id):
consumer_ref = session.query(Consumer).get(consumer_id)

@ -13,9 +13,10 @@
# under the License.
from keystone.common import sql
from keystone.common.sql import migration
from keystone.common.sql import migration_helpers
from keystone import credential
from keystone import exception
from keystone.openstack.common.db.sqlalchemy import migration
from keystone.openstack.common.db.sqlalchemy import session as db_session
@ -34,7 +35,8 @@ class CredentialModel(sql.ModelBase, sql.DictBase):
class Credential(sql.Base, credential.Driver):
# Internal interface to manage the database
def db_sync(self, version=None):
migration.db_sync(version=version)
migration.db_sync(
migration_helpers.find_migrate_repo(), version=version)
# credential crud

@ -14,10 +14,11 @@
from keystone.common import dependency
from keystone.common import sql
from keystone.common.sql import migration
from keystone.common.sql import migration_helpers
from keystone.common import utils
from keystone import exception
from keystone import identity
from keystone.openstack.common.db.sqlalchemy import migration
from keystone.openstack.common.db.sqlalchemy import session as db_session
# Import assignment sql to ensure that the models defined in there are
@ -80,7 +81,8 @@ class Identity(sql.Base, identity.Driver):
# Internal interface to manage the database
def db_sync(self, version=None):
migration.db_sync(version=version)
migration.db_sync(
migration_helpers.find_migrate_repo(), version=version)
def _check_password(self, password, user_ref):
"""Check the specified password against the data store.

@ -13,8 +13,9 @@
# under the License.
from keystone.common import sql
from keystone.common.sql import migration
from keystone.common.sql import migration_helpers
from keystone import exception
from keystone.openstack.common.db.sqlalchemy import migration
from keystone.openstack.common.db.sqlalchemy import session as db_session
from keystone.policy.backends import rules
@ -31,7 +32,8 @@ class PolicyModel(sql.ModelBase, sql.DictBase):
class Policy(sql.Base, rules.Policy):
# Internal interface to manage the database
def db_sync(self, version=None):
migration.db_sync(version=version)
migration.db_sync(
migration_helpers.find_migrate_repo(), version=version)
@sql.handle_conflicts(conflict_type='policy')
def create_policy(self, policy_id, policy):

@ -54,10 +54,12 @@ from keystone.common import dependency
from keystone.common import kvs
from keystone.common.kvs import core as kvs_core
from keystone.common import sql
from keystone.common.sql import migration_helpers
from keystone.common import utils
from keystone import config
from keystone import exception
from keystone import notifications
from keystone.openstack.common.db.sqlalchemy import migration
from keystone.openstack.common.db.sqlalchemy import session
from keystone.openstack.common import log
from keystone.openstack.common import timeutils
@ -153,7 +155,7 @@ def setup_database():
if os.path.exists(db):
os.unlink(db)
if not os.path.exists(pristine):
sql.migration.db_sync()
migration.db_sync(migration_helpers.find_migrate_repo())
shutil.copyfile(db, pristine)
else:
shutil.copyfile(pristine, db)

@ -14,8 +14,9 @@
import uuid
from keystone.common.sql import migration
from keystone.common.sql import migration_helpers
from keystone import contrib
from keystone.openstack.common.db.sqlalchemy import migration
from keystone.openstack.common import importutils
from keystone import tests
from keystone.tests import test_v3
@ -33,8 +34,9 @@ class TestExtensionCase(test_v3.RestfulTestCase):
super(TestExtensionCase, self).setup_database()
package_name = '.'.join((contrib.__name__, self.EXTENSION_NAME))
package = importutils.import_module(package_name)
migration.db_version_control(package=package)
migration.db_sync(package=package)
abs_path = migration_helpers.find_migrate_repo(package)
migration.db_version_control(abs_path)
migration.db_sync(abs_path)
def setUp(self):
super(TestExtensionCase, self).setUp()

@ -36,12 +36,13 @@ import uuid
from migrate.versioning import api as versioning_api
import sqlalchemy
from keystone.common.sql import migration
from keystone.common import sql
from keystone.common.sql import migration_helpers
from keystone.common import utils
from keystone import config
from keystone import credential
from keystone import exception
from keystone.openstack.common.db.sqlalchemy import migration
from keystone.openstack.common.db.sqlalchemy import session
from keystone import tests
from keystone.tests import default_fixtures
@ -65,7 +66,7 @@ class SqlMigrateBase(tests.TestCase):
return self._config_file_list
def repo_package(self):
return None
return sql
def setUp(self):
super(SqlMigrateBase, self).setUp()
@ -156,8 +157,8 @@ class SqlUpgradeTests(SqlMigrateBase):
self.assertTableDoesNotExist('user')
def test_start_version_0(self):
version = migration.db_version()
self.assertEqual(version, 0, "DB is at version 0")
version = migration.db_version(self.repo_path, 0)
self.assertEqual(version, 0, "DB is not at version 0")
def test_two_steps_forward_one_step_back(self):
"""You should be able to cleanly undo and re-apply all upgrades.

@ -13,10 +13,11 @@
import random
import uuid
from keystone.common.sql import migration
from keystone.common.sql import migration_helpers
from keystone import config
from keystone import contrib
from keystone.contrib.federation import utils as mapping_utils
from keystone.openstack.common.db.sqlalchemy import migration
from keystone.openstack.common import importutils
from keystone.openstack.common import jsonutils
from keystone.openstack.common import log
@ -41,8 +42,9 @@ class FederationTests(test_v3.RestfulTestCase):
super(FederationTests, self).setup_database()
package_name = '.'.join((contrib.__name__, self.EXTENSION_NAME))
package = importutils.import_module(package_name)
migration.db_version_control(package=package)
migration.db_sync(package=package)
abs_path = migration_helpers.find_migrate_repo(package)
migration.db_version_control(abs_path)
migration.db_sync(abs_path)
class FederatedIdentityProviderTests(FederationTests):

@ -17,12 +17,13 @@ import uuid
from six.moves import urllib
from keystone.common.sql import migration
from keystone.common.sql import migration_helpers
from keystone import config
from keystone import contrib
from keystone.contrib import oauth1
from keystone.contrib.oauth1 import controllers
from keystone import exception
from keystone.openstack.common.db.sqlalchemy import migration
from keystone.openstack.common import importutils
from keystone.tests import test_v3
@ -39,8 +40,9 @@ class OAuth1Tests(test_v3.RestfulTestCase):
super(OAuth1Tests, self).setup_database()
package_name = '.'.join((contrib.__name__, self.EXTENSION_NAME))
package = importutils.import_module(package_name)
migration.db_version_control(package=package)
migration.db_sync(package=package)
abs_path = migration_helpers.find_migrate_repo(package)
migration.db_version_control(abs_path)
migration.db_sync(abs_path)
def setUp(self):
super(OAuth1Tests, self).setUp()