From 86e56f58d014a1a9ba80f4a73361b98b06b07f91 Mon Sep 17 00:00:00 2001 From: Xicheng Chang Date: Tue, 4 Aug 2015 11:22:59 -0700 Subject: [PATCH] fixed bug in xiaodong's commit Change-Id: Ifff027bfcccabc797bb4d0c57037cf83a46ab126 --- compass/db/api/cluster.py | 3 ++- compass/db/api/metadata_holder.py | 33 +++++++++++++++++++------------ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/compass/db/api/cluster.py b/compass/db/api/cluster.py index 1a675692..fe21735b 100644 --- a/compass/db/api/cluster.py +++ b/compass/db/api/cluster.py @@ -1597,8 +1597,9 @@ def update_cluster_hosts( _set_clusterhosts( cluster, session=session, user=user, **set_hosts ) + return { - 'hosts': cluster.clusterhosts + 'hosts': list_cluster_hosts(cluster_id, session=session) } diff --git a/compass/db/api/metadata_holder.py b/compass/db/api/metadata_holder.py index 44245347..24afc673 100644 --- a/compass/db/api/metadata_holder.py +++ b/compass/db/api/metadata_holder.py @@ -177,20 +177,22 @@ def validate_flavor_config( ): """Validate flavor config.""" load_metadatas() - if flavor_id not in FLAVOR_METADATA_MAPPING: + if not flavor_id: + logging.info('There is no flavor, skipping flavor validation...') + elif flavor_id not in FLAVOR_METADATA_MAPPING: raise exception.InvalidParameter( 'flavor %s is not found in flavor metedata mapping' % flavor_id ) - _validate_config( - '', config, FLAVOR_METADATA_MAPPING[flavor_id], - whole_check, **kwargs - ) + else: + _validate_config( + '', config, FLAVOR_METADATA_MAPPING[flavor_id], + whole_check, **kwargs + ) def _filter_metadata(metadata, **kwargs): """Filter metadata before return it to api. - Some metadata fields are not json compatible or only used in db/api internally. We should strip these fields out before return to api. @@ -251,11 +253,14 @@ def get_package_metadata(adapter_id, user=None, session=None, **kwargs): def _get_flavor_metadata(flavor_id): """get flavor metadata.""" load_metadatas() - if flavor_id not in FLAVOR_METADATA_MAPPING: + if not flavor_id: + logging.info('There is no flavor id, skipping...') + elif flavor_id not in FLAVOR_METADATA_MAPPING: raise exception.RecordNotExists( 'flavor %s does not exist' % flavor_id ) - return _filter_metadata(FLAVOR_METADATA_MAPPING[flavor_id]) + else: + return _filter_metadata(FLAVOR_METADATA_MAPPING[flavor_id]) @utils.supported_filters([]) @@ -714,11 +719,13 @@ def autofill_flavor_config( config, flavor_id, **kwargs ): load_metadatas() - if flavor_id not in FLAVOR_METADATA_MAPPING: + if not flavor_id: + logging.info('There is no flavor, skipping...') + elif flavor_id not in FLAVOR_METADATA_MAPPING: raise exception.InvalidParameter( 'flavor %s is not found in flavor metadata mapping' % flavor_id ) - - return _autofill_config( - '', config, FLAVOR_METADATA_MAPPING[flavor_id], **kwargs - ) + else: + return _autofill_config( + '', config, FLAVOR_METADATA_MAPPING[flavor_id], **kwargs + )