Merge lp:~stub/charms/trusty/cassandra/fix-diskchecks into lp:charms/trusty/cassandra

Proposed by Stuart Bishop
Status: Merged
Merged at revision: 374
Proposed branch: lp:~stub/charms/trusty/cassandra/fix-diskchecks
Merge into: lp:charms/trusty/cassandra
Diff against target: 106 lines (+24/-18)
3 files modified
hooks/actions.py (+4/-1)
hooks/helpers.py (+8/-0)
tests/test_actions.py (+12/-17)
To merge this branch: bzr merge lp:~stub/charms/trusty/cassandra/fix-diskchecks
Reviewer Review Type Date Requested Status
Cory Johns (community) Approve
Review Queue (community) automated testing Needs Fixing
Review via email: mp+283760@code.launchpad.net

Description of the change

Nagios disk space monitoring would fail if the various directories being monitored where not acessible to the nagios user.

This branch fixes this by instead determining the mount points of the interesting directories and checking available space on them. This also removes redundant checks, such as the common situation of the commitlog and saved_caches directories both being on the root volume.

To post a comment you must log in.
Revision history for this message
Review Queue (review-queue) wrote :

This item has failed automated testing! Results available here http://juju-ci.vapour.ws:8080/job/charm-bundle-test-lxc/2420/

review: Needs Fixing (automated testing)
371. By Stuart Bishop

Fix unittests

372. By Stuart Bishop

Merge trunk, resolve conflicts

373. By Stuart Bishop

delint

Revision history for this message
Cory Johns (johnsca) wrote :

This is an excellent improvement, and has been merged.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'hooks/actions.py'
--- hooks/actions.py 2016-02-26 16:47:03 +0000
+++ hooks/actions.py 2016-03-17 11:13:01 +0000
@@ -825,7 +825,10 @@
825 dirs = helpers.get_all_database_directories()825 dirs = helpers.get_all_database_directories()
826 dirs = set(dirs['data_file_directories'] +826 dirs = set(dirs['data_file_directories'] +
827 [dirs['commitlog_directory'], dirs['saved_caches_directory']])827 [dirs['commitlog_directory'], dirs['saved_caches_directory']])
828 for disk in dirs:828 # We need to check the space on the mountpoint, not on the actual
829 # directory, as the nagios user won't have access to the actual directory.
830 mounts = set(helpers.mountpoint(d) for d in dirs)
831 for disk in mounts:
829 check_name = re.sub('[^A-Za-z0-9_]', '_', disk)832 check_name = re.sub('[^A-Za-z0-9_]', '_', disk)
830 if cassandra_disk_warn and cassandra_disk_crit:833 if cassandra_disk_warn and cassandra_disk_crit:
831 shortname = "cassandra_disk{}".format(check_name)834 shortname = "cassandra_disk{}".format(check_name)
832835
=== modified file 'hooks/helpers.py'
--- hooks/helpers.py 2016-02-26 16:47:03 +0000
+++ hooks/helpers.py 2016-03-17 11:13:01 +0000
@@ -192,6 +192,14 @@
192 return dirs192 return dirs
193193
194194
195def mountpoint(path):
196 '''Return the mountpoint that path exists on.'''
197 path = os.path.realpath(path)
198 while path != '/' and not os.path.ismount(path):
199 path = os.path.dirname(path)
200 return path
201
202
195# FOR CHARMHELPERS203# FOR CHARMHELPERS
196def is_lxc():204def is_lxc():
197 '''Return True if we are running inside an LXC container.'''205 '''Return True if we are running inside an LXC container.'''
198206
=== modified file 'tests/test_actions.py'
--- tests/test_actions.py 2016-02-26 16:47:03 +0000
+++ tests/test_actions.py 2016-03-17 11:13:01 +0000
@@ -906,12 +906,15 @@
906 call('1.1.0.2', 'any', 7002)],906 call('1.1.0.2', 'any', 7002)],
907 any_order=True)907 any_order=True)
908908
909 @patch('helpers.mountpoint')
909 @patch('helpers.get_cassandra_version')910 @patch('helpers.get_cassandra_version')
910 @patch('charmhelpers.core.host.write_file')911 @patch('charmhelpers.core.host.write_file')
911 @patch('charmhelpers.contrib.charmsupport.nrpe.NRPE')912 @patch('charmhelpers.contrib.charmsupport.nrpe.NRPE')
912 @patch('helpers.local_plugins_dir')913 @patch('helpers.local_plugins_dir')
913 def test_nrpe_external_master_relation(self, local_plugins_dir, nrpe,914 def test_nrpe_external_master_relation(self, local_plugins_dir, nrpe,
914 write_file, cassandra_version):915 write_file, cassandra_version,
916 mountpoint):
917 mountpoint.side_effect = os.path.dirname
915 cassandra_version.return_value = '2.2'918 cassandra_version.return_value = '2.2'
916 # The fake charm_dir() needs populating.919 # The fake charm_dir() needs populating.
917 plugin_src_dir = os.path.join(os.path.dirname(__file__),920 plugin_src_dir = os.path.join(os.path.dirname(__file__),
@@ -936,16 +939,10 @@
936 description='Check Cassandra Heap',939 description='Check Cassandra Heap',
937 check_cmd='check_cassandra_heap.sh localhost 80 90'),940 check_cmd='check_cassandra_heap.sh localhost 80 90'),
938 call(description=('Check Cassandra Disk '941 call(description=('Check Cassandra Disk '
939 '/var/lib/cassandra/data'),942 '/var/lib/cassandra'),
940 shortname='cassandra_disk_var_lib_cassandra_data',943 shortname='cassandra_disk_var_lib_cassandra',
941 check_cmd=('check_disk -u GB -w 50% -c 25% -K 5% '944 check_cmd=('check_disk -u GB -w 50% -c 25% -K 5% '
942 '-p /var/lib/cassandra/data')),945 '-p /var/lib/cassandra'))],
943 call(description=ANY,
944 shortname='cassandra_disk_var_lib_cassandra_saved_caches',
945 check_cmd=ANY),
946 call(description=ANY,
947 shortname='cassandra_disk_var_lib_cassandra_commitlog',
948 check_cmd=ANY)],
949 any_order=True)946 any_order=True)
950947
951 nrpe().write.assert_called_once_with()948 nrpe().write.assert_called_once_with()
@@ -964,13 +961,15 @@
964 actions.nrpe_external_master_relation('')961 actions.nrpe_external_master_relation('')
965 self.assertFalse(write_file.called)962 self.assertFalse(write_file.called)
966963
964 @patch('helpers.mountpoint')
967 @patch('helpers.get_cassandra_version')965 @patch('helpers.get_cassandra_version')
968 @patch('os.path.exists')966 @patch('os.path.exists')
969 @patch('charmhelpers.contrib.charmsupport.nrpe.NRPE')967 @patch('charmhelpers.contrib.charmsupport.nrpe.NRPE')
970 def test_nrpe_external_master_relation_disable_heapchk(self, nrpe,968 def test_nrpe_external_master_relation_disable_heapchk(self, nrpe, exists,
971 exists, ver):969 ver, mountpoint):
972 ver.return_value = '2.2'970 ver.return_value = '2.2'
973 exists.return_value = False971 exists.return_value = False
972 mountpoint.side_effect = os.path.dirname
974973
975 # Disable our checks974 # Disable our checks
976 config = hookenv.config()975 config = hookenv.config()
@@ -981,11 +980,7 @@
981 exists.assert_called_once_with(helpers.local_plugins_dir())980 exists.assert_called_once_with(helpers.local_plugins_dir())
982981
983 nrpe().add_check.assert_has_calls([982 nrpe().add_check.assert_has_calls([
984 call(shortname='cassandra_disk_var_lib_cassandra_data',983 call(shortname='cassandra_disk_var_lib_cassandra',
985 description=ANY, check_cmd=ANY),
986 call(shortname='cassandra_disk_var_lib_cassandra_saved_caches',
987 description=ANY, check_cmd=ANY),
988 call(shortname='cassandra_disk_var_lib_cassandra_commitlog',
989 description=ANY, check_cmd=ANY)], any_order=True)984 description=ANY, check_cmd=ANY)], any_order=True)
990985
991 @patch('helpers.get_cassandra_version')986 @patch('helpers.get_cassandra_version')

Subscribers

People subscribed via source and target branches

to all changes: