From 780293388ac499792d96f63e582a2c5b4b6abb75 Mon Sep 17 00:00:00 2001 From: slava Date: Fri, 8 Apr 2016 05:50:50 +0300 Subject: [PATCH] Add migration for new ceph fields Change-Id: I4cd7211d66491c7af837586d94cb18c22d3105dc Closes-Bug: #1563850 --- .../alembic_migrations/versions/fuel_9_0.py | 72 +++++++++++++++++++ .../test/unit/test_migration_fuel_9_0.py | 37 ++++++++++ 2 files changed, 109 insertions(+) diff --git a/nailgun/nailgun/db/migration/alembic_migrations/versions/fuel_9_0.py b/nailgun/nailgun/db/migration/alembic_migrations/versions/fuel_9_0.py index 823df6d884..cfce6cccd1 100644 --- a/nailgun/nailgun/db/migration/alembic_migrations/versions/fuel_9_0.py +++ b/nailgun/nailgun/db/migration/alembic_migrations/versions/fuel_9_0.py @@ -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) + ) diff --git a/nailgun/nailgun/test/unit/test_migration_fuel_9_0.py b/nailgun/nailgun/test/unit/test_migration_fuel_9_0.py index 9272c8fdfd..1bbbaba55c 100644 --- a/nailgun/nailgun/test/unit/test_migration_fuel_9_0.py +++ b/nailgun/nailgun/test/unit/test_migration_fuel_9_0.py @@ -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'])