2.1.0 dcaepolicyplugin and data types 73/38173/2
authorAlex Shatov <alexs@att.com>
Fri, 23 Mar 2018 18:35:12 +0000 (14:35 -0400)
committerAlex Shatov <alexs@att.com>
Fri, 23 Mar 2018 18:35:12 +0000 (14:35 -0400)
- 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 <alexs@att.com>
Issue-ID: DCAEGEN2-413

12 files changed:
dcae-policy/LICENSE.txt
dcae-policy/README.md
dcae-policy/dcaepolicy-node-type.yaml
dcae-policy/dcaepolicyplugin/__init__.py
dcae-policy/dcaepolicyplugin/discovery.py
dcae-policy/dcaepolicyplugin/tasks.py
dcae-policy/pom.xml
dcae-policy/setup.py
dcae-policy/tests/__init__.py
dcae-policy/tests/log_ctx.py
dcae-policy/tests/mock_cloudify_ctx.py
dcae-policy/tests/test_tasks.py

index 9200239..948807c 100644 (file)
@@ -1,5 +1,3 @@
-============LICENSE_START=======================================================
-org.onap.dcae
 ================================================================================
 Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
 ================================================================================
index 42fa53b..042a550 100644 (file)
@@ -1,9 +1,11 @@
 # dcae-policy plugin and node-type
+
 - python-package dcaepolicyplugin to be used in cloudify plugins to retrieve the policy from policy-handler
 
 ---
 
 ## dcaepolicy node type [dcaepolicy-node-type.yaml](./dcaepolicy-node-type.yaml)
+
 - node type for dcae.nodes.policy
 
 ---
@@ -14,7 +16,7 @@ import the dcaepolicy-node-type.yaml into your blueprint to use the dcae.nodes.t
 
 ```yaml
 imports:
-    - https://YOUR_NEXUS_RAW_SERVER/type_files/dcaepolicy/1.0.0/node-type.yaml
+    - https://YOUR_NEXUS_RAW_SERVER/type_files/dcaepolicy/2.1.0/node-type.yaml
 ```
 
 provide the value for policy_id property
index 7206a8b..04b2fd6 100644 (file)
@@ -1,5 +1,3 @@
-# ============LICENSE_START=======================================================
-# org.onap.dcae
 # ================================================================================
 # Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
 # ================================================================================
@@ -27,7 +25,7 @@ plugins:
   dcaepolicy:
     executor: 'central_deployment_agent'
     package_name: dcaepolicyplugin
-    package_version: 2.0.0
+    package_version: 2.1.0
 
 data_types:
     # the properties inside dcae.data.policy_filter are identical to /getConfig API of policy-engine except the requestID field.
@@ -35,7 +33,7 @@ data_types:
     # policy-engine /getConfig wiki: The filter works as a combined "AND" operation.
     #                                To retrieve all policies using "sample" as configName,
     #                                   the request needs to have policyName = ".*"  and configName as = "sample"
-    # configAttributes is a key-value dictionary
+    # configAttributes is a key-value dictionary or a stringified json of the dictionary
     dcae.data.policy_filter:
         properties:
             policyName:
index f2df3d8..173c1eb 100644 (file)
@@ -1,5 +1,3 @@
-# ============LICENSE_START=======================================================
-# org.onap.dcae
 # ================================================================================
 # Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
 # ================================================================================
index 11f8a17..f463b04 100644 (file)
@@ -1,5 +1,3 @@
-# ============LICENSE_START=======================================================
-# org.onap.dcae
 # ================================================================================
 # Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
 # ================================================================================
index 455b41b..fd3e37c 100644 (file)
@@ -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())
 
index 5f96122..33fd9f6 100644 (file)
@@ -28,7 +28,7 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property.
   <groupId>org.onap.dcaegen2.platform.plugins</groupId>
   <artifactId>dcae-policy</artifactId>
   <name>dcae-policy-plugin</name>
-  <version>2.0.0-SNAPSHOT</version>
+  <version>2.1.0-SNAPSHOT</version>
   <url>http://maven.apache.org</url>
   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
index dad0bf5..c1714f9 100644 (file)
@@ -1,5 +1,3 @@
-# ============LICENSE_START=======================================================
-# org.onap.dcae
 # ================================================================================
 # Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
 # ================================================================================
@@ -25,7 +23,7 @@ from setuptools import setup
 setup(
     name='dcaepolicyplugin',
     description='Cloudify plugin for dcae.nodes.policy node to retrieve the policy config',
-    version="2.0.0",
+    version="2.1.0",
     author='Alex Shatov',
     packages=['dcaepolicyplugin'],
     install_requires=[
index e5e8bc9..5d59d8b 100644 (file)
@@ -1,4 +1,3 @@
-# org.onap.dcae
 # ================================================================================
 # Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
 # ================================================================================
index 51d3c67..0d82687 100644 (file)
@@ -1,4 +1,3 @@
-# org.onap.dcae
 # ================================================================================
 # Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
 # ================================================================================
index 574d561..eab7ab1 100644 (file)
@@ -1,5 +1,3 @@
-# ============LICENSE_START=======================================================
-# org.onap.dcae
 # ================================================================================
 # Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
 # ================================================================================
index 94bbbd5..9bcf4ff 100644 (file)
@@ -1,5 +1,3 @@
-# ============LICENSE_START=======================================================
-# org.onap.dcae
 # ================================================================================
 # Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
 # ================================================================================
@@ -39,6 +37,7 @@ POLICY_NAME = "policyName"
 POLICY_BODY = 'policy_body'
 POLICY_CONFIG = 'config'
 LATEST_POLICIES = "latest_policies"
+CONFIG_NAME = "ConfigName"
 
 MONKEYED_POLICY_ID = 'monkeyed.Config_peach'
 LOG_FILE = 'logs/test_dcaepolicyplugin.log'
@@ -88,7 +87,7 @@ class MonkeyedPolicyBody(object):
             POLICY_CONFIG: config,
             "matchingConditions": {
                 "ONAPName": "DCAE",
-                "ConfigName": "alex_config_name"
+                CONFIG_NAME: "alex_config_name"
             },
             "responseAttributes": {},
             "property": None
@@ -235,7 +234,7 @@ def monkeyed_policy_handler_find(full_path, json, headers):
         {LATEST_POLICIES: {
             MONKEYED_POLICY_ID: MonkeyedPolicyBody.create_policy(MONKEYED_POLICY_ID)}})
 
-def test_policy_find(monkeypatch):
+def test_policies_find(monkeypatch):
     """test policy_get operation on dcae.nodes.policies node"""
     monkeypatch.setattr('requests.post', monkeyed_policy_handler_find)
 
@@ -243,7 +242,14 @@ def test_policy_find(monkeypatch):
         'test_dcae_policies_node_id',
         'test_dcae_policies_node_name',
         tasks.DCAE_POLICIES_TYPE,
-        {tasks.POLICY_FILTER: {POLICY_NAME: MONKEYED_POLICY_ID}}
+        {
+            tasks.POLICY_FILTER: {
+                POLICY_NAME: MONKEYED_POLICY_ID,
+                tasks.CONFIG_ATTRIBUTES: json.dumps({
+                    CONFIG_NAME: "alex_config_name"
+                })
+            }
+        }
     )
 
     try: