def create_stress_eventhub(stress_config, eventhub_name): hub_value = EventHub( message_retention_in_days=stress_config["BASIC_CONFIG"] ["message_retention_in_days"], partition_count=stress_config["BASIC_CONFIG"] ["partition_cnt_to_create"]) if stress_config["CREDENTIALS"]["EVENT_HUB_CONN_STR"]: _, namespace, shared_access_key_name, shared_access_key, _ = parse_eventhub_conn_str( stress_config["CREDENTIALS"]["EVENT_HUB_CONN_STR"]) client = ServiceBusService( service_namespace=namespace, shared_access_key_name=shared_access_key_name, shared_access_key_value=shared_access_key) else: client = ServiceBusService( service_namespace=stress_config["CREDENTIALS"] ["EVENT_HUB_NAMESPACE"], shared_access_key_name=stress_config['CREDENTIALS'] ["EVENT_HUB_SAS_POLICY"], shared_access_key_value=stress_config['CREDENTIALS'] ["EVENT_HUB_SAS_KEY"]) client.delete_event_hub(eventhub_name) if client.create_event_hub(eventhub_name, hub=hub_value, fail_on_exist=True): return eventhub_name raise ValueError("EventHub creation failed.")
def create_eventhub(eventhub_config, client=None): from azure.servicebus.control_client import ServiceBusService, EventHub hub_name = str(uuid.uuid4()) hub_value = EventHub(partition_count=2) client = client or ServiceBusService( service_namespace=eventhub_config['namespace'], shared_access_key_name=eventhub_config['key_name'], shared_access_key_value=eventhub_config['access_key']) if client.create_event_hub(hub_name, hub=hub_value, fail_on_exist=True): return hub_name raise ValueError("EventHub creation failed.")
def test_create_event_hub_with_options(self): # Arrange # Act hub = EventHub() hub.message_retention_in_days = 5 hub.status = 'Active' hub.user_metadata = 'hello world' hub.partition_count = 32 created = self.sbs.create_event_hub(self.event_hub_name, hub) # Assert self.assertTrue(created) created_hub = self.sbs.get_event_hub(self.event_hub_name) self.assertEqual(created_hub.name, self.event_hub_name) self.assertEqual(created_hub.message_retention_in_days, hub.message_retention_in_days) self.assertEqual(created_hub.status, hub.status) self.assertEqual(created_hub.partition_count, hub.partition_count) self.assertEqual(created_hub.user_metadata, hub.user_metadata) self.assertEqual(len(created_hub.partition_ids), hub.partition_count)