summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Shatov <alexs@att.com>2018-03-23 14:35:12 -0400
committerAlex Shatov <alexs@att.com>2018-03-23 14:35:12 -0400
commit8534af4f1ef5be3c6f946913824d5ed807e2321c (patch)
tree7f883519886a43d6664d698f2f319ae4b4cc4353
parent19a075b395d687753de0f0266842cb9af8f24682 (diff)
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 <alexs@att.com> Issue-ID: DCAEGEN2-413
-rw-r--r--dcae-policy/LICENSE.txt2
-rw-r--r--dcae-policy/README.md4
-rw-r--r--dcae-policy/dcaepolicy-node-type.yaml6
-rw-r--r--dcae-policy/dcaepolicyplugin/__init__.py2
-rw-r--r--dcae-policy/dcaepolicyplugin/discovery.py2
-rw-r--r--dcae-policy/dcaepolicyplugin/tasks.py21
-rw-r--r--dcae-policy/pom.xml2
-rw-r--r--dcae-policy/setup.py4
-rw-r--r--dcae-policy/tests/__init__.py1
-rw-r--r--dcae-policy/tests/log_ctx.py1
-rw-r--r--dcae-policy/tests/mock_cloudify_ctx.py2
-rw-r--r--dcae-policy/tests/test_tasks.py16
12 files changed, 37 insertions, 26 deletions
diff --git a/dcae-policy/LICENSE.txt b/dcae-policy/LICENSE.txt
index 9200239..948807c 100644
--- a/dcae-policy/LICENSE.txt
+++ b/dcae-policy/LICENSE.txt
@@ -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/README.md b/dcae-policy/README.md
index 42fa53b..042a550 100644
--- a/dcae-policy/README.md
+++ b/dcae-policy/README.md
@@ -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
diff --git a/dcae-policy/dcaepolicy-node-type.yaml b/dcae-policy/dcaepolicy-node-type.yaml
index 7206a8b..04b2fd6 100644
--- a/dcae-policy/dcaepolicy-node-type.yaml
+++ b/dcae-policy/dcaepolicy-node-type.yaml
@@ -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:
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())
diff --git a/dcae-policy/pom.xml b/dcae-policy/pom.xml
index 5f96122..33fd9f6 100644
--- a/dcae-policy/pom.xml
+++ b/dcae-policy/pom.xml
@@ -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>
diff --git a/dcae-policy/setup.py b/dcae-policy/setup.py
index dad0bf5..c1714f9 100644
--- a/dcae-policy/setup.py
+++ b/dcae-policy/setup.py
@@ -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=[
diff --git a/dcae-policy/tests/__init__.py b/dcae-policy/tests/__init__.py
index e5e8bc9..5d59d8b 100644
--- a/dcae-policy/tests/__init__.py
+++ b/dcae-policy/tests/__init__.py
@@ -1,4 +1,3 @@
-# org.onap.dcae
# ================================================================================
# Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
# ================================================================================
diff --git a/dcae-policy/tests/log_ctx.py b/dcae-policy/tests/log_ctx.py
index 51d3c67..0d82687 100644
--- a/dcae-policy/tests/log_ctx.py
+++ b/dcae-policy/tests/log_ctx.py
@@ -1,4 +1,3 @@
-# org.onap.dcae
# ================================================================================
# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
# ================================================================================
diff --git a/dcae-policy/tests/mock_cloudify_ctx.py b/dcae-policy/tests/mock_cloudify_ctx.py
index 574d561..eab7ab1 100644
--- a/dcae-policy/tests/mock_cloudify_ctx.py
+++ b/dcae-policy/tests/mock_cloudify_ctx.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/tests/test_tasks.py b/dcae-policy/tests/test_tasks.py
index 94bbbd5..9bcf4ff 100644
--- a/dcae-policy/tests/test_tasks.py
+++ b/dcae-policy/tests/test_tasks.py
@@ -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: