summaryrefslogtreecommitdiffstats
path: root/onap-dcae-cbs-docker-client
diff options
context:
space:
mode:
authorTommy Carpenter <tommy@research.att.com>2018-02-23 16:05:45 -0500
committerTommy Carpenter <tommy@research.att.com>2018-02-23 16:06:42 -0500
commitbfc70e565fd18d10f65d61e233bbf9bf1d770b63 (patch)
treefa0d0770088d7ceaf27e937d739c3d7241e8ae2b /onap-dcae-cbs-docker-client
parentd1a814370eb3e45368af9d6a76f8ded77cca5c82 (diff)
Make this compatible with CBS1 and CBS2
Change-Id: I3e221cbc9f7e9554829b2a88f4cc3277a349f1ae Issue-ID: DCAEGEN2-351 Signed-off-by: Tommy Carpenter <tommy@research.att.com>
Diffstat (limited to 'onap-dcae-cbs-docker-client')
-rw-r--r--onap-dcae-cbs-docker-client/onap_dcae_cbs_docker_client/client.py15
-rw-r--r--onap-dcae-cbs-docker-client/setup.py2
-rw-r--r--onap-dcae-cbs-docker-client/tests/test_client.py5
3 files changed, 15 insertions, 7 deletions
diff --git a/onap-dcae-cbs-docker-client/onap_dcae_cbs_docker_client/client.py b/onap-dcae-cbs-docker-client/onap_dcae_cbs_docker_client/client.py
index f83111c..f21ad0e 100644
--- a/onap-dcae-cbs-docker-client/onap_dcae_cbs_docker_client/client.py
+++ b/onap-dcae-cbs-docker-client/onap_dcae_cbs_docker_client/client.py
@@ -52,9 +52,7 @@ def _get_envs():
return HOSTNAME, CONSUL_HOST
-#########
-# Public
-def get_all():
+def _get_path(path):
"""
This call does not raise an exception if Consul or the CBS cannot complete the request.
It logs an error and returns {} if the config is not bindable.
@@ -77,7 +75,7 @@ def get_all():
logger.error("Cannot bind config at this time, cbs is unreachable")
else:
#get my config
- my_config_endpoint = "{0}/service_component_all/{1}".format(cbs_url, HOSTNAME)
+ my_config_endpoint = "{0}/{1}/{2}".format(cbs_url, path, HOSTNAME)
res = requests.get(my_config_endpoint)
try:
res.raise_for_status()
@@ -87,6 +85,11 @@ def get_all():
logger.error("in get_config, the config binding service endpoint {0} blew up on me. Error code: {1}, Error text: {2}".format(my_config_endpoint, res.status_code, res.text))
return config
+
+#########
+# Public
+def get_all():
+ return _get_path("service_component_all")
+
def get_config():
- allk = get_all()
- return allk["config"]
+ return _get_path("service_component")
diff --git a/onap-dcae-cbs-docker-client/setup.py b/onap-dcae-cbs-docker-client/setup.py
index d3236e8..fd7dc4b 100644
--- a/onap-dcae-cbs-docker-client/setup.py
+++ b/onap-dcae-cbs-docker-client/setup.py
@@ -22,7 +22,7 @@ from setuptools import setup, find_packages
setup(
name = "onap_dcae_cbs_docker_client",
description = "very lightweight client for a DCAE dockerized component to get it's config from the CBS",
- version = "1.0.0",
+ version = "1.0.1",
packages=find_packages(),
author = "Tommy Carpenter",
author_email = "tommy@research.att.com",
diff --git a/onap-dcae-cbs-docker-client/tests/test_client.py b/onap-dcae-cbs-docker-client/tests/test_client.py
index 1e4ec13..8512fad 100644
--- a/onap-dcae-cbs-docker-client/tests/test_client.py
+++ b/onap-dcae-cbs-docker-client/tests/test_client.py
@@ -40,6 +40,11 @@ def monkeyed_requests_get(url):
"items": [{"foo2": "bar2"}]},
"otherkey": {"foo3": "bar3"}})
+ elif url == "http://666.666.666.666:8888/service_component/mybestfrienddotcom":
+ return FakeResponse(status_code=200,
+ thejson={"key_to_your_heart": 666})
+
+
def test_config(monkeypatch):
monkeypatch.setattr('requests.get', monkeyed_requests_get)
assert(get_config() == {"key_to_your_heart": 666})