From 882e78c5ad76df9232dfd4b741031c4b36341b9c Mon Sep 17 00:00:00 2001 From: Alex Kavanagh Date: Fri, 23 Nov 2018 16:04:44 +0000 Subject: [PATCH] Sync c-h nrpe.py file to fix nrpe files copy issue Due to a change to PY3, the charmhelpers directory is not in the CHARMDIR rather than in CHARMDIR/hooks. This broke the copy_nrpe_checks() function in c-h. c-h has been updated, to look in both CHARMDIR and CHARMDIR/hooks for the charmhelpers directory, and this patchset includes the new function definition. Change-Id: I95250d6624827eb159a450523e05284c9248ba07 Closes-Bug: #1796830 --- charmhelpers/contrib/charmsupport/nrpe.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/charmhelpers/contrib/charmsupport/nrpe.py b/charmhelpers/contrib/charmsupport/nrpe.py index e3d10c1c..10d86ac0 100644 --- a/charmhelpers/contrib/charmsupport/nrpe.py +++ b/charmhelpers/contrib/charmsupport/nrpe.py @@ -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_*")):