コード例 #1
0
    def test_update_nrpe_config(self, nrpe, services, apt_install):
        # Setup Mocks
        nrpe.get_nagios_hostname.return_value = 'foo'
        nrpe.get_nagios_unit_name.return_value = 'bar'
        nrpe_setup = MagicMock()
        nrpe.NRPE.return_value = nrpe_setup
        services.return_value = ['baz', 'qux']

        # Call the routine
        ceph_hooks.update_nrpe_config()

        # Verify calls
        apt_install.assert_called()
        nrpe.get_nagios_hostname.assert_called()
        nrpe.get_nagios_unit_name.assert_called()
        nrpe.copy_nrpe_checks.assert_called()
        nrpe.remove_check.assert_not_called()
        nrpe.add_init_service_checks.assert_called_with(
            nrpe_setup, ['baz', 'qux'], 'bar')
        nrpe.add_haproxy_checks.assert_called_with(nrpe_setup, 'bar')
        nrpe_setup.write.assert_called()

        # Verify that remove_check is called appropriately if we pass
        # checks_to_remove
        ceph_hooks.update_nrpe_config(checks_to_remove=['quux', 'quuux'])
        nrpe_setup.remove_check.assert_has_calls(
            [call(shortname='quux'),
             call(shortname='quuux')])
コード例 #2
0
    def test_update_nrpe_config(self, nrpe, services, apt_install):
        # Setup Mocks
        nrpe.get_nagios_hostname.return_value = 'foo'
        nrpe.get_nagios_unit_name.return_value = 'bar'
        nrpe_setup = MagicMock()
        nrpe.NRPE.return_value = nrpe_setup
        services.return_value = ['baz', 'qux']

        # Call the routine
        ceph_hooks.update_nrpe_config()

        # Verify calls
        apt_install.assert_called()
        nrpe.get_nagios_hostname.assert_called()
        nrpe.get_nagios_unit_name.assert_called()
        nrpe.copy_nrpe_checks.assert_called()
        nrpe.remove_check.assert_not_called()
        nrpe.add_init_service_checks.assert_called_with(nrpe_setup,
                                                        ['baz', 'qux'], 'bar')
        nrpe.add_haproxy_checks.assert_called_with(nrpe_setup, 'bar')
        nrpe_setup.write.assert_called()

        # Verify that remove_check is called appropriately if we pass
        # checks_to_remove
        ceph_hooks.update_nrpe_config(checks_to_remove=['quux', 'quuux'])
        nrpe_setup.remove_check.assert_has_calls([call(shortname='quux'),
                                                  call(shortname='quuux')])
コード例 #3
0
    def test_update_nrpe_config(self, nrpe, install_nrpe_scripts):
        nrpe_compat = MagicMock()
        nrpe_compat.checks = [MagicMock(shortname="haproxy"),
                              MagicMock(shortname="haproxy_queue")]
        nrpe.return_value = nrpe_compat

        hooks.update_nrpe_config()

        self.assertEqual(
            nrpe_compat.mock_calls,
            [call.add_check('haproxy', 'Check HAProxy', 'check_haproxy.sh'),
             call.add_check('haproxy_queue', 'Check HAProxy queue depth',
                            'check_haproxy_queue_depth.sh'),
             call.write()])
コード例 #4
0
    def test_update_nrpe_config(self, nrpe, install_nrpe_scripts):
        nrpe_compat = MagicMock()
        nrpe_compat.checks = [
            MagicMock(shortname="haproxy"),
            MagicMock(shortname="haproxy_queue")
        ]
        nrpe.return_value = nrpe_compat

        hooks.update_nrpe_config()

        self.assertEqual(nrpe_compat.mock_calls, [
            call.add_check('haproxy', 'Check HAProxy', 'check_haproxy.sh'),
            call.add_check('haproxy_queue', 'Check HAProxy queue depth',
                           'check_haproxy_queue_depth.sh'),
            call.write()
        ])
コード例 #5
0
    def test_update_nrpe_config(self, config, status_set, mock_glob, mock_os,
                                nrpe, apt_install, mock_distrib_codename):

        cfg = {
            'failed_actions_threshold': 0,
            'res_failcount_warn': 0,
            'res_failcount_crit': 5
        }
        config.side_effect = lambda key: cfg.get(key)

        mock_distrib_codename.side_effect = ['bionic', 'eoan', 'focal']
        ring_check_expected = iter([True, False, False])

        # Set up valid values to try for 'failed_actions_alert_type'
        alert_type_params = ["IGNore", "warning", "CRITICAL"]
        for alert_type in alert_type_params:
            cfg['failed_actions_alert_type'] = alert_type
            nrpe.get_nagios_hostname.return_value = 'localhost'
            nrpe.get_nagios_unit_name.return_value = 'nagios/1'
            mock_nrpe_setup = mock.MagicMock()
            nrpe.NRPE.return_value = mock_nrpe_setup

            hooks.update_nrpe_config()

            nrpe.NRPE.assert_called_once_with(hostname='localhost')
            apt_install.assert_called_once_with('python-dbus')

            check_crm_cmd = ('check_crm -s --failedactions={} '
                             '--failcount-warn={} --failcount-crit={}'.format(
                                 cfg['failed_actions_alert_type'].lower(),
                                 cfg['res_failcount_warn'],
                                 cfg['res_failcount_crit']))

            if next(ring_check_expected):
                mock_nrpe_setup.add_check.assert_any_call(
                    shortname='corosync_rings',
                    description='Check Corosync rings nagios/1',
                    check_cmd='check_corosync_rings')
            else:
                mock_nrpe_setup.remove_check.assert_any_call(
                    shortname='corosync_rings',
                    description='Check Corosync rings nagios/1',
                    check_cmd='check_corosync_rings')
            mock_nrpe_setup.add_check.assert_any_call(
                shortname='crm_status',
                description='Check crm status nagios/1',
                check_cmd=check_crm_cmd)

            mock_nrpe_setup.add_check.assert_any_call(
                shortname='corosync_proc',
                description='Check Corosync process nagios/1',
                check_cmd='check_procs -c 1:1 -C corosync')
            mock_nrpe_setup.add_check.assert_any_call(
                shortname='pacemakerd_proc',
                description='Check Pacemakerd process nagios/1',
                check_cmd='check_procs -c 1:1 -C pacemakerd')
            mock_nrpe_setup.write.assert_called_once()

            nrpe.reset_mock()
            apt_install.reset_mock()

        # Check unsupported case for failed_actions_alert_type
        cfg['failed_actions_alert_type'] = 'unsupported'
        cfg['failed_actions_threshold'] = 1
        hooks.update_nrpe_config()
        valid_alerts = ['ignore', 'warning', 'critical']
        status_set.assert_called_once_with(
            'blocked', 'The value of option '
            'failed_actions_alert_type must be '
            'among {}'.format(valid_alerts))
        status_set.reset_mock()

        # Check unsupported case for failed_actions_threshold
        cfg['failed_actions_alert_type'] = 'ignore'
        cfg['failed_actions_threshold'] = -5
        hooks.update_nrpe_config()
        status_set.assert_called_once_with(
            'blocked', 'The value of option failed_'
            'actions_threshold must be a '
            'positive integer')