Exemple #1
0
def cli_eheventhub_create(client, resource_group_name, namespace_name, event_hub_name, message_retention_in_days=None, partition_count=None, status=None,
                          enabled=None, skip_empty_archives=None, capture_interval_seconds=None, capture_size_limit_bytes=None, destination_name=None, storage_account_resource_id=None, blob_container=None, archive_name_format=None):
    from azure.mgmt.eventhub.models import Eventhub, CaptureDescription, Destination, EncodingCaptureDescription
    eventhubparameter1 = Eventhub()
    if message_retention_in_days:
        eventhubparameter1.message_retention_in_days = message_retention_in_days

    if partition_count:
        eventhubparameter1.partition_count = partition_count

    if status:
        eventhubparameter1.status = status

    if enabled and enabled is True:
        eventhubparameter1.capture_description = CaptureDescription(
            enabled=enabled,
            skip_empty_archives=skip_empty_archives,
            encoding=EncodingCaptureDescription.avro,
            interval_in_seconds=capture_interval_seconds,
            size_limit_in_bytes=capture_size_limit_bytes,
            destination=Destination(
                name=destination_name,
                storage_account_resource_id=storage_account_resource_id,
                blob_container=blob_container,
                archive_name_format=archive_name_format)
        )
    return client.create_or_update(
        resource_group_name=resource_group_name,
        namespace_name=namespace_name,
        event_hub_name=event_hub_name,
        parameters=eventhubparameter1)
Exemple #2
0
def cli_eheventhub_update(instance,
                          message_retention_in_days=None,
                          partition_count=None,
                          status=None,
                          enabled=None,
                          capture_interval_seconds=None,
                          capture_size_limit_bytes=None,
                          destination_name=None,
                          storage_account_resource_id=None,
                          blob_container=None,
                          archive_name_format=None):
    from azure.mgmt.eventhub.models import CaptureDescription, Destination, EncodingCaptureDescription
    if message_retention_in_days:
        instance.message_retention_in_days = message_retention_in_days

    if partition_count:
        instance.partition_count = partition_count

    if status:
        instance.status = status

    if enabled:
        instance.capture_description.enabled = enabled

        if not instance.capture_description:
            instance.capture_description = CaptureDescription()
            instance.capture_description.destination = Destination()
            instance.capture_description.encoding = EncodingCaptureDescription.avro

        if capture_interval_seconds:
            instance.interval_in_seconds = capture_interval_seconds
        if capture_size_limit_bytes:
            instance.size_limit_in_bytes = capture_size_limit_bytes
        if destination_name:
            instance.capture_description.destination.name = destination_name
        if storage_account_resource_id:
            instance.capture_description.destination.storage_account_resource_id = storage_account_resource_id
        if blob_container:
            instance.capture_description.destination.blob_container = blob_container
        if archive_name_format:
            instance.capture_description.destination.archive_name_format = archive_name_format

    return instance
    def test_eh_eventhub_curd(self, resource_group, location):

        resource_group_name = resource_group.name

        #Create a Namespace
        namespace_name = "pythontestcaseeventhubnamespaceEventhub"

        namespaceparameter = EHNamespace(location=location,
                                         tags={
                                             'tag1': 'value1',
                                             'tag2': 'value2'
                                         },
                                         sku=Sku(name=SkuName.standard))
        poller = self.eventhub_client.namespaces.create_or_update(
            resource_group_name, namespace_name, namespaceparameter)
        creatednamespace = poller.result()
        self.assertEqual(creatednamespace.name, namespace_name)

        #
        # # Get created Namespace
        #
        getnamespaceresponse = self.eventhub_client.namespaces.get(
            resource_group_name, namespace_name)
        self.assertEqual(getnamespaceresponse.name, namespace_name)

        # Create a Eventhub
        eventhub_name = "testingpythontestcaseeventhub"
        eventhubparameter = Eventhub(
            message_retention_in_days=4,
            partition_count=4,
            capture_description=CaptureDescription(
                enabled=True,
                encoding=EncodingCaptureDescription.avro,
                interval_in_seconds=120,
                size_limit_in_bytes=10485763,
                destination=Destination(
                    name="EventHubArchive.AzureBlockBlob",
                    storage_account_resource_id="/subscriptions/" +
                    self.settings.SUBSCRIPTION_ID +
                    "/resourceGroups/Default-Storage-SouthCentralUS/providers/Microsoft.ClassicStorage/storageAccounts/arjunteststorage",
                    blob_container="container",
                    archive_name_format=
                    "{Namespace}/{EventHub}/{PartitionId}/{Year}/{Month}/{Day}/{Hour}/{Minute}/{Second}"
                )))
        createdeventhubresponse = self.eventhub_client.event_hubs.create_or_update(
            resource_group_name, namespace_name, eventhub_name,
            eventhubparameter)

        self.assertEqual(createdeventhubresponse.name, eventhub_name)
        self.assertEqual(
            createdeventhubresponse.capture_description.interval_in_seconds,
            120)

        #Get the created eventhub
        geteventhubresponse = self.eventhub_client.event_hubs.get(
            resource_group_name, namespace_name, eventhub_name)
        self.assertEqual(geteventhubresponse.name, eventhub_name)
        self.assertEqual(
            geteventhubresponse.capture_description.interval_in_seconds, 120)

        #Get the List of eventhub by namespaces
        getlistbynamespaceeventhubresponse = list(
            self.eventhub_client.event_hubs.list_by_namespace(
                resource_group_name, namespace_name))
        self.assertGreater(len(getlistbynamespaceeventhubresponse), 0)

        # update the Created eventhub

        eventhubupdateparameter = Eventhub(
            message_retention_in_days=6,
            partition_count=4,
            capture_description=CaptureDescription(
                enabled=True,
                encoding=EncodingCaptureDescription.avro,
                interval_in_seconds=130,
                size_limit_in_bytes=10485900,
                destination=Destination(
                    name="EventHubArchive.AzureBlockBlob",
                    storage_account_resource_id="/subscriptions/" +
                    self.settings.SUBSCRIPTION_ID +
                    "/resourceGroups/Default-Storage-SouthCentralUS/providers/Microsoft.ClassicStorage/storageAccounts/arjunteststorage",
                    blob_container="container",
                    archive_name_format=
                    "{Namespace}/{EventHub}/{PartitionId}/{Year}/{Month}/{Day}/{Hour}/{Minute}/{Second}"
                )))

        updateeventhubresponse = self.eventhub_client.event_hubs.create_or_update(
            resource_group_name, namespace_name, eventhub_name,
            eventhubupdateparameter)

        self.assertEqual(updateeventhubresponse.name, eventhub_name)
        self.assertEqual(
            updateeventhubresponse.capture_description.interval_in_seconds,
            130)
        self.assertEqual(updateeventhubresponse.message_retention_in_days, 6)
        self.assertEqual(
            updateeventhubresponse.capture_description.size_limit_in_bytes,
            10485900)

        # # get the default authorizationrule
        # defaultauthorule_name = "RootManageSharedAccessKey"
        # defaultamespaceauthorule = self.eventhub_client.namespaces.get_authorization_rule(resource_group_name, namespace_name, defaultauthorule_name)
        # self.assertEqual(defaultamespaceauthorule.name, defaultauthorule_name, "Default Authorization rule not returned - RootManageSharedAccessKey")
        # self.assertEqual(len(defaultamespaceauthorule.rights), 3, "rights for deafult not as required - send, listen and manage")

        # Create a new authorizationrule
        authoRule_name = "testingauthrulepy"
        createnamespaceauthorule = self.eventhub_client.event_hubs.create_or_update_authorization_rule(
            resource_group_name, namespace_name, eventhub_name, authoRule_name,
            [AccessRights('Send'),
             AccessRights('Listen')])
        self.assertEqual(
            createnamespaceauthorule.name, authoRule_name,
            "Authorization rule name not as created - create_or_update_authorization_rule "
        )
        self.assertEqual(len(createnamespaceauthorule.rights), 2)

        # Get the created authorizationrule
        getnamespaceauthorule = self.eventhub_client.event_hubs.get_authorization_rule(
            resource_group_name, namespace_name, eventhub_name, authoRule_name)
        self.assertEqual(
            getnamespaceauthorule.name, authoRule_name,
            "Authorization rule name not as passed as parameter - get_authorization_rule "
        )
        self.assertEqual(
            len(getnamespaceauthorule.rights), 2,
            "Access rights mis match as created  - get_authorization_rule ")

        # update the rights of the authorizatiorule
        getnamespaceauthorule.rights.append('Manage')
        updatenamespaceauthorule = self.eventhub_client.event_hubs.create_or_update_authorization_rule(
            resource_group_name, namespace_name, eventhub_name, authoRule_name,
            getnamespaceauthorule.rights)
        self.assertEqual(
            updatenamespaceauthorule.name, authoRule_name,
            "Authorization rule name not as passed as parameter for update call - create_or_update_authorization_rule "
        )
        self.assertEqual(
            len(updatenamespaceauthorule.rights), 3,
            "Access rights mis match as updated  - create_or_update_authorization_rule "
        )

        #list all the authorization ruels for the given namespace
        createnamespaceauthorule = list(
            self.eventhub_client.event_hubs.list_authorization_rules(
                resource_group_name, namespace_name, eventhub_name))
        self.assertEqual(
            len(createnamespaceauthorule), 1,
            "number of authorization rule mismatch with the created + default = 2 - list_authorization_rules"
        )

        #List keys for the authorization rule
        listkeysauthorizationrule = self.eventhub_client.event_hubs.list_keys(
            resource_group_name, namespace_name, eventhub_name, authoRule_name)
        self.assertIsNotNone(listkeysauthorizationrule)

        # regenerate Keys for authorizationrule - Primary
        regenratePrimarykeyauthorizationrule = self.eventhub_client.event_hubs.regenerate_keys(
            resource_group_name, namespace_name, eventhub_name, authoRule_name,
            'PrimaryKey')
        self.assertNotEqual(listkeysauthorizationrule.primary_key,
                            regenratePrimarykeyauthorizationrule.primary_key)

        # regenerate Keys for authorizationrule - Primary
        regenrateSecondarykeyauthorizationrule = self.eventhub_client.event_hubs.regenerate_keys(
            resource_group_name, namespace_name, eventhub_name, authoRule_name,
            'SecondaryKey')
        self.assertNotEqual(
            listkeysauthorizationrule.secondary_key,
            regenrateSecondarykeyauthorizationrule.secondary_key)

        # delete the authorizationrule
        self.eventhub_client.event_hubs.delete_authorization_rule(
            resource_group_name, namespace_name, eventhub_name, authoRule_name)

        # Delete the created eventhub
        geteventhubresponse = self.eventhub_client.event_hubs.delete(
            resource_group_name, namespace_name, eventhub_name)

        # Delete the create namespace
        try:
            deletenamespace = self.eventhub_client.namespaces.delete(
                resource_group_name, namespace_name).result()
        except CloudError as ErrorResponse:
            self.assertTrue("not found" in ErrorResponse.message)
Exemple #4
0
    def test_eh_consumergroup_curd(self, resource_group, location):

        resource_group_name = resource_group.name

        # Create a Namespace
        namespace_name = "pythontestcaseeventhubnamespaceConsumerGroup"

        namespaceparameter = EHNamespace(location=location,
                                         tags={
                                             'tag1': 'value1',
                                             'tag2': 'value2'
                                         },
                                         sku=Sku(name=SkuName.standard))
        poller = self.eventhub_client.namespaces.create_or_update(
            resource_group_name, namespace_name, namespaceparameter)
        creatednamespace = poller.result()
        self.assertEqual(creatednamespace.name, namespace_name)

        #
        # # Get created Namespace
        #
        getnamespaceresponse = self.eventhub_client.namespaces.get(
            resource_group_name, namespace_name)
        self.assertEqual(getnamespaceresponse.name, namespace_name)

        # # Create a Eventhub
        eventhub_name = "testingpythontestcaseeventhubConsumerGroup"
        eventhubparameter = Eventhub(
            message_retention_in_days=4,
            partition_count=4,
            capture_description=CaptureDescription(
                enabled=True,
                encoding=EncodingCaptureDescription.avro,
                interval_in_seconds=120,
                size_limit_in_bytes=10485763,
                destination=Destination(
                    name="EventHubArchive.AzureBlockBlob",
                    storage_account_resource_id="/subscriptions/" +
                    self.settings.SUBSCRIPTION_ID +
                    "/resourceGroups/Default-Storage-SouthCentralUS/providers/Microsoft.ClassicStorage/storageAccounts/arjunteststorage",
                    blob_container="container",
                    archive_name_format=
                    "{Namespace}/{EventHub}/{PartitionId}/{Year}/{Month}/{Day}/{Hour}/{Minute}/{Second}"
                )))
        createdeventhubresponse = self.eventhub_client.event_hubs.create_or_update(
            resource_group_name, namespace_name, eventhub_name,
            eventhubparameter)
        self.assertEqual(createdeventhubresponse.name, eventhub_name)
        self.assertEqual(
            createdeventhubresponse.capture_description.interval_in_seconds,
            120)

        # Get the created eventhub
        geteventhubresponse = self.eventhub_client.event_hubs.get(
            resource_group_name, namespace_name, eventhub_name)
        self.assertEqual(geteventhubresponse.name, eventhub_name)
        self.assertEqual(
            geteventhubresponse.capture_description.interval_in_seconds, 120)
        #Get the List of eventhub by namespaces
        getlistbynamespaceeventhubresponse = list(
            self.eventhub_client.event_hubs.list_by_namespace(
                resource_group_name, namespace_name))
        self.assertGreater(len(getlistbynamespaceeventhubresponse), 0)

        # # update the Created eventhub
        eventhubupdateparameter = Eventhub(
            message_retention_in_days=6,
            partition_count=4,
            capture_description=CaptureDescription(
                enabled=True,
                encoding=EncodingCaptureDescription.avro,
                interval_in_seconds=130,
                size_limit_in_bytes=10485900,
                destination=Destination(
                    name="EventHubArchive.AzureBlockBlob",
                    storage_account_resource_id="/subscriptions/" +
                    self.settings.SUBSCRIPTION_ID +
                    "/resourceGroups/Default-Storage-SouthCentralUS/providers/Microsoft.ClassicStorage/storageAccounts/arjunteststorage",
                    blob_container="container",
                    archive_name_format=
                    "{Namespace}/{EventHub}/{PartitionId}/{Year}/{Month}/{Day}/{Hour}/{Minute}/{Second}"
                )))

        updateeventhubresponse = self.eventhub_client.event_hubs.create_or_update(
            resource_group_name, namespace_name, eventhub_name,
            eventhubupdateparameter)
        self.assertEqual(updateeventhubresponse.name, eventhub_name)
        self.assertEqual(
            updateeventhubresponse.capture_description.interval_in_seconds,
            130)
        self.assertEqual(updateeventhubresponse.message_retention_in_days, 6)
        self.assertEqual(
            updateeventhubresponse.capture_description.size_limit_in_bytes,
            10485900)

        # Create ConsumerGroup
        consumergroup_name = "testingpythontestcaseconsumergroup"
        createconsumergroupresponse = self.eventhub_client.consumer_groups.create_or_update(
            resource_group_name, namespace_name, eventhub_name,
            consumergroup_name, "Testing the User Metadata")

        self.assertEqual(createconsumergroupresponse.name, consumergroup_name)
        self.assertEqual(createconsumergroupresponse.user_metadata,
                         "Testing the User Metadata")

        # Get the Created Consumer group
        getconsumergroupresponse = self.eventhub_client.consumer_groups.get(
            resource_group_name, namespace_name, eventhub_name,
            consumergroup_name)
        # update the Created Consumer group
        updateconsumergroupresponse = self.eventhub_client.consumer_groups.create_or_update(
            resource_group_name, namespace_name, eventhub_name,
            consumergroup_name, "update user matadata for testing")
        self.assertEqual(updateconsumergroupresponse.name, consumergroup_name)
        self.assertEqual(updateconsumergroupresponse.user_metadata,
                         "update user matadata for testing")

        # delete the consumergroup
        deleteconsumergroupresponse = self.eventhub_client.consumer_groups.delete(
            resource_group_name, namespace_name, eventhub_name,
            consumergroup_name)
        # Delete the created eventhub
        geteventhubresponse = self.eventhub_client.event_hubs.delete(
            resource_group_name, namespace_name, eventhub_name)

        # Delete the create namespace
        try:
            deletenamespace = self.eventhub_client.namespaces.delete(
                resource_group_name, namespace_name).result()
        except CloudError as ErrorResponse:
            self.assertTrue("not found" in ErrorResponse.message)