summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSchmalzried, Terry (ts862m) <ts862m@att.com>2019-11-14 13:07:56 -0500
committerSchmalzried, Terry (ts862m) <ts862m@att.com>2019-11-14 15:26:45 -0500
commit77e27adeab5ff155b690f2e058c06f0a7812e225 (patch)
treec67450b92793ba2b503ddc596188e8f1319f43fe
parent6b7857037b8c82471395a929aba950677693d151 (diff)
DCAEGEN2-1920 enhance policy plugin for error conditions
Issue-ID: DCAEGEN2-1920 Change-Id: I7e1b08cb008f60d7f08ed2db41236a03b8490287 Signed-off-by: Schmalzried, Terry (ts862m) <ts862m@att.com>
-rw-r--r--dcae-policy/README.md2
-rw-r--r--dcae-policy/dcaepolicy-node-type.yaml13
-rw-r--r--dcae-policy/dcaepolicyplugin/discovery.py6
-rw-r--r--dcae-policy/dcaepolicyplugin/tasks.py17
-rw-r--r--dcae-policy/pom.xml4
-rw-r--r--dcae-policy/setup.py4
-rw-r--r--dcae-policy/tests/test_discovery.py8
-rw-r--r--dcae-policy/tests/test_tasks.py6
8 files changed, 32 insertions, 28 deletions
diff --git a/dcae-policy/README.md b/dcae-policy/README.md
index a3a070b..db729e9 100644
--- a/dcae-policy/README.md
+++ b/dcae-policy/README.md
@@ -35,7 +35,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/2.3.0/node-type.yaml
+ - https://YOUR_NEXUS_RAW_SERVER/type_files/dcaepolicy/2.3.2/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 1c07b7a..ec7f373 100644
--- a/dcae-policy/dcaepolicy-node-type.yaml
+++ b/dcae-policy/dcaepolicy-node-type.yaml
@@ -1,5 +1,5 @@
# ================================================================================
-# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -16,16 +16,11 @@
#
# ECOMP is a trademark and service mark of AT&T Intellectual Property.
-tosca_definitions_version: cloudify_dsl_1_3
-
-imports:
- - http://www.getcloudify.org/spec/cloudify/3.4/types.yaml
-
plugins:
dcaepolicy:
executor: 'central_deployment_agent'
package_name: dcaepolicyplugin
- package_version: 2.3.0
+ package_version: 2.3.2
data_types:
# the properties inside dcae.data.policy_filter are identical to /getConfig API of policy-engine except the requestID field.
@@ -77,6 +72,10 @@ node_types:
policy_filter:
type: dcae.data.policy_filter
default: {}
+ policy_required:
+ description: whether to throw an exception when failed to get a policy
+ type: boolean
+ default: false
interfaces:
cloudify.interfaces.lifecycle:
create:
diff --git a/dcae-policy/dcaepolicyplugin/discovery.py b/dcae-policy/dcaepolicyplugin/discovery.py
index 0517377..8612160 100644
--- a/dcae-policy/dcaepolicyplugin/discovery.py
+++ b/dcae-policy/dcaepolicyplugin/discovery.py
@@ -1,5 +1,5 @@
# ================================================================================
-# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -40,7 +40,7 @@ def discover_service_url(service_name):
ctx.logger.info("getting service_url at {0}".format(service_url))
try:
- response = requests.get(service_url)
+ response = requests.get(service_url, timeout=60)
except requests.ConnectionError as ex:
raise NonRecoverableError(
"ConnectionError - failed to get {0}: {1}".format(service_url, str(ex)))
@@ -63,7 +63,7 @@ def discover_value(key):
ctx.logger.info("getting kv at {0}".format(kv_url))
try:
- response = requests.get(kv_url)
+ response = requests.get(kv_url, timeout=60)
except requests.ConnectionError as ex:
raise NonRecoverableError(
"ConnectionError - failed to get {0}: {1}".format(kv_url, str(ex)))
diff --git a/dcae-policy/dcaepolicyplugin/tasks.py b/dcae-policy/dcaepolicyplugin/tasks.py
index bbf3ec1..4e3b37a 100644
--- a/dcae-policy/dcaepolicyplugin/tasks.py
+++ b/dcae-policy/dcaepolicyplugin/tasks.py
@@ -1,5 +1,5 @@
# ================================================================================
-# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -94,7 +94,7 @@ class PolicyHandler(object):
ctx.logger.info("getting latest policy from {0} headers={1}".format(
ph_path, json.dumps(headers)))
- res = requests.get(ph_path, headers=headers)
+ res = requests.get(ph_path, headers=headers, timeout=60)
ctx.logger.info("latest policy for policy_id({0}) status({1}) response: {2}"
.format(policy_id, res.status_code, res.text))
@@ -117,7 +117,7 @@ class PolicyHandler(object):
ctx.logger.info("finding the latest polices from {0} by {1} headers={2}".format(
ph_path, json.dumps(policy_filter), json.dumps(headers)))
- res = requests.post(ph_path, json=policy_filter, headers=headers)
+ res = requests.post(ph_path, json=policy_filter, headers=headers, timeout=60)
ctx.logger.info("latest policies status({0}) response: {1}"
.format(res.status_code, res.text))
@@ -150,8 +150,7 @@ def _policy_get():
except Exception as ex:
error = "failed to get policy({0}): {1}".format(policy_id, str(ex))
ctx.logger.error("{0}: {1}".format(error, traceback.format_exc()))
- if policy_required:
- raise NonRecoverableError(error)
+ raise NonRecoverableError(error)
if not policy:
error = "policy not found for policy_id {0}".format(policy_id)
@@ -192,6 +191,8 @@ def _policies_find():
if DCAE_POLICIES_TYPE not in ctx.node.type_hierarchy:
return
+ policy_required = ctx.node.properties.get(POLICY_REQUIRED)
+
try:
policy_filter = copy.deepcopy(dict(
(k, v) for (k, v) in dict(ctx.node.properties.get(POLICY_FILTER, {})).iteritems()
@@ -205,7 +206,10 @@ def _policies_find():
policies_filtered = PolicyHandler.find_latest_policies(policy_filter)
if not policies_filtered:
- ctx.logger.info("policies not found by {0}".format(json.dumps(policy_filter)))
+ error = "policies not found by {0}".format(json.dumps(policy_filter))
+ ctx.logger.info(error)
+ if policy_required:
+ raise NonRecoverableError(error)
return True
ctx.logger.info("found policies by {0}: {1}".format(
@@ -216,6 +220,7 @@ def _policies_find():
except Exception as ex:
error = "failed to find policies: {0}".format(str(ex))
ctx.logger.error("{0}: {1}".format(error, traceback.format_exc()))
+ raise NonRecoverableError(error)
return True
diff --git a/dcae-policy/pom.xml b/dcae-policy/pom.xml
index 949ecf8..0b8da47 100644
--- a/dcae-policy/pom.xml
+++ b/dcae-policy/pom.xml
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!--
================================================================================
-Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
+Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -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.3.0-SNAPSHOT</version>
+ <version>2.3.2-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 d1a014e..d7a6756 100644
--- a/dcae-policy/setup.py
+++ b/dcae-policy/setup.py
@@ -1,5 +1,5 @@
# ================================================================================
-# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -23,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.3.0",
+ version="2.3.2",
author='Alex Shatov',
packages=['dcaepolicyplugin'],
install_requires=[
diff --git a/dcae-policy/tests/test_discovery.py b/dcae-policy/tests/test_discovery.py
index 129ad99..0c41fe3 100644
--- a/dcae-policy/tests/test_discovery.py
+++ b/dcae-policy/tests/test_discovery.py
@@ -1,5 +1,5 @@
# ================================================================================
-# Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -35,7 +35,7 @@ from tests.mock_setup import (MONKEYED_POLICY_ID, POLICY_ID, MonkeyedNode,
POLICY_HANDLER_FROM_KV = "http://policy_handler_from_kv:25577"
-def monkeyed_discovery_get_failure(full_path):
+def monkeyed_discovery_get_failure(full_path, **kwargs):
"""monkeypatch for the GET to consul"""
raise requests.ConnectionError("monkey-boom")
@@ -65,7 +65,7 @@ def test_discovery_failure(monkeypatch):
current_ctx.clear()
-def monkeyed_discovery_get_kv(full_path):
+def monkeyed_discovery_get_kv(full_path, **kwargs):
"""monkeypatch for the GET to consul"""
if full_path.startswith(discovery.CONSUL_SERVICE_URL.format("")):
return MonkeyedResponse(full_path)
@@ -102,7 +102,7 @@ def test_discovery_kv(monkeypatch):
current_ctx.clear()
-def monkeyed_discovery_get(full_path):
+def monkeyed_discovery_get(full_path, **kwargs):
"""monkeypatch for the GET to consul"""
return MonkeyedResponse(full_path, {},
[{"ServiceAddress": "monkey-policy-handler-address", "ServicePort": "9999"}])
diff --git a/dcae-policy/tests/test_tasks.py b/dcae-policy/tests/test_tasks.py
index f2ca205..dc89d65 100644
--- a/dcae-policy/tests/test_tasks.py
+++ b/dcae-policy/tests/test_tasks.py
@@ -1,5 +1,5 @@
# ================================================================================
-# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -36,7 +36,7 @@ from tests.mock_setup import (CONFIG_NAME, MONKEYED_POLICY_ID, POLICY_BODY,
LATEST_POLICIES = "latest_policies"
-def monkeyed_policy_handler_get(full_path, headers=None):
+def monkeyed_policy_handler_get(full_path, headers=None, **kwargs):
"""monkeypatch for the GET to policy-engine"""
return MonkeyedResponse(full_path, headers,
MonkeyedPolicyBody.create_policy(MONKEYED_POLICY_ID))
@@ -105,7 +105,7 @@ def test_policy_get_fail(monkeypatch):
current_ctx.clear()
-def monkeyed_policy_handler_find(full_path, json, headers):
+def monkeyed_policy_handler_find(full_path, json, headers, **kwargs):
"""monkeypatch for the GET to policy-engine"""
return MonkeyedResponse(
full_path, headers,