You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by nc...@apache.org on 2016/09/16 13:57:50 UTC
[17/27] ambari git commit: AMBARI-18403 - YAML Maps Can Include
Dashes and Other Non-Word Characters (jonathanhurley)
AMBARI-18403 - YAML Maps Can Include Dashes and Other Non-Word Characters (jonathanhurley)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/edf1b9b9
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/edf1b9b9
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/edf1b9b9
Branch: refs/heads/branch-dev-patch-upgrade
Commit: edf1b9b9f2182de2e14a194c5ca243f6cf39170d
Parents: bead01c
Author: Jonathan Hurley <jh...@hortonworks.com>
Authored: Thu Sep 15 11:51:12 2016 -0400
Committer: Jonathan Hurley <jh...@hortonworks.com>
Committed: Thu Sep 15 12:37:27 2016 -0400
----------------------------------------------------------------------
.../main/python/ambari_commons/yaml_utils.py | 16 ++++++++---
ambari-server/src/test/python/TestYAMLUtils.py | 30 ++++++++++++++------
2 files changed, 34 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/edf1b9b9/ambari-common/src/main/python/ambari_commons/yaml_utils.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_commons/yaml_utils.py b/ambari-common/src/main/python/ambari_commons/yaml_utils.py
index 9753177..dae5b56 100644
--- a/ambari-common/src/main/python/ambari_commons/yaml_utils.py
+++ b/ambari-common/src/main/python/ambari_commons/yaml_utils.py
@@ -26,13 +26,21 @@ REGEX_LIST = '^\w*\[.+\]\w*$'
REGEX_DICTIONARY = '^\w*\{.+\}\w*$'
"""
-storm:
+storm-cluster:
hosts:
- [c6401.ambari.apache.org, c6402.ambari.apache.org]
+ [c6401.ambari.apache.org, c6402.ambari.apache.org, c6403-master.ambari.apache.org]
groups:
- [hadoop, foo]
+ [hadoop, hadoop-secure]
+
+^\s* - allow any whitespace or newlines to start
+\S+ - at least 1 word character (including dashes)
+[ ]*:[ ]* - followed by a colon (allowing spaces around the colon)
+[\r\n\f]+ - at least 1 newline
+
+\s*\S+[ ]*:[ ]*[\r\n\f] - follow with the same basically to ensure a map of maps
"""
-REGEX_NESTED_MAPS = '^[\w+\s*:\s*\n\s*]+\[(.*?)\]+'
+REGEX_NESTED_MAPS = "^\s*\S+[ ]*:[ ]*[\r\n\f]+\s*\S+[ ]*:[ ]*[\r\n\f]"
+
def escape_yaml_property(value):
unquouted_values = ["null", "Null", "NULL", "true", "True", "TRUE", "false",
http://git-wip-us.apache.org/repos/asf/ambari/blob/edf1b9b9/ambari-server/src/test/python/TestYAMLUtils.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestYAMLUtils.py b/ambari-server/src/test/python/TestYAMLUtils.py
index c6ee343..4d2d035 100644
--- a/ambari-server/src/test/python/TestYAMLUtils.py
+++ b/ambari-server/src/test/python/TestYAMLUtils.py
@@ -64,19 +64,33 @@ class TestYAMLUtils(TestCase):
# test maps
map = """
- storm:
+ storm-cluster:
hosts:
- [c6401.ambari.apache.org, c6402.ambari.apache.org]
+ [c6401.ambari.apache.org, c6402.ambari.apache.org, c6403-master.ambari.apache.org]
groups:
- [hadoop, foo]
- foo:
- [bar, baz]
- foo2:
- bar2:
- [baz2]
+ [hadoop, hadoop-secure]
"""
escaped_map = yaml_utils.escape_yaml_property(map)
self.assertTrue(escaped_map.startswith("\n"))
self.assertFalse("'" in escaped_map)
+ # try some weird but valid formatting
+ map = """
+
+
+ storm-cluster :
+ hosts :
+[c6401.ambari.apache.org, c6402.ambari.apache.org, c6403-master.ambari.apache.org]
+ groups :
+ [hadoop!!!, hadoop-secure!!!!-----]
+ """
+ escaped_map = yaml_utils.escape_yaml_property(map)
+ self.assertTrue(escaped_map.startswith("\n"))
+ self.assertFalse("'" in escaped_map)
+ # try some bad formatting - this is not a map
+ map = """ foo : bar :
+ [baz]"""
+ escaped_map = yaml_utils.escape_yaml_property(map)
+ self.assertFalse(escaped_map.startswith("\n"))
+ self.assertTrue("'" in escaped_map)