Fix issue where getting empty consul in discovery 65/36765/1
authorMichael Hwang <mhwang@research.att.com>
Mon, 19 Mar 2018 15:29:27 +0000 (11:29 -0400)
committerMichael Hwang <mhwang@research.att.com>
Mon, 19 Mar 2018 15:31:27 +0000 (11:31 -0400)
Change-Id: Ic9bda3bf7d88ad9f9c11caf9c6231d8acd829bff
Issue-ID: DCAEGEN2-402
Signed-off-by: Michael Hwang <mhwang@research.att.com>
dcae-cli/ChangeLog.md
dcae-cli/dcae_cli/_version.py
dcae-cli/dcae_cli/util/discovery.py
dcae-cli/dcae_cli/util/tests/test_discovery.py
dcae-cli/pom.xml

index 311165c..e3aaac4 100644 (file)
@@ -5,6 +5,10 @@ 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/).
 
+## [2.10.1]
+
+* Fix DCAEGEN2-402
+
 ## [2.10.0]
 
 * Make server url (url to webserver that has static artifacts like json schemas) a configuration parameter
index f3ba354..be3a135 100644 (file)
@@ -19,4 +19,4 @@
 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
 
 # -*- coding: utf-8 -*-
-__version__ = "2.10.0"
+__version__ = "2.10.1"
index 8689092..ba74f1f 100644 (file)
@@ -69,6 +69,14 @@ def default_consul_host():
     return get_profile().consul_host
 
 
+def _choose_consul_host(consul_host):
+    """Chooses the appropriate consul host
+
+    Chooses between a provided value and a default
+    """
+    return default_consul_host() if consul_host == None else consul_host
+
+
 def replace_dots(comp_name, reverse=False):
     '''Converts dots to dashes to prevent downstream users of Consul from exploding'''
     if not reverse:
@@ -237,7 +245,7 @@ def get_user_instances(user, consul_host=None, filter_instances_func=is_healthy)
     --------
     Dict whose keys are component (name,version) tuples and values are list of component instance names
     '''
-    consul_host = consul_host if consul_host == None else default_consul_host()
+    consul_host = _choose_consul_host(consul_host)
     filter_func = partial(filter_instances_func, consul_host)
     instances = list(filter(filter_func, _get_instances(consul_host, user)))
 
@@ -278,7 +286,7 @@ def get_healthy_instances(user, cname, cver, consul_host=None):
     -------
     List of strings where the strings are fully qualified instance names
     """
-    consul_host = consul_host if consul_host == None else default_consul_host()
+    consul_host = _choose_consul_host(consul_host)
     return _get_component_instances(is_healthy, user, cname, cver, consul_host)
 
 def get_defective_instances(user, cname, cver, consul_host=None):
@@ -294,7 +302,7 @@ def get_defective_instances(user, cname, cver, consul_host=None):
     def is_not_healthy(consul_host, component):
         return not is_healthy(consul_host, component)
 
-    consul_host = consul_host if consul_host == None else default_consul_host()
+    consul_host = _choose_consul_host(consul_host)
     return _get_component_instances(is_not_healthy, user, cname, cver, consul_host)
 
 
@@ -336,7 +344,7 @@ def _create_dmaap_key(config_key):
 
 def clear_user_instances(user, host=None):
     '''Removes all Consul key:value entries for a given user'''
-    host = host if host == None else default_consul_host()
+    host = _choose_consul_host(host)
     cons = Consul(host)
     cons.kv.delete(user, recurse=True)
 
@@ -486,7 +494,7 @@ def get_docker_logins(host=None):
         {"registry": .., "username":.., "password":.. }
     """
     key = get_docker_logins_key()
-    host = host if host == None else default_consul_host()
+    host = _choose_consul_host(host)
     (index, val) = Consul(host).kv.get(key)
 
     if val:
@@ -497,7 +505,7 @@ def get_docker_logins(host=None):
 
 def push_config(conf_key, conf, rels_key, rels, dmaap_key, dmaap_map, host=None):
     '''Uploads the config and rels to Consul'''
-    host = host if host == None else default_consul_host()
+    host = _choose_consul_host(host)
     cons = Consul(host)
     for k, v in ((conf_key, conf), (rels_key, rels), (dmaap_key, dmaap_map)):
         cons.kv.put(k, json.dumps(v))
@@ -510,7 +518,7 @@ def remove_config(config_key, host=None):
     -------
     True when all artifacts have been successfully deleted else False
     """
-    host = host if host == None else default_consul_host()
+    host = _choose_consul_host(host)
     cons = Consul(host)
     results = [ cons.kv.delete(k) for k in (config_key, _create_rels_key(config_key), \
             _create_dmaap_key(config_key)) ]
@@ -558,7 +566,7 @@ def config_context(user, cname, cver, params, interface_map, instance_map,
         Config will continue to be created even if there are no downstream compatible
         component when this flag is set to True. Default is False.
     '''
-    host = host if host == None else default_consul_host()
+    host = _choose_consul_host(host)
 
     try:
         conf_key, conf, rels_key, rels, dmaap_key, dmaap_map = create_config(
index b37ac17..2148ea3 100644 (file)
@@ -433,6 +433,15 @@ def test_apply_inputs():
     assert updated_config == {"foo": "baz"}
 
 
+def test_choose_consul_host(monkeypatch):
+    def fake_default_consul_host():
+        return "default-consul-host"
+
+    monkeypatch.setattr(dis, "default_consul_host", fake_default_consul_host)
+    assert "default-consul-host" == dis._choose_consul_host(None)
+    assert "provided-consul-host" == dis._choose_consul_host("provided-consul-host")
+
+
 if __name__ == '__main__':
     '''Test area'''
     pytest.main([__file__, ])
index f8b9e8a..3eef54a 100644 (file)
@@ -28,7 +28,7 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property.
   <groupId>org.onap.dcaegen2.platform.cli</groupId>
   <artifactId>dcae-cli</artifactId>
   <name>dcaegen2-platform-cli-dcae-cli</name>
-  <version>2.10.0</version>
+  <version>2.10.1</version>
   <url>http://maven.apache.org</url>
   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>