def test_check_commands_on_units(self):
        self.patch("zaza.openstack.utilities.generic.model.run_on_unit",
                   new_callable=mock.MagicMock(),
                   name="_run")

        num_units = 2
        _units = [mock.MagicMock() for i in range(num_units)]

        num_cmds = 3
        cmds = ["/usr/bin/fakecmd"] * num_cmds

        # Test success, all calls return 0
        # zero is a string to replicate run_on_unit return data type
        _cmd_results = [{"Code": "0"}] * len(_units) * len(cmds)
        self._run.side_effect = _cmd_results

        result = generic_utils.check_commands_on_units(cmds, _units)
        self.assertIsNone(result)
        self.assertEqual(self._run.call_count, len(_units) * len(cmds))

        # Test failure, some call returns 1
        _cmd_results[2] = {"Code": "1"}
        self._run.side_effect = _cmd_results

        result = generic_utils.check_commands_on_units(cmds, _units)
        self.assertIsNotNone(result)
Exemplo n.º 2
0
    def test_414_rmq_nrpe_monitors(self):
        """Check rabbimq-server nrpe monitor basic functionality."""
        units = zaza.model.get_units(self.application_name)
        host_names = generic_utils.get_unit_hostnames(units)

        # check_rabbitmq monitor
        logging.info('Checking nrpe check_rabbitmq on units...')
        cmds = ['egrep -oh /usr/local.* /etc/nagios/nrpe.d/'
                'check_rabbitmq.cfg']
        ret = self._retry_check_commands_on_units(cmds, units)
        self.assertIsNone(ret, msg=ret)

        # check_rabbitmq_queue monitor
        logging.info('Checking nrpe check_rabbitmq_queue on units...')
        cmds = ['egrep -oh /usr/local.* /etc/nagios/nrpe.d/'
                'check_rabbitmq_queue.cfg']
        ret = self._retry_check_commands_on_units(cmds, units)
        self.assertIsNone(ret, msg=ret)

        # check dat file existence
        logging.info('Checking nrpe dat file existence on units...')
        for u in units:
            unit_host_name = host_names[u.entity_id]

            cmds = [
                'stat /var/lib/rabbitmq/data/{}_general_stats.dat'.format(
                    unit_host_name),
                'stat /var/lib/rabbitmq/data/{}_queue_stats.dat'.format(
                    unit_host_name)
            ]

            ret = generic_utils.check_commands_on_units(cmds, [u])
            self.assertIsNone(ret, msg=ret)

        logging.info('OK')
Exemplo n.º 3
0
    def test_902_nrpe_service_checks(self):
        """Confirm that the NRPE service check files are created."""
        units = zaza.model.get_units('manila')
        services = ['apache2', 'haproxy', 'manila-scheduler', 'manila-data']

        cmds = []
        for check_name in services:
            cmds.append('egrep -oh /usr/local.* /etc/nagios/nrpe.d/'
                        'check_{}.cfg'.format(check_name))

        for attempt in tenacity.Retrying(wait=tenacity.wait_fixed(20),
                                         stop=tenacity.stop_after_attempt(2),
                                         reraise=True):
            with attempt:
                ret = generic_utils.check_commands_on_units(cmds, units)
                self.assertIsNone(ret, msg=ret)
Exemplo n.º 4
0
 def _retry_check_commands_on_units(self, cmds, units):
     return generic_utils.check_commands_on_units(cmds, units)