Browse Source

AMBARI-22040. configs.py does not work properly when dealing with files (aonishuk)

Andrew Onishuk 8 years ago
parent
commit
12abba0b74

+ 32 - 6
ambari-server/src/test/python/TestConfigs.py

@@ -73,7 +73,7 @@ class TestConfigs(TestCase):
       self.assertEquals(config['properties'], {'config1': 'value1', 'config2': 'value2'})
       self.assertEquals(config['properties'], {'config1': 'value1', 'config2': 'value2'})
     urlopen_method.side_effect = self.get_url_open_side_effect(response_mapping)
     urlopen_method.side_effect = self.get_url_open_side_effect(response_mapping)
     to_file_method.return_value = config_assertion
     to_file_method.return_value = config_assertion
-    sys.argv = ['configs.py', 'user', 'password', '8081', 'http', 'get', 'localhost', 'cluster1', 'hdfs-site', '1.conf']
+    sys.argv = ['configs.py', '-u', 'user', '-p', 'password', '-t', '8081', '-s', 'http', '-a', 'get', '-l','localhost','-n', 'cluster1', '-c','hdfs-site']
     configs.main()
     configs.main()
 
 
   @patch.object(configs, 'output_to_file')
   @patch.object(configs, 'output_to_file')
@@ -94,7 +94,7 @@ class TestConfigs(TestCase):
       }
       }
     }
     }
     urlopen_method.side_effect = self.get_url_open_side_effect(response_mapping)
     urlopen_method.side_effect = self.get_url_open_side_effect(response_mapping)
-    sys.argv = ['configs.py', 'user', 'password', '8081', 'https', 'set', 'localhost', 'cluster1', 'hdfs-site', 'config1', 'value3']
+    sys.argv = ['configs.py', '-u', 'user', '-p', 'password', '-t', '8081', '-s', 'https', '-a', 'set', '-l','localhost','-n', 'cluster1', '-c','hdfs-site', '-k', 'config1', '-v', 'value3']
     configs.main()
     configs.main()
 
 
   @patch.object(configs, 'output_to_file')
   @patch.object(configs, 'output_to_file')
@@ -115,7 +115,7 @@ class TestConfigs(TestCase):
       }
       }
     }
     }
     urlopen_method.side_effect = self.get_url_open_side_effect(response_mapping)
     urlopen_method.side_effect = self.get_url_open_side_effect(response_mapping)
-    sys.argv = ['configs.py', 'user', 'password', '8081', 'https', 'set', 'localhost', 'cluster1', 'hdfs-site', 'config1', 'value3']
+    sys.argv = ['configs.py', '-u', 'user', '-p', 'password', '-t', '8081', '-s', 'https', '-a', 'set', '-l','localhost','-n', 'cluster1', '-c','hdfs-site', '-k', 'config1', '-v', 'value3']
     configs.main()
     configs.main()
 
 
   @patch.object(configs, 'output_to_file')
   @patch.object(configs, 'output_to_file')
@@ -138,7 +138,7 @@ class TestConfigs(TestCase):
       }
       }
     }
     }
     urlopen_method.side_effect = self.get_url_open_side_effect(response_mapping)
     urlopen_method.side_effect = self.get_url_open_side_effect(response_mapping)
-    sys.argv = ['configs.py', 'user', 'password', '8081', 'https', 'set', 'localhost', 'cluster2', 'hdfs-site', 'config1', 'value4']
+    sys.argv = ['configs.py', '-u', 'user', '-p', 'password', '-t', '8081', '-s', 'https', '-a', 'set', '-l','localhost','-n', 'cluster2', '-c','hdfs-site', '-k', 'config1', '-v', 'value4']
     configs.main()
     configs.main()
 
 
   @patch.object(configs, 'output_to_file')
   @patch.object(configs, 'output_to_file')
@@ -159,7 +159,8 @@ class TestConfigs(TestCase):
       }
       }
     }
     }
     urlopen_method.side_effect = self.get_url_open_side_effect(response_mapping)
     urlopen_method.side_effect = self.get_url_open_side_effect(response_mapping)
-    sys.argv = ['configs.py', 'user', 'password', '8081', 'https', 'delete', 'localhost', 'cluster1', 'hdfs-site', 'config1']
+
+    sys.argv = ['configs.py', '-u', 'user', '-p', 'password', '-t', '8081', '-s', 'https', '-a', 'delete', '-l','localhost','-n', 'cluster1', '-c','hdfs-site', '-k', 'config1']
     configs.main()
     configs.main()
 
 
   @patch.object(configs, 'output_to_file')
   @patch.object(configs, 'output_to_file')
@@ -182,5 +183,30 @@ class TestConfigs(TestCase):
       }
       }
     }
     }
     urlopen_method.side_effect = self.get_url_open_side_effect(response_mapping)
     urlopen_method.side_effect = self.get_url_open_side_effect(response_mapping)
-    sys.argv = ['configs.py', 'user', 'password', '8081', 'https', 'delete', 'localhost', 'cluster2', 'hdfs-site', 'config1']
+    sys.argv = ['configs.py', '-u', 'user', '-p', 'password', '-t', '8081', '-s', 'https', '-a', 'delete', '-l','localhost','-n', 'cluster2', '-c','hdfs-site', '-k', 'config1']
+    configs.main()
+
+  @patch.object(configs, 'output_to_file')
+  @patch('urllib2.urlopen')
+  def test_set_properties_from_xml(self, urlopen_method, to_file_method):
+    response_mapping = {
+      'GET': {
+        'body': {
+          'https://localhost:8081/api/v1/clusters/cluster1?fields=Clusters/desired_configs' : '{"Clusters":{"desired_configs":{"hdfs-site":{"tag":"version1"}}}}',
+          'https://localhost:8081/api/v1/clusters/cluster1/configurations?type=hdfs-site&tag=version1': '{"items":[{"properties":{"config3": "value3", "config4": "value4"}}]}'
+        }
+      },
+      'PUT': {
+        'request_assertion': {
+          'https://localhost:8081/api/v1/clusters/cluster1':
+            lambda request_body: self.assertEquals(request_body['Clusters']['desired_configs']['properties'], {"config1": "value1", "config2": "value2"})
+        }
+      }
+    }
+    urlopen_method.side_effect = self.get_url_open_side_effect(response_mapping)
+
+    test_directory = os.path.dirname(os.path.abspath(__file__))
+    configs_path = os.path.join(test_directory, '../resources/TestConfigs-content.xml')
+
+    sys.argv = ['configs.py', '-u', 'user', '-p', 'password', '-t', '8081', '-s', 'https', '-a', 'set', '-l','localhost','-n', 'cluster1', '-c','hdfs-site', '-f', configs_path]
     configs.main()
     configs.main()

+ 28 - 0
ambari-server/src/test/resources/TestConfigs-content.xml

@@ -0,0 +1,28 @@
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+-->
+
+<configuration>
+  <property>
+    <name>config1</name>
+    <value>value1</value>
+    <final>true</final>
+  </property>
+  <property>
+    <name>config2</name>
+    <value>value2</value>
+  </property>
+</configuration>