ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aonis...@apache.org
Subject ambari git commit: AMBARI-13227. Debian 7. Host check does not show warning about THP enabled on hosts. (aonishuk)
Date Thu, 01 Oct 2015 16:44:04 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.1 055e184c9 -> 4c1acb1ce


AMBARI-13227. Debian 7. Host check does not show warning about THP enabled on hosts. (aonishuk)


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

Branch: refs/heads/branch-2.1
Commit: 4c1acb1cec6bc96d3bfeb7ec2c5b1ee8563ba7c9
Parents: 055e184
Author: Andrew Onishuk <aonishuk@hortonworks.com>
Authored: Thu Oct 1 19:43:35 2015 +0300
Committer: Andrew Onishuk <aonishuk@hortonworks.com>
Committed: Thu Oct 1 19:43:35 2015 +0300

----------------------------------------------------------------------
 .../src/main/python/ambari_agent/HostInfo.py    | 14 +++++++---
 .../test/python/ambari_agent/TestHostInfo.py    | 28 ++++++++++++++++++--
 .../custom_actions/scripts/check_host.py        | 13 ++++++---
 .../test/python/custom_actions/TestCheckHost.py |  1 +
 4 files changed, 46 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/4c1acb1c/ambari-agent/src/main/python/ambari_agent/HostInfo.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/HostInfo.py b/ambari-agent/src/main/python/ambari_agent/HostInfo.py
index e9d4110..4082ebe 100644
--- a/ambari-agent/src/main/python/ambari_agent/HostInfo.py
+++ b/ambari-agent/src/main/python/ambari_agent/HostInfo.py
@@ -157,7 +157,8 @@ class HostInfoLinux(HostInfo):
   DEFAULT_SERVICE_NAME = "ntpd"
   SERVICE_STATUS_CMD = "%s %s status" % (SERVICE_CMD, DEFAULT_SERVICE_NAME)
 
-  THP_FILE = "/sys/kernel/mm/redhat_transparent_hugepage/enabled"
+  THP_FILE_REDHAT = "/sys/kernel/mm/redhat_transparent_hugepage/enabled"
+  THP_FILE_UBUNTU = "/sys/kernel/mm/transparent_hugepage/enabled"
 
   def __init__(self, config=None):
     super(HostInfoLinux, self).__init__(config)
@@ -216,10 +217,15 @@ class HostInfoLinux(HostInfo):
     pass
 
   def getTransparentHugePage(self):
-    # This file exist only on redhat 6
     thp_regex = "\[(.+)\]"
-    if os.path.isfile(self.THP_FILE):
-      with open(self.THP_FILE) as f:
+    file_name = None
+    if OSCheck.is_ubuntu_family():
+      file_name = self.THP_FILE_UBUNTU
+    elif OSCheck.is_redhat_family():
+      file_name = self.THP_FILE_REDHAT
+
+    if file_name and os.path.isfile(file_name):
+      with open(file_name) as f:
         file_content = f.read()
         return re.search(thp_regex, file_content).groups()[0]
     else:

http://git-wip-us.apache.org/repos/asf/ambari/blob/4c1acb1c/ambari-agent/src/test/python/ambari_agent/TestHostInfo.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestHostInfo.py b/ambari-agent/src/test/python/ambari_agent/TestHostInfo.py
index 58745f9..9a9dcb2 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestHostInfo.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestHostInfo.py
@@ -515,12 +515,36 @@ class TestHostInfo(TestCase):
     run_os_command_mock.return_value = 3, "", ""
     self.assertFalse(Firewall().getFirewallObject().check_firewall())
 
-  @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = ('redhat','11','Final')))
+  @patch.object(OSCheck, "get_os_family")
+  @patch("os.path.isfile")
+  @patch('__builtin__.open')
+  def test_transparent_huge_page(self, open_mock, os_path_isfile_mock, get_os_family_mock):
+    context_manager_mock = MagicMock()
+    open_mock.return_value = context_manager_mock
+    get_os_family_mock.return_value = OSConst.REDHAT_FAMILY
+    file_mock = MagicMock()
+    file_mock.read.return_value = "[never] always"
+    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 )
+
+    hostInfo = HostInfoLinux()
+
+    os_path_isfile_mock.return_value = True
+    self.assertEqual("never", hostInfo.getTransparentHugePage())
+
+    os_path_isfile_mock.return_value = False
+    self.assertEqual("", hostInfo.getTransparentHugePage())
+
+  @patch.object(OSCheck, "get_os_family")
   @patch("os.path.isfile")
   @patch('__builtin__.open')
-  def test_transparent_huge_page(self, open_mock, os_path_isfile_mock):
+  def test_transparent_huge_page_debian(self, open_mock, os_path_isfile_mock, get_os_family_mock):
     context_manager_mock = MagicMock()
     open_mock.return_value = context_manager_mock
+    get_os_family_mock.return_value = OSConst.UBUNTU_FAMILY
     file_mock = MagicMock()
     file_mock.read.return_value = "[never] always"
     enter_mock = MagicMock()

http://git-wip-us.apache.org/repos/asf/ambari/blob/4c1acb1c/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 12483c5..7c8290c 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
@@ -73,7 +73,8 @@ JARS_PATH_IN_ARCHIVE_SQLA = "/sqla-client-jdbc/java"
 LIBS_PATH_IN_ARCHIVE_SQLA = "/sqla-client-jdbc/native/lib64"
 JDBC_DRIVER_SQLA_JAR_PATH_IN_ARCHIVE = "/sqla-client-jdbc/java/" + JDBC_DRIVER_SQLA_JAR
 
-THP_FILE = "/sys/kernel/mm/redhat_transparent_hugepage/enabled"
+THP_FILE_REDHAT = "/sys/kernel/mm/redhat_transparent_hugepage/enabled"
+THP_FILE_UBUNTU = "/sys/kernel/mm/transparent_hugepage/enabled"
 
 class CheckHost(Script):
   # Packages that are used to find repos (then repos are used to find other packages)
@@ -171,10 +172,14 @@ class CheckHost(Script):
     # 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_name = None
+        if OSCheck.is_ubuntu_family():
+          file_name = THP_FILE_UBUNTU
+        elif OSCheck.is_redhat_family():
+          file_name = THP_FILE_REDHAT
+        if file_name and os.path.isfile(file_name):
+          with open(file_name) 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])}

http://git-wip-us.apache.org/repos/asf/ambari/blob/4c1acb1c/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 ef08938..14cb8e3 100644
--- a/ambari-server/src/test/python/custom_actions/TestCheckHost.py
+++ b/ambari-server/src/test/python/custom_actions/TestCheckHost.py
@@ -292,6 +292,7 @@ class TestCheckHost(TestCase):
     put_structured_out_mock.assert_called_with({'last_agent_env_check': {'message': 'test
exception', 'exit_code': 1}})
 
 
+  @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = ('debian','7','Final')))
   @patch.object(HostCheckReportFileHandler, "resolve_ambari_config")
   @patch("resource_management.libraries.script.Script.put_structured_out")
   @patch.object(Script, 'get_tmp_dir')


Mime
View raw message