From 8534af4f1ef5be3c6f946913824d5ed807e2321c Mon Sep 17 00:00:00 2001 From: Alex Shatov Date: Fri, 23 Mar 2018 14:35:12 -0400 Subject: 2.1.0 dcaepolicyplugin and data types - configAttributes in policy_filter being a stringified json, rather than the map due to SDC UI limitations - safely parse the configAttributes string into json Change-Id: I934b6254aed285ddab245b440f43403a4fe918fe Signed-off-by: Alex Shatov Issue-ID: DCAEGEN2-413 --- dcae-policy/dcaepolicyplugin/__init__.py | 2 -- dcae-policy/dcaepolicyplugin/discovery.py | 2 -- dcae-policy/dcaepolicyplugin/tasks.py | 21 +++++++++++++++++++-- 3 files changed, 19 insertions(+), 6 deletions(-) (limited to 'dcae-policy/dcaepolicyplugin') diff --git a/dcae-policy/dcaepolicyplugin/__init__.py b/dcae-policy/dcaepolicyplugin/__init__.py index f2df3d8..173c1eb 100644 --- a/dcae-policy/dcaepolicyplugin/__init__.py +++ b/dcae-policy/dcaepolicyplugin/__init__.py @@ -1,5 +1,3 @@ -# ============LICENSE_START======================================================= -# org.onap.dcae # ================================================================================ # Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved. # ================================================================================ diff --git a/dcae-policy/dcaepolicyplugin/discovery.py b/dcae-policy/dcaepolicyplugin/discovery.py index 11f8a17..f463b04 100644 --- a/dcae-policy/dcaepolicyplugin/discovery.py +++ b/dcae-policy/dcaepolicyplugin/discovery.py @@ -1,5 +1,3 @@ -# ============LICENSE_START======================================================= -# org.onap.dcae # ================================================================================ # Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved. # ================================================================================ diff --git a/dcae-policy/dcaepolicyplugin/tasks.py b/dcae-policy/dcaepolicyplugin/tasks.py index 455b41b..fd3e37c 100644 --- a/dcae-policy/dcaepolicyplugin/tasks.py +++ b/dcae-policy/dcaepolicyplugin/tasks.py @@ -1,5 +1,3 @@ -# ============LICENSE_START======================================================= -# org.onap.dcae # ================================================================================ # Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved. # ================================================================================ @@ -45,6 +43,7 @@ REQUEST_ID = "requestID" DCAE_POLICY_TYPE = 'dcae.nodes.policy' DCAE_POLICIES_TYPE = 'dcae.nodes.policies' DCAE_POLICY_TYPES = [DCAE_POLICY_TYPE, DCAE_POLICIES_TYPE] +CONFIG_ATTRIBUTES = "configAttributes" class PolicyHandler(object): """talk to policy-handler""" @@ -141,6 +140,22 @@ def _policy_get(): ctx.instance.runtime_properties[POLICY_BODY] = policy[POLICY_BODY] return True +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] + def _policies_find(): """ dcae.nodes.policies - @@ -155,6 +170,8 @@ def _policies_find(): (k, v) for (k, v) in dict(ctx.node.properties.get(POLICY_FILTER, {})).iteritems() if v or isinstance(v, (int, float)) )) + _fix_policy_filter(policy_filter) + if REQUEST_ID not in policy_filter: policy_filter[REQUEST_ID] = str(uuid.uuid4()) -- cgit 1.2.3-korg