summaryrefslogtreecommitdiffstats
path: root/dcae-policy/tests
diff options
context:
space:
mode:
authorAlex Shatov <alexs@att.com>2018-03-26 17:16:29 -0400
committerAlex Shatov <alexs@att.com>2018-03-26 17:16:29 -0400
commit19470fb77656cd6680058f456fb0f09e86f504dc (patch)
treea8cbb44de0d6ae9a1196f448f6f6a2ed7ebcaba5 /dcae-policy/tests
parent7d9895ebb2ed0554ed8fafa5c909a9a930c3f962 (diff)
2.2.0 dcaepolicyplugin and data types
- dcaepolicyplugin to use default policy-handler url by dns to discover policy-handler under k8s when policy_handler record not found under consul-service - pending hardcoding the proper dns based url that is to be provided by k8s + MSB solution Change-Id: I8bf49fe29735ec842235c0b58595c7196f5d24ca Signed-off-by: Alex Shatov <alexs@att.com> Issue-ID: DCAEGEN2-419
Diffstat (limited to 'dcae-policy/tests')
-rw-r--r--dcae-policy/tests/test_tasks.py47
1 files changed, 40 insertions, 7 deletions
diff --git a/dcae-policy/tests/test_tasks.py b/dcae-policy/tests/test_tasks.py
index 9bcf4ff..b9b69b9 100644
--- a/dcae-policy/tests/test_tasks.py
+++ b/dcae-policy/tests/test_tasks.py
@@ -166,9 +166,22 @@ def monkeyed_discovery_get_failure(full_path):
def test_discovery_failure(monkeypatch):
"""test finding policy-handler in consul"""
monkeypatch.setattr('requests.get', monkeyed_discovery_get_failure)
- expected = None
- tasks.PolicyHandler._lazy_init()
- assert expected == tasks.PolicyHandler._url
+
+ node_policy = MonkeyedNode(
+ 'test_dcae_policy_node_id',
+ 'test_dcae_policy_node_name',
+ tasks.DCAE_POLICY_TYPE,
+ {POLICY_ID: MONKEYED_POLICY_ID}
+ )
+ try:
+ current_ctx.set(node_policy.ctx)
+ tasks.PolicyHandler._lazy_init()
+ assert tasks.PolicyHandler.DEFAULT_URL == tasks.PolicyHandler._url
+
+ finally:
+ tasks.PolicyHandler._url = None
+ MockCloudifyContextFull.clear()
+ current_ctx.clear()
def monkeyed_discovery_get(full_path):
"""monkeypatch for the GET to consul"""
@@ -178,17 +191,36 @@ def monkeyed_discovery_get(full_path):
def test_discovery(monkeypatch):
"""test finding policy-handler in consul"""
monkeypatch.setattr('requests.get', monkeyed_discovery_get)
- expected = "http://monkey-policy-handler-address:9999"
- tasks.PolicyHandler._lazy_init()
- assert expected == tasks.PolicyHandler._url
-def monkeyed_policy_handler_get(full_path, headers):
+ node_policy = MonkeyedNode(
+ 'test_dcae_policy_node_id',
+ 'test_dcae_policy_node_name',
+ tasks.DCAE_POLICY_TYPE,
+ {POLICY_ID: MONKEYED_POLICY_ID}
+ )
+
+ try:
+ current_ctx.set(node_policy.ctx)
+ expected = "http://monkey-policy-handler-address:9999"
+ CtxLogger.log_ctx_info("before PolicyHandler._lazy_init")
+ tasks.PolicyHandler._lazy_init()
+ CtxLogger.log_ctx_info("after PolicyHandler._lazy_init")
+ assert expected == tasks.PolicyHandler._url
+
+ finally:
+ tasks.PolicyHandler._url = None
+ MockCloudifyContextFull.clear()
+ current_ctx.clear()
+
+
+def monkeyed_policy_handler_get(full_path, headers=None):
"""monkeypatch for the GET to policy-engine"""
return MonkeyedResponse(full_path, headers, \
MonkeyedPolicyBody.create_policy(MONKEYED_POLICY_ID))
def test_policy_get(monkeypatch):
"""test policy_get operation on dcae.nodes.policy node"""
+ tasks.PolicyHandler._url = tasks.PolicyHandler.DEFAULT_URL
monkeypatch.setattr('requests.get', monkeyed_policy_handler_get)
node_policy = MonkeyedNode(
@@ -236,6 +268,7 @@ def monkeyed_policy_handler_find(full_path, json, headers):
def test_policies_find(monkeypatch):
"""test policy_get operation on dcae.nodes.policies node"""
+ tasks.PolicyHandler._url = tasks.PolicyHandler.DEFAULT_URL
monkeypatch.setattr('requests.post', monkeyed_policy_handler_find)
node_policies = MonkeyedNode(