You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by jo...@apache.org on 2016/09/15 17:14:57 UTC
[2/2] 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/5cd1d306
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/5cd1d306
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/5cd1d306
Branch: refs/heads/branch-2.4
Commit: 5cd1d306ff95d534414707f10faedc6e1b1437f6
Parents: 19e3715
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 13:14:40 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/5cd1d306/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/5cd1d306/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)