|
@@ -0,0 +1,78 @@
|
|
|
+#!/usr/bin/env python
|
|
|
+
|
|
|
+'''
|
|
|
+Licensed to the Apache Software Foundation (ASF) under one
|
|
|
+or more contributor license agreements. See the NOTICE file
|
|
|
+distributed with this work for additional information
|
|
|
+regarding copyright ownership. The ASF licenses this file
|
|
|
+to you under the Apache License, Version 2.0 (the
|
|
|
+"License"); you may not use this file except in compliance
|
|
|
+with the License. You may obtain a copy of the License at
|
|
|
+
|
|
|
+ http://www.apache.org/licenses/LICENSE-2.0
|
|
|
+
|
|
|
+Unless required by applicable law or agreed to in writing, software
|
|
|
+distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
+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):
|
|
|
+
|
|
|
+ @patch('alert_disk_space._get_disk_usage')
|
|
|
+ def test_linux_flow(self, disk_usage_mock):
|
|
|
+ # / OK, /usr/hdp OK
|
|
|
+ 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]']))
|
|
|
+
|
|
|
+ # / WARNING, /usr/hdp OK
|
|
|
+ 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]']))
|
|
|
+
|
|
|
+ # / CRITICAL, /usr/hdp OK
|
|
|
+ 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]']))
|
|
|
+
|
|
|
+ # / < 5GB, /usr/hdp OK
|
|
|
+ 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']))
|
|
|
+
|
|
|
+ # / 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)]
|
|
|
+ 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]"]))
|
|
|
+
|
|
|
+ # / 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)]
|
|
|
+ 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]"]))
|
|
|
+
|
|
|
+ # / 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)]
|
|
|
+ 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"]))
|