Install lockfile-progs when related to nagios

The nrpe ceph status script relies on lockfile-create, but
lockfile-progs (package containing lockfile-create) was missing from
the install. Install it when related to nagios, and on upgrade-charm
when related to nagios.

Change-Id: I0addf9993d486a4d305dd554237efe554d4608d4
Closes-Bug: #1629104
This commit is contained in:
Adam Collard 2016-11-29 14:24:51 +00:00
parent 0ed4671955
commit 5d635ae394
2 changed files with 35 additions and 4 deletions

View File

@ -32,6 +32,7 @@ from charmhelpers.core.hookenv import (
config,
relation_ids,
related_units,
is_relation_made,
relation_get,
relation_set,
remote_unit,
@ -514,6 +515,8 @@ def upgrade_charm():
ceph.update_monfs()
upgrade_keys()
mon_relation_joined()
if is_relation_made("nrpe-external-master"):
update_nrpe_config()
@hooks.hook('start')
@ -532,7 +535,8 @@ def start():
@hooks.hook('nrpe-external-master-relation-changed')
def update_nrpe_config():
# python-dbus is used by check_upstart_job
apt_install('python-dbus')
# lockfile-create is used by collect_ceph_status
apt_install(['python-dbus', 'lockfile-progs'])
log('Refreshing nagios checks')
if os.path.isdir(NAGIOS_PLUGINS):
rsync(os.path.join(os.getenv('CHARM_DIR'), 'files', 'nagios',

View File

@ -15,7 +15,7 @@
import copy
import unittest
from mock import patch
from mock import patch, DEFAULT
import charmhelpers.contrib.storage.linux.ceph as ceph
import ceph_hooks
@ -33,8 +33,6 @@ CHARM_CONFIG = {'config-flags': '',
class CephHooksTestCase(unittest.TestCase):
def setUp(self):
super(CephHooksTestCase, self).setUp()
@patch.object(ceph_hooks, 'get_public_addr', lambda *args: "10.0.0.1")
@patch.object(ceph_hooks, 'get_cluster_addr', lambda *args: "10.1.0.1")
@ -125,3 +123,32 @@ class CephHooksTestCase(unittest.TestCase):
'short_object_len': True,
'use_syslog': 'true'}
self.assertEqual(ctxt, expected)
def test_nrpe_dependency_installed(self):
with patch.multiple(ceph_hooks,
apt_install=DEFAULT,
rsync=DEFAULT,
log=DEFAULT,
write_file=DEFAULT,
nrpe=DEFAULT) as mocks:
ceph_hooks.update_nrpe_config()
mocks["apt_install"].assert_called_once_with(
["python-dbus", "lockfile-progs"])
def test_upgrade_charm_with_nrpe_relation_installs_dependencies(self):
with patch.multiple(
ceph_hooks,
apt_install=DEFAULT,
rsync=DEFAULT,
log=DEFAULT,
write_file=DEFAULT,
nrpe=DEFAULT,
emit_cephconf=DEFAULT,
upgrade_keys=DEFAULT,
mon_relation_joined=DEFAULT,
is_relation_made=DEFAULT) as mocks, patch(
"charmhelpers.contrib.hardening.harden.config"):
mocks["is_relation_made"].return_value = True
ceph_hooks.upgrade_charm()
mocks["apt_install"].assert_called_with(
["python-dbus", "lockfile-progs"])