summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLusheng Ji <lji@research.att.com>2018-04-12 21:42:15 +0000
committerGerrit Code Review <gerrit@onap.org>2018-04-12 21:42:15 +0000
commitfe5179575191dd40af3d9e4a8d4bd0144e4d08de (patch)
treeae096943a244065006fc21b750fb61e6ef00f529
parent0b36661caa4c32d652614f256b41644ade09a937 (diff)
parent5a412c36b76f375aba863e3668ce6cb4f457e0d7 (diff)
Merge "2.3.0 dcaepolicyplugin and data types"
-rw-r--r--dcae-policy/README.md2
-rw-r--r--dcae-policy/dcaepolicy-node-type.yaml2
-rw-r--r--dcae-policy/dcaepolicyplugin/discovery.py23
-rw-r--r--dcae-policy/pom.xml2
-rw-r--r--dcae-policy/setup.py2
-rw-r--r--dcae-policy/tests/mock_setup.py1
-rw-r--r--dcae-policy/tests/test_discovery.py14
-rw-r--r--dcae-policy/tests/test_tasks.py66
8 files changed, 89 insertions, 23 deletions
diff --git a/dcae-policy/README.md b/dcae-policy/README.md
index 2b06519..a3a070b 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.2.1/node-type.yaml
+ - https://YOUR_NEXUS_RAW_SERVER/type_files/dcaepolicy/2.3.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 fdb29ed..1c07b7a 100644
--- a/dcae-policy/dcaepolicy-node-type.yaml
+++ b/dcae-policy/dcaepolicy-node-type.yaml
@@ -25,7 +25,7 @@ plugins:
dcaepolicy:
executor: 'central_deployment_agent'
package_name: dcaepolicyplugin
- package_version: 2.2.1
+ package_version: 2.3.0
data_types:
# the properties inside dcae.data.policy_filter are identical to /getConfig API of policy-engine except the requestID field.
diff --git a/dcae-policy/dcaepolicyplugin/discovery.py b/dcae-policy/dcaepolicyplugin/discovery.py
index 1faee08..0517377 100644
--- a/dcae-policy/dcaepolicyplugin/discovery.py
+++ b/dcae-policy/dcaepolicyplugin/discovery.py
@@ -23,10 +23,15 @@ import json
import requests
from cloudify import ctx
+from cloudify.exceptions import NonRecoverableError
-# it is safe to assume that consul agent is at localhost:8500 along with cloudify manager
-CONSUL_SERVICE_URL = "http://localhost:8500/v1/catalog/service/{0}"
-CONSUL_KV_MASK = "http://localhost:8500/v1/kv/{0}"
+# it is safe to assume that consul agent is at consul:8500
+# define consul alis in /etc/hosts on cloudify manager vm
+# $ cat /etc/hosts
+# 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 consul
+
+CONSUL_SERVICE_URL = "http://consul:8500/v1/catalog/service/{0}"
+CONSUL_KV_MASK = "http://consul:8500/v1/kv/{0}"
def discover_service_url(service_name):
@@ -34,7 +39,11 @@ def discover_service_url(service_name):
service_url = CONSUL_SERVICE_URL.format(service_name)
ctx.logger.info("getting service_url at {0}".format(service_url))
- response = requests.get(service_url)
+ try:
+ response = requests.get(service_url)
+ except requests.ConnectionError as ex:
+ raise NonRecoverableError(
+ "ConnectionError - failed to get {0}: {1}".format(service_url, str(ex)))
ctx.logger.info("got {0} for service_url at {1} response: {2}"
.format(response.status_code, service_url, response.text))
@@ -53,7 +62,11 @@ def discover_value(key):
kv_url = CONSUL_KV_MASK.format(key)
ctx.logger.info("getting kv at {0}".format(kv_url))
- response = requests.get(kv_url)
+ try:
+ response = requests.get(kv_url)
+ except requests.ConnectionError as ex:
+ raise NonRecoverableError(
+ "ConnectionError - failed to get {0}: {1}".format(kv_url, str(ex)))
ctx.logger.info("got {0} for kv at {1} response: {2}"
.format(response.status_code, kv_url, response.text))
diff --git a/dcae-policy/pom.xml b/dcae-policy/pom.xml
index b46e9b8..949ecf8 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.2.1-SNAPSHOT</version>
+ <version>2.3.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 8072873..d1a014e 100644
--- a/dcae-policy/setup.py
+++ b/dcae-policy/setup.py
@@ -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.2.1",
+ version="2.3.0",
author='Alex Shatov',
packages=['dcaepolicyplugin'],
install_requires=[
diff --git a/dcae-policy/tests/mock_setup.py b/dcae-policy/tests/mock_setup.py
index c74b236..cbc4a35 100644
--- a/dcae-policy/tests/mock_setup.py
+++ b/dcae-policy/tests/mock_setup.py
@@ -153,4 +153,3 @@ class MonkeyedNode(object):
relationships=relationships
)
MonkeyedLogHandler.add_handler_to(self.ctx.logger)
-
diff --git a/dcae-policy/tests/test_discovery.py b/dcae-policy/tests/test_discovery.py
index 893b7ce..129ad99 100644
--- a/dcae-policy/tests/test_discovery.py
+++ b/dcae-policy/tests/test_discovery.py
@@ -22,6 +22,8 @@ import base64
import json
import pytest
+import requests
+from cloudify.exceptions import NonRecoverableError
from cloudify.state import current_ctx
from dcaepolicyplugin import discovery, tasks
@@ -30,12 +32,12 @@ from tests.mock_cloudify_ctx import MockCloudifyContextFull
from tests.mock_setup import (MONKEYED_POLICY_ID, POLICY_ID, MonkeyedNode,
MonkeyedResponse)
-POLICY_HANDLER_FROM_KV = "http:policy_handler_from_kv:25577"
+POLICY_HANDLER_FROM_KV = "http://policy_handler_from_kv:25577"
def monkeyed_discovery_get_failure(full_path):
"""monkeypatch for the GET to consul"""
- return MonkeyedResponse(full_path)
+ raise requests.ConnectionError("monkey-boom")
def test_discovery_failure(monkeypatch):
@@ -50,8 +52,12 @@ def test_discovery_failure(monkeypatch):
)
try:
current_ctx.set(node_policy.ctx)
- tasks.PolicyHandler._lazy_init()
- assert tasks.PolicyHandler.DEFAULT_URL == tasks.PolicyHandler._url
+ with pytest.raises(NonRecoverableError) as excinfo:
+ tasks.PolicyHandler._lazy_init()
+
+ CtxLogger.log_ctx_info("test_discovery_failure: {0}".format(str(excinfo.value)))
+ assert str(excinfo.value).startswith("ConnectionError")
+
finally:
tasks.PolicyHandler._url = None
diff --git a/dcae-policy/tests/test_tasks.py b/dcae-policy/tests/test_tasks.py
index 9f9121d..f2ca205 100644
--- a/dcae-policy/tests/test_tasks.py
+++ b/dcae-policy/tests/test_tasks.py
@@ -70,9 +70,29 @@ def test_policy_get(monkeypatch):
assert MonkeyedPolicyBody.is_the_same_dict(result, expected)
assert MonkeyedPolicyBody.is_the_same_dict(expected, result)
- node_ms = MonkeyedNode('test_ms_id', 'test_ms_name', "ms.nodes.type", None,
- [{TARGET_NODE_ID: node_policy.node_id,
- TARGET_NODE_NAME: node_policy.node_name}])
+ finally:
+ MockCloudifyContextFull.clear()
+ current_ctx.clear()
+
+
+def test_policy_get_fail(monkeypatch):
+ """test policy_get operation on non dcae.nodes.policy node"""
+ tasks.PolicyHandler._url = tasks.PolicyHandler.DEFAULT_URL
+ monkeypatch.setattr('requests.get', monkeyed_policy_handler_get)
+
+ node_policy = MonkeyedNode(
+ 'test_dcae_policy_node_id',
+ 'test_dcae_policy_node_name',
+ tasks.DCAE_POLICY_TYPE,
+ {POLICY_ID: MONKEYED_POLICY_ID}
+ )
+
+ node_ms = MonkeyedNode(
+ 'test_ms_id', 'test_ms_name', "ms.nodes.type", None,
+ [{TARGET_NODE_ID: node_policy.node_id, TARGET_NODE_NAME: node_policy.node_name}]
+ )
+
+ try:
current_ctx.set(node_ms.ctx)
CtxLogger.log_ctx_info("ctx of node_ms not policy type")
with pytest.raises(NonRecoverableError) as excinfo:
@@ -87,9 +107,11 @@ def test_policy_get(monkeypatch):
def monkeyed_policy_handler_find(full_path, json, headers):
"""monkeypatch for the GET to policy-engine"""
- return MonkeyedResponse(full_path, headers,
+ return MonkeyedResponse(
+ full_path, headers,
{LATEST_POLICIES: {
- MONKEYED_POLICY_ID: MonkeyedPolicyBody.create_policy(MONKEYED_POLICY_ID)}})
+ MONKEYED_POLICY_ID: MonkeyedPolicyBody.create_policy(MONKEYED_POLICY_ID)}}
+ )
def test_policies_find(monkeypatch):
@@ -128,10 +150,36 @@ def test_policies_find(monkeypatch):
assert MonkeyedPolicyBody.is_the_same_dict(result, expected)
assert MonkeyedPolicyBody.is_the_same_dict(expected, result)
- node_ms_multi = MonkeyedNode('test_ms_multi_id', 'test_ms_multi_name', "ms.nodes.type",
- None,
- [{TARGET_NODE_ID: node_policies.node_id,
- TARGET_NODE_NAME: node_policies.node_name}])
+ finally:
+ MockCloudifyContextFull.clear()
+ current_ctx.clear()
+
+
+def test_policies_find_fail(monkeypatch):
+ """test policy_get operation on non dcae.nodes.policies node"""
+ tasks.PolicyHandler._url = tasks.PolicyHandler.DEFAULT_URL
+ monkeypatch.setattr('requests.post', monkeyed_policy_handler_find)
+
+ node_policies = MonkeyedNode(
+ 'test_dcae_policies_node_id',
+ 'test_dcae_policies_node_name',
+ tasks.DCAE_POLICIES_TYPE,
+ {
+ tasks.POLICY_FILTER: {
+ POLICY_NAME: MONKEYED_POLICY_ID,
+ tasks.CONFIG_ATTRIBUTES: json.dumps({
+ CONFIG_NAME: "alex_config_name"
+ })
+ }
+ }
+ )
+ node_ms_multi = MonkeyedNode(
+ 'test_ms_multi_id', 'test_ms_multi_name', "ms.nodes.type",
+ None,
+ [{TARGET_NODE_ID: node_policies.node_id, TARGET_NODE_NAME: node_policies.node_name}]
+ )
+
+ try:
current_ctx.set(node_ms_multi.ctx)
CtxLogger.log_ctx_info("ctx of node_ms_multi not policy type")
with pytest.raises(NonRecoverableError) as excinfo: