ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject [2/2] git commit: AMBARI-5941. Ambari should generate config files in sorted order.
Date Tue, 29 Jul 2014 19:45:21 GMT
AMBARI-5941. Ambari should generate config files in sorted order.


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/0f79b23b
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/0f79b23b
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/0f79b23b

Branch: refs/heads/trunk
Commit: 0f79b23bc64e5020f4c71c4fa6f6cdf8091e5831
Parents: 488e4d3
Author: Mahadev Konar <mahadev@apache.org>
Authored: Tue Jul 29 12:45:10 2014 -0700
Committer: Mahadev Konar <mahadev@apache.org>
Committed: Tue Jul 29 12:45:10 2014 -0700

----------------------------------------------------------------------
 .../libraries/providers/xml_config.py           |  2 +-
 .../TestXmlConfigResource.py                    | 39 +++++++++++++++++++-
 2 files changed, 39 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/0f79b23b/ambari-agent/src/main/python/resource_management/libraries/providers/xml_config.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/resource_management/libraries/providers/xml_config.py
b/ambari-agent/src/main/python/resource_management/libraries/providers/xml_config.py
index b2c6acb..c962847 100644
--- a/ambari-agent/src/main/python/resource_management/libraries/providers/xml_config.py
+++ b/ambari-agent/src/main/python/resource_management/libraries/providers/xml_config.py
@@ -31,7 +31,7 @@ class XmlConfigProvider(Provider):
     # |e - for html-like escaping of <,>,',"
     config_content = InlineTemplate('''<!--{{time.asctime(time.localtime())}}-->
     <configuration>
-    {% for key, value in configurations_dict.items() %}
+    {% for key, value in configurations_dict|dictsort %}
     <property>
       <name>{{ key|e }}</name>
       <value>{{ value|e }}</value>

http://git-wip-us.apache.org/repos/asf/ambari/blob/0f79b23b/ambari-agent/src/test/python/resource_management/TestXmlConfigResource.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/resource_management/TestXmlConfigResource.py b/ambari-agent/src/test/python/resource_management/TestXmlConfigResource.py
index a1ecbe5..2ecfc4d 100644
--- a/ambari-agent/src/test/python/resource_management/TestXmlConfigResource.py
+++ b/ambari-agent/src/test/python/resource_management/TestXmlConfigResource.py
@@ -156,4 +156,41 @@ class TestXmlConfigResource(TestCase):
                 })
 
     open_mock.assert_called_with('/dir/conf/file.xml', 'wb')
-    result_file.__enter__().write.assert_called_with(u'<!--Wed 2014-02-->\n    <configuration>\n
   \n    <property>\n      <name></name>\n      <value></value>\n
   </property>\n    \n    <property>\n      <name>prop.empty</name>\n
     <value></value>\n      <attr_value_empty></attr_value_empty>\n
   </property>\n    \n    <property>\n      <name>prop.3</name>\n
     <value>%d{ISO8601} %5p %c{1}:%L - %m%n</value>\n      <attr2>value3</attr2>\n
   </property>\n    \n    <property>\n      <name>prop.2</name>\n
     <value>INFO, openjpa</value>\n    </property>\n    \n    <property>\n
     <name>prop.1</name>\n      <value>&#39;.&#39;yyyy-MM-dd-HH</value>\n
     <attr1>x</attr1>\n    </property>\n    \n    <property>\n   
  <name>prop.4</name>\n      <value>${oozie.log.dir}/oozie.log</value>\n
     <attr_value_empty></attr_value_empty>\n      <attr2>value4</attr2>\n
   </property>\n    \n  </configuration>\n')
+    result_file.__enter__().write.assert_called_with(u'<!--Wed 2014-02-->\n    <configuration>\n
   \n    <property>\n      <name></name>\n      <value></value>\n
   </property>\n    \n    <property>\n      <name>prop.1</name>\n
     <value>&#39;.&#39;yyyy-MM-dd-HH</value>\n      <attr1>x</attr1>\n
   </property>\n    \n    <property>\n      <name>prop.2</name>\n
     <value>INFO, openjpa</value>\n    </property>\n    \n    <property>\n
     <name>prop.3</name>\n      <value>%d{ISO8601} %5p %c{1}:%L - %m%n</value>\n
     <attr2>value3</attr2>\n    </property>\n    \n    <property>\n
     <name>prop.4</name>\n      <value>${oozie.log.dir}/oozie.log</value>\n
     <attr_value_empty></attr_value_empty>\n      <attr2>value4</attr2>\n
   </property>\n    \n    <property>\n      <name>prop.empty</name>\n
     <value></value>\n      <attr_value_empty></attr_value_empty>\n
   </property>\n    \n  </configuration>\n')
+
+  @patch("resource_management.core.providers.system._ensure_metadata")
+  @patch("__builtin__.open")
+  @patch.object(os.path, "exists")
+  @patch.object(os.path, "isdir")
+  @patch.object(time, "asctime")
+  def test_action_create_xml_config_sorted_by_key(self,
+                                                  time_asctime_mock,
+                                                  os_path_isdir_mock,
+                                                  os_path_exists_mock,
+                                                  open_mock,
+                                                  ensure_mock):
+    """
+    Tests if 'create' action - creates new non existent xml file and writes proper data
+    where configurations={"Key":"Value"} are stored in sorted by key order
+    """
+    os_path_isdir_mock.side_effect = [False, True]
+    os_path_exists_mock.return_value = False
+    time_asctime_mock.return_value = 'Wed 2014-02'
+
+    result_file = MagicMock()
+    open_mock.return_value = result_file
+
+    with Environment('/') as env:
+      XmlConfig('file.xml',
+                conf_dir='/dir/conf',
+                configurations={"": "",
+                                "third": "should be third",
+                                "first": "should be first",
+                                "z_last": "should be last",
+                                "second": "should be second",
+                                },
+                configuration_attributes={}
+                )
+
+    open_mock.assert_called_with('/dir/conf/file.xml', 'wb')
+    result_file.__enter__().write.assert_called_with(u'<!--Wed 2014-02-->\n    <configuration>\n
   \n    <property>\n      <name></name>\n      <value></value>\n
   </property>\n    \n    <property>\n      <name>first</name>\n 
    <value>should be first</value>\n    </property>\n    \n    <property>\n
     <name>second</name>\n      <value>should be second</value>\n
   </property>\n    \n    <property>\n      <name>third</name>\n 
    <value>should be third</value>\n    </property>\n    \n    <property>\n
     <name>z_last</name>\n      <value>should be last</value>\n  
 </property>\n    \n  </configuration>\n')
\ No newline at end of file


Mime
View raw message