diff options
-rw-r--r-- | onap-dcae-cbs-docker-client/Changelog.md | 3 | ||||
-rw-r--r-- | onap-dcae-cbs-docker-client/README.md | 6 | ||||
-rw-r--r-- | onap-dcae-cbs-docker-client/onap_dcae_cbs_docker_client/client.py | 16 | ||||
-rw-r--r-- | onap-dcae-cbs-docker-client/pom.xml | 2 | ||||
-rw-r--r-- | onap-dcae-cbs-docker-client/setup.py | 6 | ||||
-rw-r--r-- | onap-dcae-cbs-docker-client/tests/test_client.py | 5 | ||||
-rw-r--r-- | onap-dcae-cbs-docker-client/tox-local.ini | 1 | ||||
-rw-r--r-- | onap-dcae-cbs-docker-client/tox.ini | 1 |
8 files changed, 22 insertions, 18 deletions
diff --git a/onap-dcae-cbs-docker-client/Changelog.md b/onap-dcae-cbs-docker-client/Changelog.md index 3c29fcc..354bc2a 100644 --- a/onap-dcae-cbs-docker-client/Changelog.md +++ b/onap-dcae-cbs-docker-client/Changelog.md @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [1.0.4] +* Allow the CBS to be registered in Consul under a different name than "config_binding_service"; instead read from the already-set ENV variable CONFIG_BINDING_SERVICE + ## [1.0.3] * Fix an issue caused by flake8 upgrading diff --git a/onap-dcae-cbs-docker-client/README.md b/onap-dcae-cbs-docker-client/README.md index 47ec9e4..8466e50 100644 --- a/onap-dcae-cbs-docker-client/README.md +++ b/onap-dcae-cbs-docker-client/README.md @@ -1,13 +1,14 @@ # Python CBS Docker Client -Used for DCAE Dockerized microservices written in Python. Pulls your configuration from the config_binding_service. Expects that CONSUL_HOST and HOSTNAME are set as env variables, which is true in DCAE. +Used for DCAE Dockerized microservices written in Python. Pulls your configuration from the config_binding_service. Expects that CONSUL_HOST, HOSTNAME, CONFIG_BINDING_SERVICE are set as env variables, which is true in DCAE. # Client Usage ## Development outside of Docker To test your raw code without Docker, you will need to set the env variables CONSUL_HOST and HOSTNAME (name of your key to pull from) that are set in DCAEs Docker environment. 1. `CONSUL_HOST` is the hostname only of the Consul instance you are talking to -2. HOSTNAME is the name of your component in Consul +2. `HOSTNAME` is the name of your component in Consul +3. `CONFIG_BINDING_SERVICE` is the name under which the CBS is registered in Consul ## Usage in your code ``` @@ -27,4 +28,3 @@ pip install onap-dcae-cbs-docker-client ``` tox ``` - 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 3f2fcf2..80c9f75 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 @@ -53,11 +53,13 @@ def _get_envs(): Returns hostname, consul_host. If the necessary ENVs are not found, this is fatal, and raises an exception. """ - if "HOSTNAME" not in os.environ or "CONSUL_HOST" not in os.environ: - raise ENVsMissing("HOSTNAME or CONSUL_HOST missing") - hostname = os.environ["HOSTNAME"] - consul_host = os.environ["CONSUL_HOST"] - return hostname, consul_host + try: + hostname = os.environ["HOSTNAME"] # this is the name of the component itself + consul_host = os.environ["CONSUL_HOST"] # this is the host of consul itself + cbs_name = os.environ["CONFIG_BINDING_SERVICE"] # this is the name under which the CBS is registered in Consul. + except KeyError as e: + raise ENVsMissing("Required ENV Variable {0} missing".format(e)) + return hostname, consul_host, cbs_name def _get_path(path): @@ -72,14 +74,14 @@ def _get_path(path): config = {} - hostname, consul_host = _get_envs() + hostname, consul_host, cbs_name = _get_envs() # not sure how I as the component developer is supposed to know consul port consul_url = "http://{0}:8500".format(consul_host) try: # get my config - cbs_url = _get_uri_from_consul(consul_url, "config_binding_service") + cbs_url = _get_uri_from_consul(consul_url, cbs_name) my_config_endpoint = "{0}/{1}/{2}".format(cbs_url, path, hostname) res = requests.get(my_config_endpoint) diff --git a/onap-dcae-cbs-docker-client/pom.xml b/onap-dcae-cbs-docker-client/pom.xml index a8d861d..0a2c763 100644 --- a/onap-dcae-cbs-docker-client/pom.xml +++ b/onap-dcae-cbs-docker-client/pom.xml @@ -28,7 +28,7 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property. <groupId>org.onap.dcaegen2.utils</groupId> <artifactId>onap-dcae-cbs-docker-client</artifactId> <name>dcaegen2-utils-python-cbs-docker-client</name> - <version>1.0.3-SNAPSHOT</version> + <version>1.0.4-SNAPSHOT</version> <url>http://maven.apache.org</url> <properties> diff --git a/onap-dcae-cbs-docker-client/setup.py b/onap-dcae-cbs-docker-client/setup.py index 48660a1..3d4467c 100644 --- a/onap-dcae-cbs-docker-client/setup.py +++ b/onap-dcae-cbs-docker-client/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. @@ -13,15 +13,13 @@ # See the License for the specific language governing permissions and # limitations under the License. # ============LICENSE_END========================================================= -# -# ECOMP is a trademark and service mark of AT&T Intellectual Property. 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.3", + version="1.0.4", 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 dd6ab10..c87f573 100644 --- a/onap-dcae-cbs-docker-client/tests/test_client.py +++ b/onap-dcae-cbs-docker-client/tests/test_client.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. @@ -13,8 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # ============LICENSE_END========================================================= -# -# ECOMP is a trademark and service mark of AT&T Intellectual Property. + from onap_dcae_cbs_docker_client.client import get_config, get_all diff --git a/onap-dcae-cbs-docker-client/tox-local.ini b/onap-dcae-cbs-docker-client/tox-local.ini index 8e48932..7faf386 100644 --- a/onap-dcae-cbs-docker-client/tox-local.ini +++ b/onap-dcae-cbs-docker-client/tox-local.ini @@ -9,6 +9,7 @@ deps= setenv = CONSUL_HOST = consuldotcom HOSTNAME = mybestfrienddotcom + CONFIG_BINDING_SERVICE = config_binding_service commands=pytest --cov {envsitepackagesdir}/onap_dcae_cbs_docker_client --cov-report html [testenv:flake8] diff --git a/onap-dcae-cbs-docker-client/tox.ini b/onap-dcae-cbs-docker-client/tox.ini index 6bbe73f..a8c9272 100644 --- a/onap-dcae-cbs-docker-client/tox.ini +++ b/onap-dcae-cbs-docker-client/tox.ini @@ -10,6 +10,7 @@ deps= setenv = CONSUL_HOST = consuldotcom HOSTNAME = mybestfrienddotcom + CONFIG_BINDING_SERVICE = config_binding_service PYTHONPATH={toxinidir} commands= |