Merge "Add migration for new ceph fields" into stable/mitaka

This commit is contained in:
Jenkins 2016-04-19 13:15:47 +00:00 committed by Gerrit Code Review
commit aa0ddc2a68
2 changed files with 109 additions and 0 deletions

View File

@ -134,6 +134,49 @@ history_task_statuses = (
'skipped',
)
q_get_cluster_attrs = sa.text('''
SELECT cluster_id, editable FROM attributes
''')
q_update_cluster_attrs = sa.text('''
UPDATE attributes
SET editable = :editable
WHERE cluster_id = :cluster_id
''')
ceph_storage_attrs = {
'fsid': {
'type': 'hidden',
'value': {
'generator': 'uuid4'
}
},
'mon_key': {
'type': 'hidden',
'value': {
'generator': 'cephx_key'
}
},
'admin_key': {
'type': 'hidden',
'value': {
'generator': 'cephx_key'
}
},
'bootstrap_osd_key': {
'type': 'hidden',
'value': {
'generator': 'cephx_key'
}
},
'radosgw_key': {
'type': 'hidden',
'value': {
'generator': 'cephx_key'
}
}
}
def upgrade():
add_foreign_key_ondelete()
@ -151,9 +194,11 @@ def upgrade():
upgrade_bond_modes()
upgrade_task_attributes()
upgrade_store_deployment_history()
upgrade_ceph_cluster_attrs()
def downgrade():
downgrade_ceph_cluster_attrs()
downgrade_store_deployment_history()
downgrade_task_attributes()
downgrade_bond_modes()
@ -1353,3 +1398,30 @@ def upgrade_store_deployment_history():
def downgrade_store_deployment_history():
op.drop_table('deployment_history')
drop_enum('history_task_statuses')
def upgrade_ceph_cluster_attrs():
connection = op.get_bind()
for cluster_id, editable in connection.execute(q_get_cluster_attrs):
editable = jsonutils.loads(editable)
editable.get('storage', {}).update(ceph_storage_attrs)
connection.execute(
q_update_cluster_attrs,
cluster_id=cluster_id,
editable=jsonutils.dumps(editable)
)
def downgrade_ceph_cluster_attrs():
connection = op.get_bind()
for cluster_id, editable in connection.execute(q_get_cluster_attrs):
editable = jsonutils.loads(editable)
for ceph_attr in ceph_storage_attrs:
editable.get('storage', {}).pop(ceph_attr, None)
connection.execute(
q_update_cluster_attrs,
cluster_id=cluster_id,
editable=jsonutils.dumps(editable)
)

View File

@ -135,6 +135,16 @@ JSON_TASKS_AFTER_DB = [
]
editable = {
'storage': {
'metadata': {
'label': 'Storage Backends',
'weight': 60,
'group': 'storage'
}
}
}
def prepare():
meta = base.reflect_db_metadata()
@ -230,6 +240,9 @@ def prepare():
}
}]),
'is_deployable': True,
'attributes_metadata': jsonutils.dumps({
'editable': editable
})
}])
releaseid = result.inserted_primary_key[0]
@ -245,6 +258,14 @@ def prepare():
'fuel_version': '8.0',
'deployment_tasks': jsonutils.dumps(JSON_TASKS)
}])
cluster_id = result.inserted_primary_key[0]
db.execute(
meta.tables['attributes'].insert(),
[{
'cluster_id': cluster_id,
'editable': jsonutils.dumps(editable)
}])
db.execute(
meta.tables['nodes'].insert(),
@ -846,3 +867,19 @@ class TestTasksMigration(base.BaseAlembicMigrationTest):
None
)
self.assertIsNotNone(cluster_name_idx)
class TestCephAttributesMigration(base.BaseAlembicMigrationTest):
def test_ceph_cluster_attrs(self):
ceph_opts = ['fsid', 'mon_key', 'admin_key', 'bootstrap_osd_key',
'radosgw_key']
clusters_attributes = self.meta.tables['attributes']
results = db.execute(
sa.select([clusters_attributes.c.editable])
).fetchall()
for cluster_attrs_row in results:
cluster_attrs = jsonutils.loads(cluster_attrs_row[0])
for ceph_opt in ceph_opts:
self.assertIn(ceph_opt, cluster_attrs['storage'])
self.assertIn('metadata', cluster_attrs['storage'])