Merge "Adds NRPE checks for services"

This commit is contained in:
Zuul 2021-09-09 13:32:53 +00:00 committed by Gerrit Code Review
commit b75e6ed3ce
21 changed files with 149 additions and 9 deletions

View File

@ -61,3 +61,18 @@ options:
description: |
The 'default_share_type' must match the configured default_share_type
set up in manila using 'manila create-type'.
nagios_context:
type: string
default: "juju"
description: |
Used by the nrpe-external-master subordinate charm. A string that will
be prepended to instance names in order to set the hostname in nagios.
With the default value for example the resulting hostname will look
like 'juju-myservice-0'. If you are running multiple environments with
the same services this allows you to differentiate between them.
nagios_servicegroups:
type: string
default: ""
description: |
A comma-separated list of nagios servicegroups. If left empty, the
nagios_context will be used as the servicegroup

View File

@ -5,6 +5,7 @@ includes:
- interface:keystone
- interface:neutron-plugin
- interface:manila-plugin
- interface:nrpe-external-master
repo: https://github.com/openstack/charm-manila
options:
basic:

View File

@ -22,6 +22,7 @@ import re
import subprocess
import charmhelpers.core.host as host
import charmhelpers.contrib.charmsupport.nrpe as nrpe
import charms_openstack.charm
import charms_openstack.adapters
import charms_openstack.ip as os_ip
@ -468,6 +469,15 @@ class ManilaCharm(charms_openstack.charm.HAOpenStackCharm):
host.service_reload('apache2',
restart_on_failure=True)
def render_nrpe_checks(self):
"""Configure Nagios NRPE checks."""
hostname = nrpe.get_nagios_hostname()
current_unit = nrpe.get_nagios_unit_name()
charm_nrpe = nrpe.NRPE(hostname=hostname)
nrpe.add_init_service_checks(
charm_nrpe, self.services, current_unit)
charm_nrpe.write()
class ManilaCharmRocky(ManilaCharm):

View File

@ -33,3 +33,7 @@ requires:
scope: container
remote-manila-plugin:
interface: manila-plugin
provides:
nrpe-external-master:
interface: nrpe-external-master
scope: container

View File

@ -197,3 +197,15 @@ def cluster_connected(hacluster):
with charms_openstack.charm.provide_charm_instance() as manila_charm:
manila_charm.configure_ha_resources(hacluster)
manila_charm.assess_status()
@charms.reactive.when_none('charm.paused', 'is-update-status-hook')
@charms.reactive.when('config.rendered')
@charms.reactive.when_any('config.changed.nagios_context',
'config.changed.nagios_servicegroups',
'endpoint.nrpe-external-master.changed',
'nrpe-external-master.available')
def configure_nrpe():
"""Handle config-changed for NRPE options."""
with charms_openstack.charm.provide_charm_instance() as manila_charm:
manila_charm.render_nrpe_checks()

View File

@ -19,6 +19,8 @@ services:
keystone:
charm: cs:~openstack-charmers-next/keystone
num_units: 1
nrpe:
charm: cs:nrpe
relations:
- - manila:manila-plugin
@ -30,4 +32,6 @@ relations:
- - keystone
- percona-cluster
- - manila
- percona-cluster
- percona-cluster
- - nrpe:nrpe-external-master
- manila:nrpe-external-master

View File

@ -83,6 +83,9 @@ services:
num_units: 1
options:
openstack-origin: *source
nrpe:
charm: cs:nrpe
relations:
- - ceph-mon
- ceph-osd
@ -143,4 +146,6 @@ relations:
- - 'nova-cloud-controller:image-service'
- 'glance:image-service'
- - 'nova-cloud-controller:quantum-network-service'
- 'neutron-gateway:quantum-network-service'
- 'neutron-gateway:quantum-network-service'
- - 'nrpe:nrpe-external-master'
- 'manila:nrpe-external-master'

View File

@ -83,6 +83,8 @@ services:
num_units: 1
options:
openstack-origin: *source
nrpe:
charm: cs:nrpe
relations:
- - ceph-mon
@ -145,3 +147,5 @@ relations:
- 'glance:image-service'
- - 'nova-cloud-controller:quantum-network-service'
- 'neutron-gateway:quantum-network-service'
- - 'nrpe:nrpe-external-master'
- 'manila:nrpe-external-master'

View File

@ -88,6 +88,9 @@ services:
num_units: 3
options:
openstack-origin: *source
nrpe:
charm: cs:nrpe
relations:
- - ceph-mon
- ceph-osd
@ -156,4 +159,6 @@ relations:
- - 'placement:shared-db'
- 'percona-cluster:shared-db'
- - 'placement:identity-service'
- 'keystone:identity-service'
- 'keystone:identity-service'
- - 'nrpe:nrpe-external-master'
- 'manila:nrpe-external-master'

View File

@ -90,6 +90,9 @@ services:
num_units: 1
options:
openstack-origin: *source
nrpe:
charm: cs:nrpe
relations:
- - 'ceph-mon'
- 'ceph-osd'
@ -159,3 +162,5 @@ relations:
- 'percona-cluster:shared-db'
- - 'placement:identity-service'
- 'keystone:identity-service'
- - 'nrpe:nrpe-external-master'
- 'manila:nrpe-external-master'

View File

@ -195,6 +195,9 @@ services:
to:
- '23'
nrpe:
charm: cs:nrpe
relations:
- - 'ceph-mon'
- 'ceph-osd'
@ -311,3 +314,6 @@ relations:
- - 'placement:identity-service'
- 'keystone:identity-service'
- - 'nrpe:nrpe-external-master'
- 'manila:nrpe-external-master'

View File

@ -195,6 +195,9 @@ services:
to:
- '23'
nrpe:
charm: cs:nrpe
relations:
- - 'ceph-mon'
- 'ceph-osd'
@ -311,3 +314,6 @@ relations:
- - 'placement:identity-service'
- 'keystone:identity-service'
- - 'nrpe:nrpe-external-master'
- 'manila:nrpe-external-master'

View File

@ -195,6 +195,9 @@ services:
to:
- '23'
nrpe:
charm: cs:nrpe
relations:
- - 'ceph-mon'
- 'ceph-osd'
@ -311,3 +314,6 @@ relations:
- - 'placement:identity-service'
- 'keystone:identity-service'
- - 'nrpe:nrpe-external-master'
- 'manila:nrpe-external-master'

View File

@ -28,6 +28,8 @@ services:
num_units: 1
options:
openstack-origin: *source
nrpe:
charm: cs:nrpe
relations:
- - manila:manila-plugin
@ -40,3 +42,6 @@ relations:
- percona-cluster
- - manila
- percona-cluster
- - nrpe:nrpe-external-master
- manila:nrpe-external-master

View File

@ -28,6 +28,8 @@ services:
num_units: 1
options:
openstack-origin: *source
nrpe:
charm: cs:nrpe
relations:
- - manila:manila-plugin
@ -39,4 +41,6 @@ relations:
- - keystone
- percona-cluster
- - manila
- percona-cluster
- percona-cluster
- - nrpe:nrpe-external-master
- manila:nrpe-external-master

View File

@ -28,6 +28,9 @@ services:
num_units: 1
options:
openstack-origin: *source
nrpe:
charm: cs:nrpe
relations:
- - manila:manila-plugin
- manila-generic
@ -38,4 +41,6 @@ relations:
- - keystone
- percona-cluster
- - manila
- percona-cluster
- percona-cluster
- - nrpe:nrpe-external-master
- manila:nrpe-external-master

View File

@ -28,6 +28,8 @@ services:
num_units: 1
options:
openstack-origin: *source
nrpe:
charm: cs:nrpe
relations:
- - manila:manila-plugin
@ -39,4 +41,6 @@ relations:
- - keystone
- percona-cluster
- - manila
- percona-cluster
- percona-cluster
- - nrpe:nrpe-external-master
- manila:nrpe-external-master

View File

@ -18,10 +18,14 @@ dev_bundles:
- xenial-queens
smoke_bundles:
- ganesha: bionic-stein
target_deploy_status: {}
target_deploy_status:
nrpe:
workload-status: blocked
workload-status-message: "Nagios server not configured or related"
tests:
- zaza.openstack.charm_tests.manila.tests.ManilaTests
- ganesha:
- zaza.openstack.charm_tests.manila.tests.ManilaTests
- zaza.openstack.charm_tests.manila_ganesha.tests.ManilaGaneshaTests
configure:
- zaza.openstack.charm_tests.keystone.setup.add_demo_user
@ -32,6 +36,11 @@ configure:
- zaza.openstack.charm_tests.nova.setup.manage_ssh_key
- zaza.openstack.charm_tests.keystone.setup.add_demo_user
- zaza.openstack.charm_tests.manila_ganesha.setup.setup_ganesha_share_type
configure_options:
configure_gateway_ext_port_use_juju_wait: False
tests_options:
force_deploy:
# NOTE(lourot): this is needed because the NRPE charm isn't available on
# non-LTS Ubuntu series. See lp:1933643
- groovy-victoria
- hirsute-wallaby

View File

@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import mock
import sys
sys.path.append('src')
@ -20,3 +21,4 @@ sys.path.append('src/lib')
# Mock out charmhelpers so that we can test without it.
import charms_openstack.test_mocks # noqa
charms_openstack.test_mocks.mock_charmhelpers()
sys.modules['charmhelpers.contrib.charmsupport.nrpe'] = mock.MagicMock()

View File

@ -253,3 +253,22 @@ class TestManilaCharm(Helper):
self.assertEqual(c.config_lines_for('conf'), ["conf-string", ''])
self.assertEqual(c.config_lines_for('conf2'), ["conf2-string", ''])
self.assertEqual(c.config_lines_for('conf3'), ["conf3-string", ''])
def test_render_nrpe_checks(self):
"""Test NRPE renders correctly"""
self.patch_object(manila.nrpe, 'NRPE')
self.patch_object(manila.nrpe, 'add_init_service_checks')
target = manila.ManilaCharm()
target.render_nrpe_checks()
self.add_init_service_checks.assert_has_calls([
mock.call().add_init_service_checks(
mock.ANY,
target.services,
mock.ANY
),
])
self.NRPE.assert_has_calls([
mock.call().write(),
])

View File

@ -42,7 +42,8 @@ class TestRegisteredHooks(test_utils.TestRegisteredHooks):
'identity-service.available',
'amqp.available', ),
'config_rendered': ('db.synced', 'manila.config.rendered',),
'cluster_connected': ('ha.connected',)
'cluster_connected': ('ha.connected',),
'configure_nrpe': ('config.rendered',)
},
'when_not': {
'register_endpoints': ('identity-service.available', ),
@ -55,8 +56,16 @@ class TestRegisteredHooks(test_utils.TestRegisteredHooks):
'remote-manila-plugin.changed', ),
'share_to_manila_plugins_auth': (
'manila-plugin.connected',
'remote-manila-plugin.connected', )
'remote-manila-plugin.connected', ),
'configure_nrpe': (
'config.changed.nagios_context',
'config.changed.nagios_servicegroups',
'endpoint.nrpe-external-master.changed',
'nrpe-external-master.available', )
},
'when_none': {
'configure_nrpe': ('charm.paused', 'is-update-status-hook', )
}
}
# test that the hooks were registered via the
# reactive.barbican_handlers