AMBARI-22040. configs.py does not work properly when dealing with files (aonishuk)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/12abba0b Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/12abba0b Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/12abba0b Branch: refs/heads/branch-3.0-ams Commit: 12abba0b743ec198067001a64608ccbcc904a869 Parents: 50b6475 Author: Andrew Onishuk <aonis...@hortonworks.com> Authored: Mon Sep 25 12:38:39 2017 +0300 Committer: Andrew Onishuk <aonis...@hortonworks.com> Committed: Mon Sep 25 12:38:39 2017 +0300 ---------------------------------------------------------------------- ambari-server/src/test/python/TestConfigs.py | 38 ++++++++++++++++---- .../src/test/resources/TestConfigs-content.xml | 28 +++++++++++++++ 2 files changed, 60 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/12abba0b/ambari-server/src/test/python/TestConfigs.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/TestConfigs.py b/ambari-server/src/test/python/TestConfigs.py index cc6cb31..6d2ab34 100644 --- a/ambari-server/src/test/python/TestConfigs.py +++ b/ambari-server/src/test/python/TestConfigs.py @@ -73,7 +73,7 @@ class TestConfigs(TestCase): self.assertEquals(config['properties'], {'config1': 'value1', 'config2': 'value2'}) urlopen_method.side_effect = self.get_url_open_side_effect(response_mapping) 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() @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) - 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() @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) - 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() @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) - 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() @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) - 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() @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) - 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() http://git-wip-us.apache.org/repos/asf/ambari/blob/12abba0b/ambari-server/src/test/resources/TestConfigs-content.xml ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/resources/TestConfigs-content.xml b/ambari-server/src/test/resources/TestConfigs-content.xml new file mode 100644 index 0000000..4039da9 --- /dev/null +++ b/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> \ No newline at end of file