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.

Note: the change in unit_tests/test_actions.py is to cope with a
difference between how subprocess.CalledProcessError() formats strings
when using str() between py35 and py36.  Python3.6 adds a period/dot to
the end of the sentence that Python3.5 didn't.

Change-Id: I8ebb1d6d78f0804007a9f79f31b3b0c4e0c441bd
Closes-Bug: #1796830
This commit is contained in:
Alex Kavanagh 2018-11-23 17:03:23 +00:00
parent 65c90e7c27
commit 96741629b4
2 changed files with 17 additions and 13 deletions

View File

@ -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_*")):

View File

@ -237,8 +237,8 @@ class AddUserTestCase(CharmTestCase):
self.determine_api_port.return_value = 8070
self.CalledProcessError = ValueError
self.check_call.side_effect = subprocess.CalledProcessError(
0, "hi", "no")
e = subprocess.CalledProcessError(0, "hi", "no")
self.check_call.side_effect = e
actions.add_user.add_user()
self.leader_get.assert_called_with("swauth-admin-key")
calls = [call("account"), call("username"), call("password")]
@ -246,8 +246,7 @@ class AddUserTestCase(CharmTestCase):
self.action_set.assert_not_called()
self.action_fail.assert_called_once_with(
'Adding user test failed with: "Command \'hi\' returned non-zero '
'exit status 0"')
'Adding user test failed with: "{}"'.format(str(e)))
class DiskUsageTestCase(CharmTestCase):