Merge "Move endpoint_filter migrations into keystone core"
This commit is contained in:
commit
40453931a9
@ -0,0 +1,70 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import sqlalchemy as sql
|
||||
|
||||
from keystone.common.sql import migration_helpers
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
try:
|
||||
extension_version = migration_helpers.get_db_version(
|
||||
extension='endpoint_filter',
|
||||
engine=migrate_engine)
|
||||
except Exception:
|
||||
extension_version = 0
|
||||
|
||||
# This migration corresponds to endpoint_filter extension migration 2. Only
|
||||
# update if it has not been run.
|
||||
if extension_version >= 2:
|
||||
return
|
||||
|
||||
# Upgrade operations go here. Don't create your own engine; bind
|
||||
# migrate_engine to your metadata
|
||||
meta = sql.MetaData()
|
||||
meta.bind = migrate_engine
|
||||
|
||||
EP_GROUP_ID = 'endpoint_group_id'
|
||||
PROJECT_ID = 'project_id'
|
||||
|
||||
endpoint_filtering_table = sql.Table(
|
||||
'project_endpoint',
|
||||
meta,
|
||||
sql.Column(
|
||||
'endpoint_id',
|
||||
sql.String(64),
|
||||
primary_key=True,
|
||||
nullable=False),
|
||||
sql.Column(
|
||||
'project_id',
|
||||
sql.String(64),
|
||||
primary_key=True,
|
||||
nullable=False))
|
||||
endpoint_filtering_table.create(migrate_engine, checkfirst=True)
|
||||
|
||||
endpoint_group_table = sql.Table(
|
||||
'endpoint_group',
|
||||
meta,
|
||||
sql.Column('id', sql.String(64), primary_key=True),
|
||||
sql.Column('name', sql.String(255), nullable=False),
|
||||
sql.Column('description', sql.Text, nullable=True),
|
||||
sql.Column('filters', sql.Text(), nullable=False))
|
||||
endpoint_group_table.create(migrate_engine, checkfirst=True)
|
||||
|
||||
project_endpoint_group_table = sql.Table(
|
||||
'project_endpoint_group',
|
||||
meta,
|
||||
sql.Column(EP_GROUP_ID, sql.String(64),
|
||||
sql.ForeignKey('endpoint_group.id'), nullable=False),
|
||||
sql.Column(PROJECT_ID, sql.String(64), nullable=False),
|
||||
sql.PrimaryKeyConstraint(EP_GROUP_ID, PROJECT_ID))
|
||||
project_endpoint_group_table.create(migrate_engine, checkfirst=True)
|
@ -34,13 +34,13 @@ from keystone.i18n import _
|
||||
|
||||
|
||||
CONF = cfg.CONF
|
||||
DEFAULT_EXTENSIONS = ['endpoint_filter',
|
||||
]
|
||||
DEFAULT_EXTENSIONS = []
|
||||
|
||||
MIGRATED_EXTENSIONS = ['endpoint_policy',
|
||||
'federation',
|
||||
'oauth1',
|
||||
'revoke',
|
||||
'endpoint_filter'
|
||||
]
|
||||
|
||||
|
||||
|
@ -12,27 +12,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import sqlalchemy as sql
|
||||
from keystone import exception
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
# Upgrade operations go here. Don't create your own engine; bind
|
||||
# migrate_engine to your metadata
|
||||
meta = sql.MetaData()
|
||||
meta.bind = migrate_engine
|
||||
|
||||
endpoint_filtering_table = sql.Table(
|
||||
'project_endpoint',
|
||||
meta,
|
||||
sql.Column(
|
||||
'endpoint_id',
|
||||
sql.String(64),
|
||||
primary_key=True,
|
||||
nullable=False),
|
||||
sql.Column(
|
||||
'project_id',
|
||||
sql.String(64),
|
||||
primary_key=True,
|
||||
nullable=False))
|
||||
|
||||
endpoint_filtering_table.create(migrate_engine, checkfirst=True)
|
||||
raise exception.MigrationMovedFailure(extension='endpoint_filter')
|
||||
|
@ -12,30 +12,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import sqlalchemy as sql
|
||||
from keystone import exception
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
# Upgrade operations go here. Don't create your own engine; bind
|
||||
# migrate_engine to your metadata
|
||||
meta = sql.MetaData()
|
||||
meta.bind = migrate_engine
|
||||
|
||||
endpoint_group_table = sql.Table(
|
||||
'endpoint_group',
|
||||
meta,
|
||||
sql.Column('id', sql.String(64), primary_key=True),
|
||||
sql.Column('name', sql.String(255), nullable=False),
|
||||
sql.Column('description', sql.Text, nullable=True),
|
||||
sql.Column('filters', sql.Text(), nullable=False))
|
||||
endpoint_group_table.create(migrate_engine, checkfirst=True)
|
||||
|
||||
project_endpoint_group_table = sql.Table(
|
||||
'project_endpoint_group',
|
||||
meta,
|
||||
sql.Column('endpoint_group_id', sql.String(64),
|
||||
sql.ForeignKey('endpoint_group.id'), nullable=False),
|
||||
sql.Column('project_id', sql.String(64), nullable=False),
|
||||
sql.PrimaryKeyConstraint('endpoint_group_id',
|
||||
'project_id'))
|
||||
project_endpoint_group_table.create(migrate_engine, checkfirst=True)
|
||||
raise exception.MigrationMovedFailure(extension='endpoint_filter')
|
||||
|
@ -66,32 +66,12 @@ class EndpointFilterExtension(test_sql_upgrade.SqlMigrateBase):
|
||||
def repo_package(self):
|
||||
return endpoint_filter
|
||||
|
||||
def upgrade(self, version):
|
||||
super(EndpointFilterExtension, self).upgrade(
|
||||
version, repository=self.repo_path)
|
||||
|
||||
def _assert_v1_tables(self):
|
||||
self.assertTableColumns('project_endpoint',
|
||||
['endpoint_id', 'project_id'])
|
||||
self.assertTableDoesNotExist('endpoint_group')
|
||||
self.assertTableDoesNotExist('project_endpoint_group')
|
||||
|
||||
def _assert_v2_tables(self):
|
||||
self.assertTableColumns('project_endpoint',
|
||||
['endpoint_id', 'project_id'])
|
||||
self.assertTableColumns('endpoint_group',
|
||||
['id', 'name', 'description', 'filters'])
|
||||
self.assertTableColumns('project_endpoint_group',
|
||||
['endpoint_group_id', 'project_id'])
|
||||
|
||||
def test_upgrade(self):
|
||||
self.assertTableDoesNotExist('project_endpoint')
|
||||
self.upgrade(1)
|
||||
self._assert_v1_tables()
|
||||
self.assertTableColumns('project_endpoint',
|
||||
['endpoint_id', 'project_id'])
|
||||
self.upgrade(2)
|
||||
self._assert_v2_tables()
|
||||
for version in range(2):
|
||||
v = version + 1
|
||||
self.assertRaises(exception.MigrationMovedFailure,
|
||||
self.upgrade, version=v,
|
||||
repository=self.repo_path)
|
||||
|
||||
|
||||
class EndpointPolicyExtension(test_sql_upgrade.SqlMigrateBase):
|
||||
|
@ -779,6 +779,35 @@ class SqlUpgradeTests(SqlMigrateBase):
|
||||
self.upgrade(75)
|
||||
self.assertTableColumns(config_registration, ['type', 'domain_id'])
|
||||
|
||||
def test_endpoint_filter_upgrade(self):
|
||||
def assert_tables_columns_exist():
|
||||
self.assertTableColumns('project_endpoint',
|
||||
['endpoint_id', 'project_id'])
|
||||
self.assertTableColumns('endpoint_group',
|
||||
['id', 'name', 'description', 'filters'])
|
||||
self.assertTableColumns('project_endpoint_group',
|
||||
['endpoint_group_id', 'project_id'])
|
||||
|
||||
self.assertTableDoesNotExist('project_endpoint')
|
||||
self.upgrade(85)
|
||||
assert_tables_columns_exist()
|
||||
|
||||
@mock.patch.object(migration_helpers, 'get_db_version', return_value=2)
|
||||
def test_endpoint_filter_already_migrated(self, mock_endpoint_filter):
|
||||
|
||||
# By setting the return value to 2, the migration has already been
|
||||
# run, and there's no need to create the table again.
|
||||
self.upgrade(85)
|
||||
|
||||
mock_endpoint_filter.assert_any_call(extension='endpoint_filter',
|
||||
engine=mock.ANY)
|
||||
|
||||
# It won't exist because we are mocking it, but we can verify
|
||||
# that 085 did not create the table.
|
||||
self.assertTableDoesNotExist('project_endpoint')
|
||||
self.assertTableDoesNotExist('endpoint_group')
|
||||
self.assertTableDoesNotExist('project_endpoint_group')
|
||||
|
||||
def populate_user_table(self, with_pass_enab=False,
|
||||
with_pass_enab_domain=False):
|
||||
# Populate the appropriate fields in the user
|
||||
|
1
tox.ini
1
tox.ini
@ -55,7 +55,6 @@ commands =
|
||||
keystone/tests/unit/test_policy.py \
|
||||
keystone/tests/unit/test_singular_plural.py \
|
||||
keystone/tests/unit/test_sql_livetest.py \
|
||||
keystone/tests/unit/test_sql_migrate_extensions.py \
|
||||
keystone/tests/unit/test_sql_upgrade.py \
|
||||
keystone/tests/unit/test_ssl.py \
|
||||
keystone/tests/unit/tests/test_core.py \
|
||||
|
Loading…
Reference in New Issue
Block a user