def __setup_log_streaming(cls): log_streaming_config = None account = None error = None try: # Load keystore keystore_file = get(Program.__yaml_config[Program.__env], "/keystore_file") with open(keystore_file) as k: keystore = load(k) account = Web3.toChecksumAddress('0x' + keystore['address']) # Get log streaming config (if any) log_streaming_config = get(Program.__yaml_config[Program.__env], "/logging/streaming") except KeyError: error = InvalidKeyStoreException("Invalid keystore file") except Exception as unknown_error: error = unknown_error finally: # Initialize the log streaming module (should be done once) import log_streaming log_streaming.initialize(account, log_streaming_config) if error: raise error
def test_create_logging_streaming_provider_ok(self): """ Tests that the CloudWatch provider can be created and is properly returned. """ log_streaming.initialize("account", {}, force=True) streaming_provider_name = "CloudWatchProvider" streaming_provider_args = { 'log_group': 'grp', 'log_stream': 'stream', 'send_interval_seconds': 10 } result = log_streaming.create_streaming_provider( streaming_provider_name, streaming_provider_args) self.assertTrue(isinstance(result, CloudWatchProvider), "The created provider is not a CloudWatchProvider")
def test_initialize(self): config_file_uri = resource_uri("test_config.yaml") config = ConfigFactory.create_from_file( config_file_uri, "dev", validate_contract_settings=False) log_streaming.initialize("account", config_value(config, "/logging/streaming", {}), force=True) self.assertEqual(get_config(), {}) self.assertEqual(get_account(), "account") self.assertEqual(get_loggers(), {}) try: log_streaming.initialize("account", {}) self.fail("An exception was expected") except Exception: # expected pass
def test_configure_logging_no_stream(self): # Since streaming is set to False, this will not invoke logger creating and will pass streaming_provider_name = "Nonsense" # The logger is not initialized proper streaming_provider_args = { 'log_group': 'grp', 'log_stream': 'stream', 'send_interval_seconds': 10 } config = { 'is_enabled': False, 'provider': streaming_provider_name, 'args': streaming_provider_args } log_streaming.initialize("test-account", config, force=True) self.assertEqual(get_loggers(), {}) log_streaming.get_logger("test_get_logger") # No configuration should happen self.assertFalse("test_get_logger" in get_loggers())
def test_configure_logging_stream_provider(self): streaming_provider_name = "CloudWatchProvider" # The logger is not initialized proper streaming_provider_args = { 'log_group': 'grp', 'log_stream': 'stream', 'send_interval_seconds': 10 } config = { 'is_enabled': True, 'provider': streaming_provider_name, 'args': streaming_provider_args } log_streaming.initialize("test-account", config, force=True) logger = log_streaming.get_logger("test_get_logger") self.assertTrue(logger is log_streaming.get_logger("test_get_logger")) self.assertTrue("test_get_logger" in get_loggers()) # Reset logging after this call log_streaming.initialize("account", {'is_enabled': False}, force=True)
def test_create_logging_streaming_provider_not_ok(self): """ Tests that wrong streaming provider specification causes an exception being thrown. """ log_streaming.initialize("account", {}, force=True) streaming_provider_name = "nonsense" streaming_provider_args = { 'log_group': 'grp', 'log_stream': 'stream', 'send_interval_seconds': 10 } try: log_streaming.create_streaming_provider(streaming_provider_name, streaming_provider_args) self.fail( "Succeeded to create streaming provider without proper provider name." ) except Exception: # expected pass
def __setup_log_streaming(cls): # Load keystore keystore_file = get(Program.__yaml_config[Program.__env], "/keystore_file") with open(keystore_file) as k: keystore = load(k) # Get account account = Web3.toChecksumAddress('0x' + keystore['address']) # Get log streaming config (if any) log_streaming_config = None try: log_streaming_config = get(Program.__yaml_config[Program.__env], "/logging/streaming") except KeyError: pass # Initialize the log streaming module (should be done once) import log_streaming log_streaming.initialize(account, log_streaming_config)
def tearDownClass(cls): # resets logging setup_logging() log_streaming.initialize("account", {'is_enabled': False}, force=True)