Repository: ambari
Updated Branches:
  refs/heads/trunk 3cdc032ee -> 4b8cd75d6


http://git-wip-us.apache.org/repos/asf/ambari/blob/4b8cd75d/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 7035a43..628c9b6 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
@@ -797,6 +797,117 @@ 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
+    import status_params
+
+    security_params = {}
+    security_params['core-site'] = {}
+    security_params['core-site']['hadoop.security.authentication'] = 'kerberos'
+    security_params['hdfs-site'] = {}
+    security_params['hdfs-site']['dfs.namenode.keytab.file'] = 
'path/to/namenode/keytab/file'
+    security_params['hdfs-site']['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",
+                       hdp_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(status_params.kinit_path_local,
+                                           status_params.hdfs_user,
+                                           
security_params['hdfs-site']['dfs.namenode.keytab.file'],
+                                           
security_params['hdfs-site']['dfs.namenode.kerberos.principal'],
+                                           status_params.hostname,
+                                           status_params.tmp_dir)
+
+    # 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",
+                       hdp_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",
+                         hdp_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 = {}
+    empty_security_params['core-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",
+                       hdp_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['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",
+                       hdp_stack_version = self.STACK_VERSION,
+                       target = RMFTestCase.TARGET_COMMON_SERVICES
+    )
+    put_structured_out_mock.assert_called_with({"securityState": "UNSECURED"})
+
+
 
 class Popen_Mock:
   return_value = 1

http://git-wip-us.apache.org/repos/asf/ambari/blob/4b8cd75d/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 9bfe836..9b67011 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
@@ -283,3 +283,114 @@ class TestSNamenode(RMFTestCase):
                               recursive = 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
+    import status_params
+
+    security_params = {}
+    security_params['core-site'] = {}
+    security_params['core-site']['hadoop.security.authentication'] = 'kerberos'
+    security_params['hdfs-site'] = {}
+    security_params['hdfs-site']['dfs.secondary.namenode.keytab.file'] = 
'path/to/snamenode/keytab/file'
+    security_params['hdfs-site']['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",
+                       hdp_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(status_params.kinit_path_local,
+                                           status_params.hdfs_user,
+                                           
security_params['hdfs-site']['dfs.secondary.namenode.keytab.file'],
+                                           security_params['hdfs-site'][
+                                             
'dfs.secondary.namenode.kerberos.principal'],
+                                           status_params.hostname,
+                                           status_params.tmp_dir)
+
+    # 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",
+                       hdp_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",
+                         hdp_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 = {}
+    empty_security_params['core-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",
+                       hdp_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['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",
+                       hdp_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

http://git-wip-us.apache.org/repos/asf/ambari/blob/4b8cd75d/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 3b7299f..c0fb86f 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
@@ -338,3 +338,101 @@ class TestZkfc(RMFTestCase):
                               not_if = 'ls 
/var/run/hadoop/hdfs/hadoop-hdfs-zkfc.pid >/dev/null 2>&1 && ps -p `cat 
/var/run/hadoop/hdfs/hadoop-hdfs-zkfc.pid` >/dev/null 2>&1',
                               )
     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
+    import status_params
+
+    security_params = {}
+    security_params['core-site'] = {}
+    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",
+                       hdp_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(status_params.kinit_path_local,
+                                           status_params.hdfs_user,
+                                           status_params.hdfs_user_keytab,
+                                           status_params.hdfs_user_principal,
+                                           status_params.hostname,
+                                           status_params.tmp_dir)
+
+    # 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",
+                           hdp_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",
+                       hdp_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 = {}
+    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",
+                       hdp_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",
+                       hdp_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

http://git-wip-us.apache.org/repos/asf/ambari/blob/4b8cd75d/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 06d3902..0c20e7d 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
@@ -675,8 +675,7 @@ class TestNodeManager(RMFTestCase):
     security_params['yarn-site']['yarn.nodemanager.webapp.spnego-keytab-file'] 
= 'path/to/nodemanager/webapp/keytab'
     security_params['yarn-site']['yarn.nodemanager.webapp.spnego-principal'] = 
'nodemanager_webapp_principal'
     result_issues = []
-    props_value_check = {"yarn.timeline-service.enabled": "true",
-                         "yarn.timeline-service.http-authentication.type": 
"kerberos",
+    props_value_check = {"yarn.timeline-service.http-authentication.type": 
"kerberos",
                          "yarn.acl.enable": "true"}
     props_empty_check = ["yarn.nodemanager.principal",
                          "yarn.nodemanager.keytab",

http://git-wip-us.apache.org/repos/asf/ambari/blob/4b8cd75d/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 cddb89b..67da537 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
@@ -465,8 +465,7 @@ class TestResourceManager(RMFTestCase):
     
security_params['yarn-site']['yarn.resourcemanager.webapp.spnego-keytab-file'] 
= 'path/to/resourcemanager/webapp/keytab'
     
security_params['yarn-site']['yarn.resourcemanager.webapp.spnego-principal'] = 
'resourcemanager_webapp_principal'
     result_issues = []
-    props_value_check = {"yarn.timeline-service.enabled": "true",
-                         "yarn.timeline-service.http-authentication.type": 
"kerberos",
+    props_value_check = {"yarn.timeline-service.http-authentication.type": 
"kerberos",
                          "yarn.acl.enable": "true"}
     props_empty_check = ["yarn.resourcemanager.principal",
                          "yarn.resourcemanager.keytab",

http://git-wip-us.apache.org/repos/asf/ambari/blob/4b8cd75d/ambari-server/src/test/python/stacks/2.0.6/configs/default.json
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/2.0.6/configs/default.json 
b/ambari-server/src/test/python/stacks/2.0.6/configs/default.json
index cac0370..d1701bd 100644
--- a/ambari-server/src/test/python/stacks/2.0.6/configs/default.json
+++ b/ambari-server/src/test/python/stacks/2.0.6/configs/default.json
@@ -469,6 +469,8 @@
         },
       "cluster-env": {
         "security_enabled": "false",
+        "hdfs_user_principal" : "",
+        "hdfs_user_keytab" : "",
         "ignore_groupsusers_create": "false",
         "smokeuser": "ambari-qa",
         "kerberos_domain": "EXAMPLE.COM",

http://git-wip-us.apache.org/repos/asf/ambari/blob/4b8cd75d/ambari-server/src/test/python/stacks/2.1/YARN/test_apptimelineserver.py
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/python/stacks/2.1/YARN/test_apptimelineserver.py 
b/ambari-server/src/test/python/stacks/2.1/YARN/test_apptimelineserver.py
index 8658889..a5b8aa2 100644
--- a/ambari-server/src/test/python/stacks/2.1/YARN/test_apptimelineserver.py
+++ b/ambari-server/src/test/python/stacks/2.1/YARN/test_apptimelineserver.py
@@ -230,3 +230,112 @@ class TestAppTimelineServer(RMFTestCase):
         only_if = 'test -e 
/var/run/hadoop-yarn/yarn/yarn-yarn-historyserver.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
+    import status_params
+
+    security_params = {}
+    security_params['yarn-site'] = {}
+    security_params['yarn-site']['yarn.timeline-service.keytab'] = 
'/path/to/applicationtimeline/keytab'
+    security_params['yarn-site']['yarn.timeline-service.principal'] = 
'applicationtimeline_principal'
+    
security_params['yarn-site']['yarn.timeline-service.http-authentication.kerberos.keytab']
 = 'path/to/timeline/kerberos/keytab'
+    
security_params['yarn-site']['yarn.timeline-service.http-authentication.kerberos.principal']
 = 'timeline_principal'
+    result_issues = []
+    props_value_check = {"yarn.timeline-service.enabled": "true",
+                         "yarn.timeline-service.http-authentication.type": 
"kerberos",
+                         "yarn.acl.enable": "true"}
+    props_empty_check = ["yarn.timeline-service.principal",
+                         "yarn.timeline-service.keytab",
+                         
"yarn.timeline-service.http-authentication.kerberos.principal",
+                         
"yarn.timeline-service.http-authentication.kerberos.keytab"]
+
+    props_read_check = ["yarn.timeline-service.keytab",
+                        
"yarn.timeline-service.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/application_timeline_server.py",
+                       classname="ApplicationTimelineServer",
+                       command="security_status",
+                       config_file="secured.json",
+                       hdp_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(status_params.kinit_path_local,
+                                                  status_params.yarn_user,
+                                                  
security_params['yarn-site']['yarn.timeline-service.http-authentication.kerberos.keytab'],
+                                                  
security_params['yarn-site']['yarn.timeline-service.http-authentication.kerberos.principal'],
+                                                  status_params.hostname,
+                                                  status_params.tmp_dir,
+                                                  30)
+
+    # 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/application_timeline_server.py",
+                         classname="ApplicationTimelineServer",
+                         command="security_status",
+                         config_file="secured.json",
+                         hdp_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/application_timeline_server.py",
+                       classname="ApplicationTimelineServer",
+                       command="security_status",
+                       config_file="secured.json",
+                       hdp_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['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/application_timeline_server.py",
+                       classname="ApplicationTimelineServer",
+                       command="security_status",
+                       config_file="secured.json",
+                       hdp_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/application_timeline_server.py",
+                       classname="ApplicationTimelineServer",
+                       command="security_status",
+                       config_file="default.json",
+                       hdp_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

Reply via email to