Merge lp:~axino/charm-helpers/set-primary-charm-on-nrpe-relation into lp:charm-helpers

Proposed by Junien F
Status: Merged
Merged at revision: 621
Proposed branch: lp:~axino/charm-helpers/set-primary-charm-on-nrpe-relation
Merge into: lp:charm-helpers
Diff against target: 66 lines (+18/-4)
2 files modified
charmhelpers/contrib/charmsupport/nrpe.py (+15/-1)
tests/contrib/charmsupport/test_nrpe.py (+3/-3)
To merge this branch: bzr merge lp:~axino/charm-helpers/set-primary-charm-on-nrpe-relation
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Review via email: mp+290097@code.launchpad.net

Description of the change

(Stolen from https://code.launchpad.net/~thedac/charm-helpers/set-primary-charm-on-nrpe-relation/+merge/256057)

In IS we have scenarios where a unit may have its primary charm and multiple subordinate charms related to nrpe{,-external-master}.

The nrpe-external-master and nrpe charms determine the hostname to use by the charm service name when using nagios_hostname_type unit. This process is non-deterministic and the ordering of which charm is related to nrpe is significant.

This leads to situations where the hostname generated uses the subordinate charm's service name rather than the primary charm.

The only way to guarantee that the primary charm is used, is to set the information on the relation in the charm and then test for it in the nrpe-external-master charm.

This MP is one half of the solution. Primary charms will default to True and subordinate charms can set primary=False.

Explicitly set when a charm is the primary charm (vs a subordinate charm) in the npre-external-master relation.
For use when multiple charms primary and subordinate are related to nrpe{,-external-master} on the same unit.
The default is set to True as this is the case 99% of the time.
Only subordinate charms which are related to nrpe{,-external-master} need set primary=False on the relation.

To post a comment you must log in.
Revision history for this message
Stuart Bishop (stub) wrote :

Calling relation_set without an explicit relation_id only works if inside a relation hook, so that needs to be fixed (see inline comments). Otherwise looking fine.

review: Needs Fixing
555. By Charles Butler

[r=beisner,a=lazypower] Anton Skriptsov 2016-03-22 add NexentaEdge's charms to no_origin list

556. By David Ames

[jamespage, r=thedac] Add extra-binding awareness to openstack api endpoint resolver

557. By James Page

Add InternalEndpointContext to contrib.openstack.context

558. By Edward Hope-Morley

[gnuoy,r=hopem]

When checking if a System V service is running, query
service --all-status which keeps track of the services
and their return codes.

Closes-Bug: 1564842

559. By David Ames

[thedac, r=jamespage] Apparmor context class for OpenStack charms

The class will validate aa-profile-mode config settings and either set
the profile to enforce, complain or disable.

560. By David Ames

[coreycb, r=thedac] Add support for keystone liberty release 8.1.0

561. By David Ames

[jamespage, r=thedac] Add support for specifying the datapath type of an ovs bridge

562. By Ryan Beisner

[chris.macnaughton, r=1chb1n] Allow the validate_unit_process_ids test helper to accept a list of valid values

563. By Ryan Beisner

[chris.macnaughton, r=1chb1n] Trivial lint fix

564. By James Page

Allow custom functions to be used to restart services in the restart_on_change functions.

565. By James Page

[trivial] Add 2.7.0 to the list of swift mitaka releases.

566. By Ryan Beisner

[xfactor973, r=1chb1n] Add the final update_pool call in Ceph pool creation to set the replica count (bug 1565120)

567. By Ryan Beisner

[xfactor973, r=1chb1n] Add mandatory flag for ceph jewel and above

568. By Liam Young

[gnuoy, r=james-page] Add openstack mitaka compatible template for keystone-authtoken

569. By Edward Hope-Morley

[hopem,r=gnuoy]

Fix contib.storage.linux.ceph pool_exists()
Partially-Closes-Bug: 1572506

570. By James Page

Switch is_device_mounted to use lsblk

This will correct detect a wider range of 'is use' states compared
to parsing the output of /proc/mounts, including block devices that
are part of LVM volumes.

571. By James Page

Add support for mitaka/neutron 8.1.x series

572. By David Ames

[thedac,r=tinwood] Actively check for stopped message(s) in service_running

573. By James Page

Fix ipv6 address recongition under xenial.

574. By James Page

Refactor service_running to determine init approach

Use of "service --status-all" has some challenges on trusty where
a recent lsb-base update resulted in all calls being diverted to
upstart, where return codes for non-running daemons are still 0.

Detect whether to use upstart or the base init.d script to
determine whether a service is running, and look at either the
upstart output, or for a non-zero return code from an init.d
status call.

575. By James Page

Add support for generation of systemd unit files for OpenStack
deploy from source.

576. By James Page

Add support for Netwon and Ocata OpenStack release

Drop back to matching major versions only for projects that use semantic versioning.

577. By Edward Hope-Morley

[hopem,r=jamespage]

Add CephConfContext to contrib.storage.linux.ceph

Also moved contrib.openstack.context.config_flags_parser to
contrib.openstack.utils and created contrib.openstack.exceptions
Related-Bug: 1522375

578. By James Page

Add support for fallback matching on major.minor version for Swift

This allows trunk package builds to be used with the charms.

579. By James Page

Ensure is_ip detects both IPv4 and IPv6 addresses

580. By Edward Hope-Morley

[trivial] context should use set().difference not set().symmetric_difference when validating keys

581. By Matt Bruzek

[jamesbeedy] Added uid and gid specification functionality for adduser and addgroup.
[mbruzek] Added a newline to fix lint.

582. By Ryan Beisner

[jamespage,r=1chb1n] Update amulet helpers to deploy charms from the charm store

As part of the migration to git/gerrit and with the introduction of
layered charms, the charm store really needs to be the definative
source of truth for all charms during test.

Switch the charm resolver code to pick the correct charms from the
charm store for amulet tests.

This does change behaviour in that base charms are deployed aligned
to the test series where possible; otherwise the most recent Ubuntu
series is used instead - results in mysql/trusty + keystone/xenial
for example.

583. By James Page

Enable default git repo generation if a default openstack-origin-git value is specified.

584. By David Ames

[thedac, r=tinwood] DNS HA Helpers

Start the process of moving HA helpers into the openstack contrib area
Add the helper for API charms to use DNS HA
Add validation for new DNS config options in HA
Allow resolve_address to override with DNS or not

585. By Stuart Bishop

[marcoceppi, r=stub] Fix bzr branch installer

586. By Stuart Bishop

[george-edison55, r=stub] Fix fetch.install_remote() when multiple handlers match the URL

587. By Stuart Bishop

[chris-gondolin, r=stub] Option to specify a revno when fetching from a bzr repo

588. By Stuart Bishop

[stub] Add test to bzr revno fetcher, fix casting of bzr revno

589. By Stuart Bishop

[freyes, r=stub] Mock contrib.network.ufw.modprobe in tests as required

590. By James Page

Updates for DNS-HA support in non-api OpenStack charms.

591. By James Page

Rebase

592. By Liam Young

[gnuoy, r=james-page] Decode result of check_output in network_get_primary_address

Under python3.5 check_output returns bytes which need decoding. This change
adds the decode to network_get_primary_address and brings it in line with other
core hookenv functions.

593. By James Page

Fixes for deploy from source for openstack

594. By James Page

Fixes for apparmor support for openstack contrib module

595. By James Page

Misc fixes and improvements for deploy-from-source.

596. By James Page

Add missing openstack.ha package to setup.py

597. By Marco Ceppi <marco@T430>

[james-page] Re-license charm-helpers inline with agreed licensing approaches for charms, interfaces and layers.

598. By Marco Ceppi <marco@T430>

version bump

599. By Marco Ceppi <marco@T430>

flake8 fixes

600. By James Page

[trivial] Support nrpe for testing on wily and xenial

601. By James Page

Add option to allow location of user home directory to be provided when creating users.

602. By Ryan Beisner

[chris.macnaughton, r=1chb1n] Add ceph-proxy to source charms for openstack amulet helper

603. By Ryan Beisner

[thedac, r=1chb1n] Send LSB release to apparmor context templates

Set the LSB release to be consumed by apparmor context profiles

604. By David Ames

[billy-olsen, r=thedac] Allow float for worker-multiplier.

605. By James Page

Misc updates for deploy from source

Improve OpenStack release determination.

606. By Jorge Niedbalski

[billy-olsen, r=niedbalski, cholcombe] Partially fixes bug LP: #1492742

607. By Jorge Niedbalski

[niedbalski, r=] Fix broken tests for py2.7

608. By Stuart Bishop

[stub,r=james-page] Make fetch.apt_cache() quiet by default

609. By Stuart Bishop

[fginther, r=stub] Install python3-jinja2 when running Python3

610. By James Page

Add 2.9.0 to list of releases for newton

611. By David Ames

[thedac, r=gnuoy] Make apt_install fatal=True for dnspython install

612. By Liam Young

[gnuoy, r=jamespage] Only write out CA cert if it has changed

Only write out CA cert and run the update-ca-certificates if the cert has
actually changed. This reduces the risk of certs being pulled from under services
which are trying to do client side certificate validation on remote https
endpoints.

613. By Liam Young

[1chb1n, r=gnuoy] Consume env var AMULET_SETUP_TIMEOUT if set

614. By Liam Young

[corey.bryant, r=gnuoy] Install networking-hyperv when deploying neutron-api from source.

615. By Stuart Bishop

[axino, r=stub] nrpe: make add_init_service_checks support systemd

616. By Liam Young

[ajkavanagh r=gnuoy] Add a v3 version of service catalog checking

This adds a keystone v3 version of service catalog checking to the
contrib/openstack/amulet/utils.py file.

617. By Liam Young

[gnuoy, trivial] Lint fix

618. By James Page

Set a minimum PG count of 2, to avoid math domain errors in small OSD setups

619. By Ryan Beisner

[thedac, 1chb1n] Add support for Mitaka NSX

Update Neutron plugins for NSX on Mitaka

620. By Marco Ceppi <marco@T430>

[dbuliga] Added support for CentOS

621. By Junien F

Explicitly set when a charm is the primary charm (vs a subordinate charm) in the npre-external-master relation.
For use when multiple charms primary and subordinate are related to nrpe{,-external-master} on the same unit.
The default is set to True as this is the case 99% of the time.
Only subordinate charms which are related to nrpe{,-external-master} need to set primary=False on the relation.

Revision history for this message
Stuart Bishop (stub) wrote :

All good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/contrib/charmsupport/nrpe.py'
2--- charmhelpers/contrib/charmsupport/nrpe.py 2016-07-29 10:15:48 +0000
3+++ charmhelpers/contrib/charmsupport/nrpe.py 2016-09-06 06:26:52 +0000
4@@ -109,6 +109,13 @@
5 # def local_monitors_relation_changed():
6 # update_nrpe_config()
7 #
8+# 4.a If your charm is a subordinate charm set primary=False
9+#
10+# from charmsupport.nrpe import NRPE
11+# (...)
12+# def update_nrpe_config():
13+# nrpe_compat = NRPE(primary=False)
14+#
15 # 5. ln -s hooks.py nrpe-external-master-relation-changed
16 # ln -s hooks.py local-monitors-relation-changed
17
18@@ -221,9 +228,10 @@
19 nagios_exportdir = '/var/lib/nagios/export'
20 nrpe_confdir = '/etc/nagios/nrpe.d'
21
22- def __init__(self, hostname=None):
23+ def __init__(self, hostname=None, primary=True):
24 super(NRPE, self).__init__()
25 self.config = config()
26+ self.primary = primary
27 self.nagios_context = self.config['nagios_context']
28 if 'nagios_servicegroups' in self.config and self.config['nagios_servicegroups']:
29 self.nagios_servicegroups = self.config['nagios_servicegroups']
30@@ -239,6 +247,12 @@
31 else:
32 self.hostname = "{}-{}".format(self.nagios_context, self.unit_name)
33 self.checks = []
34+ # Iff in an nrpe-external-master relation hook, set primary status
35+ relation = relation_ids('nrpe-external-master')
36+ if relation:
37+ log("Setting charm primary status {}".format(primary))
38+ for rid in relation_ids('nrpe-external-master'):
39+ relation_set(relation_id=rid, relation_settings={'primary': self.primary})
40
41 def add_check(self, *args, **kwargs):
42 self.checks.append(Check(*args, **kwargs))
43
44=== modified file 'tests/contrib/charmsupport/test_nrpe.py'
45--- tests/contrib/charmsupport/test_nrpe.py 2016-07-29 10:15:48 +0000
46+++ tests/contrib/charmsupport/test_nrpe.py 2016-09-06 06:26:52 +0000
47@@ -90,8 +90,8 @@
48 self.assertEqual(None, checker.write())
49
50 expected = 'Nagios user not set up, nrpe checks not updated'
51- self.patched['log'].assert_called_once_with(expected)
52- self.check_call_counts(log=1, config=1, getpwnam=1, getgrnam=1)
53+ self.patched['log'].assert_called_with(expected)
54+ self.check_call_counts(log=2, config=1, getpwnam=1, getgrnam=1)
55
56 def test_write_no_checker(self):
57 self.patched['config'].return_value = {'nagios_context': 'test',
58@@ -175,7 +175,7 @@
59 self.patched['relation_set'].assert_has_calls(relation_set_calls, any_order=True)
60 self.check_call_counts(config=1, getpwnam=1, getgrnam=1,
61 exists=4, open=2, listdir=1,
62- relation_ids=2, relation_set=2)
63+ relation_ids=4, relation_set=3)
64
65
66 class NRPECheckTestCase(NRPEBaseTestCase):

Subscribers

People subscribed via source and target branches