summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Shatov <alexs@att.com>2018-03-23 14:34:34 -0400
committerAlex Shatov <alexs@att.com>2018-03-23 14:34:34 -0400
commitb73f81e6d155610a9279ae5a1fd6f1298cc21173 (patch)
treec119fee2742c207b9291e2ed31ce832039876210
parent8374ca27bb8ad13be686d689301edef2f4c1fb0f (diff)
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 <alexs@att.com> Issue-ID: DCAEGEN2-414
-rw-r--r--onap-dcae-dcaepolicy-lib/onap_dcae_dcaepolicy_lib/dcae_policy.py27
-rw-r--r--onap-dcae-dcaepolicy-lib/pom.xml2
-rw-r--r--onap-dcae-dcaepolicy-lib/setup.py2
-rw-r--r--onap-dcae-dcaepolicy-lib/tests/test_dcae_policy.py42
4 files changed, 35 insertions, 38 deletions
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 = {}
@@ -99,6 +101,23 @@ class Policies(object):
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"""
if DCAE_POLICIES_TYPE not in target.node.type_hierarchy:
@@ -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)
diff --git a/onap-dcae-dcaepolicy-lib/pom.xml b/onap-dcae-dcaepolicy-lib/pom.xml
index a60d848..8fce077 100644
--- a/onap-dcae-dcaepolicy-lib/pom.xml
+++ b/onap-dcae-dcaepolicy-lib/pom.xml
@@ -28,7 +28,7 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property.
<groupId>org.onap.dcaegen2.utils</groupId>
<artifactId>onap-dcae-dcaepolicy-lib</artifactId>
<name>dcaegen2-utils-onap-dcae-dcaepolicy-lib</name>
- <version>2.2.0-SNAPSHOT</version>
+ <version>2.3.0-SNAPSHOT</version>
<url>http://maven.apache.org</url>
<properties>
diff --git a/onap-dcae-dcaepolicy-lib/setup.py b/onap-dcae-dcaepolicy-lib/setup.py
index eed69f0..55dbaf3 100644
--- a/onap-dcae-dcaepolicy-lib/setup.py
+++ b/onap-dcae-dcaepolicy-lib/setup.py
@@ -23,7 +23,7 @@ from setuptools import setup, find_packages
setup(
name='onap-dcae-dcaepolicy-lib',
description='lib of policy decorators to be used by cloudify plugins of dcae controller',
- version="2.2.0",
+ version="2.3.0",
author='Alex Shatov',
author_email="alexs@att.com",
license='Apache 2',
diff --git a/onap-dcae-dcaepolicy-lib/tests/test_dcae_policy.py b/onap-dcae-dcaepolicy-lib/tests/test_dcae_policy.py
index 81958f0..37ab9f6 100644
--- a/onap-dcae-dcaepolicy-lib/tests/test_dcae_policy.py
+++ b/onap-dcae-dcaepolicy-lib/tests/test_dcae_policy.py
@@ -40,6 +40,7 @@ POLICY_VERSION = "policyVersion"
POLICY_NAME = "policyName"
POLICY_BODY = 'policy_body'
POLICY_CONFIG = 'config'
+CONFIG_NAME = "ConfigName"
MONKEYED_POLICY_ID = 'monkeyed.Config_peach'
MONKEYED_POLICY_ID_2 = 'monkeyed.Config_peach_2'
@@ -90,7 +91,7 @@ class MonkeyedPolicyBody(object):
matching_conditions = {
"ONAPName": "DCAE",
- "ConfigName": "alex_config_name"
+ CONFIG_NAME: "alex_config_name"
}
if priority is not None:
matching_conditions["priority"] = priority
@@ -183,12 +184,6 @@ def operation_node_configure(**kwargs):
@CtxLogger.log_ctx(pre_log=True, after_log=True, exe_task='exe_task')
@Policies.gather_policies_to_node()
-def node_configure_default_order(**kwargs):
- """default policy sorting because no param of policy_apply_order_path"""
- operation_node_configure(**kwargs)
-
-@CtxLogger.log_ctx(pre_log=True, after_log=True, exe_task='exe_task')
-@Policies.gather_policies_to_node()
def node_configure(**kwargs):
"""decorate with @Policies.gather_policies_to_node on policy consumer node to
bring all policies to runtime_properties["policies"]
@@ -333,7 +328,12 @@ class CurrentCtx(object):
'dcae_policies_node_id',
'dcae_policies_node_name',
dcae_policy.DCAE_POLICIES_TYPE,
- {dcae_policy.POLICY_FILTER: {POLICY_NAME: MONKEYED_POLICY_ID_M + ".*"}},
+ {dcae_policy.POLICY_FILTER: {
+ POLICY_NAME: MONKEYED_POLICY_ID_M + ".*",
+ dcae_policy.CONFIG_ATTRIBUTES: json.dumps({
+ CONFIG_NAME: "alex_config_name"
+ })
+ }},
None,
{dcae_policy.POLICIES_FILTERED: {
MONKEYED_POLICY_ID_M:
@@ -471,31 +471,7 @@ def cfy_ctx(include_bad=True, include_good=True):
@cfy_ctx(include_bad=True)
def test_gather_policies_to_node():
"""test gather_policies_to_node"""
- node_configure_default_order()
-
- runtime_properties = ctx.instance.runtime_properties
- ctx.logger.info("runtime_properties: {0}".format(json.dumps(runtime_properties)))
-
- assert dcae_policy.POLICIES in runtime_properties
- policies = runtime_properties[dcae_policy.POLICIES]
- ctx.logger.info("policies: {0}".format(json.dumps(policies)))
-
-@cfy_ctx(include_bad=True)
-def test_policies_wrong_order():
- """test gather_policies_to_node"""
- node_configure_wrong_order_path()
-
- runtime_properties = ctx.instance.runtime_properties
- ctx.logger.info("runtime_properties: {0}".format(json.dumps(runtime_properties)))
-
- assert dcae_policy.POLICIES in runtime_properties
- policies = runtime_properties[dcae_policy.POLICIES]
- ctx.logger.info("policies: {0}".format(json.dumps(policies)))
-
-@cfy_ctx(include_bad=True)
-def test_policies_empty_order():
- """test gather_policies_to_node"""
- node_configure_empty_order_path()
+ node_configure()
runtime_properties = ctx.instance.runtime_properties
ctx.logger.info("runtime_properties: {0}".format(json.dumps(runtime_properties)))