示例#1
0
def cli_sbqueue_create(client, resource_group_name, namespace_name, queue_name, lock_duration=None,
                       max_size_in_megabytes=None, requires_duplicate_detection=None, requires_session=None,
                       default_message_time_to_live=None, dead_lettering_on_message_expiration=None,
                       duplicate_detection_history_time_window=None, max_delivery_count=None, status=None,
                       auto_delete_on_idle=None, enable_partitioning=None, enable_express=None,
                       forward_to=None, forward_dead_lettered_messages_to=None, enable_batched_operations=None):

    from azure.mgmt.servicebus.models import SBQueue

    queue_params = SBQueue(
        lock_duration=return_valid_duration_create(lock_duration),
        max_size_in_megabytes=max_size_in_megabytes,
        requires_duplicate_detection=requires_duplicate_detection,
        requires_session=requires_session,
        default_message_time_to_live=return_valid_duration_create(default_message_time_to_live),
        dead_lettering_on_message_expiration=dead_lettering_on_message_expiration,
        duplicate_detection_history_time_window=return_valid_duration_create(duplicate_detection_history_time_window),
        max_delivery_count=max_delivery_count,
        status=status,
        auto_delete_on_idle=return_valid_duration_create(auto_delete_on_idle),
        enable_partitioning=enable_partitioning,
        enable_express=enable_express,
        forward_to=forward_to,
        forward_dead_lettered_messages_to=forward_dead_lettered_messages_to,
        enable_batched_operations=enable_batched_operations
    )
    return client.create_or_update(
        resource_group_name=resource_group_name,
        namespace_name=namespace_name,
        queue_name=queue_name,
        parameters=queue_params)
示例#2
0
    def create_resource(self, name, **kwargs):
        if self.is_live:
            self.client = self.create_mgmt_client(ServiceBusManagementClient)
            group = self._get_resource_group(**kwargs)
            namespace = self._get_namespace(**kwargs)
            retries = 4
            for i in range(retries):
                try:
                    self.resource = self.client.queues.create_or_update(
                        group.name, namespace.name, name,
                        SBQueue(lock_duration=self.lock_duration,
                                requires_duplicate_detection=self.
                                requires_duplicate_detection,
                                dead_lettering_on_message_expiration=self.
                                dead_lettering_on_message_expiration,
                                requires_session=self.requires_session))
                    break
                except Exception as ex:
                    error = "The requested resource {} does not exist".format(
                        namespace)
                    not_found_error = "Operation returned an invalid status code 'Not Found'"
                    if (error not in str(ex) and not_found_error
                            not in str(ex)) or i == retries - 1:
                        raise
                    time.sleep(3)

            self.test_class_instance.scrubber.register_name_pair(
                name, self.resource_moniker)
        else:
            self.resource = FakeResource(name=name, id=name)
        return {
            self.parameter_name: self.resource,
        }
示例#3
0
    def create_resource(self, name, **kwargs):
        if self.is_live:
            self.client = self.create_mgmt_client(ServiceBusManagementClient)
            group = self._get_resource_group(**kwargs)
            namespace = self._get_namespace(**kwargs)
            self.resource = self.client.queues.create_or_update(
                group.name,
                namespace.name,
                name,
                SBQueue(
                    lock_duration='PT30S',
                    requires_duplicate_detection = self.requires_duplicate_detection,
                    dead_lettering_on_message_expiration = self.dead_lettering_on_message_expiration,
                    requires_session = self.requires_session)
            )

            self.test_class_instance.scrubber.register_name_pair(
                name,
                self.resource_moniker
            )
        else:
            self.resource = FakeResource(name=name, id=name)
        return {
            self.parameter_name: self.resource,
        }
示例#4
0
    def test_sb_queue_curd(self, resource_group, location):
        # List all topic types
        resource_group_name = resource_group.name

        # Create a Namespace
        namespace_name = "testingpythontestcasequeue"

        namespaceparameter = SBNamespace(location, {'tag1': 'value1', 'tag2': 'value2'}, SBSku(SkuName.standard))
        creatednamespace = self.servicebus_client.namespaces.create_or_update(resource_group_name, namespace_name, namespaceparameter,None,True).output
        self.assertEqual(creatednamespace.name, namespace_name)

        while (self.servicebus_client.namespaces.get(resource_group_name, namespace_name).provisioning_state != 'Succeeded'):
            time.sleep(15)
            continue

        # Create a Queue
        queue_name = "testingpythonsdkqueue"
        createqueueresponse = self.servicebus_client.queues.create_or_update(resource_group_name, namespace_name,queue_name,SBQueue())
        self.assertEqual(createqueueresponse.name, queue_name)

        # Get the created Queue
        getqueueresponse = self.servicebus_client.queues.get(resource_group_name, namespace_name,queue_name)
        self.assertEqual(getqueueresponse.name, queue_name)

        # Get all the queues
        listbynamespacequeueresponse = list(self.servicebus_client.queues.list_by_namespace(resource_group_name, namespace_name))
        self.assertEqual(len(listbynamespacequeueresponse),1)
        self.assertEqual(listbynamespacequeueresponse[0].name, queue_name)

        # update queue
        updatequeueresponse = self.servicebus_client.queues.create_or_update(resource_group_name, namespace_name, queue_name, SBQueue( enable_express=True, max_delivery_count=5, max_size_in_megabytes=1024 ))
        self.assertEqual(updatequeueresponse.name, queue_name)
        self.assertEqual(updatequeueresponse.max_delivery_count, 5)
        self.assertEqual(updatequeueresponse.max_size_in_megabytes, 1024)
        self.assertEqual(updatequeueresponse.enable_express, True)

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

        # Get the created authorizationrule
        getqueueauthorule = self.servicebus_client.queues.get_authorization_rule(resource_group_name, namespace_name, queue_name, authoRule_name)
        self.assertEqual(getqueueauthorule.name, authoRule_name, "Authorization rule name not as passed as parameter - get_authorization_rule")
        self.assertEqual(len(getqueueauthorule.rights), 2, "Access rights mis match as created  - get_authorization_rule ")

        # update the rights of the authorizatiorule
        getqueueauthorule.rights.append('Manage')
        updatequeueauthorule = self.servicebus_client.queues.create_or_update_authorization_rule(resource_group_name, namespace_name, queue_name, authoRule_name, getqueueauthorule.rights)
        self.assertEqual(updatequeueauthorule.name, authoRule_name,"Authorization rule name not as passed as parameter for update call - create_or_update_authorization_rule ")
        self.assertEqual(len(updatequeueauthorule.rights), 3,"Access rights mis match as updated  - create_or_update_authorization_rule ")

        # list all the authorization ruels for the given Queue
        listqueueauthorule = list(self.servicebus_client.queues.list_authorization_rules(resource_group_name, namespace_name, queue_name))
        self.assertEqual(len(listqueueauthorule), 1,"number of authorization rule mismatch, created = 1 - list_authorization_rules")

        # List keys for the authorization rule
        listkeysauthorizationrule = self.servicebus_client.queues.list_keys(resource_group_name, namespace_name, queue_name, authoRule_name)
        self.assertIsNotNone(listkeysauthorizationrule)

        # regenerate Keys for authorizationrule - Primary
        regenratePrimarykeyauthorizationrule = self.servicebus_client.queues.regenerate_keys(resource_group_name,namespace_name, queue_name, authoRule_name,'PrimaryKey')
        self.assertNotEqual(listkeysauthorizationrule.primary_key, regenratePrimarykeyauthorizationrule.primary_key)

        # regenerate Keys for authorizationrule - Primary
        regenrateSecondarykeyauthorizationrule = self.servicebus_client.queues.regenerate_keys(resource_group_name,namespace_name, queue_name, authoRule_name,'SecondaryKey')
        self.assertNotEqual(listkeysauthorizationrule.secondary_key,regenrateSecondarykeyauthorizationrule.secondary_key)

        # delete the authorizationrule
        self.servicebus_client.queues.delete_authorization_rule(resource_group_name, namespace_name, queue_name, authoRule_name)

        # list all the authorization ruels for the given Queue
        listqueueauthorule = list(self.servicebus_client.queues.list_authorization_rules(resource_group_name, namespace_name, queue_name))
        lenTemp = len(listqueueauthorule)

        # delete the Queue
        self.servicebus_client.queues.delete(resource_group_name, namespace_name, queue_name)

        # Delete the create namespace
        deletenamespace = self.servicebus_client.namespaces.delete(resource_group_name, namespace_name,None,True).output
示例#5
0
def cli_sbqueue_update(instance,
                       lock_duration=None,
                       max_size_in_megabytes=None,
                       requires_duplicate_detection=None,
                       requires_session=None,
                       default_message_time_to_live=None,
                       dead_lettering_on_message_expiration=None,
                       duplicate_detection_history_time_window=None,
                       max_delivery_count=None,
                       status=None,
                       auto_delete_on_idle=None,
                       enable_partitioning=None,
                       enable_express=None,
                       forward_to=None,
                       forward_dead_lettered_messages_to=None,
                       enable_batched_operations=None):

    from azure.mgmt.servicebus.models import SBQueue
    returnobj = SBQueue()

    if lock_duration:
        returnobj.lock_duration = return_valid_duration(
            instance, 'lock_duration', lock_duration)

    if max_size_in_megabytes:
        returnobj.max_size_in_megabytes = max_size_in_megabytes

    if requires_duplicate_detection:
        returnobj.requires_duplicate_detection = requires_duplicate_detection

    if requires_session:
        returnobj.requires_session = requires_session

    if default_message_time_to_live:
        returnobj.default_message_time_to_live = return_valid_duration(
            instance, 'default_message_time_to_live',
            default_message_time_to_live)

    if dead_lettering_on_message_expiration:
        returnobj.dead_lettering_on_message_expiration = dead_lettering_on_message_expiration

    if duplicate_detection_history_time_window:
        returnobj.duplicate_detection_history_time_window = return_valid_duration(
            instance, 'duplicate_detection_history_time_window',
            duplicate_detection_history_time_window)

    if max_delivery_count:
        returnobj.max_delivery_count = max_delivery_count

    if status:
        returnobj.status = status

    if auto_delete_on_idle:
        returnobj.auto_delete_on_idle = return_valid_duration(
            instance, 'auto_delete_on_idle', auto_delete_on_idle)

    if enable_partitioning:
        returnobj.enable_partitioning = enable_partitioning

    if enable_express:
        returnobj.enable_express = enable_express

    if forward_to:
        returnobj.forward_to = forward_to

    if forward_dead_lettered_messages_to:
        returnobj.forward_dead_lettered_messages_to = forward_dead_lettered_messages_to

    if enable_batched_operations:
        returnobj.enable_batched_operations = enable_batched_operations

    return returnobj
示例#6
0
def cli_sbqueue_update(instance, lock_duration=None,
                       max_size_in_megabytes=None, requires_duplicate_detection=None, requires_session=None,
                       default_message_time_to_live=None, dead_lettering_on_message_expiration=None,
                       duplicate_detection_history_time_window=None, max_delivery_count=None, status=None,
                       auto_delete_on_idle=None, enable_partitioning=None, enable_express=None,
                       forward_to=None, forward_dead_lettered_messages_to=None, enable_batched_operations=None):

    from azure.mgmt.servicebus.models import SBQueue
    returnobj = SBQueue()

    if lock_duration:
        returnobj.lock_duration = return_valid_duration(instance, 'lock_duration', lock_duration)

    if max_size_in_megabytes:
        returnobj.max_size_in_megabytes = max_size_in_megabytes

    if requires_duplicate_detection:
        returnobj.requires_duplicate_detection = requires_duplicate_detection

    if requires_session:
        returnobj.requires_session = requires_session

    if default_message_time_to_live:
        returnobj.default_message_time_to_live = return_valid_duration(instance, 'default_message_time_to_live', default_message_time_to_live)

    if dead_lettering_on_message_expiration:
        returnobj.dead_lettering_on_message_expiration = dead_lettering_on_message_expiration

    if duplicate_detection_history_time_window:
        returnobj.duplicate_detection_history_time_window = return_valid_duration(instance, 'duplicate_detection_history_time_window', duplicate_detection_history_time_window)

    if max_delivery_count:
        returnobj.max_delivery_count = max_delivery_count

    if status:
        returnobj.status = status

    if auto_delete_on_idle:
        returnobj.auto_delete_on_idle = return_valid_duration(instance, 'auto_delete_on_idle', auto_delete_on_idle)

    if enable_partitioning:
        returnobj.enable_partitioning = enable_partitioning

    if enable_express:
        returnobj.enable_express = enable_express

    if forward_to:
        returnobj.forward_to = forward_to

    if forward_dead_lettered_messages_to:
        returnobj.forward_dead_lettered_messages_to = forward_dead_lettered_messages_to

    if enable_batched_operations:
        returnobj.enable_batched_operations = enable_batched_operations

    return returnobj