From ad004f45088ee81723b2a2420b3bce01f0bd845b Mon Sep 17 00:00:00 2001 From: Sahina Bose Date: Fri, 14 Mar 2014 12:49:59 +0530 Subject: plugins: Plugin to check the cluster utilization This plugin sums up the volume utilization outputs in a cluster Added a utils livestatus for common code related to mk_livestatus Added constants for livestatussocket path Change-Id: Id665ad3aaa1140e54c831d721ee874421ae84fa3 Signed-off-by: Sahina Bose Reviewed-on: https://cuckoo.blr.redhat.com:8443/10 Reviewed-by: Bala FA --- tests/Makefile.am | 1 + tests/test_check_cluster_volusage.py | 80 ++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 tests/test_check_cluster_volusage.py (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index e4543f7..40a09a3 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -19,6 +19,7 @@ # test_modules = \ + test_check_cluster_volusage.py \ test_check_remote_host.py \ test_notify_ovirt_engine_handler.py \ $(NULL) diff --git a/tests/test_check_cluster_volusage.py b/tests/test_check_cluster_volusage.py new file mode 100644 index 0000000..54e75c6 --- /dev/null +++ b/tests/test_check_cluster_volusage.py @@ -0,0 +1,80 @@ +# +# Copyright 2014 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# Refer to the README and COPYING files for full details of the license +# + +import mock + +from testrunner import PluginsTestCase as TestCaseBase +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') + def test_checkVolumePerfDataNoMatch(self, mock_readLiveStatus): + mock_readLiveStatus.return_value = _getTable() + testTotalUsed, testTotalAvail = (check_cluster_vol_usage + .checkVolumePerfData + ("dummy-cluster")) + assert testTotalUsed == 0 + + # Method to test volume perf data when no matching host method + @mock.patch('plugins.livestatus.readLiveStatus') + def test_checkVolumePerfDataMatch(self, mock_readLiveStatus): + mock_readLiveStatus.return_value = _getTable() + testTotalUsed, testTotalAvail = (check_cluster_vol_usage + .checkVolumePerfData + ("test-cluster")) + print ("testTotal %s" % testTotalUsed) + assert (testTotalUsed == 700) + assert (testTotalAvail == 1134) + + # Method to test volume perf data when no matching host method + @mock.patch('plugins.livestatus.readLiveStatus') + def test_checkVolumePerfNoData(self, mock_readLiveStatus): + mock_readLiveStatus.return_value = _getTableWithoutCustomAndPerData() + testTotalUsed, testTotalAvail = (check_cluster_vol_usage + .checkVolumePerfData + ("test-cluster")) + 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 _getTableWithoutCustomAndPerData(): + table = [["brick1", + "test-cluster", + "", + ""], + ["brick2", + "test-cluster", + "", + ""]] + return table -- cgit