Quellcode durchsuchen

[libzookeeper] Make sure that ensemble list is converted to a string

ensemble=localhost:2181,localhost:2182,localhost:2183
will create a list
['localhost:2181', 'localhost:2182', 'localhost:2183']

While
ensemble="localhost:2181,localhost:2182,localhost:2183"
will stay as a string
"localhost:2181,localhost:2182,localhost:2183"
Romain Rigaux vor 10 Jahren
Ursprung
Commit
52f248c

+ 1 - 8
apps/zookeeper/src/zookeeper/conf.py

@@ -15,14 +15,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from desktop.lib.conf import Config, UnspecifiedConfigSection, ConfigSection
-
-
-def coerce_string(value):
-  if type(value) == list:
-    return ','.join(value)
-  else:
-    return value
+from desktop.lib.conf import Config, UnspecifiedConfigSection, ConfigSection, coerce_string
 
 
 # Used only for ZooKeeper app proeprties, ZooKeeper specific properties should come from libzookeeper

+ 6 - 0
desktop/core/src/desktop/lib/conf.py

@@ -624,6 +624,12 @@ def coerce_bool(value):
     return True
   raise Exception("Could not coerce %r to boolean value" % (value,))
 
+def coerce_string(value):
+  if type(value) == list:
+    return ','.join(value)
+  else:
+    return value
+
 def coerce_csv(value):
   if isinstance(value, str):
     return value.split(',')

+ 2 - 2
desktop/libs/libzookeeper/src/libzookeeper/conf.py

@@ -19,7 +19,7 @@ import logging
 
 from urlparse import urlparse
 
-from desktop.lib.conf import Config
+from desktop.lib.conf import Config, coerce_string
 
 
 LOG = logging.getLogger(__name__)
@@ -57,7 +57,7 @@ ENSEMBLE=Config(
     "ensemble",
     help="ZooKeeper ensemble. Comma separated list of Host/Port, e.g. localhost:2181,localhost:2182,localhost:2183",
     dynamic_default=zkensemble,
-    type=str,
+    type=coerce_string,
 )
 
 PRINCIPAL_NAME=Config(

+ 23 - 1
desktop/libs/libzookeeper/src/libzookeeper/tests.py

@@ -29,7 +29,29 @@ from desktop.lib.test_utils import add_to_group, grant_access
 from hadoop.pseudo_hdfs4 import is_live_cluster
 
 from libzookeeper.models import ZookeeperClient
-from libzookeeper.conf import zkensemble
+from libzookeeper.conf import zkensemble, ENSEMBLE
+
+
+class UnitTests():
+
+  def test_get_ensemble(self):
+    clear = ENSEMBLE.set_for_testing('zoo:2181')
+    try:
+      assert_equal('zoo:2181', ENSEMBLE.get())
+    finally:
+      clear()
+
+    clear = ENSEMBLE.set_for_testing('zoo:2181,zoo2:2181')
+    try:
+      assert_equal('zoo:2181,zoo2:2181', ENSEMBLE.get())
+    finally:
+      clear()
+
+    clear = ENSEMBLE.set_for_testing(['zoo:2181', 'zoo2:2181'])
+    try:
+      assert_equal('zoo:2181,zoo2:2181', ENSEMBLE.get())
+    finally:
+      clear()
 
 
 class TestWithZooKeeper: