Move all commited migrations to 9_2 file

Change-Id: Ie80479780278e96bf99f6b619bc126cf3d756f5f
Implements: blueprint role-decomposition
This commit is contained in:
Viacheslav Valyavskiy 2016-11-22 16:26:05 +03:00
parent 66da26b511
commit da2b335d35
6 changed files with 159 additions and 363 deletions

View File

@ -1,146 +0,0 @@
# Copyright 2016 Mirantis, Inc.
#
# 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.
"""Fuel 11.0
Revision ID: dc8bc8751c42
Revises: c6edea552f1e
Create Date: 2016-10-22 02:11:47.708895
"""
from alembic import op
from oslo_serialization import jsonutils
import six
import sqlalchemy as sa
from nailgun.db.sqlalchemy.models import fields
# revision identifiers, used by Alembic.
revision = 'dc8bc8751c42'
down_revision = 'c6edea552f1e'
def upgrade():
upgrade_cluster_roles()
upgrade_tags_meta()
upgrade_primary_unit()
def downgrade():
downgrade_primary_unit()
downgrade_tags_meta()
downgrade_cluster_roles()
def upgrade_cluster_roles():
op.add_column(
'clusters',
sa.Column('roles_metadata',
fields.JSON(),
default={},
server_default='{}'),
)
op.add_column(
'clusters',
sa.Column('volumes_metadata',
fields.JSON(),
default={},
server_default='{}'),
)
def downgrade_cluster_roles():
op.drop_column('clusters', 'roles_metadata')
op.drop_column('clusters', 'volumes_metadata')
def upgrade_tags_meta():
connection = op.get_bind()
op.add_column(
'releases',
sa.Column('tags_metadata',
fields.JSON(),
server_default='{}',
nullable=False),
)
op.add_column(
'clusters',
sa.Column('tags_metadata',
fields.JSON(),
server_default='{}',
nullable=False),
)
op.add_column(
'plugins',
sa.Column('tags_metadata',
fields.JSON(),
server_default='{}',
nullable=False),
)
q_get_role_meta = "SELECT id, roles_metadata FROM {}"
q_update_tags_meta = ("UPDATE {} SET tags_metadata = :tags_meta "
"WHERE id = :obj_id")
q_update_roles_meta = ("UPDATE {} SET roles_metadata = :roles_meta "
"WHERE id = :obj_id")
for table in ['releases', 'plugins']:
for obj_id, roles_meta in connection.execute(
sa.text(q_get_role_meta.format(table))):
tags_meta = {}
roles_meta = jsonutils.loads(roles_meta or '{}')
for role_name, meta in six.iteritems(roles_meta):
meta['tags'] = [role_name]
tags_meta[role_name] = {'has_primary': meta.get('has_primary',
False)}
connection.execute(sa.text(q_update_roles_meta.format(table)),
roles_meta=jsonutils.dumps(roles_meta),
obj_id=obj_id)
connection.execute(sa.text(q_update_tags_meta.format(table)),
tags_meta=jsonutils.dumps(tags_meta),
obj_id=obj_id)
def downgrade_tags_meta():
op.drop_column('plugins', 'tags_metadata')
op.drop_column('clusters', 'tags_metadata')
op.drop_column('releases', 'tags_metadata')
def upgrade_primary_unit():
op.alter_column('nodes', 'primary_roles', new_column_name='primary_tags')
def downgrade_primary_unit():
connection = op.get_bind()
q_get_roles = sa.text('''
SELECT id, roles, pending_roles, primary_tags
FROM nodes
''')
q_update_primary_tags = sa.text('''
UPDATE nodes
SET primary_tags = :primary_tags
WHERE id = :node_id
''')
for node_id, roles, p_roles, pr_tags in connection.execute(q_get_roles):
primary_tags = list(set(roles + p_roles) & set(pr_tags))
connection.execute(
q_update_primary_tags,
node_id=node_id,
primary_tags=primary_tags
)
op.alter_column('nodes', 'primary_tags', new_column_name='primary_roles')

View File

@ -22,9 +22,11 @@ Create Date: 2016-10-11 16:33:57.247855
from alembic import op
from oslo_serialization import jsonutils
import six
import sqlalchemy as sa
from nailgun.db.sqlalchemy.models import fields
from nailgun.utils import migration
@ -36,9 +38,15 @@ down_revision = 'f2314e5d63c9'
def upgrade():
upgrade_vmware_attributes_metadata()
upgrade_attributes_metadata()
upgrade_cluster_roles()
upgrade_tags_meta()
upgrade_primary_unit()
def downgrade():
downgrade_primary_unit()
downgrade_tags_meta()
downgrade_cluster_roles()
downgrade_attributes_metadata()
downgrade_vmware_attributes_metadata()
@ -295,3 +303,102 @@ def downgrade_cluster_attributes(connection):
update_query,
cluster_id=cluster_id,
editable=jsonutils.dumps(editable))
def upgrade_cluster_roles():
op.add_column(
'clusters',
sa.Column('roles_metadata',
fields.JSON(),
default={},
server_default='{}'),
)
op.add_column(
'clusters',
sa.Column('volumes_metadata',
fields.JSON(),
default={},
server_default='{}'),
)
def downgrade_cluster_roles():
op.drop_column('clusters', 'volumes_metadata')
op.drop_column('clusters', 'roles_metadata')
def upgrade_tags_meta():
connection = op.get_bind()
op.add_column(
'releases',
sa.Column('tags_metadata',
fields.JSON(),
server_default='{}',
nullable=False),
)
op.add_column(
'clusters',
sa.Column('tags_metadata',
fields.JSON(),
server_default='{}',
nullable=False),
)
op.add_column(
'plugins',
sa.Column('tags_metadata',
fields.JSON(),
server_default='{}',
nullable=False),
)
q_get_role_meta = "SELECT id, roles_metadata FROM {}"
q_update_role_tags_meta = '''
UPDATE {}
SET roles_metadata = :roles_meta, tags_metadata = :tags_meta
WHERE id = :obj_id
'''
for table in ['releases', 'plugins']:
for obj_id, roles_meta in connection.execute(
sa.text(q_get_role_meta.format(table))):
tags_meta = {}
roles_meta = jsonutils.loads(roles_meta or '{}')
for role_name, meta in six.iteritems(roles_meta):
meta['tags'] = [role_name]
tags_meta[role_name] = {'has_primary': meta.get('has_primary',
False)}
connection.execute(sa.text(q_update_role_tags_meta.format(table)),
roles_meta=jsonutils.dumps(roles_meta),
tags_meta=jsonutils.dumps(tags_meta),
obj_id=obj_id)
def downgrade_tags_meta():
op.drop_column('plugins', 'tags_metadata')
op.drop_column('clusters', 'tags_metadata')
op.drop_column('releases', 'tags_metadata')
def upgrade_primary_unit():
op.alter_column('nodes', 'primary_roles', new_column_name='primary_tags')
def downgrade_primary_unit():
connection = op.get_bind()
q_get_roles = sa.text('''
SELECT id, roles, pending_roles, primary_tags
FROM nodes
''')
q_update_primary_tags = sa.text('''
UPDATE nodes
SET primary_tags = :primary_tags
WHERE id = :node_id
''')
for node_id, roles, p_roles, pr_tags in connection.execute(q_get_roles):
primary_tags = list(set(roles + p_roles) & set(pr_tags))
connection.execute(
q_update_primary_tags,
node_id=node_id,
primary_tags=primary_tags
)
op.alter_column('nodes', 'primary_tags', new_column_name='primary_roles')

View File

@ -1,101 +0,0 @@
# coding: utf-8
# Copyright 2016 Mirantis, Inc.
#
# 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 datetime
import alembic
from oslo_serialization import jsonutils
import sqlalchemy as sa
from nailgun.db import db
from nailgun.db import dropdb
from nailgun.db.migration import ALEMBIC_CONFIG
from nailgun.test import base
_prepare_revision = 'dc8bc8751c42'
_test_revision = 'c6edea552f1e'
def setup_module():
dropdb()
alembic.command.upgrade(ALEMBIC_CONFIG, _prepare_revision)
prepare()
alembic.command.downgrade(ALEMBIC_CONFIG, _test_revision)
def prepare():
meta = base.reflect_db_metadata()
result = db.execute(
meta.tables['releases'].insert(),
[{
'name': 'test_name',
'version': '2016.1-11.0',
'operating_system': 'ubuntu',
'state': 'available',
'roles': jsonutils.dumps([
'controller',
]),
'roles_metadata': jsonutils.dumps({
'controller': {
'name': 'Controller',
},
}),
'is_deployable': True
}])
release_id = result.inserted_primary_key[0]
result = db.execute(
meta.tables['clusters'].insert(),
[{
'name': 'test_env1',
'release_id': release_id,
'mode': 'ha_compact',
'status': 'operational',
'net_provider': 'neutron',
'grouping': 'roles',
'fuel_version': '10.0',
}])
cluster_id = result.inserted_primary_key[0]
result = db.execute(
meta.tables['nodes'].insert(),
[{
'uuid': 'fcd49872-3917-4a18-98f9-3f5acfe3fdec',
'cluster_id': cluster_id,
'group_id': None,
'status': 'ready',
'roles': ['role_x', 'role_y'],
'primary_tags': ['role_y', 'test'],
'meta': '{}',
'mac': 'bb:aa:aa:aa:aa:aa',
'timestamp': datetime.datetime.utcnow(),
}]
)
db.commit()
class TestPluginTags(base.BaseAlembicMigrationTest):
def test_primary_tags_downgrade(self):
nodes = self.meta.tables['nodes']
query = sa.select([nodes.c.primary_roles]).where(
nodes.c.uuid == 'fcd49872-3917-4a18-98f9-3f5acfe3fdec')
primary_roles = db.execute(query).fetchone()[0]
self.assertItemsEqual(primary_roles, ['role_y'])

View File

@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import datetime
import alembic
from copy import deepcopy
@ -101,14 +102,31 @@ def prepare():
'deployment_tasks': '[]',
}])
cluster_id = result.inserted_primary_key[0]
editable = attrs.get('editable', {})
db.execute(
meta.tables['attributes'].insert(),
[{
'cluster_id': result.inserted_primary_key[0],
'cluster_id': cluster_id,
'editable': jsonutils.dumps(editable)
}]
)
db.execute(
meta.tables['nodes'].insert(),
[{
'uuid': 'fcd49872-3917-4a18-98f9-3f5acfe3fdec',
'cluster_id': cluster_id,
'group_id': None,
'status': 'ready',
'roles': ['role_x', 'role_y'],
'primary_tags': ['role_y', 'test'],
'meta': '{}',
'mac': 'bb:aa:aa:aa:aa:aa',
'timestamp': datetime.datetime.utcnow(),
}]
)
db.commit()
@ -131,3 +149,12 @@ class TestAttributesDowngrade(base.BaseAlembicMigrationTest):
attrs = jsonutils.loads(attrs[0])
common = attrs.setdefault('editable', {}).setdefault('common', {})
self.assertEqual(common.get('security_group'), None)
class TestPluginTags(base.BaseAlembicMigrationTest):
def test_primary_tags_downgrade(self):
nodes = self.meta.tables['nodes']
query = sa.select([nodes.c.primary_roles]).where(
nodes.c.uuid == 'fcd49872-3917-4a18-98f9-3f5acfe3fdec')
primary_roles = db.execute(query).fetchone()[0]
self.assertItemsEqual(primary_roles, ['role_y'])

View File

@ -1,115 +0,0 @@
# Copyright 2016 Mirantis, Inc.
#
# 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 datetime
import alembic
from oslo_serialization import jsonutils
import six
import sqlalchemy as sa
from nailgun.db import db
from nailgun.db import dropdb
from nailgun.db.migration import ALEMBIC_CONFIG
from nailgun.test import base
_prepare_revision = 'c6edea552f1e'
_test_revision = 'dc8bc8751c42'
def setup_module():
dropdb()
alembic.command.upgrade(ALEMBIC_CONFIG, _prepare_revision)
prepare()
alembic.command.upgrade(ALEMBIC_CONFIG, _test_revision)
def prepare():
meta = base.reflect_db_metadata()
result = db.execute(
meta.tables['releases'].insert(),
[{
'name': 'test_name',
'version': '2016.1-11.0',
'operating_system': 'ubuntu',
'state': 'available',
'roles': jsonutils.dumps([
'controller',
]),
'roles_metadata': jsonutils.dumps({
'controller': {
'name': 'Controller',
'has_primary': True
},
'compute': {
'name': 'Compute'
},
}),
'is_deployable': True
}])
release_id = result.inserted_primary_key[0]
result = db.execute(
meta.tables['clusters'].insert(),
[{
'name': 'test_env1',
'release_id': release_id,
'mode': 'ha_compact',
'status': 'operational',
'net_provider': 'neutron',
'grouping': 'roles',
'fuel_version': '10.0',
}])
cluster_id = result.inserted_primary_key[0]
result = db.execute(
meta.tables['nodes'].insert(),
[{
'uuid': 'fcd49872-3917-4a18-98f9-3f5acfe3fdec',
'cluster_id': cluster_id,
'group_id': None,
'status': 'ready',
'roles': ['role_x', 'role_y'],
'primary_roles': ['role_y'],
'meta': '{}',
'mac': 'bb:aa:aa:aa:aa:aa',
'timestamp': datetime.datetime.utcnow(),
}]
)
db.commit()
class TestTags(base.BaseAlembicMigrationTest):
def test_primary_tags_migration(self):
nodes = self.meta.tables['nodes']
query = sa.select([nodes.c.primary_tags]).where(
nodes.c.uuid == 'fcd49872-3917-4a18-98f9-3f5acfe3fdec')
primary_tags = db.execute(query).fetchone()[0]
self.assertItemsEqual(primary_tags, ['role_y'])
def test_tags_meta_migration(self):
releases = self.meta.tables['releases']
query = sa.select([releases.c.roles_metadata,
releases.c.tags_metadata])
for roles_meta, tags_meta in db.execute(query):
tags_meta = jsonutils.loads(tags_meta)
for role_name, role_meta in six.iteritems(
jsonutils.loads(roles_meta)):
self.assertEqual(
tags_meta[role_name].get('has_primary', False),
role_meta.get('has_primary', False)
)

View File

@ -16,6 +16,7 @@ import datetime
import alembic
from oslo_serialization import jsonutils
import six
import sqlalchemy as sa
from nailgun.db import db
@ -188,6 +189,7 @@ def prepare():
'group_id': None,
'status': 'ready',
'roles': ['controller', 'ceph-osd'],
'primary_roles': ['controller'],
'meta': '{}',
'mac': mac,
'timestamp': datetime.datetime.utcnow(),
@ -306,3 +308,25 @@ class TestAttributesUpdate(base.BaseAlembicMigrationTest):
start_version)):
release_ids.append(release_id)
return release_ids
class TestTags(base.BaseAlembicMigrationTest):
def test_primary_tags_migration(self):
nodes = self.meta.tables['nodes']
query = sa.select([nodes.c.primary_tags]).where(
nodes.c.uuid == 'fcd49872-3917-4a18-98f9-3f5acfe3fde')
primary_tags = db.execute(query).fetchone()[0]
self.assertItemsEqual(primary_tags, ['controller'])
def test_tags_meta_migration(self):
releases = self.meta.tables['releases']
query = sa.select([releases.c.roles_metadata,
releases.c.tags_metadata])
for roles_meta, tags_meta in db.execute(query):
tags_meta = jsonutils.loads(tags_meta)
for role_name, role_meta in six.iteritems(
jsonutils.loads(roles_meta)):
self.assertEqual(
tags_meta[role_name].get('has_primary', False),
role_meta.get('has_primary', False)
)