summaryrefslogtreecommitdiffstats
path: root/tests/test_check_cluster_volusage.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_check_cluster_volusage.py')
-rw-r--r--tests/test_check_cluster_volusage.py83
1 files changed, 46 insertions, 37 deletions
diff --git a/tests/test_check_cluster_volusage.py b/tests/test_check_cluster_volusage.py
index 54e75c6..958a12b 100644
--- a/tests/test_check_cluster_volusage.py
+++ b/tests/test_check_cluster_volusage.py
@@ -19,6 +19,7 @@
#
import mock
+import json
from testrunner import PluginsTestCase as TestCaseBase
from plugins import check_cluster_vol_usage
@@ -27,54 +28,62 @@ from plugins import check_cluster_vol_usage
class TestClusterVolUsage(TestCaseBase):
# Method to test volume perf data when no matching host method
- @mock.patch('plugins.livestatus.readLiveStatus')
+ @mock.patch('plugins.livestatus.readLiveStatusAsJSON')
def test_checkVolumePerfDataNoMatch(self, mock_readLiveStatus):
- mock_readLiveStatus.return_value = _getTable()
- testTotalUsed, testTotalAvail = (check_cluster_vol_usage
- .checkVolumePerfData
- ("dummy-cluster"))
+ mock_readLiveStatus.return_value = _getJsonNoData()
+ numVolumes, testTotalUsed, testTotalAvail = (check_cluster_vol_usage
+ .checkVolumePerfData
+ ("dummy-cluster"))
+ assert numVolumes == 0
assert testTotalUsed == 0
- # Method to test volume perf data when no matching host method
- @mock.patch('plugins.livestatus.readLiveStatus')
+ # Method to test volume perf data
+ @mock.patch('plugins.livestatus.readLiveStatusAsJSON')
def test_checkVolumePerfDataMatch(self, mock_readLiveStatus):
- mock_readLiveStatus.return_value = _getTable()
- testTotalUsed, testTotalAvail = (check_cluster_vol_usage
- .checkVolumePerfData
- ("test-cluster"))
+ mock_readLiveStatus.return_value = _getJson()
+ numVolumes, testTotalUsed, testTotalAvail = (check_cluster_vol_usage
+ .checkVolumePerfData
+ ("test-cluster"))
print ("testTotal %s" % testTotalUsed)
+ assert numVolumes == 2
assert (testTotalUsed == 700)
assert (testTotalAvail == 1134)
- # Method to test volume perf data when no matching host method
- @mock.patch('plugins.livestatus.readLiveStatus')
+ # Method to test volume perf data when no perfdata method
+ @mock.patch('plugins.livestatus.readLiveStatusAsJSON')
def test_checkVolumePerfNoData(self, mock_readLiveStatus):
- mock_readLiveStatus.return_value = _getTableWithoutCustomAndPerData()
- testTotalUsed, testTotalAvail = (check_cluster_vol_usage
- .checkVolumePerfData
- ("test-cluster"))
+ mock_readLiveStatus.return_value = _getJsonWithoutCustomAndPerData()
+ numVolumes, testTotalUsed, testTotalAvail = (check_cluster_vol_usage
+ .checkVolumePerfData
+ ("test-cluster"))
+ assert numVolumes == 2
assert testTotalUsed == 0
-def _getTable():
- table = [["Volume Utilization - data-vol",
- "test-cluster",
- "utilization=4%;70;90 total=734 used=300 free=434",
- "VOL_NAME;data-vol"],
- ["Volume Utilization - dist-rep",
- "test-cluster",
- "utilization=100%;70;90 total=400 used=400 free=0",
- "VOL_NAME;dist-rep"]]
- return table
+def _getJson():
+ jOut = [["Volume Utilization - dist",
+ "test-cluster",
+ "utilization=4%;70;90 total=734 used=300 free=434",
+ {"VOL_NAME": "dist", "GLUSTER_ENTITY": "Service"}],
+ ["Volume Utilization - rep",
+ "test-cluster",
+ "utilization=100%;70;90 total=400 used=400 free=0",
+ {"VOL_NAME": "rep", "GLUSTER_ENTITY": "Service"}]]
+ return json.dumps(jOut)
+
+
+def _getJsonNoData():
+ jOut = []
+ return json.dumps(jOut)
-def _getTableWithoutCustomAndPerData():
- table = [["brick1",
- "test-cluster",
- "",
- ""],
- ["brick2",
- "test-cluster",
- "",
- ""]]
- return table
+def _getJsonWithoutCustomAndPerData():
+ jOut = [["Volume Utilization - dist",
+ "test-cluster",
+ "",
+ {}],
+ ["Volume Utilization - rep",
+ "test-cluster",
+ "",
+ {}]]
+ return json.dumps(jOut)