def test_run_malformed( self, mock_logging, mock_get_logger, mock_db_manager, mock_parse_config, mock_parse_arguments, mock_logger): mock_arguments = mock.Mock(config='config', metrics='metrics', verbosity='DEBUG') mock_parse_arguments.return_value = mock_arguments config = { 'hana': { 'port': 1234, 'user': '******', 'password': '******' } } mock_parse_config.return_value = config with pytest.raises(KeyError) as err: main.run() mock_parse_arguments.assert_called_once_with() mock_parse_config.assert_called_once_with(mock_arguments.config) mock_logging.assert_called_once_with(level='DEBUG') mock_db_manager.assert_called_once_with() assert 'Configuration file {} is malformed: {} not found'.format( 'config', '\'host\'') in str(err.value)
def test_run(self, mock_sleep, mock_get_logger, mock_start_server, mock_registry, mock_exporters, mock_db_manager, mock_setup_logging, mock_parse_config, mock_parse_arguments, mock_logger, mock_systemd): mock_arguments = mock.Mock(config='config', metrics='metrics', daemon=False) mock_parse_arguments.return_value = mock_arguments config = { 'hana': { 'host': '10.10.10.10', 'port': 1234, 'user': '******', 'password': '******' }, 'logging': { 'log_file': 'my_file', 'config_file': 'my_config_file' } } mock_parse_config.return_value = config db_instance = mock.Mock() db_instance.get_connectors.return_value = 'connectors' mock_db_manager.return_value = db_instance mock_collector = mock.Mock() mock_exporters.return_value = mock_collector mock_sleep.side_effect = Exception with pytest.raises(Exception): main.run() mock_parse_arguments.assert_called_once_with() mock_parse_config.assert_called_once_with(mock_arguments.config) mock_setup_logging.assert_called_once_with(config) mock_db_manager.assert_called_once_with() db_instance.start.assert_called_once_with('10.10.10.10', 1234, user='******', password='******', userkey=None, multi_tenant=True, timeout=30) db_instance.get_connectors.assert_called_once_with() mock_exporters.assert_called_once_with(connectors='connectors', metrics_file='metrics') mock_registry.assert_called_once_with(mock_collector) mock_logger.info.assert_has_calls([ mock.call('exporter sucessfully registered'), mock.call('starting to serve metrics') ]) mock_start_server.assert_called_once_with(9668, '0.0.0.0') mock_sleep.assert_called_once_with(1) assert mock_systemd.call_count == 0
def test_run_invalid_args(self, mock_parse_arguments): mock_arguments = mock.Mock(config=None, identifier=None) mock_parse_arguments.return_value = mock_arguments with pytest.raises(ValueError) as err: main.run() assert 'configuration file or identifier must be used' in str(err.value)
def test_run_defaults( self, mock_sleep, mock_get_logger, mock_start_server, mock_registry, mock_exporters, mock_db_manager, mock_setup_logging, mock_parse_config, mock_parse_arguments, mock_find_metrics, mock_logger): mock_arguments = mock.Mock(config=None, metrics=None, identifier='config') mock_parse_arguments.return_value = mock_arguments mock_find_metrics.return_value = 'new_metrics' config = { 'hana': { 'host': '10.10.10.10', 'port': 1234, 'user': '******', 'password': '******' }, 'logging': { 'log_file': 'my_file', 'config_file': 'my_config_file' } } mock_parse_config.return_value = config db_instance = mock.Mock() db_instance.get_connectors.return_value = 'connectors' mock_db_manager.return_value = db_instance mock_collector = mock.Mock() mock_exporters.return_value = mock_collector mock_sleep.side_effect = Exception with pytest.raises(Exception): main.run() mock_parse_arguments.assert_called_once_with() mock_parse_config.assert_called_once_with("{}/{}.json".format(main.CONFIG_FOLDER, 'config')) mock_setup_logging.assert_called_once_with(config) mock_find_metrics.assert_called_once_with() mock_db_manager.assert_called_once_with() db_instance.start.assert_called_once_with( '10.10.10.10', 1234, user='******', password='******', userkey=None, multi_tenant=True, timeout=600) db_instance.get_connectors.assert_called_once_with() mock_exporters.assert_called_once_with( connectors='connectors', metrics_file='new_metrics') mock_registry.assert_called_once_with(mock_collector) mock_logger.info.assert_has_calls([ mock.call('exporter sucessfully registered'), mock.call('starting to serve metrics') ]) mock_start_server.assert_called_once_with(8001, '0.0.0.0') mock_sleep.assert_called_once_with(1)
def test_run( self, mock_sleep, mock_start_server, mock_registry, mock_exporter, mock_hdb, mock_setup_loggin, mock_parse_config, mock_parse_arguments): mock_arguments = mock.Mock(config='config', metrics='metrics') mock_parse_arguments.return_value = mock_arguments config = { 'hana': { 'host': '123.123.123.123', 'port': 1234, 'user': '******', 'password': '******' }, 'logging': { 'log_file': 'my_file', 'config_file': 'my_config_file' } } mock_parse_config.return_value = config mock_connector = mock.Mock() mock_hdb.return_value = mock_connector mock_collector = mock.Mock() mock_exporter.return_value = mock_collector mock_sleep.side_effect = Exception with pytest.raises(Exception): main.run() mock_parse_arguments.assert_called_once_with() mock_parse_config.assert_called_once_with(mock_arguments.config) mock_setup_loggin.assert_called_once_with(config) mock_hdb.assert_called_once_with() mock_connector.connect.assert_called_once_with( '123.123.123.123', 1234, user='******', password='******') mock_exporter.assert_called_once_with( exporter_type='prometheus', metrics_file='metrics', hdb_connector=mock_connector) mock_registry.assert_called_once_with(mock_collector) mock_start_server.assert_called_once_with(8001, '0.0.0.0') mock_sleep.assert_called_once_with(1)