You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by jl...@apache.org on 2017/10/09 06:01:01 UTC
[03/50] [abbrv] ambari git commit: AMBARI-22113. Unit test fails with
Python 2.6
AMBARI-22113. Unit test fails with Python 2.6
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/b4c8e840
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/b4c8e840
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/b4c8e840
Branch: refs/heads/branch-feature-AMBARI-14714
Commit: b4c8e8409edcd01c70c15453a03d59248382f515
Parents: 03696f1
Author: Attila Doroszlai <ad...@hortonworks.com>
Authored: Mon Oct 2 12:23:40 2017 +0200
Committer: Attila Doroszlai <ad...@hortonworks.com>
Committed: Tue Oct 3 11:48:55 2017 +0200
----------------------------------------------------------------------
.../libraries/functions/conf_select.py | 4 +--
.../src/test/python/TestUpgradeSummary.py | 6 ++--
.../HIVE/test_jdbc_driver_config.py | 18 +++++++----
.../RANGER/test_db_flavor_config.py | 17 ++++++++--
.../RANGER_KMS/test_db_flavor_config.py | 17 ++++++++--
.../SQOOP/test_jdbc_driver_config.py | 16 +++++++--
.../stacks/2.3/common/test_stack_advisor.py | 2 +-
.../src/test/python/stacks/utils/RMFTestCase.py | 34 ++++++++++----------
8 files changed, 76 insertions(+), 38 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/b4c8e840/ambari-common/src/main/python/resource_management/libraries/functions/conf_select.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/libraries/functions/conf_select.py b/ambari-common/src/main/python/resource_management/libraries/functions/conf_select.py
index 86821bf..f330f39 100644
--- a/ambari-common/src/main/python/resource_management/libraries/functions/conf_select.py
+++ b/ambari-common/src/main/python/resource_management/libraries/functions/conf_select.py
@@ -310,7 +310,7 @@ def convert_conf_directories_to_symlinks(package, version, dirs, skip_existing_l
old_conf = dir_def['conf_dir']
backup_dir = _get_backup_conf_directory(old_conf)
Logger.info("Backing up {0} to {1} if destination doesn't exist already.".format(old_conf, backup_dir))
- Execute(("cp", "-R", "-p", old_conf, backup_dir),
+ Execute(("cp", "-R", "-p", unicode(old_conf), unicode(backup_dir)),
not_if = format("test -e {backup_dir}"), sudo = True)
# we're already in the HDP stack
@@ -460,4 +460,4 @@ def _get_backup_conf_directory(old_conf):
"""
old_parent = os.path.abspath(os.path.join(old_conf, os.pardir))
backup_dir = os.path.join(old_parent, "conf.backup")
- return backup_dir
\ No newline at end of file
+ return backup_dir
http://git-wip-us.apache.org/repos/asf/ambari/blob/b4c8e840/ambari-server/src/test/python/TestUpgradeSummary.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestUpgradeSummary.py b/ambari-server/src/test/python/TestUpgradeSummary.py
index 7606867..6a793e4 100644
--- a/ambari-server/src/test/python/TestUpgradeSummary.py
+++ b/ambari-server/src/test/python/TestUpgradeSummary.py
@@ -49,7 +49,7 @@ class TestUpgradeSummary(TestCase):
self.assertEqual("2.4.0.0-1234", upgrade_summary.get_source_version("HDFS"))
self.assertEqual("2.5.9.9-9999", upgrade_summary.get_target_version("HDFS"))
- self.assertIsNone(upgrade_summary.get_downgrade_from_version("HDFS"))
+ self.assertTrue(upgrade_summary.get_downgrade_from_version("HDFS") is None)
def test_get_downgrade_from_version(self):
@@ -60,7 +60,7 @@ class TestUpgradeSummary(TestCase):
command_json = TestUpgradeSummary._get_cluster_simple_downgrade_json()
Script.config = command_json
- self.assertIsNone(upgrade_summary.get_downgrade_from_version("FOO"))
+ self.assertTrue(upgrade_summary.get_downgrade_from_version("FOO") is None)
self.assertEqual("2.5.9.9-9999", upgrade_summary.get_downgrade_from_version("HDFS"))
@@ -134,4 +134,4 @@ class TestUpgradeSummary(TestCase):
"isRevert":False,
"orchestration":"STANDARD"
}
- }
\ No newline at end of file
+ }
http://git-wip-us.apache.org/repos/asf/ambari/blob/b4c8e840/ambari-server/src/test/python/common-services/HIVE/test_jdbc_driver_config.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/common-services/HIVE/test_jdbc_driver_config.py b/ambari-server/src/test/python/common-services/HIVE/test_jdbc_driver_config.py
index e4d81b1..98072f9 100644
--- a/ambari-server/src/test/python/common-services/HIVE/test_jdbc_driver_config.py
+++ b/ambari-server/src/test/python/common-services/HIVE/test_jdbc_driver_config.py
@@ -36,13 +36,18 @@ class TestJdbcDriverConfig(RMFTestCase):
config_file=os.path.join(self.CONFIG_DIR, "hive_default.json"))
def test_unsupported_jdbc_type_throws_error_0_12_0_2_0(self):
- with self.assertRaises(Fail):
+ try:
self.executeScript("HIVE/0.12.0.2.0/package/scripts/hive_server.py",
classname="HiveServer",
command="configure",
target=RMFTestCase.TARGET_COMMON_SERVICES,
stack_version=self.STACK_VERSION,
config_file=os.path.join(self.CONFIG_DIR, "hive_unsupported_jdbc_type.json"))
+ self.fail("Expected 'Fail', but call completed without throwing")
+ except Fail as e:
+ pass
+ except Exception as e:
+ self.fail("Expected 'Fail', got {}".format(e))
def test_jdbc_type_2_1_0_3_0(self):
self.executeScript("HIVE/2.1.0.3.0/package/scripts/hive_server.py",
@@ -53,14 +58,15 @@ class TestJdbcDriverConfig(RMFTestCase):
config_file=os.path.join(self.CONFIG_DIR, "hive_default.json"))
def test_unsupported_jdbc_type_throws_error_2_1_0_3_0(self):
- with self.assertRaises(Fail):
+ try:
self.executeScript("HIVE/2.1.0.3.0/package/scripts/hive_server.py",
classname="HiveServer",
command="configure",
target=RMFTestCase.TARGET_COMMON_SERVICES,
stack_version=self.STACK_VERSION,
config_file=os.path.join(self.CONFIG_DIR, "hive_unsupported_jdbc_type.json"))
-
-
-
-
+ self.fail("Expected 'Fail', but call completed without throwing")
+ except Fail as e:
+ pass
+ except Exception as e:
+ self.fail("Expected 'Fail', got {}".format(e))
http://git-wip-us.apache.org/repos/asf/ambari/blob/b4c8e840/ambari-server/src/test/python/common-services/RANGER/test_db_flavor_config.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/common-services/RANGER/test_db_flavor_config.py b/ambari-server/src/test/python/common-services/RANGER/test_db_flavor_config.py
index 568e3fd..ac626d3 100644
--- a/ambari-server/src/test/python/common-services/RANGER/test_db_flavor_config.py
+++ b/ambari-server/src/test/python/common-services/RANGER/test_db_flavor_config.py
@@ -37,13 +37,19 @@ class TestDbFlavorConfig(RMFTestCase):
config_file=os.path.join(self.CONFIG_DIR, "ranger_admin_default.json"))
def test_unsupported_db_flavor_0_4_0(self):
- with self.assertRaises(Fail):
+ try:
self.executeScript("RANGER/0.4.0/package/scripts/ranger_admin.py",
classname="RangerAdmin",
command="configure",
target=RMFTestCase.TARGET_COMMON_SERVICES,
stack_version=self.STACK_VERSION,
config_file=os.path.join(self.CONFIG_DIR, "ranger_admin_unsupported_db_flavor.json"))
+ self.fail("Expected 'Fail', but call completed without throwing")
+ except Fail as e:
+ pass
+ except Exception as e:
+ self.fail("Expected 'Fail', got {}".format(e))
+
def test_db_flavor_1_0_0_3_0(self):
self.executeScript("RANGER/1.0.0.3.0/package/scripts/ranger_admin.py",
@@ -54,10 +60,15 @@ class TestDbFlavorConfig(RMFTestCase):
config_file=os.path.join(self.CONFIG_DIR, "ranger_admin_default.json"))
def test_unsupported_db_flavor_1_0_0_3_0(self):
- with self.assertRaises(Fail):
+ try:
self.executeScript("RANGER/1.0.0.3.0/package/scripts/ranger_admin.py",
classname="RangerAdmin",
command="configure",
target=RMFTestCase.TARGET_COMMON_SERVICES,
stack_version=self.STACK_VERSION,
- config_file=os.path.join(self.CONFIG_DIR, "ranger_admin_unsupported_db_flavor.json"))
\ No newline at end of file
+ config_file=os.path.join(self.CONFIG_DIR, "ranger_admin_unsupported_db_flavor.json"))
+ self.fail("Expected 'Fail', but call completed without throwing")
+ except Fail as e:
+ pass
+ except Exception as e:
+ self.fail("Expected 'Fail', got {}".format(e))
http://git-wip-us.apache.org/repos/asf/ambari/blob/b4c8e840/ambari-server/src/test/python/common-services/RANGER_KMS/test_db_flavor_config.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/common-services/RANGER_KMS/test_db_flavor_config.py b/ambari-server/src/test/python/common-services/RANGER_KMS/test_db_flavor_config.py
index 48654ee..16d271c 100644
--- a/ambari-server/src/test/python/common-services/RANGER_KMS/test_db_flavor_config.py
+++ b/ambari-server/src/test/python/common-services/RANGER_KMS/test_db_flavor_config.py
@@ -37,13 +37,19 @@ class TestDbFlavorConfig(RMFTestCase):
config_file=os.path.join(self.CONFIG_DIR, "ranger_kms_default.json"))
def test_unsupported_db_flavor_0_5_0_2_3(self):
- with self.assertRaises(Fail):
+ try:
self.executeScript("RANGER_KMS/0.5.0.2.3/package/scripts/kms_server.py",
classname="KmsServer",
command="configure",
target=RMFTestCase.TARGET_COMMON_SERVICES,
stack_version=self.STACK_VERSION,
config_file=os.path.join(self.CONFIG_DIR, "ranger_kms_unsupported_db_flavor.json"))
+ self.fail("Expected 'Fail', but call completed without throwing")
+ except Fail as e:
+ pass
+ except Exception as e:
+ self.fail("Expected 'Fail', got {}".format(e))
+
def test_db_flavor_1_0_0_3_0(self):
self.executeScript("RANGER_KMS/1.0.0.3.0/package/scripts/kms_server.py",
@@ -54,10 +60,15 @@ class TestDbFlavorConfig(RMFTestCase):
config_file=os.path.join(self.CONFIG_DIR, "ranger_kms_default.json"))
def test_unsupported_db_flavor_1_0_0_3_0(self):
- with self.assertRaises(Fail):
+ try:
self.executeScript("RANGER_KMS/1.0.0.3.0/package/scripts/kms_server.py",
classname="KmsServer",
command="configure",
target=RMFTestCase.TARGET_COMMON_SERVICES,
stack_version=self.STACK_VERSION,
- config_file=os.path.join(self.CONFIG_DIR, "ranger_kms_unsupported_db_flavor.json"))
\ No newline at end of file
+ config_file=os.path.join(self.CONFIG_DIR, "ranger_kms_unsupported_db_flavor.json"))
+ self.fail("Expected 'Fail', but call completed without throwing")
+ except Fail as e:
+ pass
+ except Exception as e:
+ self.fail("Expected 'Fail', got {}".format(e))
http://git-wip-us.apache.org/repos/asf/ambari/blob/b4c8e840/ambari-server/src/test/python/common-services/SQOOP/test_jdbc_driver_config.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/common-services/SQOOP/test_jdbc_driver_config.py b/ambari-server/src/test/python/common-services/SQOOP/test_jdbc_driver_config.py
index 7bb809a..066d526 100644
--- a/ambari-server/src/test/python/common-services/SQOOP/test_jdbc_driver_config.py
+++ b/ambari-server/src/test/python/common-services/SQOOP/test_jdbc_driver_config.py
@@ -37,13 +37,18 @@ class TestJdbcDriverConfig(RMFTestCase):
config_file=os.path.join(self.CONFIG_DIR, "sqoop_default.json"))
def test_unsupported_jdbc_driver_1_4_4_2_0(self):
- with self.assertRaises(Fail):
+ try:
self.executeScript("SQOOP/1.4.4.2.0/package/scripts/sqoop_client.py",
classname="SqoopClient",
command="configure",
target=RMFTestCase.TARGET_COMMON_SERVICES,
stack_version=self.STACK_VERSION,
config_file=os.path.join(self.CONFIG_DIR, "sqoop_unsupported_jdbc_driver.json"))
+ self.fail("Expected 'Fail', but call completed without throwing")
+ except Fail as e:
+ pass
+ except Exception as e:
+ self.fail("Expected 'Fail', got {}".format(e))
def test_jdbc_driver_1_4_4_3_0(self):
self.executeScript("SQOOP/1.4.4.3.0/package/scripts/sqoop_client.py",
@@ -54,10 +59,15 @@ class TestJdbcDriverConfig(RMFTestCase):
config_file=os.path.join(self.CONFIG_DIR, "sqoop_default.json"))
def test_unsupported_jdbc_driver_1_4_4_3_0(self):
- with self.assertRaises(Fail):
+ try:
self.executeScript("SQOOP/1.4.4.3.0/package/scripts/sqoop_client.py",
classname="SqoopClient",
command="configure",
target=RMFTestCase.TARGET_COMMON_SERVICES,
stack_version=self.STACK_VERSION,
- config_file=os.path.join(self.CONFIG_DIR, "sqoop_unsupported_jdbc_driver.json"))
\ No newline at end of file
+ config_file=os.path.join(self.CONFIG_DIR, "sqoop_unsupported_jdbc_driver.json"))
+ self.fail("Expected 'Fail', but call completed without throwing")
+ except Fail as e:
+ pass
+ except Exception as e:
+ self.fail("Expected 'Fail', got {}".format(e))
http://git-wip-us.apache.org/repos/asf/ambari/blob/b4c8e840/ambari-server/src/test/python/stacks/2.3/common/test_stack_advisor.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/2.3/common/test_stack_advisor.py b/ambari-server/src/test/python/stacks/2.3/common/test_stack_advisor.py
index 0cc9ad0..2112fa0 100644
--- a/ambari-server/src/test/python/stacks/2.3/common/test_stack_advisor.py
+++ b/ambari-server/src/test/python/stacks/2.3/common/test_stack_advisor.py
@@ -28,7 +28,7 @@ class TestHDP23StackAdvisor(TestCase):
def setUp(self):
import imp
self.maxDiff = None
- unittest.util._MAX_LENGTH=2000
+ if 'util' in dir(unittest): unittest.util._MAX_LENGTH=2000
self.testDirectory = os.path.dirname(os.path.abspath(__file__))
stackAdvisorPath = os.path.join(self.testDirectory, '../../../../../main/resources/stacks/stack_advisor.py')
hdp206StackAdvisorPath = os.path.join(self.testDirectory, '../../../../../main/resources/stacks/HDP/2.0.6/services/stack_advisor.py')
http://git-wip-us.apache.org/repos/asf/ambari/blob/b4c8e840/ambari-server/src/test/python/stacks/utils/RMFTestCase.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/utils/RMFTestCase.py b/ambari-server/src/test/python/stacks/utils/RMFTestCase.py
index 291f22b..81ac262 100644
--- a/ambari-server/src/test/python/stacks/utils/RMFTestCase.py
+++ b/ambari-server/src/test/python/stacks/utils/RMFTestCase.py
@@ -91,7 +91,7 @@ class RMFTestCase(TestCase):
elif config_dict is not None and config_file is None:
self.config_dict = config_dict
else:
- raise RuntimeError("Please specify either config_file_path or config_dict parameter")
+ raise RuntimeError("Please specify either config_file or config_dict parameter")
# add the stack tools & features from the stack if the test case's JSON file didn't have them
if "stack_tools" not in self.config_dict["configurations"]["cluster-env"]:
@@ -139,22 +139,22 @@ class RMFTestCase(TestCase):
if 'status_params' in sys.modules:
del(sys.modules["status_params"])
- with Environment(basedir, test_mode=True) as RMFTestCase.env,\
- patch('resource_management.core.shell.checked_call', side_effect=checked_call_mocks) as mocks_dict['checked_call'],\
- patch('resource_management.core.shell.call', side_effect=call_mocks) as mocks_dict['call'],\
- patch.object(Script, 'get_config', return_value=self.config_dict) as mocks_dict['get_config'],\
- patch.object(Script, 'get_tmp_dir', return_value="/tmp") as mocks_dict['get_tmp_dir'],\
- patch.object(Script, 'post_start') as mocks_dict['post_start'],\
- patch('resource_management.libraries.functions.get_kinit_path', return_value=kinit_path_local) as mocks_dict['get_kinit_path'],\
- patch.object(platform, 'linux_distribution', return_value=os_type) as mocks_dict['linux_distribution'],\
- patch('resource_management.libraries.functions.stack_select.is_package_supported', return_value=True),\
- patch('resource_management.libraries.functions.stack_select.get_supported_packages', return_value=MagicMock()),\
- patch.object(os, "environ", new=os_env) as mocks_dict['environ']:
- if not try_install:
- with patch.object(Script, 'install_packages') as install_mock_value:
- method(RMFTestCase.env, *command_args)
- else:
- method(RMFTestCase.env, *command_args)
+ with Environment(basedir, test_mode=True) as RMFTestCase.env:
+ with patch('resource_management.core.shell.checked_call', side_effect=checked_call_mocks) as mocks_dict['checked_call']:
+ with patch('resource_management.core.shell.call', side_effect=call_mocks) as mocks_dict['call']:
+ with patch.object(Script, 'get_config', return_value=self.config_dict) as mocks_dict['get_config']:
+ with patch.object(Script, 'get_tmp_dir', return_value="/tmp") as mocks_dict['get_tmp_dir']:
+ with patch.object(Script, 'post_start') as mocks_dict['post_start']:
+ with patch('resource_management.libraries.functions.get_kinit_path', return_value=kinit_path_local) as mocks_dict['get_kinit_path']:
+ with patch.object(platform, 'linux_distribution', return_value=os_type) as mocks_dict['linux_distribution']:
+ with patch('resource_management.libraries.functions.stack_select.is_package_supported', return_value=True):
+ with patch('resource_management.libraries.functions.stack_select.get_supported_packages', return_value=MagicMock()):
+ with patch.object(os, "environ", new=os_env) as mocks_dict['environ']:
+ if not try_install:
+ with patch.object(Script, 'install_packages') as install_mock_value:
+ method(RMFTestCase.env, *command_args)
+ else:
+ method(RMFTestCase.env, *command_args)
sys.path.remove(scriptsdir)