def test_get_all_consumers(self): Sauna.import_submodules('sauna.consumers.ext') consumers = ConsumerRegister.all_consumers self.assertIsInstance(consumers, dict) self.assertGreater(len(consumers), 1) for consumer_name, consumer_info in consumers.items(): self.assertIn('consumer_cls', consumer_info) self.assert_( issubclass(consumer_info['consumer_cls'], base.Consumer))
def test_get_all_consumers(self): Sauna.import_submodules('sauna.consumers.ext') consumers = ConsumerRegister.all_consumers self.assertIsInstance(consumers, dict) self.assertGreater(len(consumers), 1) for consumer_name, consumer_info in consumers.items(): self.assertIn('consumer_cls', consumer_info) self.assert_(issubclass(consumer_info['consumer_cls'], base.Consumer))
def test_assemble_config_sample(self): mock_open = mock.mock_open() sauna_instance = Sauna() with mock.patch('builtins.open', mock_open): sauna_instance.assemble_config_sample('/foo') mock_open.assert_called_once_with('/foo/sauna-sample.yml', 'w') f = mock_open() generated_yaml_string = f.write.call_args[0][0] # Will raise a yaml error if generated content is not valid yaml yaml.safe_load(generated_yaml_string)
def test_dict_conf(self): dict_conf = { "plugins": { "Disk": { "config": { "myconf": "myvalue" }, "checks": [{ "type": "used_percent", "warn": "80%", "crit": "90%" }] } } } expected_result = [{ 'type': 'Disk', "config": { "myconf": "myvalue" }, "checks": [{ "type": "used_percent", "warn": "80%", "crit": "90%" }] }] sauna = Sauna(config=dict_conf) self.assertEqual(sauna.plugins_checks, expected_result)
def test_conf_without_concurrency_no_threadpool(self): original = { 'periodicity': 60, 'consumers': { 'Stdout': {}, }, 'plugins': [] } sauna = Sauna(config=original) self.assertIsNone(sauna._thread_pool)
def test_consumers_list_conf(self): list_conf = { 'consumers': [ { 'type': 'NSCA', 'foo': 'bar' }, { 'type': 'Stdout', } ] } sauna = Sauna(config=list_conf) for r in list_conf['consumers']: self.assert_(r in sauna.consumers)
def test_list_conf(self): list_conf = { "plugins": [{ 'type': 'Disk', "config": { "myconf": "myvalue" }, "checks": [{ "type": "used_percent", "warn": "80%", "crit": "90%" }] }] } sauna = Sauna(config=list_conf) self.assertEqual(sauna.plugins_checks, list_conf['plugins'])
def test_consumers_dict_conf(self): dict_conf = { 'consumers': { 'NSCA': { 'foo': 'bar' }, 'Stdout': None } } expected_result = [ { 'type': 'NSCA', 'foo': 'bar' }, { 'type': 'Stdout', } ] sauna = Sauna(config=dict_conf) for r in expected_result: self.assert_(r in sauna.consumers)
def test_complex_dict_conf(self): dict_conf = { "plugins": { "Disk": { "config": { "myconf": "myvalue" }, "checks": [{ "type": "used_percent", "warn": "80%", "crit": "90%" }, { "type": "used_percent", "warn": "80%", "crit": "90%" }] }, "Memory": { "config": { "myconf": "myvalue" }, "checks": [ { "type": "used_percent", "warn": "80%", "crit": "90%" }, ] } } } expected_result = [{ 'type': 'Disk', "config": { "myconf": "myvalue" }, "checks": [{ "type": "used_percent", "warn": "80%", "crit": "90%" }, { "type": "used_percent", "warn": "80%", "crit": "90%" }] }, { "type": "Memory", "config": { "myconf": "myvalue" }, "checks": [ { "type": "used_percent", "warn": "80%", "crit": "90%" }, ] }] sauna = Sauna(config=dict_conf) self.assertEqual(len(sauna.plugins_checks), len(expected_result)) for elem in sauna.plugins_checks: self.assertIn(elem, expected_result, 'missing element')