ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vbrodets...@apache.org
Subject ambari git commit: AMBARI-12514. THP changes / package issues (and possibly others) aren’t detected with a ‘Re-run’ action.(vbrodetskyi)
Date Thu, 23 Jul 2015 15:09:32 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 8e9f5e8da -> cc03263ee


AMBARI-12514. THP changes / package issues (and possibly others) aren’t detected with a
‘Re-run’ action.(vbrodetskyi)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/cc03263e
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/cc03263e
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/cc03263e

Branch: refs/heads/trunk
Commit: cc03263ee64cfff77259d3c64e825c90d1aced9e
Parents: 8e9f5e8
Author: Vitaly Brodetskyi <vbrodetskyi@hortonworks.com>
Authored: Thu Jul 23 18:09:10 2015 +0300
Committer: Vitaly Brodetskyi <vbrodetskyi@hortonworks.com>
Committed: Thu Jul 23 18:09:10 2015 +0300

----------------------------------------------------------------------
 .../custom_actions/scripts/check_host.py        | 22 ++++++++++-
 .../test/python/custom_actions/TestCheckHost.py | 41 +++++++++++++++++++-
 2 files changed, 61 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/cc03263e/ambari-server/src/main/resources/custom_actions/scripts/check_host.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/custom_actions/scripts/check_host.py b/ambari-server/src/main/resources/custom_actions/scripts/check_host.py
index 046e60f..40bea98 100644
--- a/ambari-server/src/main/resources/custom_actions/scripts/check_host.py
+++ b/ambari-server/src/main/resources/custom_actions/scripts/check_host.py
@@ -21,6 +21,7 @@ Ambari Agent
 """
 
 import os
+import re
 import subprocess
 import socket
 import getpass
@@ -42,6 +43,7 @@ CHECK_HOST_RESOLUTION = "host_resolution_check"
 CHECK_LAST_AGENT_ENV = "last_agent_env_check"
 CHECK_INSTALLED_PACKAGES = "installed_packages"
 CHECK_EXISTING_REPOS = "existing_repos"
+CHECK_TRANSPARENT_HUGE_PAGE = "transparentHugePage"
 
 DB_MYSQL = "mysql"
 DB_ORACLE = "oracle"
@@ -59,6 +61,8 @@ JDBC_DRIVER_SYMLINK_POSTGRESQL = "postgres-jdbc-driver.jar"
 JDBC_DRIVER_SYMLINK_MSSQL = "sqljdbc4.jar"
 JDBC_AUTH_SYMLINK_MSSQL = "sqljdbc_auth.dll"
 
+THP_FILE = "/sys/kernel/mm/redhat_transparent_hugepage/enabled"
+
 class CheckHost(Script):
   # Packages that are used to find repos (then repos are used to find other packages)
   PACKAGES = [
@@ -146,7 +150,23 @@ class CheckHost(Script):
         print "There was an unknown error while checking installed packages and existing
repositories: " + str(exception)
         structured_output[CHECK_INSTALLED_PACKAGES] = {"exit_code" : 1, "message": str(exception)}
         structured_output[CHECK_EXISTING_REPOS] = {"exit_code" : 1, "message": str(exception)}
-        
+
+    # Here we are checking transparent huge page if CHECK_TRANSPARENT_HUGE_PAGE is in check_execute_list
+    if CHECK_TRANSPARENT_HUGE_PAGE in check_execute_list:
+      try :
+        # This file exist only on redhat 6
+        thp_regex = "\[(.+)\]"
+        if os.path.isfile(THP_FILE):
+          with open(THP_FILE) as f:
+            file_content = f.read()
+            structured_output[CHECK_TRANSPARENT_HUGE_PAGE] = {"exit_code" : 0, "message":
str(re.search(thp_regex,
+                                                                                        
   file_content).groups()[0])}
+        else:
+          structured_output[CHECK_TRANSPARENT_HUGE_PAGE] = {"exit_code" : 0, "message": ""}
+      except Exception, exception :
+        print "There was an unknown error while getting transparent huge page data: " + str(exception)
+        structured_output[CHECK_TRANSPARENT_HUGE_PAGE] = {"exit_code" : 1, "message": str(exception)}
+
     # this is necessary for HostCleanup to know later what were the results.
     self.reportFileHandler.writeHostChecksCustomActionsFile(structured_output)
     

http://git-wip-us.apache.org/repos/asf/ambari/blob/cc03263e/ambari-server/src/test/python/custom_actions/TestCheckHost.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/custom_actions/TestCheckHost.py b/ambari-server/src/test/python/custom_actions/TestCheckHost.py
index cb09136..6d57fed 100644
--- a/ambari-server/src/test/python/custom_actions/TestCheckHost.py
+++ b/ambari-server/src/test/python/custom_actions/TestCheckHost.py
@@ -287,4 +287,43 @@ class TestCheckHost(TestCase):
     checkHost.actionexecute(None)
 
     #ensure the correct response is returned
-    put_structured_out_mock.assert_called_with({'last_agent_env_check': {'message': 'test
exception', 'exit_code': 1}})
\ No newline at end of file
+    put_structured_out_mock.assert_called_with({'last_agent_env_check': {'message': 'test
exception', 'exit_code': 1}})
+
+
+  @patch("resource_management.libraries.script.Script.put_structured_out")
+  @patch.object(Script, 'get_tmp_dir')
+  @patch.object(Script, 'get_config')
+  @patch("os.path.isfile")
+  @patch('__builtin__.open')
+  def testTransparentHugePage(self, open_mock, os_path_isfile_mock, mock_config, get_tmp_dir_mock,
structured_out_mock):
+    context_manager_mock = MagicMock()
+    open_mock.return_value = context_manager_mock
+    file_mock = MagicMock()
+    file_mock.read.return_value = "[never] always"
+    enter_mock = MagicMock()
+    enter_mock.return_value = file_mock
+    enter_mock = MagicMock()
+    enter_mock.return_value = file_mock
+    exit_mock  = MagicMock()
+    setattr( context_manager_mock, '__enter__', enter_mock )
+    setattr( context_manager_mock, '__exit__', exit_mock )
+    os_path_isfile_mock.return_value = True
+    get_tmp_dir_mock.return_value = "/tmp"
+    mock_config.return_value = {"commandParams" : {"check_execute_list" : "transparentHugePage"}}
+
+    checkHost = CheckHost()
+    checkHost.actionexecute(None)
+
+    self.assertEquals(structured_out_mock.call_args[0][0], {'transparentHugePage' : {'message':
'never', 'exit_code': 0}})
+
+    # case 2, file not exists
+    os_path_isfile_mock.return_value = False
+    checkHost.actionexecute(None)
+
+    self.assertEquals(structured_out_mock.call_args[0][0], {'transparentHugePage' : {'message':
'', 'exit_code': 0}})
+
+
+
+
+
+


Mime
View raw message