Fix 9.2 migration

Downgrade field "tags" from roles_metadata

Change-Id: Ic1a2b23a7abcdd2686e5911778ea2c57118da501
Implements: blueprint role-decomposition
(cherry picked from commit 56f8ecbb16)
This commit is contained in:
Mikhail 2016-11-28 15:03:15 +03:00
parent db16aa0a64
commit abb4019c21
2 changed files with 105 additions and 71 deletions

View File

@ -234,67 +234,6 @@ DEFAULT_RELEASE_BOND_ATTRIBUTES = {
}
VCENTER_INSECURE = {
'name': "vcenter_insecure",
'type': "checkbox",
'label': "Bypass vCenter certificate verification"
}
VCENTER_SECURITY_DISABLED = {
'name': "vcenter_security_disabled",
'type': "checkbox",
'label': "Bypass vCenter certificate verification"
}
VCENTER_CA_FILE = {
'name': "vcenter_ca_file",
'type': 'file',
'label': "CA file",
'description': ('File containing the trusted CA bundle that emitted '
'vCenter server certificate. Even if CA bundle is not '
'uploaded, certificate verification is turned on.'),
'restrictions': [{
'message': ('Bypass vCenter certificate verification should be '
'disabled.'),
'condition': 'current_vcenter:vcenter_security_disabled == true'
}]
}
CA_FILE = {
'name': "ca_file",
'type': 'file',
'label': "CA file",
'description': ('File containing the trusted CA bundle that emitted '
'vCenter server certificate. Even if CA bundle is not '
'uploaded, certificate verification is turned on.'),
'restrictions': [{
'message': ('Bypass vCenter certificate verification should be '
'disabled.'),
'condition': 'glance:vcenter_security_disabled == true'
}]
}
SECURITY_GROUP = {
'value': 'iptables_hybrid',
'values': [
{
'data': 'openvswitch',
'label': 'Open vSwitch Firewall Driver',
'description': 'Choose this type of firewall driver if you'
' use OVS Bridges for networking needs.'
},
{
'data': 'iptables_hybrid',
'label': 'Iptables-based Firewall Driver',
'description': 'Choose this type of firewall driver if you'
' use Linux Bridges for networking needs.'
}
],
'group': 'security',
'weight': 20,
'type': 'radio',
}
# version of Fuel when security group switch was added
FUEL_SECURITY_GROUP_VERSION = '9.0'
@ -979,9 +918,28 @@ def downgrade_tags_set():
tags_to_remove = set(NEW_TAGS_META) & set(tags_meta)
for tag_name in tags_to_remove:
tags_meta.pop(tags_meta)
tags_meta.pop(tag_name)
connection.execute(q_update_role_tags_meta,
roles_meta=jsonutils.dumps(roles_meta),
tags_meta=jsonutils.dumps(tags_meta),
obj_id=obj_id)
def downgrade_role_tags():
connection = op.get_bind()
q_get_role_meta = "SELECT id, roles_metadata FROM {}"
q_update_role_tags_meta = '''
UPDATE {}
SET roles_metadata = :roles_meta WHERE id = :obj_id
'''
tables = ["releases", "clusters", "plugins"]
for table in tables:
for obj_id, roles_meta in connection.execute(
sa.text(q_get_role_meta.format(table))):
roles_meta = jsonutils.loads(roles_meta or '{}')
for role, meta in six.iteritems(roles_meta):
meta.pop("tags")
connection.execute(sa.text(q_update_role_tags_meta.format(table)),
roles_meta=jsonutils.dumps(roles_meta),
obj_id=obj_id)

View File

@ -56,6 +56,47 @@ SECURITY_GROUP = {
'type': 'radio',
}
ROLES_META = {
'controller': {
'tags': [
'controller',
'rabbitmq',
'database',
'keystone',
'neutron'
]
}
}
PLUGIN_ROLE_META = {
'test_plugin_role': {
'tags': ['test_plugin_tag']
}
}
PLUGIN_TAGS_META = {
'test_plugin_tag':
{'has_primary': False}
}
TAGS_META = {
'controller': {
'has_primary': True,
},
'rabbitmq': {
'has_primary': True
},
'database': {
'has_primary': True
},
'keystone': {
'has_primary': True
},
'neutron': {
'has_primary': True
}
}
def setup_module():
dropdb()
@ -70,6 +111,15 @@ def prepare():
attrs_with_sec_group = deepcopy(ATTRIBUTES_METADATA)
attrs_with_sec_group.setdefault('editable', {}).setdefault(
'common', {}).setdefault('security_group', SECURITY_GROUP)
plugin = {
'name': 'Test_P',
'version': '3.0.0',
'title': 'Test Plugin',
'package_version': '5.0.0',
'roles_metadata': jsonutils.dumps(PLUGIN_ROLE_META),
'tags_metadata': jsonutils.dumps(PLUGIN_TAGS_META)
}
result = db.execute(meta.tables['plugins'].insert(), [plugin])
result = db.execute(
meta.tables['releases'].insert(),
@ -78,6 +128,8 @@ def prepare():
'version': 'mitaka-9.0',
'operating_system': 'ubuntu',
'state': 'available',
'roles_metadata': jsonutils.dumps(ROLES_META),
'tags_metadata': jsonutils.dumps(TAGS_META),
'networks_metadata': jsonutils.dumps({
'neutron': {
'networks': [],
@ -100,6 +152,8 @@ def prepare():
'grouping': 'roles',
'fuel_version': '10.0',
'deployment_tasks': '[]',
'roles_metadata': jsonutils.dumps(ROLES_META),
'tags_metadata': '{}',
'replaced_deployment_info': '[]'
}]
)
@ -237,6 +291,37 @@ def prepare():
db.commit()
class TestTags(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, ['controller'])
def test_downgrade_tags_metadata(self):
releases = self.meta.tables['releases']
self.assertNotIn('tags_metadata', releases.c._all_columns)
clusters = self.meta.tables['clusters']
self.assertNotIn('tags_metadata', clusters.c._all_columns)
self.assertNotIn('roles_metadata', clusters.c._all_columns)
plugins = self.meta.tables['plugins']
self.assertNotIn('tags_metadata', plugins.c._all_columns)
def test_downgrade_field_tags_from_roles(self):
releases = self.meta.tables['releases']
query = sa.select([releases.c.roles_metadata])
for role_meta in db.execute(query).fetchall():
self.assertNotIn('tags', role_meta)
plugins = self.meta.tables['plugins']
query = sa.select([plugins.c.roles_metadata])
for role_meta in db.execute(query):
self.assertNotIn('tags', role_meta)
class TestNodeNICAndBondAttributesMigration(base.BaseAlembicMigrationTest):
def test_downgrade_node_nic_attributes_with_empty_attributes(self):
@ -359,12 +444,3 @@ 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, ['controller'])