← Back to team overview

nagios-charmers team mailing list archive

[Bug 1712977] Re: config-changed hook fails: nrpe_helpers.py:nagios_hostname in _metadata_unit with FileNotFoundError error for metadata.yaml of related unit on another host

 

This also affects the Nagios charm, e.g.:

(added pdb.set_trace() to L210 of core/hookenv.py)

root@juju-machine-0-lxc-6:/var/lib/juju/agents/unit-nagios-0/charm# ./hooks/upgrade-charm 
> /var/lib/juju/agents/unit-nagios-0/charm/hooks/charmhelpers/core/hookenv.py(218)principal_unit()
-> for reltype in relation_types():
(Pdb) principal_unit
(Pdb) os.environ['JUJU_UNIT_NAME']
'nagios/0'
(Pdb) relation_types()
['website', 'monitors', 'nagios']

(Pdb) relation_ids('monitors')                                                                                       
[u'monitors:143', u'monitors:144', u'monitors:148']
(Pdb) related_units('monitors:143')
[u'nrpe/0', u'nrpe/1', u'nrpe/10', u'nrpe/11', u'nrpe/12', u'nrpe/13', u'nrpe/14', u'nrpe/15', u'nrpe/16', u'nrpe/17', u'nrpe/19', u'nrpe/2', u'nrpe/20', u'nrpe/3', u'nrpe/4', u'nrpe/5', u'nrpe/6', u'nrpe/7', u'nrpe/8', u'nrpe/9']

(Pdb) _metadata_unit('nrpe/1')
*** IOError: [Errno 2] No such file or directory: '/var/lib/juju/agents/unit-nrpe-1/charm/metadata.yaml'

(Pdb) relation_ids('nagios')
[]

This change seems to come about from rev 773 (merge/rebase) which adds
the principal_unit().

-- 
You received this bug notification because you are a member of Nagios
Charm developers, which is subscribed to Nagios Charm.
https://bugs.launchpad.net/bugs/1712977

Title:
  config-changed hook fails: nrpe_helpers.py:nagios_hostname in
  _metadata_unit with FileNotFoundError error for metadata.yaml of
  related unit on another host

Status in Charm Helpers:
  Confirmed
Status in Nagios Charm:
  New
Status in NRPE Charm:
  Confirmed

Bug description:
  Due to recent changes, nrpe_helpers.py:nagios_hostname calls
  charmhelpers.core.hookenv.principal_unit to get the parent unit's
  hostname.

  On Juju 2.1 or earlier, it does this by walking all relations of the
  unit and inspecting it's metadata file using _metadata_unit.

  This fails because it attempts to inspect units on another host, i.e.
  the parent nagios unit and _metadata_unit fires a FileNotFoundError
  exception for the file that doesn't exist.

  You can simulate this on Juju 2.2 by commenting out the Juju 2.2
  checks at the start and deploying the nagios and nrpe charms on
  separate machines.

  
  Traceback (most recent call last):
    File "/var/lib/juju/agents/unit-nrpe-0/charm/hooks/config-changed", line 3, in <module> 
      services.manage()
    File "/var/lib/juju/agents/unit-nrpe-0/charm/hooks/services.py", line 27, in manage
      nrpe_helpers.NagiosInfo(),
    File "/var/lib/juju/agents/unit-nrpe-0/charm/hooks/nrpe_helpers.py", line 202, in __init__
      self['nagios_hostname'] = self.principle_relation.nagios_hostname()
    File "/var/lib/juju/agents/unit-nrpe-0/charm/hooks/nrpe_helpers.py", line 163, in nagios_hostname
      principle_unitname = hookenv.principal_unit()
    File "/var/lib/juju/agents/unit-nrpe-0/charm/hooks/charmhelpers/core/hookenv.py", line 219, in principal_unit 
      md = _metadata_unit(unit)
    File "/var/lib/juju/agents/unit-nrpe-0/charm/hooks/charmhelpers/core/hookenv.py", line 513, in _metadata_unit 
      with open(os.path.join(basedir, unitdir, 'charm', 'metadata.yaml')) as md:
  FileNotFoundError: [Errno 2] No such file or directory: '/var/lib/juju/agents/unit-nagios-0/charm/metadata.yaml'

To manage notifications about this bug go to:
https://bugs.launchpad.net/charm-helpers/+bug/1712977/+subscriptions