示例#1
0
    def test_allok(self):
        self.mocks['check_growth.ScriptConfiguration'].get_val.side_effect = \
            self._script_conf_factory()
        with self.assertRaises(SystemExit):
            check_growth.main(config_file=paths.TEST_CONFIG_FILE)

        # Configuration is loaded:
        self.mocks['check_growth.ScriptConfiguration'].load_config.assert_called_once_with(
            paths.TEST_CONFIG_FILE)
        self.assertTrue(self.mocks['check_growth.verify_conf'].called)

        # Lock is properly handled:
        self.mocks['check_growth.ScriptLock'].init.assert_called_once_with(
            paths.TEST_LOCKFILE)
        self.assertTrue(self.mocks['check_growth.ScriptLock'].aqquire.called)

        # Monitoring is notified:
        self.assertTrue(self.mocks['check_growth.ScriptStatus'].init.called)
        self.assertTrue(self.mocks['check_growth.ScriptStatus'].notify_agregated.called)

        # Data is stored:
        self.mocks['check_growth.HistoryFile'].init.assert_called_once_with(
            location=paths.TEST_STATUSFILE,
            max_averaging_window=14,
            min_averaging_window=7)
        self.assertTrue(self.mocks['check_growth.HistoryFile'].save.called)

        # Status is OK
        status, msg = self.mocks['check_growth.ScriptStatus'].update.call_args[0]
        self.assertEqual(status, 'ok')
示例#2
0
    def test_history_cleaning(self):
        self.mocks['check_growth.ScriptConfiguration'].get_val.side_effect = \
            self._script_conf_factory()
        with self.assertRaises(SystemExit):
            check_growth.main(config_file=paths.TEST_CONFIG_FILE,
                              clean_histdata=True)

        self.assertTrue(self.mocks['check_growth.HistoryFile'].clear_history.called)
        self.assertTrue(self.mocks['check_growth.HistoryFile'].save.called)
示例#3
0
    def test_memory_alert_condition(self, data):
        self.mocks['check_growth.ScriptConfiguration'].get_val.side_effect = \
            self._script_conf_factory(disk_mon_enabled=False)

        self.mocks['check_growth.find_current_grow_ratio'].return_value = data[1]

        with self.assertRaises(SystemExit):
            check_growth.main(config_file=paths.TEST_CONFIG_FILE)

        self.mocks['check_growth.find_planned_grow_ratio'].assert_called_with(1000, 2000, 365)
        self.mocks['check_growth.find_current_grow_ratio'].assert_called_with((1212, 1232, 500, 1563),)

        status, msg = self.mocks['check_growth.ScriptStatus'].update.call_args[0]
        self.assertEqual(status, data[0])
示例#4
0
    def test_insufficient_input_data(self, prefix):
        if prefix == 'disk':
            # Test memory checks:
            self.mocks['check_growth.ScriptConfiguration'].get_val.side_effect = \
                self._script_conf_factory(memory_mon_enabled=False,
                                          disk_mountpoints=['/tmp/'])
        elif prefix == 'memory':
            # Test memory checks:
            self.mocks['check_growth.ScriptConfiguration'].get_val.side_effect = \
                self._script_conf_factory(disk_mon_enabled=False)

        self.mocks['check_growth.HistoryFile'].verify_dataspan.return_value = -1

        with self.assertRaises(SystemExit):
            check_growth.main(config_file=paths.TEST_CONFIG_FILE)

        status, msg = self.mocks['check_growth.ScriptStatus'].update.call_args[0]
        self.assertEqual(status, 'unknown')