Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update copy_nrpe_checks() for optional c-h directory (#247) #251

Merged
merged 1 commit into from
Nov 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions charmhelpers/contrib/charmsupport/nrpe.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,15 +416,20 @@ def copy_nrpe_checks(nrpe_files_dir=None):

"""
NAGIOS_PLUGINS = '/usr/local/lib/nagios/plugins'
default_nrpe_files_dir = os.path.join(
os.getenv('CHARM_DIR'),
'hooks',
'charmhelpers',
'contrib',
'openstack',
'files')
if not nrpe_files_dir:
nrpe_files_dir = default_nrpe_files_dir
if nrpe_files_dir is None:
# determine if "charmhelpers" is in CHARMDIR or CHARMDIR/hooks
for segment in ['.', 'hooks']:
nrpe_files_dir = os.path.abspath(os.path.join(
os.getenv('CHARM_DIR'),
segment,
'charmhelpers',
'contrib',
'openstack',
'files'))
if os.path.isdir(nrpe_files_dir):
break
else:
raise RuntimeError("Couldn't find charmhelpers directory")
if not os.path.exists(NAGIOS_PLUGINS):
os.makedirs(NAGIOS_PLUGINS)
for fname in glob.glob(os.path.join(nrpe_files_dir, "check_*")):
Expand Down
18 changes: 18 additions & 0 deletions tests/contrib/charmsupport/test_nrpe.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class NRPEBaseTestCase(TestCase):
'remove': {'object': os},
'open': {'object': nrpe, 'create': True},
'isfile': {'object': os.path},
'isdir': {'object': os.path},
'call': {'object': subprocess},
'relation_ids': {'object': nrpe},
'relation_set': {'object': nrpe},
Expand Down Expand Up @@ -370,6 +371,7 @@ def test_copy_nrpe_checks(self):
'fileb': False}
self.patched['exists'].return_value = True
self.patched['glob'].return_value = ['filea', 'fileb']
self.patched['isdir'].side_effect = [False, True]
self.patched['isfile'].side_effect = lambda x: file_presence[x]
nrpe.copy_nrpe_checks()
self.patched['glob'].assert_called_once_with(
Expand All @@ -379,6 +381,22 @@ def test_copy_nrpe_checks(self):
'filea',
'/usr/local/lib/nagios/plugins/filea')

def test_copy_nrpe_checks_other_root(self):
file_presence = {
'filea': True,
'fileb': False}
self.patched['exists'].return_value = True
self.patched['glob'].return_value = ['filea', 'fileb']
self.patched['isdir'].side_effect = [True, False]
self.patched['isfile'].side_effect = lambda x: file_presence[x]
nrpe.copy_nrpe_checks()
self.patched['glob'].assert_called_once_with(
('/usr/lib/test_charm_dir/charmhelpers/contrib/openstack/'
'files/check_*'))
self.patched['copy2'].assert_called_once_with(
'filea',
'/usr/local/lib/nagios/plugins/filea')

def test_copy_nrpe_checks_nrpe_files_dir(self):
file_presence = {
'filea': True,
Expand Down