From b73f81e6d155610a9279ae5a1fd6f1298cc21173 Mon Sep 17 00:00:00 2001 From: Alex Shatov Date: Fri, 23 Mar 2018 14:34:34 -0400 Subject: 2.3.0 onap-dcae-dcaepolicy-lib - configAttributes in policy_filter being a stringified json, rather than the map due to SDC UI limitations - safely parse the configAttributes string into json waiting for the merge before uploading to public pypi Change-Id: If054c2c5e3d95bb97057bb4b2486dbff40e6b244 Signed-off-by: Alex Shatov Issue-ID: DCAEGEN2-414 --- .../onap_dcae_dcaepolicy_lib/dcae_policy.py | 27 +++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'onap-dcae-dcaepolicy-lib/onap_dcae_dcaepolicy_lib/dcae_policy.py') diff --git a/onap-dcae-dcaepolicy-lib/onap_dcae_dcaepolicy_lib/dcae_policy.py b/onap-dcae-dcaepolicy-lib/onap_dcae_dcaepolicy_lib/dcae_policy.py index 5a3a0b2..65c2614 100644 --- a/onap-dcae-dcaepolicy-lib/onap_dcae_dcaepolicy_lib/dcae_policy.py +++ b/onap-dcae-dcaepolicy-lib/onap_dcae_dcaepolicy_lib/dcae_policy.py @@ -48,6 +48,8 @@ DCAE_POLICIES_TYPE = 'dcae.nodes.policies' ACTION_GATHERED = "gathered" ACTION_UPDATED = "updated" +CONFIG_ATTRIBUTES = "configAttributes" + class Policies(object): """static class for policy operations""" _updated_policies = {} @@ -98,6 +100,23 @@ class Policies(object): Policies._add_policy(policy_id, policy, True, policies) return True + @staticmethod + def _fix_policy_filter(policy_filter): + if CONFIG_ATTRIBUTES in policy_filter: + config_attributes = policy_filter.get(CONFIG_ATTRIBUTES) + if isinstance(config_attributes, dict): + return + try: + config_attributes = json.loads(config_attributes) + if config_attributes and isinstance(config_attributes, dict): + policy_filter[CONFIG_ATTRIBUTES] = config_attributes + return + except (ValueError, TypeError): + pass + if config_attributes: + ctx.logger.warn("unexpected %s: %s", CONFIG_ATTRIBUTES, config_attributes) + del policy_filter[CONFIG_ATTRIBUTES] + @staticmethod def _gather_policies(target, policies, policy_filters): """adds the policies and policy-filter from dcae.nodes.policies node to policies""" @@ -106,14 +125,16 @@ class Policies(object): property_policy_filter = target.node.properties.get(POLICY_FILTER) if property_policy_filter: - policy_filter = dict( + policy_filter = deepcopy(dict( (k, v) for (k, v) in dict(property_policy_filter).iteritems() if v or isinstance(v, (int, float)) - ) + )) + Policies._fix_policy_filter(policy_filter) + if policy_filter: policy_filters[target.instance.id] = { POLICY_FILTER_ID : target.instance.id, - POLICY_FILTER : deepcopy(policy_filter) + POLICY_FILTER : policy_filter } filtered_policies = target.instance.runtime_properties.get(POLICIES_FILTERED) -- cgit 1.2.3-korg