http://git-wip-us.apache.org/repos/asf/ambari/blob/712b3d21/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_journalnode.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_journalnode.py b/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_journalnode.py index 4b63de4..2202661 100644 --- a/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_journalnode.py +++ b/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_journalnode.py @@ -369,120 +369,6 @@ class TestJournalnode(RMFTestCase): except: pass - @patch("resource_management.libraries.functions.security_commons.build_expectations") - @patch("resource_management.libraries.functions.security_commons.get_params_from_filesystem") - @patch("resource_management.libraries.functions.security_commons.validate_security_config_properties") - @patch("resource_management.libraries.functions.security_commons.cached_kinit_executor") - @patch("resource_management.libraries.script.Script.put_structured_out") - def test_security_status(self, put_structured_out_mock, cached_kinit_executor_mock, validate_security_config_mock, get_params_mock, build_exp_mock): - # Test that function works when is called with correct parameters - security_params = { - 'core-site': { - 'hadoop.security.authentication': 'kerberos' - }, - 'hdfs-site': { - 'dfs.journalnode.kerberos.keytab.file': 'path/to/journalnode/keytab/file', - 'dfs.journalnode.kerberos.principal': 'journalnode_principal' - } - } - - props_value_check = None - props_empty_check = ['dfs.journalnode.keytab.file', - 'dfs.journalnode.kerberos.principal'] - props_read_check = ['dfs.journalnode.keytab.file'] - - result_issues = [] - - get_params_mock.return_value = security_params - validate_security_config_mock.return_value = result_issues - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/journalnode.py", - classname = "JournalNode", - command = "security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - - build_exp_mock.assert_called_with('hdfs-site', props_value_check, props_empty_check, props_read_check) - put_structured_out_mock.assert_called_with({"securityState": "SECURED_KERBEROS"}) - cached_kinit_executor_mock.called_with('/usr/bin/kinit', - self.config_dict['configurations']['hadoop-env']['hdfs_user'], - security_params['hdfs-site']['dfs.journalnode.kerberos.keytab.file'], - security_params['hdfs-site']['dfs.journalnode.kerberos.principal'], - self.config_dict['hostname'], - '/tmp') - - # Testing when hadoop.security.authentication is simple - security_params['core-site']['hadoop.security.authentication'] = 'simple' - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/journalnode.py", - classname = "JournalNode", - command = "security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - - put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"}) - security_params['core-site']['hadoop.security.authentication'] = 'kerberos' - - # Testing that the exception throw by cached_executor is caught - cached_kinit_executor_mock.reset_mock() - cached_kinit_executor_mock.side_effect = Exception("Invalid command") - - try: - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/journalnode.py", - classname = "JournalNode", - command = "security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - except: - self.assertTrue(True) - - # Testing with a security_params which doesn't contains hdfs-site - empty_security_params = { - 'core-site': { - 'hadoop.security.authentication': 'kerberos' - } - } - cached_kinit_executor_mock.reset_mock() - get_params_mock.reset_mock() - put_structured_out_mock.reset_mock() - get_params_mock.return_value = empty_security_params - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/journalnode.py", - classname = "JournalNode", - command = "security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - - put_structured_out_mock.assert_called_with({"securityIssuesFound": "Keytab file or principal are not set property."}) - - # Testing with not empty result_issues - result_issues_with_params = { - 'hdfs-site': "Something bad happened" - } - - validate_security_config_mock.reset_mock() - get_params_mock.reset_mock() - validate_security_config_mock.return_value = result_issues_with_params - get_params_mock.return_value = security_params - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/journalnode.py", - classname = "JournalNode", - command = "security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"}) - - def test_pre_upgrade_restart(self): config_file = self.get_src_folder()+"/test/python/stacks/2.0.6/configs/default.json" with open(config_file, "r") as f:
http://git-wip-us.apache.org/repos/asf/ambari/blob/712b3d21/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_namenode.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_namenode.py b/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_namenode.py index da5d353..02edff4 100644 --- a/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_namenode.py +++ b/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_namenode.py @@ -1277,120 +1277,6 @@ class TestNamenode(RMFTestCase): self.assertTrue(isfile_mock.called) - @patch("resource_management.libraries.functions.security_commons.build_expectations") - @patch("resource_management.libraries.functions.security_commons.get_params_from_filesystem") - @patch("resource_management.libraries.functions.security_commons.validate_security_config_properties") - @patch("resource_management.libraries.functions.security_commons.cached_kinit_executor") - @patch("resource_management.libraries.script.Script.put_structured_out") - def test_security_status(self, put_structured_out_mock, cached_kinit_executor_mock, validate_security_config_mock, get_params_mock, build_exp_mock): - # Test that function works when is called with correct parameters - - security_params = { - 'core-site': { - 'hadoop.security.authentication': 'kerberos' - }, - 'hdfs-site': { - 'dfs.namenode.keytab.file': 'path/to/namenode/keytab/file', - 'dfs.namenode.kerberos.principal': 'namenode_principal' - } - } - props_value_check = None - props_empty_check = ['dfs.namenode.kerberos.internal.spnego.principal', - 'dfs.namenode.keytab.file', - 'dfs.namenode.kerberos.principal'] - props_read_check = ['dfs.namenode.keytab.file'] - - result_issues = [] - - get_params_mock.return_value = security_params - validate_security_config_mock.return_value = result_issues - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/namenode.py", - classname = "NameNode", - command = "security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - - build_exp_mock.assert_called_with('hdfs-site', props_value_check, props_empty_check, props_read_check) - put_structured_out_mock.assert_called_with({"securityState": "SECURED_KERBEROS"}) - cached_kinit_executor_mock.called_with('/usr/bin/kinit', - self.config_dict['configurations']['hadoop-env']['hdfs_user'], - security_params['hdfs-site']['dfs.namenode.keytab.file'], - security_params['hdfs-site']['dfs.namenode.kerberos.principal'], - self.config_dict['hostname'], - '/tmp') - - # Testing when hadoop.security.authentication is simple - security_params['core-site']['hadoop.security.authentication'] = 'simple' - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/namenode.py", - classname = "NameNode", - command = "security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - - put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"}) - security_params['core-site']['hadoop.security.authentication'] = 'kerberos' - - # Testing that the exception throw by cached_executor is caught - cached_kinit_executor_mock.reset_mock() - cached_kinit_executor_mock.side_effect = Exception("Invalid command") - - try: - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/namenode.py", - classname = "NameNode", - command = "security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - except: - self.assertTrue(True) - - # Testing with a security_params which doesn't contains hdfs-site - empty_security_params = { - 'core-site': { - 'hadoop.security.authentication': 'kerberos' - } - } - cached_kinit_executor_mock.reset_mock() - get_params_mock.reset_mock() - put_structured_out_mock.reset_mock() - get_params_mock.return_value = empty_security_params - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/namenode.py", - classname = "NameNode", - command = "security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - - put_structured_out_mock.assert_called_with({"securityIssuesFound": "Keytab file or principal are not set property."}) - - # Testing with not empty result_issues - result_issues_with_params = { - 'hdfs-site': "Something bad happened" - } - - validate_security_config_mock.reset_mock() - get_params_mock.reset_mock() - validate_security_config_mock.return_value = result_issues_with_params - get_params_mock.return_value = security_params - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/namenode.py", - classname = "NameNode", - command = "security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"}) - @patch.object(time, "sleep") @patch("resource_management.libraries.functions.namenode_ha_utils.get_namenode_states") def test_upgrade_restart(self, get_namenode_states_mock, sleep_mock): http://git-wip-us.apache.org/repos/asf/ambari/blob/712b3d21/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_nfsgateway.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_nfsgateway.py b/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_nfsgateway.py index 396778d..b8fee12 100644 --- a/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_nfsgateway.py +++ b/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_nfsgateway.py @@ -267,122 +267,6 @@ class TestNFSGateway(RMFTestCase): group = 'hadoop', ) - - - @patch("resource_management.libraries.functions.security_commons.build_expectations") - @patch("resource_management.libraries.functions.security_commons.get_params_from_filesystem") - @patch("resource_management.libraries.functions.security_commons.validate_security_config_properties") - @patch("resource_management.libraries.functions.security_commons.cached_kinit_executor") - @patch("resource_management.libraries.script.Script.put_structured_out") - def test_security_status(self, put_structured_out_mock, cached_kinit_executor_mock, validate_security_config_mock, get_params_mock, build_exp_mock): - # Test that function works when is called with correct parameters - security_params = { - 'core-site': { - 'hadoop.security.authentication': 'kerberos' - }, - 'hdfs-site': { - 'nfs.keytab.file': 'path/to/nfsgateway/keytab/file', - 'nfs.kerberos.principal': 'nfs_principal' - } - } - - props_value_check = None - props_empty_check = ['nfs.keytab.file', - 'nfs.kerberos.principal'] - props_read_check = ['nfs.keytab.file'] - - result_issues = [] - - get_params_mock.return_value = security_params - validate_security_config_mock.return_value = result_issues - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/nfsgateway.py", - classname = "NFSGateway", - command = "security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - - build_exp_mock.assert_called_with('hdfs-site', props_value_check, props_empty_check, props_read_check) - put_structured_out_mock.assert_called_with({"securityState": "SECURED_KERBEROS"}) - cached_kinit_executor_mock.called_with('/usr/bin/kinit', - self.config_dict['configurations']['hadoop-env']['hdfs_user'], - security_params['hdfs-site']['nfs.keytab.file'], - security_params['hdfs-site']['nfs.kerberos.principal'], - self.config_dict['hostname'], - '/tmp') - - # Testing when hadoop.security.authentication is simple - security_params['core-site']['hadoop.security.authentication'] = 'simple' - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/nfsgateway.py", - classname = "NFSGateway", - command = "security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - - put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"}) - security_params['core-site']['hadoop.security.authentication'] = 'kerberos' - - # Testing that the exception throw by cached_executor is caught - cached_kinit_executor_mock.reset_mock() - cached_kinit_executor_mock.side_effect = Exception("Invalid command") - - try: - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/nfsgateway.py", - classname = "NFSGateway", - command = "security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - except: - self.assertTrue(True) - - # Testing with a security_params which doesn't contains hdfs-site - empty_security_params = { - 'core-site': { - 'hadoop.security.authentication': 'kerberos' - } - } - cached_kinit_executor_mock.reset_mock() - get_params_mock.reset_mock() - put_structured_out_mock.reset_mock() - get_params_mock.return_value = empty_security_params - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/nfsgateway.py", - classname = "NFSGateway", - command = "security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - - put_structured_out_mock.assert_called_with({"securityIssuesFound": "Keytab file or principal are not set property."}) - - # Testing with not empty result_issues - result_issues_with_params = { - 'hdfs-site': "Something bad happened" - } - - validate_security_config_mock.reset_mock() - get_params_mock.reset_mock() - validate_security_config_mock.return_value = result_issues_with_params - get_params_mock.return_value = security_params - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/nfsgateway.py", - classname = "NFSGateway", - command = "security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"}) - self.assertNoMoreResources() - @patch("resource_management.core.shell.call") def test_pre_upgrade_restart(self, call_mock): call_mock.side_effects = [(0, None), (0, None)] http://git-wip-us.apache.org/repos/asf/ambari/blob/712b3d21/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_snamenode.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_snamenode.py b/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_snamenode.py index 7b9dcb4..9e9366d 100644 --- a/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_snamenode.py +++ b/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_snamenode.py @@ -274,119 +274,4 @@ class TestSNamenode(RMFTestCase): mode = 0755, create_parents = True, cd_access='a' - ) - - @patch("resource_management.libraries.functions.security_commons.build_expectations") - @patch("resource_management.libraries.functions.security_commons.get_params_from_filesystem") - @patch("resource_management.libraries.functions.security_commons.validate_security_config_properties") - @patch("resource_management.libraries.functions.security_commons.cached_kinit_executor") - @patch("resource_management.libraries.script.Script.put_structured_out") - def test_security_status(self, put_structured_out_mock, cached_kinit_executor_mock, validate_security_config_mock, get_params_mock, build_exp_mock): - # Test that function works when is called with correct parameters - - security_params = { - 'core-site': { - 'hadoop.security.authentication': 'kerberos' - }, - 'hdfs-site': { - 'dfs.secondary.namenode.keytab.file': 'path/to/snamenode/keytab/file', - 'dfs.secondary.namenode.kerberos.principal': 'snamenode_principal' - } - } - - props_value_check = None - props_empty_check = ['dfs.secondary.namenode.kerberos.internal.spnego.principal', - 'dfs.secondary.namenode.keytab.file', - 'dfs.secondary.namenode.kerberos.principal'] - props_read_check = ['dfs.secondary.namenode.keytab.file'] - - result_issues = [] - - get_params_mock.return_value = security_params - validate_security_config_mock.return_value = result_issues - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/snamenode.py", - classname = "SNameNode", - command = "security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - - build_exp_mock.assert_called_with('hdfs-site', props_value_check, props_empty_check, props_read_check) - put_structured_out_mock.assert_called_with({"securityState": "SECURED_KERBEROS"}) - cached_kinit_executor_mock.called_with('/usr/bin/kinit', - self.config_dict['configurations']['hadoop-env']['hdfs_user'], - security_params['hdfs-site']['dfs.secondary.namenode.keytab.file'], - security_params['hdfs-site']['dfs.secondary.namenode.kerberos.principal'], - self.config_dict['hostname'], - '/tmp') - - # Testing when hadoop.security.authentication is simple - security_params['core-site']['hadoop.security.authentication'] = 'simple' - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/snamenode.py", - classname = "SNameNode", - command = "security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - - put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"}) - security_params['core-site']['hadoop.security.authentication'] = 'kerberos' - - # Testing that the exception throw by cached_executor is caught - cached_kinit_executor_mock.reset_mock() - cached_kinit_executor_mock.side_effect = Exception("Invalid command") - - try: - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/snamenode.py", - classname = "SNameNode", - command = "security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - except: - self.assertTrue(True) - - # Testing with a security_params which doesn't contains hdfs-site - empty_security_params = { - 'core-site': { - 'hadoop.security.authentication': 'kerberos' - } - } - cached_kinit_executor_mock.reset_mock() - get_params_mock.reset_mock() - put_structured_out_mock.reset_mock() - get_params_mock.return_value = empty_security_params - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/snamenode.py", - classname = "SNameNode", - command = "security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - - put_structured_out_mock.assert_called_with({"securityIssuesFound": "Keytab file or principal are not set property."}) - - # Testing with not empty result_issues - result_issues_with_params = { - 'hdfs-site': "Something bad happened" - } - - validate_security_config_mock.reset_mock() - get_params_mock.reset_mock() - validate_security_config_mock.return_value = result_issues_with_params - get_params_mock.return_value = security_params - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/snamenode.py", - classname = "SNameNode", - command = "security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"}) \ No newline at end of file + ) \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/712b3d21/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_zkfc.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_zkfc.py b/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_zkfc.py index 0f64291..ca1a5ba 100644 --- a/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_zkfc.py +++ b/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_zkfc.py @@ -382,103 +382,3 @@ class TestZkfc(RMFTestCase): not_if = "ambari-sudo.sh [RMF_ENV_PLACEHOLDER] -H -E test -f /var/run/hadoop/hdfs/hadoop-hdfs-zkfc.pid && ambari-sudo.sh [RMF_ENV_PLACEHOLDER] -H -E pgrep -F /var/run/hadoop/hdfs/hadoop-hdfs-zkfc.pid", ) self.assertNoMoreResources() - - - @patch("resource_management.libraries.functions.security_commons.build_expectations") - @patch("resource_management.libraries.functions.security_commons.get_params_from_filesystem") - @patch("resource_management.libraries.functions.security_commons.validate_security_config_properties") - @patch("resource_management.libraries.functions.security_commons.cached_kinit_executor") - @patch("resource_management.libraries.script.Script.put_structured_out") - def test_security_status(self, put_structured_out_mock, cached_kinit_executor_mock, validate_security_config_mock, get_params_mock, build_exp_mock): - - # Test that function works when is called with correct parameters - security_params = { - 'core-site': { - 'hadoop.security.authentication': 'kerberos' - } - } - - props_value_check = {"hadoop.security.authentication": "kerberos", - "hadoop.security.authorization": "true"} - props_empty_check = ["hadoop.security.auth_to_local"] - props_read_check = None - - result_issues = [] - - get_params_mock.return_value = security_params - validate_security_config_mock.return_value = result_issues - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/zkfc_slave.py", - classname = "ZkfcSlave", - command = "security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - - build_exp_mock.assert_called_with('core-site', props_value_check, props_empty_check, props_read_check) - put_structured_out_mock.assert_called_with({"securityState": "SECURED_KERBEROS"}) - cached_kinit_executor_mock.called_with('/usr/bin/kinit', - self.config_dict['configurations']['hadoop-env']['hdfs_user'], - self.config_dict['configurations']['hadoop-env']['hdfs_user_keytab'], - self.config_dict['configurations']['hadoop-env']['hdfs_user_principal_name'], - self.config_dict['hostname'], - '/tmp') - - # Testing that the exception throw by cached_executor is caught - cached_kinit_executor_mock.reset_mock() - cached_kinit_executor_mock.side_effect = Exception("Invalid command") - - try: - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/zkfc_slave.py", - classname = "ZkfcSlave", - command = "security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - except: - self.assertTrue(True) - - # Testing when hadoop.security.authentication is simple - security_params['core-site']['hadoop.security.authentication'] = 'simple' - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/zkfc_slave.py", - classname = "ZkfcSlave", - command = "security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - - put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"}) - security_params['core-site']['hadoop.security.authentication'] = 'kerberos' - - # Testing with not empty result_issues - result_issues_with_params = { - 'hdfs-site': "Something bad happened" - } - - validate_security_config_mock.reset_mock() - get_params_mock.reset_mock() - validate_security_config_mock.return_value = result_issues_with_params - get_params_mock.return_value = security_params - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/zkfc_slave.py", - classname = "ZkfcSlave", - command = "security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"}) - - # Testing with empty hdfs_user_principal and hdfs_user_keytab - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/zkfc_slave.py", - classname = "ZkfcSlave", - command = "security_status", - config_file="default.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"}) http://git-wip-us.apache.org/repos/asf/ambari/blob/712b3d21/ambari-server/src/test/python/stacks/2.0.6/HIVE/test_hive_server.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/stacks/2.0.6/HIVE/test_hive_server.py b/ambari-server/src/test/python/stacks/2.0.6/HIVE/test_hive_server.py index 52156ab..5a4f8d9 100644 --- a/ambari-server/src/test/python/stacks/2.0.6/HIVE/test_hive_server.py +++ b/ambari-server/src/test/python/stacks/2.0.6/HIVE/test_hive_server.py @@ -850,118 +850,6 @@ From source with checksum 150f554beae04f76f814f59549dead8b""" self.assertNoMoreResources() - @patch("resource_management.libraries.functions.security_commons.build_expectations") - @patch("resource_management.libraries.functions.security_commons.get_params_from_filesystem") - @patch("resource_management.libraries.functions.security_commons.validate_security_config_properties") - @patch("resource_management.libraries.functions.security_commons.cached_kinit_executor") - @patch("resource_management.libraries.script.Script.put_structured_out") - def test_security_status(self, put_structured_out_mock, cached_kinit_executor_mock, validate_security_config_mock, get_params_mock, build_exp_mock): - # Test that function works when is called with correct parameters - - security_params = { - 'hive-site': { - "hive.server2.authentication": "KERBEROS", - "hive.metastore.sasl.enabled": "true", - "hive.security.authorization.enabled": "true", - "hive.server2.authentication.kerberos.keytab": "path/to/keytab", - "hive.server2.authentication.kerberos.principal": "principal", - "hive.server2.authentication.spnego.keytab": "path/to/spnego_keytab", - "hive.server2.authentication.spnego.principal": "spnego_principal" - } - } - result_issues = [] - props_value_check = {"hive.server2.authentication": "KERBEROS", - "hive.metastore.sasl.enabled": "true", - "hive.security.authorization.enabled": "true"} - props_empty_check = ["hive.server2.authentication.kerberos.keytab", - "hive.server2.authentication.kerberos.principal", - "hive.server2.authentication.spnego.principal", - "hive.server2.authentication.spnego.keytab"] - - props_read_check = ["hive.server2.authentication.kerberos.keytab", - "hive.server2.authentication.spnego.keytab"] - - get_params_mock.return_value = security_params - validate_security_config_mock.return_value = result_issues - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/hive_server.py", - classname = "HiveServer", - command = "security_status", - config_file="../../2.1/configs/secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - - get_params_mock.assert_called_with('/usr/hdp/current/hive-server2/conf', {'hive-site.xml': "XML"}) - build_exp_mock.assert_called_with('hive-site', props_value_check, props_empty_check, props_read_check) - put_structured_out_mock.assert_called_with({"securityState": "SECURED_KERBEROS"}) - self.assertTrue(cached_kinit_executor_mock.call_count, 2) - cached_kinit_executor_mock.assert_called_with('/usr/bin/kinit', - self.config_dict['configurations']['hive-env']['hive_user'], - security_params['hive-site']['hive.server2.authentication.spnego.keytab'], - security_params['hive-site']['hive.server2.authentication.spnego.principal'], - self.config_dict['hostname'], - '/tmp') - - # Testing that the exception throw by cached_executor is caught - cached_kinit_executor_mock.reset_mock() - cached_kinit_executor_mock.side_effect = Exception("Invalid command") - - try: - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/hive_server.py", - classname = "HiveServer", - command = "security_status", - config_file="../../2.1/configs/secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - except: - self.assertTrue(True) - - # Testing with a security_params which doesn't contains startup - empty_security_params = {} - cached_kinit_executor_mock.reset_mock() - get_params_mock.reset_mock() - put_structured_out_mock.reset_mock() - get_params_mock.return_value = empty_security_params - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/hive_server.py", - classname = "HiveServer", - command = "security_status", - config_file="../../2.1/configs/secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - put_structured_out_mock.assert_called_with({"securityIssuesFound": "Keytab file or principal are not set property."}) - - # Testing with not empty result_issues - result_issues_with_params = {} - result_issues_with_params['hive-site']="Something bad happened" - - validate_security_config_mock.reset_mock() - get_params_mock.reset_mock() - validate_security_config_mock.return_value = result_issues_with_params - get_params_mock.return_value = security_params - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/hive_server.py", - classname = "HiveServer", - command = "security_status", - config_file="../../2.1/configs/secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"}) - - # Testing with security_enable = false - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/hive_server.py", - classname = "HiveServer", - command = "security_status", - config_file="../../2.1/configs/default.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"}) - @patch("resource_management.libraries.functions.copy_tarball.copy_to_hdfs") def test_pre_upgrade_restart(self, copy_to_hdfs_mock): copy_to_hdfs_mock.return_value = True http://git-wip-us.apache.org/repos/asf/ambari/blob/712b3d21/ambari-server/src/test/python/stacks/2.0.6/HIVE/test_webhcat_server.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/stacks/2.0.6/HIVE/test_webhcat_server.py b/ambari-server/src/test/python/stacks/2.0.6/HIVE/test_webhcat_server.py index 718ad4d..03dd391 100644 --- a/ambari-server/src/test/python/stacks/2.0.6/HIVE/test_webhcat_server.py +++ b/ambari-server/src/test/python/stacks/2.0.6/HIVE/test_webhcat_server.py @@ -276,122 +276,6 @@ class TestWebHCatServer(RMFTestCase): mode = 0644, ) - @patch("resource_management.libraries.functions.security_commons.build_expectations") - @patch("resource_management.libraries.functions.security_commons.get_params_from_filesystem") - @patch("resource_management.libraries.functions.security_commons.validate_security_config_properties") - @patch("resource_management.libraries.functions.security_commons.cached_kinit_executor") - @patch("resource_management.libraries.script.Script.put_structured_out") - def test_security_status(self, put_structured_out_mock, cached_kinit_executor_mock, validate_security_config_mock, get_params_mock, build_exp_mock): - # Test that function works when is called with correct parameters - - security_params = { - 'webhcat-site': { - "templeton.kerberos.secret": "secret", - "templeton.kerberos.keytab": 'path/to/keytab', - "templeton.kerberos.principal": "principal" - }, - "hive-site": { - "hive.server2.authentication": "KERBEROS", - "hive.metastore.sasl.enabled": "true", - "hive.security.authorization.enabled": "true" - } - } - result_issues = [] - webhcat_props_value_check = {"templeton.kerberos.secret": "secret"} - webhcat_props_empty_check = ["templeton.kerberos.keytab", - "templeton.kerberos.principal"] - webhcat_props_read_check = ["templeton.kerberos.keytab"] - - hive_props_value_check = {"hive.server2.authentication": "KERBEROS", - "hive.metastore.sasl.enabled": "true", - "hive.security.authorization.enabled": "true"} - hive_props_empty_check = None - hive_props_read_check = None - - get_params_mock.return_value = security_params - validate_security_config_mock.return_value = result_issues - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/webhcat_server.py", - classname = "WebHCatServer", - command = "security_status", - config_file="../../2.1/configs/secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - - build_exp_mock.assert_called_with('hive-site', hive_props_value_check, hive_props_empty_check, hive_props_read_check) - # get_params_mock.assert_called_with(status_params.hive_conf_dir, {'hive-site.xml': "XML"}) - get_params_mock.assert_called_with('/usr/hdp/current/hive-webhcat/conf', {'webhcat-site.xml': "XML"}) - put_structured_out_mock.assert_called_with({"securityState": "SECURED_KERBEROS"}) - self.assertTrue(cached_kinit_executor_mock.call_count, 2) - cached_kinit_executor_mock.assert_called_with('/usr/bin/kinit', - self.config_dict['configurations']['hive-env']['webhcat_user'], - security_params['webhcat-site']['templeton.kerberos.keytab'], - security_params['webhcat-site']['templeton.kerberos.principal'], - self.config_dict['hostname'], - '/tmp') - - # Testing that the exception throw by cached_executor is caught - cached_kinit_executor_mock.reset_mock() - cached_kinit_executor_mock.side_effect = Exception("Invalid command") - - try: - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/webhcat_server.py", - classname = "WebHCatServer", - command = "security_status", - config_file="../../2.1/configs/secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - except: - self.assertTrue(True) - - # Testing with a security_params which doesn't contains startup - empty_security_params = {} - cached_kinit_executor_mock.reset_mock() - get_params_mock.reset_mock() - put_structured_out_mock.reset_mock() - get_params_mock.return_value = empty_security_params - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/webhcat_server.py", - classname = "WebHCatServer", - command = "security_status", - config_file="../../2.1/configs/secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - put_structured_out_mock.assert_called_with({"securityIssuesFound": "Keytab file or principal are not set property."}) - - # Testing with not empty result_issues - result_issues_with_params = { - 'hive-site': "Something bad happened" - } - - validate_security_config_mock.reset_mock() - get_params_mock.reset_mock() - validate_security_config_mock.return_value = result_issues_with_params - get_params_mock.return_value = security_params - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/webhcat_server.py", - classname = "WebHCatServer", - command = "security_status", - config_file="../../2.1/configs/secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"}) - - # Testing with security_enable = false - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/webhcat_server.py", - classname = "WebHCatServer", - command = "security_status", - config_file="../../2.1/configs/default.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"}) - - def test_pre_upgrade_restart(self): config_file = self.get_src_folder()+"/test/python/stacks/2.0.6/configs/default.json" with open(config_file, "r") as f: http://git-wip-us.apache.org/repos/asf/ambari/blob/712b3d21/ambari-server/src/test/python/stacks/2.0.6/OOZIE/test_oozie_server.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/stacks/2.0.6/OOZIE/test_oozie_server.py b/ambari-server/src/test/python/stacks/2.0.6/OOZIE/test_oozie_server.py index f5bd4aa..426c36a 100644 --- a/ambari-server/src/test/python/stacks/2.0.6/OOZIE/test_oozie_server.py +++ b/ambari-server/src/test/python/stacks/2.0.6/OOZIE/test_oozie_server.py @@ -1150,119 +1150,6 @@ class TestOozieServer(RMFTestCase): ) self.assert_configure_default() - @patch("resource_management.libraries.functions.security_commons.build_expectations") - @patch("resource_management.libraries.functions.security_commons.get_params_from_filesystem") - @patch("resource_management.libraries.functions.security_commons.validate_security_config_properties") - @patch("resource_management.libraries.functions.security_commons.cached_kinit_executor") - @patch("resource_management.libraries.script.Script.put_structured_out") - def test_security_status(self, put_structured_out_mock, cached_kinit_executor_mock, validate_security_config_mock, get_params_mock, build_exp_mock): - # Test that function works when is called with correct parameters - security_params = { - "oozie-site": { - "oozie.authentication.type": "kerberos", - "oozie.service.AuthorizationService.security.enabled": "true", - "oozie.service.HadoopAccessorService.kerberos.enabled": "true", - "local.realm": "EXAMPLE.COM", - "oozie.authentication.kerberos.principal": "principal", - "oozie.authentication.kerberos.keytab": "/path/to_keytab", - "oozie.service.HadoopAccessorService.kerberos.principal": "principal", - "oozie.service.HadoopAccessorService.keytab.file": "/path/to_keytab"} - } - - result_issues = [] - props_value_check = {"oozie.authentication.type": "kerberos", - "oozie.service.AuthorizationService.security.enabled": "true", - "oozie.service.HadoopAccessorService.kerberos.enabled": "true"} - props_empty_check = [ "local.realm", - "oozie.authentication.kerberos.principal", - "oozie.authentication.kerberos.keytab", - "oozie.service.HadoopAccessorService.kerberos.principal", - "oozie.service.HadoopAccessorService.keytab.file"] - props_read_check = None - - get_params_mock.return_value = security_params - validate_security_config_mock.return_value = result_issues - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py", - classname = "OozieServer", - command = "security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - - get_params_mock.assert_called_with("/etc/oozie/conf", {'oozie-site.xml': 'XML'}) - build_exp_mock.assert_called_with('oozie-site', props_value_check, props_empty_check, props_read_check) - put_structured_out_mock.assert_called_with({"securityState": "SECURED_KERBEROS"}) - self.assertTrue(cached_kinit_executor_mock.call_count, 2) - cached_kinit_executor_mock.assert_called_with('/usr/bin/kinit', - self.config_dict['configurations']['oozie-env']['oozie_user'], - security_params['oozie-site']['oozie.service.HadoopAccessorService.keytab.file'], - security_params['oozie-site']['oozie.service.HadoopAccessorService.kerberos.principal'], - self.config_dict['hostname'], - '/tmp') - - # Testing that the exception throw by cached_executor is caught - cached_kinit_executor_mock.reset_mock() - cached_kinit_executor_mock.side_effect = Exception("Invalid command") - - try: - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py", - classname = "OozieServer", - command = "security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - except: - self.assertTrue(True) - - # Testing with a security_params which doesn't contains oozie-site - empty_security_params = {} - cached_kinit_executor_mock.reset_mock() - get_params_mock.reset_mock() - put_structured_out_mock.reset_mock() - get_params_mock.return_value = empty_security_params - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py", - classname = "OozieServer", - command = "security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - put_structured_out_mock.assert_called_with({"securityIssuesFound": "Keytab file or principal are not set property."}) - - # Testing with not empty result_issues - result_issues_with_params = { - 'oozie-site': "Something bad happened" - } - - validate_security_config_mock.reset_mock() - get_params_mock.reset_mock() - validate_security_config_mock.return_value = result_issues_with_params - get_params_mock.return_value = security_params - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py", - classname = "OozieServer", - command = "security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"}) - - # Testing with security_enable = false - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/oozie_server.py", - classname = "OozieServer", - command = "security_status", - config_file="default.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"}) - - @patch("os.path.isdir") @patch("os.path.exists") @patch("os.path.isfile") http://git-wip-us.apache.org/repos/asf/ambari/blob/712b3d21/ambari-server/src/test/python/stacks/2.0.6/YARN/test_historyserver.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/stacks/2.0.6/YARN/test_historyserver.py b/ambari-server/src/test/python/stacks/2.0.6/YARN/test_historyserver.py index e5449d3..4f22416 100644 --- a/ambari-server/src/test/python/stacks/2.0.6/YARN/test_historyserver.py +++ b/ambari-server/src/test/python/stacks/2.0.6/YARN/test_historyserver.py @@ -742,112 +742,6 @@ class TestHistoryServer(RMFTestCase): group = 'hadoop', ) - @patch("resource_management.libraries.functions.security_commons.build_expectations") - @patch("resource_management.libraries.functions.security_commons.get_params_from_filesystem") - @patch("resource_management.libraries.functions.security_commons.validate_security_config_properties") - @patch("resource_management.libraries.functions.security_commons.cached_kinit_executor") - @patch("resource_management.libraries.script.Script.put_structured_out") - def test_security_status(self, put_structured_out_mock, cached_kinit_executor_mock, validate_security_config_mock, get_params_mock, build_exp_mock): - # Test that function works when is called with correct parameters - - security_params = { - "mapred-site": { - 'mapreduce.jobhistory.keytab': "/path/to/keytab1", - 'mapreduce.jobhistory.principal': "principal1", - 'mapreduce.jobhistory.webapp.spnego-keytab-file': "/path/to/keytab2", - 'mapreduce.jobhistory.webapp.spnego-principal': "principal2" - } - } - result_issues = [] - - get_params_mock.return_value = security_params - validate_security_config_mock.return_value = result_issues - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/historyserver.py", - classname="HistoryServer", - command="security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - - get_params_mock.assert_called_with("/etc/hadoop/conf", {'mapred-site.xml': 'XML'}) - build_exp_mock.assert_called_with('mapred-site', - None, - [ - 'mapreduce.jobhistory.keytab', - 'mapreduce.jobhistory.principal', - 'mapreduce.jobhistory.webapp.spnego-keytab-file', - 'mapreduce.jobhistory.webapp.spnego-principal' - ], - None) - put_structured_out_mock.assert_called_with({"securityState": "SECURED_KERBEROS"}) - self.assertTrue(cached_kinit_executor_mock.call_count, 2) - cached_kinit_executor_mock.assert_called_with('/usr/bin/kinit', - self.config_dict['configurations']['mapred-env']['mapred_user'], - security_params['mapred-site']['mapreduce.jobhistory.webapp.spnego-keytab-file'], - security_params['mapred-site']['mapreduce.jobhistory.webapp.spnego-principal'], - self.config_dict['hostname'], - '/tmp') - - # Testing that the exception throw by cached_executor is caught - cached_kinit_executor_mock.reset_mock() - cached_kinit_executor_mock.side_effect = Exception("Invalid command") - - try: - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/historyserver.py", - classname="HistoryServer", - command="security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - except: - self.assertTrue(True) - - # Testing with a security_params which doesn't contain mapred-site - empty_security_params = {} - cached_kinit_executor_mock.reset_mock() - get_params_mock.reset_mock() - put_structured_out_mock.reset_mock() - get_params_mock.return_value = empty_security_params - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/historyserver.py", - classname="HistoryServer", - command="security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - put_structured_out_mock.assert_called_with({"securityIssuesFound": "Keytab file or principal not set."}) - - # Testing with not empty result_issues - result_issues_with_params = {'mapred-site': "Something bad happened"} - - validate_security_config_mock.reset_mock() - get_params_mock.reset_mock() - validate_security_config_mock.return_value = result_issues_with_params - get_params_mock.return_value = security_params - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/historyserver.py", - classname="HistoryServer", - command="security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"}) - - # Testing with security_enable = false - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/historyserver.py", - classname="HistoryServer", - command="security_status", - config_file="default.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"}) - def assert_call_to_get_hadoop_conf_dir(self): # From call to conf_select.get_hadoop_conf_dir() self.assertResourceCalled("Execute", ("cp", "-R", "-p", "/etc/hadoop/conf", "/etc/hadoop/conf.backup"), http://git-wip-us.apache.org/repos/asf/ambari/blob/712b3d21/ambari-server/src/test/python/stacks/2.0.6/YARN/test_nodemanager.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/stacks/2.0.6/YARN/test_nodemanager.py b/ambari-server/src/test/python/stacks/2.0.6/YARN/test_nodemanager.py index ab5e2cd..63c8a90 100644 --- a/ambari-server/src/test/python/stacks/2.0.6/YARN/test_nodemanager.py +++ b/ambari-server/src/test/python/stacks/2.0.6/YARN/test_nodemanager.py @@ -628,115 +628,6 @@ class TestNodeManager(RMFTestCase): self.assertTrue(mocks_dict['call'].called) self.assertEqual(mocks_dict['call'].call_count,1) - @patch("resource_management.libraries.functions.security_commons.build_expectations") - @patch("resource_management.libraries.functions.security_commons.get_params_from_filesystem") - @patch("resource_management.libraries.functions.security_commons.validate_security_config_properties") - @patch("resource_management.libraries.functions.security_commons.cached_kinit_executor") - @patch("resource_management.libraries.script.Script.put_structured_out") - def test_security_status(self, put_structured_out_mock, cached_kinit_executor_mock, validate_security_config_mock, get_params_mock, build_exp_mock): - # Test that function works when is called with correct parameters - - security_params = { - 'yarn-site': { - 'yarn.nodemanager.keytab': 'path/to/nodemanager/keytab', - 'yarn.nodemanager.principal': 'nodemanager_principal', - 'yarn.nodemanager.webapp.spnego-keytab-file': 'path/to/nodemanager/webapp/keytab', - 'yarn.nodemanager.webapp.spnego-principal': 'nodemanager_webapp_principal' - } - } - result_issues = [] - props_value_check = {"yarn.timeline-service.http-authentication.type": "kerberos", - "yarn.acl.enable": "true"} - props_empty_check = ["yarn.nodemanager.principal", - "yarn.nodemanager.keytab", - "yarn.nodemanager.webapp.spnego-principal", - "yarn.nodemanager.webapp.spnego-keytab-file"] - - props_read_check = ["yarn.nodemanager.keytab", - "yarn.nodemanager.webapp.spnego-keytab-file"] - - get_params_mock.return_value = security_params - validate_security_config_mock.return_value = result_issues - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/nodemanager.py", - classname="Nodemanager", - command="security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - - build_exp_mock.assert_called_with('yarn-site', props_value_check, props_empty_check, props_read_check) - put_structured_out_mock.assert_called_with({"securityState": "SECURED_KERBEROS"}) - self.assertTrue(cached_kinit_executor_mock.call_count, 2) - cached_kinit_executor_mock.assert_called_with('/usr/bin/kinit', - self.config_dict['configurations']['yarn-env']['yarn_user'], - security_params['yarn-site']['yarn.nodemanager.webapp.spnego-keytab-file'], - security_params['yarn-site']['yarn.nodemanager.webapp.spnego-principal'], - self.config_dict['hostname'], - '/tmp') - - # Testing that the exception throw by cached_executor is caught - cached_kinit_executor_mock.reset_mock() - cached_kinit_executor_mock.side_effect = Exception("Invalid command") - - try: - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/nodemanager.py", - classname="Nodemanager", - command="security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - except: - self.assertTrue(True) - - # Testing with a security_params which doesn't contains yarn-site - empty_security_params = {} - cached_kinit_executor_mock.reset_mock() - get_params_mock.reset_mock() - put_structured_out_mock.reset_mock() - get_params_mock.return_value = empty_security_params - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/nodemanager.py", - classname="Nodemanager", - command="security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - put_structured_out_mock.assert_called_with({"securityIssuesFound": "Keytab file or principal are not set property."}) - - # Testing with not empty result_issues - result_issues_with_params = { - 'yarn-site': "Something bad happened" - } - - validate_security_config_mock.reset_mock() - get_params_mock.reset_mock() - validate_security_config_mock.return_value = result_issues_with_params - get_params_mock.return_value = security_params - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/nodemanager.py", - classname="Nodemanager", - command="security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"}) - - # Testing with security_enable = false - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/nodemanager.py", - classname="Nodemanager", - command="security_status", - config_file="default.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"}) - - @patch.object(resource_management.libraries.functions, "get_stack_version", new = MagicMock(return_value='2.3.0.0-1234')) def test_pre_upgrade_restart_23(self): config_file = self.get_src_folder()+"/test/python/stacks/2.0.6/configs/default.json" http://git-wip-us.apache.org/repos/asf/ambari/blob/712b3d21/ambari-server/src/test/python/stacks/2.0.6/YARN/test_resourcemanager.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/stacks/2.0.6/YARN/test_resourcemanager.py b/ambari-server/src/test/python/stacks/2.0.6/YARN/test_resourcemanager.py index dc40e5e..1616e18 100644 --- a/ambari-server/src/test/python/stacks/2.0.6/YARN/test_resourcemanager.py +++ b/ambari-server/src/test/python/stacks/2.0.6/YARN/test_resourcemanager.py @@ -527,114 +527,6 @@ class TestResourceManager(RMFTestCase): group = 'hadoop', ) - @patch("resource_management.libraries.functions.security_commons.build_expectations") - @patch("resource_management.libraries.functions.security_commons.get_params_from_filesystem") - @patch("resource_management.libraries.functions.security_commons.validate_security_config_properties") - @patch("resource_management.libraries.functions.security_commons.cached_kinit_executor") - @patch("resource_management.libraries.script.Script.put_structured_out") - def test_security_status(self, put_structured_out_mock, cached_kinit_executor_mock, validate_security_config_mock, get_params_mock, build_exp_mock): - # Test that function works when is called with correct parameters - - security_params = { - 'yarn-site': { - 'yarn.resourcemanager.keytab': '/path/to/resourcemanager/keytab', - 'yarn.resourcemanager.principal': 'nresourcemanager_principal', - 'yarn.resourcemanager.webapp.spnego-keytab-file': 'path/to/resourcemanager/webapp/keytab', - 'yarn.resourcemanager.webapp.spnego-principal': 'resourcemanager_webapp_principal' - } - } - result_issues = [] - props_value_check = {"yarn.timeline-service.http-authentication.type": "kerberos", - "yarn.acl.enable": "true"} - props_empty_check = ["yarn.resourcemanager.principal", - "yarn.resourcemanager.keytab", - "yarn.resourcemanager.webapp.spnego-principal", - "yarn.resourcemanager.webapp.spnego-keytab-file"] - - props_read_check = ["yarn.resourcemanager.keytab", - "yarn.resourcemanager.webapp.spnego-keytab-file"] - - get_params_mock.return_value = security_params - validate_security_config_mock.return_value = result_issues - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/resourcemanager.py", - classname="Resourcemanager", - command="security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - - build_exp_mock.assert_called_with('yarn-site', props_value_check, props_empty_check, props_read_check) - put_structured_out_mock.assert_called_with({"securityState": "SECURED_KERBEROS"}) - self.assertTrue(cached_kinit_executor_mock.call_count, 2) - cached_kinit_executor_mock.assert_called_with('/usr/bin/kinit', - self.config_dict['configurations']['yarn-env']['yarn_user'], - security_params['yarn-site']['yarn.resourcemanager.webapp.spnego-keytab-file'], - security_params['yarn-site']['yarn.resourcemanager.webapp.spnego-principal'], - self.config_dict['hostname'], - '/tmp') - - # Testing that the exception throw by cached_executor is caught - cached_kinit_executor_mock.reset_mock() - cached_kinit_executor_mock.side_effect = Exception("Invalid command") - - try: - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/resourcemanager.py", - classname="Resourcemanager", - command="security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - except: - self.assertTrue(True) - - # Testing with a security_params which doesn't contains yarn-site - empty_security_params = {} - cached_kinit_executor_mock.reset_mock() - get_params_mock.reset_mock() - put_structured_out_mock.reset_mock() - get_params_mock.return_value = empty_security_params - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/resourcemanager.py", - classname="Resourcemanager", - command="security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - put_structured_out_mock.assert_called_with({"securityIssuesFound": "Keytab file or principal are not set property."}) - - # Testing with not empty result_issues - result_issues_with_params = { - 'yarn-site': "Something bad happened" - } - - validate_security_config_mock.reset_mock() - get_params_mock.reset_mock() - validate_security_config_mock.return_value = result_issues_with_params - get_params_mock.return_value = security_params - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/resourcemanager.py", - classname="Resourcemanager", - command="security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"}) - - # Testing with security_enable = false - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/resourcemanager.py", - classname="Resourcemanager", - command="security_status", - config_file="default.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"}) - def test_pre_upgrade_restart_23(self): config_file = self.get_src_folder()+"/test/python/stacks/2.0.6/configs/default.json" with open(config_file, "r") as f: http://git-wip-us.apache.org/repos/asf/ambari/blob/712b3d21/ambari-server/src/test/python/stacks/2.0.6/ZOOKEEPER/test_zookeeper_server.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/stacks/2.0.6/ZOOKEEPER/test_zookeeper_server.py b/ambari-server/src/test/python/stacks/2.0.6/ZOOKEEPER/test_zookeeper_server.py index b9ebea2..6d38a67 100644 --- a/ambari-server/src/test/python/stacks/2.0.6/ZOOKEEPER/test_zookeeper_server.py +++ b/ambari-server/src/test/python/stacks/2.0.6/ZOOKEEPER/test_zookeeper_server.py @@ -247,109 +247,6 @@ class TestZookeeperServer(RMFTestCase): group = 'hadoop', ) - @patch("resource_management.libraries.functions.security_commons.build_expectations") - @patch("resource_management.libraries.functions.security_commons.get_params_from_filesystem") - @patch("resource_management.libraries.functions.security_commons.validate_security_config_properties") - @patch("resource_management.libraries.functions.security_commons.cached_kinit_executor") - @patch("resource_management.libraries.script.Script.put_structured_out") - def test_security_status(self, put_structured_out_mock, cached_kinit_executor_mock, validate_security_config_mock, get_params_mock, build_exp_mock): - # Test that function works when is called with correct parameters - - security_params = { - 'zookeeper_jaas': { - 'Server': { - 'keyTab': 'path/to/zookeeper/service/keytab', - 'principal': 'zookeeper_keytab' - } - } - } - result_issues = [] - props_value_check = None - props_empty_check = ['Server/keyTab', 'Server/principal'] - props_read_check = ['Server/keyTab'] - - get_params_mock.return_value = security_params - validate_security_config_mock.return_value = result_issues - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/zookeeper_server.py", - classname = "ZookeeperServer", - command = "security_status", - config_file = "secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - - build_exp_mock.assert_called_with('zookeeper_jaas', props_value_check, props_empty_check, props_read_check) - put_structured_out_mock.assert_called_with({"securityState": "SECURED_KERBEROS"}) - self.assertTrue(cached_kinit_executor_mock.call_count, 2) - cached_kinit_executor_mock.assert_called_with('/usr/bin/kinit', - self.config_dict['configurations']['zookeeper-env']['zk_user'], - security_params['zookeeper_jaas']['Server']['keyTab'], - security_params['zookeeper_jaas']['Server']['principal'], - self.config_dict['hostname'], - '/tmp') - - # Testing that the exception throw by cached_executor is caught - cached_kinit_executor_mock.reset_mock() - cached_kinit_executor_mock.side_effect = Exception("Invalid command") - - try: - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/zookeeper_server.py", - classname = "ZookeeperServer", - command = "security_status", - config_file = "secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - except: - self.assertTrue(True) - - # Testing with a security_params which doesn't contains zookeeper_jaas - empty_security_params = {} - cached_kinit_executor_mock.reset_mock() - get_params_mock.reset_mock() - put_structured_out_mock.reset_mock() - get_params_mock.return_value = empty_security_params - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/zookeeper_server.py", - classname = "ZookeeperServer", - command = "security_status", - config_file = "secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - put_structured_out_mock.assert_called_with({"securityIssuesFound": "Keytab file or principal are not set property."}) - - # Testing with not empty result_issues - result_issues_with_params = { - 'zookeeper_jaas': "Something bad happened" - } - - validate_security_config_mock.reset_mock() - get_params_mock.reset_mock() - validate_security_config_mock.return_value = result_issues_with_params - get_params_mock.return_value = security_params - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/zookeeper_server.py", - classname = "ZookeeperServer", - command = "security_status", - config_file = "secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"}) - - # Testing with security_enable = false - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/zookeeper_server.py", - classname = "ZookeeperServer", - command = "security_status", - config_file = "default.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"}) - - def test_pre_upgrade_restart(self): config_file = self.get_src_folder()+"/test/python/stacks/2.0.6/configs/default.json" with open(config_file, "r") as f: http://git-wip-us.apache.org/repos/asf/ambari/blob/712b3d21/ambari-server/src/test/python/stacks/2.1/FALCON/test_falcon_client.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/stacks/2.1/FALCON/test_falcon_client.py b/ambari-server/src/test/python/stacks/2.1/FALCON/test_falcon_client.py index 5f88b6b..b9747a2 100644 --- a/ambari-server/src/test/python/stacks/2.1/FALCON/test_falcon_client.py +++ b/ambari-server/src/test/python/stacks/2.1/FALCON/test_falcon_client.py @@ -91,30 +91,6 @@ class TestFalconClient(RMFTestCase): ) self.assertNoMoreResources() - @patch("resource_management.libraries.script.Script.put_structured_out") - def test_security_status(self, put_structured_out_mock): - # Test that function works when is called with correct parameters - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/falcon_client.py", - classname="FalconClient", - command="security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - - put_structured_out_mock.assert_called_with({"securityState": "SECURED_KERBEROS"}) - - # Testing with security_enable = false - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/falcon_client.py", - classname="FalconClient", - command="security_status", - config_file="default.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - - put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"}) - def test_pre_upgrade_restart(self): config_file = self.get_src_folder()+"/test/python/stacks/2.0.6/configs/default.json" with open(config_file, "r") as f: http://git-wip-us.apache.org/repos/asf/ambari/blob/712b3d21/ambari-server/src/test/python/stacks/2.1/FALCON/test_falcon_server.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/stacks/2.1/FALCON/test_falcon_server.py b/ambari-server/src/test/python/stacks/2.1/FALCON/test_falcon_server.py index feba0c4..44da365 100644 --- a/ambari-server/src/test/python/stacks/2.1/FALCON/test_falcon_server.py +++ b/ambari-server/src/test/python/stacks/2.1/FALCON/test_falcon_server.py @@ -414,115 +414,6 @@ class TestFalconServer(RMFTestCase): ) self.assertNoMoreResources() - @patch("resource_management.libraries.functions.security_commons.build_expectations") - @patch("resource_management.libraries.functions.security_commons.get_params_from_filesystem") - @patch("resource_management.libraries.functions.security_commons.validate_security_config_properties") - @patch("resource_management.libraries.functions.security_commons.cached_kinit_executor") - @patch("resource_management.libraries.script.Script.put_structured_out") - def test_security_status(self, put_structured_out_mock, cached_kinit_executor_mock, validate_security_config_mock, get_params_mock, build_exp_mock): - # Test that function works when is called with correct parameters - - security_params = { - 'startup': { - '*.falcon.service.authentication.kerberos.keytab': 'path/to/falcon/service/keytab', - '*.falcon.service.authentication.kerberos.principal': 'falcon_service_keytab', - '*.falcon.http.authentication.kerberos.keytab': 'path/to/falcon/http/keytab', - '*.falcon.http.authentication.kerberos.principal': 'falcon_http_principal' - } - } - result_issues = [] - props_value_check = {"*.falcon.authentication.type": "kerberos", - "*.falcon.http.authentication.type": "kerberos"} - props_empty_check = ["*.falcon.service.authentication.kerberos.principal", - "*.falcon.service.authentication.kerberos.keytab", - "*.falcon.http.authentication.kerberos.principal", - "*.falcon.http.authentication.kerberos.keytab"] - - props_read_check = ["*.falcon.service.authentication.kerberos.keytab", - "*.falcon.http.authentication.kerberos.keytab"] - - get_params_mock.return_value = security_params - validate_security_config_mock.return_value = result_issues - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/falcon_server.py", - classname="FalconServer", - command="security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - - get_params_mock.assert_called_with('/etc/falcon/conf', {'startup.properties': 'PROPERTIES'}) - build_exp_mock.assert_called_with('startup', props_value_check, props_empty_check, props_read_check) - put_structured_out_mock.assert_called_with({"securityState": "SECURED_KERBEROS"}) - self.assertTrue(cached_kinit_executor_mock.call_count, 2) - cached_kinit_executor_mock.assert_called_with('/usr/bin/kinit', - self.config_dict['configurations']['falcon-env']['falcon_user'], - security_params['startup']['*.falcon.http.authentication.kerberos.keytab'], - security_params['startup']['*.falcon.http.authentication.kerberos.principal'], - self.config_dict['hostname'], - '/tmp') - - # Testing that the exception throw by cached_executor is caught - cached_kinit_executor_mock.reset_mock() - cached_kinit_executor_mock.side_effect = Exception("Invalid command") - - try: - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/falcon_server.py", - classname="FalconServer", - command="security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - except: - self.assertTrue(True) - - # Testing with a security_params which doesn't contains startup - empty_security_params = {} - cached_kinit_executor_mock.reset_mock() - get_params_mock.reset_mock() - put_structured_out_mock.reset_mock() - get_params_mock.return_value = empty_security_params - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/falcon_server.py", - classname="FalconServer", - command="security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - put_structured_out_mock.assert_called_with({"securityIssuesFound": "Keytab file or principal are not set property."}) - - # Testing with not empty result_issues - result_issues_with_params = { - 'startup': "Something bad happened" - } - - validate_security_config_mock.reset_mock() - get_params_mock.reset_mock() - validate_security_config_mock.return_value = result_issues_with_params - get_params_mock.return_value = security_params - - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/falcon_server.py", - classname="FalconServer", - command="security_status", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"}) - - # Testing with security_enable = false - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/falcon_server.py", - classname="FalconServer", - command="security_status", - config_file="default.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES - ) - put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"}) - @patch('os.path.isfile', new=MagicMock(return_value=True)) def test_pre_upgrade_restart(self): config_file = self.get_src_folder()+"/test/python/stacks/2.2/configs/falcon-upgrade.json"