From 765370b89fd8a65dbfa8e50e86c2aa17b53b8ad6 Mon Sep 17 00:00:00 2001 From: Gordon Chung Date: Wed, 4 Dec 2013 10:16:22 -0500 Subject: [PATCH] sql migration error in 020_add_metadata_tables - add check to verify resource_metadata is not empty - fix check to verify insert statement is set Change-Id: I6b7c1d4a8ebf35af2547d97baa39831597012468 Closes-Bug: #1257779 --- .../versions/020_add_metadata_tables.py | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/ceilometer/storage/sqlalchemy/migrate_repo/versions/020_add_metadata_tables.py b/ceilometer/storage/sqlalchemy/migrate_repo/versions/020_add_metadata_tables.py index f0ec1648a..e22fe5d03 100644 --- a/ceilometer/storage/sqlalchemy/migrate_repo/versions/020_add_metadata_tables.py +++ b/ceilometer/storage/sqlalchemy/migrate_repo/versions/020_add_metadata_tables.py @@ -50,20 +50,21 @@ def upgrade(migrate_engine): meta_tables[t_name].create() for row in select([meter]).execute(): - meter_id = row['id'] - rmeta = json.loads(row['resource_metadata']) - for key, v in utils.dict_to_keyval(rmeta): - ins = None - if isinstance(v, basestring) or v is None: - ins = meta_tables['metadata_text'].insert() - elif isinstance(v, bool): - ins = meta_tables['metadata_bool'].insert() - elif isinstance(v, (int, long)): - ins = meta_tables['metadata_int'].insert() - elif isinstance(v, float): - ins = meta_tables['metadata_float'].insert() - if ins: - ins.values(id=meter_id, meta_key=key, value=v).execute() + if row['resource_metadata']: + meter_id = row['id'] + rmeta = json.loads(row['resource_metadata']) + for key, v in utils.dict_to_keyval(rmeta): + ins = None + if isinstance(v, basestring) or v is None: + ins = meta_tables['metadata_text'].insert() + elif isinstance(v, bool): + ins = meta_tables['metadata_bool'].insert() + elif isinstance(v, (int, long)): + ins = meta_tables['metadata_int'].insert() + elif isinstance(v, float): + ins = meta_tables['metadata_float'].insert() + if ins is not None: + ins.values(id=meter_id, meta_key=key, value=v).execute() def downgrade(migrate_engine):