You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by jo...@apache.org on 2015/03/03 03:54:27 UTC

ambari git commit: AMBARI-9878 - Ambari Agent Disk Usage Alert is UNKNOWN on HDP 2.0 or 2.1 (jonathanhurley)

Repository: ambari
Updated Branches:
  refs/heads/trunk 26aaca7fb -> 05c2d2f25


AMBARI-9878 - Ambari Agent Disk Usage Alert is UNKNOWN on HDP 2.0 or 2.1 (jonathanhurley)


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

Branch: refs/heads/trunk
Commit: 05c2d2f257fc784f13628af188101fa780f199fc
Parents: 26aaca7
Author: Jonathan Hurley <jh...@hortonworks.com>
Authored: Mon Mar 2 17:27:30 2015 -0500
Committer: Jonathan Hurley <jh...@hortonworks.com>
Committed: Mon Mar 2 21:54:21 2015 -0500

----------------------------------------------------------------------
 .../resources/host_scripts/alert_disk_space.py  | 25 ++++--
 .../python/host_scripts/TestAlertDiskSpace.py   | 92 +++++++++++++-------
 2 files changed, 79 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/05c2d2f2/ambari-server/src/main/resources/host_scripts/alert_disk_space.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/host_scripts/alert_disk_space.py b/ambari-server/src/main/resources/host_scripts/alert_disk_space.py
index d069f48..f51db1f 100644
--- a/ambari-server/src/main/resources/host_scripts/alert_disk_space.py
+++ b/ambari-server/src/main/resources/host_scripts/alert_disk_space.py
@@ -26,7 +26,12 @@ from ambari_commons import OSConst
 
 DiskInfo = collections.namedtuple('DiskInfo', 'total used free')
 MIN_FREE_SPACE = 5000000000L   # 5GB
-USR_HDP = '/usr/hdp'
+
+# the location where HDP installs components when using HDP 2.2+
+HDP_HOME_DIR = "/usr/hdp"
+
+# the location where HDP installs components when using HDP 2.0 to 2.1
+HDP_HOME_LEGACY_DIR = "/usr/lib"
 
 def get_tokens():
   """
@@ -53,13 +58,21 @@ def execute(parameters=None, host_name=None):
   except NotImplementedError, platform_error:
     return 'CRITICAL', [str(platform_error)]
 
-  if result_code == 'OK':
-    # Root partition seems to be OK, let's check /usr/hdp
+  # determine the location of HDP home; if it exists then we should also
+  # check it in addition to /
+  hdp_home = None
+  if os.path.isdir(HDP_HOME_DIR):
+    hdp_home = HDP_HOME_DIR
+  elif os.path.isdir(HDP_HOME_LEGACY_DIR):
+    hdp_home = HDP_HOME_LEGACY_DIR
+
+  if result_code == 'OK' and hdp_home:
+    # Root partition seems to be OK, let's check HDP home
     try:
-      disk_usage = _get_disk_usage(USR_HDP)
+      disk_usage = _get_disk_usage(hdp_home)
       result_code_usr_hdp, label_usr_hdp = _get_warnings_for_partition(disk_usage)
       if result_code_usr_hdp != 'OK':
-        label = "{0}. Insufficient space at {1}: {2}".format(label, USR_HDP, label_usr_hdp)
+        label = "{0}. Insufficient space at {1}: {2}".format(label, hdp_home, label_usr_hdp)
         result_code = 'WARNING'
     except NotImplementedError, platform_error:
       return 'CRITICAL', [str(platform_error)]
@@ -87,7 +100,7 @@ def _get_warnings_for_partition(disk_usage):
     # Check absolute disk space value
     if disk_usage.free < MIN_FREE_SPACE:
       result_code = 'WARNING'
-      label += '. Free space < {0}'.format(_get_formatted_size(MIN_FREE_SPACE))
+      label += '. Total free space is less than {0}'.format(_get_formatted_size(MIN_FREE_SPACE))
 
   return result_code, label
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/05c2d2f2/ambari-server/src/test/python/host_scripts/TestAlertDiskSpace.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/host_scripts/TestAlertDiskSpace.py b/ambari-server/src/test/python/host_scripts/TestAlertDiskSpace.py
index 4a265e1..8194bba 100644
--- a/ambari-server/src/test/python/host_scripts/TestAlertDiskSpace.py
+++ b/ambari-server/src/test/python/host_scripts/TestAlertDiskSpace.py
@@ -17,63 +17,91 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 '''
-import json
-import os
-import socket, pprint
 import alert_disk_space
 from mock.mock import patch, MagicMock
 from ambari_commons.os_check import OSCheck
 from stacks.utils.RMFTestCase import *
 
-class TestAlertDiskSpace(RMFTestCase):
 
+class TestAlertDiskSpace(RMFTestCase):
   @patch('alert_disk_space._get_disk_usage')
+  @patch("os.path.isdir")
   @patch.object(OSCheck, "get_os_family", new = MagicMock(return_value = 'redhat'))
-  def test_linux_flow(self, disk_usage_mock):
+  def test_linux_flow(self, isdir_mock, disk_usage_mock):
+    isdir_mock.return_value = False
+
     # / OK, /usr/hdp OK
-    disk_usage_mock.return_value = \
-      alert_disk_space.DiskInfo(total=21673930752L, used=5695861760L, free=15978068992L)
+    disk_usage_mock.return_value = alert_disk_space.DiskInfo(
+      total = 21673930752L, used = 5695861760L,
+      free = 15978068992L)
+
     res = alert_disk_space.execute()
-    self.assertEqual(res, ('OK', ['Capacity Used: [26.28%, 5.7 GB], Capacity Total: [21.7 GB]']))
+    self.assertEqual(res,
+      ('OK', ['Capacity Used: [26.28%, 5.7 GB], Capacity Total: [21.7 GB]']))
 
     # / WARNING, /usr/hdp OK
-    disk_usage_mock.return_value = \
-      alert_disk_space.DiskInfo(total=21673930752L, used=14521533603L, free=7152397149L)
+    disk_usage_mock.return_value = alert_disk_space.DiskInfo(
+      total = 21673930752L, used = 14521533603L,
+      free = 7152397149L)
+
     res = alert_disk_space.execute()
-    self.assertEqual(res, ('WARNING', ['Capacity Used: [67.00%, 14.5 GB], Capacity Total: [21.7 GB]']))
+    self.assertEqual(res, (
+      'WARNING',
+      ['Capacity Used: [67.00%, 14.5 GB], Capacity Total: [21.7 GB]']))
 
     # / CRITICAL, /usr/hdp OK
-    disk_usage_mock.return_value = \
-      alert_disk_space.DiskInfo(total=21673930752L, used=20590234214L, free=1083696538)
+    disk_usage_mock.return_value = alert_disk_space.DiskInfo(
+      total = 21673930752L, used = 20590234214L,
+      free = 1083696538)
+
     res = alert_disk_space.execute()
-    self.assertEqual(res, ('CRITICAL', ['Capacity Used: [95.00%, 20.6 GB], Capacity Total: [21.7 GB]']))
+    self.assertEqual(res, ('CRITICAL',
+    ['Capacity Used: [95.00%, 20.6 GB], Capacity Total: [21.7 GB]']))
 
     # / < 5GB, /usr/hdp OK
-    disk_usage_mock.return_value = \
-      alert_disk_space.DiskInfo(total=5418482688L, used=1625544806L, free=3792937882L)
+    disk_usage_mock.return_value = alert_disk_space.DiskInfo(
+      total = 5418482688L, used = 1625544806L,
+      free = 3792937882L)
+
     res = alert_disk_space.execute()
-    self.assertEqual(res, ('WARNING', ['Capacity Used: [30.00%, 1.6 GB], Capacity Total: [5.4 GB]. Free space < 5.0 GB']))
+    self.assertEqual(res, ('WARNING', [
+      'Capacity Used: [30.00%, 1.6 GB], Capacity Total: [5.4 GB]. Total free space is less than 5.0 GB']))
 
     # / OK, /usr/hdp WARNING
-    disk_usage_mock.side_effect = \
-      [alert_disk_space.DiskInfo(total=21673930752L, used=5695861760L, free=15978068992L),
-       alert_disk_space.DiskInfo(total=21673930752L, used=14521533603L, free=7152397149L)]
+    disk_usage_mock.side_effect = [
+      alert_disk_space.DiskInfo(total = 21673930752L, used = 5695861760L,
+        free = 15978068992L),
+      alert_disk_space.DiskInfo(total = 21673930752L, used = 14521533603L,
+        free = 7152397149L)]
+
+    # trigger isdir(/usr/hdp) to True
+    isdir_mock.return_value = True
+
     res = alert_disk_space.execute()
-    self.assertEqual(res, ('WARNING', ["Capacity Used: [26.28%, 5.7 GB], Capacity Total: [21.7 GB]. "
-                                       "Insufficient space at /usr/hdp: Capacity Used: [67.00%, 14.5 GB], Capacity Total: [21.7 GB]"]))
+    self.assertEqual(res, (
+      'WARNING', ["Capacity Used: [26.28%, 5.7 GB], Capacity Total: [21.7 GB]. "
+                  "Insufficient space at /usr/hdp: Capacity Used: [67.00%, 14.5 GB], Capacity Total: [21.7 GB]"]))
 
     # / OK, /usr/hdp CRITICAL
-    disk_usage_mock.side_effect = \
-      [alert_disk_space.DiskInfo(total=21673930752L, used=5695861760L, free=15978068992L),
-       alert_disk_space.DiskInfo(total=21673930752L, used=20590234214L, free=1083696538L)]
+    disk_usage_mock.side_effect = [
+      alert_disk_space.DiskInfo(total = 21673930752L, used = 5695861760L,
+        free = 15978068992L),
+      alert_disk_space.DiskInfo(total = 21673930752L, used = 20590234214L,
+        free = 1083696538L)]
+
     res = alert_disk_space.execute()
-    self.assertEqual(res, ('WARNING', ["Capacity Used: [26.28%, 5.7 GB], Capacity Total: [21.7 GB]. "
-                                       "Insufficient space at /usr/hdp: Capacity Used: [95.00%, 20.6 GB], Capacity Total: [21.7 GB]"]))
+    self.assertEqual(res, (
+      'WARNING', ["Capacity Used: [26.28%, 5.7 GB], Capacity Total: [21.7 GB]. "
+                  "Insufficient space at /usr/hdp: Capacity Used: [95.00%, 20.6 GB], Capacity Total: [21.7 GB]"]))
 
     # / OK, /usr/hdp < 5GB
-    disk_usage_mock.side_effect = \
-      [alert_disk_space.DiskInfo(total=21673930752L, used=5695861760L, free=15978068992L),
-       alert_disk_space.DiskInfo(total=5418482688L, used=1625544806L, free=3792937882L)]
+    disk_usage_mock.side_effect = [
+      alert_disk_space.DiskInfo(total = 21673930752L, used = 5695861760L,
+        free = 15978068992L),
+      alert_disk_space.DiskInfo(total = 5418482688L, used = 1625544806L,
+        free = 3792937882L)]
+
     res = alert_disk_space.execute()
-    self.assertEqual(res, ('WARNING', ["Capacity Used: [26.28%, 5.7 GB], Capacity Total: [21.7 GB]. "
-                                       "Insufficient space at /usr/hdp: Capacity Used: [30.00%, 1.6 GB], Capacity Total: [5.4 GB]. Free space < 5.0 GB"]))
+    self.assertEqual(res, (
+      'WARNING', ["Capacity Used: [26.28%, 5.7 GB], Capacity Total: [21.7 GB]. "
+                  "Insufficient space at /usr/hdp: Capacity Used: [30.00%, 1.6 GB], Capacity Total: [5.4 GB]. Total free space is less than 5.0 GB"]))