def cli_sbsubscription_create(client, resource_group_name, namespace_name, topic_name, subscription_name, lock_duration=None, requires_session=None, default_message_time_to_live=None, dead_lettering_on_message_expiration=None, max_delivery_count=None, status=None, enable_batched_operations=None, auto_delete_on_idle=None, forward_to=None, forward_dead_lettered_messages_to=None, dead_lettering_on_filter_evaluation_exceptions=None): from azure.mgmt.servicebus.models import SBSubscription subscription_params = SBSubscription( lock_duration=return_valid_duration_create(lock_duration), 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, max_delivery_count=max_delivery_count, status=status, enable_batched_operations=enable_batched_operations, auto_delete_on_idle=return_valid_duration_create(auto_delete_on_idle), forward_to=forward_to, forward_dead_lettered_messages_to=forward_dead_lettered_messages_to, dead_lettering_on_filter_evaluation_exceptions=dead_lettering_on_filter_evaluation_exceptions ) return client.create_or_update( resource_group_name=resource_group_name, namespace_name=namespace_name, topic_name=topic_name, subscription_name=subscription_name, parameters=subscription_params)
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) topic = self._get_topic(**kwargs) retries = 4 for i in range(retries): try: self.resource = self.client.subscriptions.create_or_update( group.name, namespace.name, topic.name, name, SBSubscription(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, }
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) topic = self._get_topic(**kwargs) self.resource = self.client.subscriptions.create_or_update( group.name, namespace.name, topic.name, name, SBSubscription( 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, }
def test_sb_rule_curd(self, resource_group, location): # List all topic types resource_group_name = resource_group.name # "ardsouza-resourcemovetest-group2" # Create a Namespace namespace_name = "testingpythontestcaserule" namespaceparameter = SBNamespace(location=location, tags={ 'tag1': 'value1', 'tag2': 'value2' }, sku=SBSku(name=SkuName.standard)) creatednamespace = self.servicebus_client.namespaces.create_or_update( resource_group_name, namespace_name, namespaceparameter).result() self.assertEqual(creatednamespace.name, namespace_name) while (self.servicebus_client.namespaces.get( resource_group_name, namespace_name).provisioning_state != 'Succeeded'): if self.is_live: time.sleep(15) continue # Create a Topic topic_name = "testingpythonsdktopic" createtopicresponse = self.servicebus_client.topics.create_or_update( resource_group_name, namespace_name, topic_name, SBTopic()) self.assertEqual(createtopicresponse.name, topic_name) # Get the created Topic gettopicresponse = self.servicebus_client.topics.get( resource_group_name, namespace_name, topic_name) self.assertEqual(gettopicresponse.name, topic_name) # Create subscription subscription_name = "testingpythonsdksubscription" createsubscriptionresponse = self.servicebus_client.subscriptions.create_or_update( resource_group_name, namespace_name, topic_name, subscription_name, SBSubscription()) self.assertEqual(createsubscriptionresponse.name, subscription_name) # Get created subscription getsubscriptionresponse = self.servicebus_client.subscriptions.get( resource_group_name, namespace_name, topic_name, subscription_name) self.assertEqual(getsubscriptionresponse.name, subscription_name) # create rule rule_name = "testingpythonsdkrule" createruleresponse = self.servicebus_client.rules.create_or_update( resource_group_name, namespace_name, topic_name, subscription_name, rule_name, Rule()) self.assertEqual(createruleresponse.name, rule_name) # get create rule getruleresponse = self.servicebus_client.rules.get( resource_group_name, namespace_name, topic_name, subscription_name, rule_name) self.assertEqual(getruleresponse.name, rule_name) # get all rules getallrulesresponse = list( self.servicebus_client.rules.list_by_subscriptions( resource_group_name, namespace_name, topic_name, subscription_name)) self.assertEqual(len(getallrulesresponse), 1) # update create rule with filter and action strSqlExp = "myproperty='test'" ruleparameter = Rule(action=None, filter_type=FilterType.sql_filter, sql_filter=SqlFilter(sql_expression=strSqlExp), correlation_filter=None) createruleresponse = self.servicebus_client.rules.create_or_update( resource_group_name, namespace_name, topic_name, subscription_name, rule_name, ruleparameter) self.assertEqual(createruleresponse.name, rule_name) # Delete the created subscription self.servicebus_client.subscriptions.delete(resource_group_name, namespace_name, topic_name, subscription_name) # delete the Topic self.servicebus_client.topics.delete(resource_group_name, namespace_name, topic_name) # Delete the create namespace deletenamespace = self.servicebus_client.namespaces.delete( resource_group_name, namespace_name).result()
def cli_sbsubscription_update( instance, lock_duration=None, requires_session=None, default_message_time_to_live=None, dead_lettering_on_message_expiration=None, max_delivery_count=None, status=None, enable_batched_operations=None, auto_delete_on_idle=None, forward_to=None, forward_dead_lettered_messages_to=None, dead_lettering_on_filter_evaluation_exceptions=None): from azure.mgmt.servicebus.models import SBSubscription subscription_params = SBSubscription() if lock_duration: subscription_params.lock_duration = return_valid_duration( instance, 'lock_duration', lock_duration) if requires_session: subscription_params.requires_session = requires_session if default_message_time_to_live: subscription_params.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: subscription_params.dead_lettering_on_message_expiration = dead_lettering_on_message_expiration if max_delivery_count: subscription_params.max_delivery_count = max_delivery_count if status: subscription_params.status = status if lock_duration: subscription_params.enable_batched_operations = enable_batched_operations subscription_params.auto_delete_on_idle = return_valid_duration( instance, 'auto_delete_on_idle', auto_delete_on_idle) if forward_to: subscription_params.forward_to = forward_to if forward_dead_lettered_messages_to: subscription_params.forward_dead_lettered_messages_to = forward_dead_lettered_messages_to if dead_lettering_on_filter_evaluation_exceptions: subscription_params.dead_lettering_on_filter_evaluation_exceptions = dead_lettering_on_filter_evaluation_exceptions return subscription_params
def cli_sbsubscription_update(instance, lock_duration=None, requires_session=None, default_message_time_to_live=None, dead_lettering_on_message_expiration=None, max_delivery_count=None, status=None, enable_batched_operations=None, auto_delete_on_idle=None, forward_to=None, forward_dead_lettered_messages_to=None, dead_lettering_on_filter_evaluation_exceptions=None): from azure.mgmt.servicebus.models import SBSubscription subscription_params = SBSubscription() if lock_duration: subscription_params.lock_duration = return_valid_duration(instance, 'lock_duration', lock_duration) if requires_session: subscription_params.requires_session = requires_session if default_message_time_to_live: subscription_params.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: subscription_params.dead_lettering_on_message_expiration = dead_lettering_on_message_expiration if max_delivery_count: subscription_params.max_delivery_count = max_delivery_count if status: subscription_params.status = status if lock_duration: subscription_params.enable_batched_operations = enable_batched_operations subscription_params.auto_delete_on_idle = return_valid_duration(instance, 'auto_delete_on_idle', auto_delete_on_idle) if forward_to: subscription_params.forward_to = forward_to if forward_dead_lettered_messages_to: subscription_params.forward_dead_lettered_messages_to = forward_dead_lettered_messages_to if dead_lettering_on_filter_evaluation_exceptions: subscription_params.dead_lettering_on_filter_evaluation_exceptions = dead_lettering_on_filter_evaluation_exceptions return subscription_params
def test_sb_subscription_curd(self, resource_group, location): # List all topic types resource_group_name = resource_group.name # "ardsouza-resourcemovetest-group2" # Create a Namespace namespace_name = self.get_replayable_random_resource_name( "testingpythontestcasesubscription") namespaceparameter = SBNamespace(location=location, tags={ 'tag1': 'value1', 'tag2': 'value2' }, sku=SBSku(name=SkuName.standard)) creatednamespace = self.servicebus_client.namespaces.create_or_update( resource_group_name, namespace_name, namespaceparameter).result() self.assertEqual(creatednamespace.name, namespace_name) while (self.servicebus_client.namespaces.get( resource_group_name, namespace_name).provisioning_state != 'Succeeded'): if self.is_live: time.sleep(15) continue # Create a Topic topic_name = self.get_replayable_random_resource_name( "testingpythonsdktopic") createtopicresponse = self.servicebus_client.topics.create_or_update( resource_group_name, namespace_name, topic_name, SBTopic()) self.assertEqual(createtopicresponse.name, topic_name) # Get the created Topic gettopicresponse = self.servicebus_client.topics.get( resource_group_name, namespace_name, topic_name) self.assertEqual(gettopicresponse.name, topic_name) # Create subscription subscription_name = self.get_replayable_random_resource_name( "testingpythonsdksubscription") createsubscriptionresponse = self.servicebus_client.subscriptions.create_or_update( resource_group_name, namespace_name, topic_name, subscription_name, SBSubscription()) self.assertEqual(createsubscriptionresponse.name, subscription_name) # Get created subscription getsubscriptionresponse = self.servicebus_client.subscriptions.get( resource_group_name, namespace_name, topic_name, subscription_name) self.assertEqual(getsubscriptionresponse.name, subscription_name) # list the subscription by Topic listsubscriptionresponse = list( self.servicebus_client.subscriptions.list_by_topic( resource_group_name, namespace_name, topic_name)) self.assertEqual(len(listsubscriptionresponse), 1) # Update created subscription updatesubscriptionresponse = self.servicebus_client.subscriptions.create_or_update( resource_group_name, namespace_name, topic_name, subscription_name, SBSubscription(enable_batched_operations=True, dead_lettering_on_message_expiration=True)) self.assertEqual(updatesubscriptionresponse.enable_batched_operations, True) self.assertEqual( updatesubscriptionresponse.dead_lettering_on_message_expiration, True) # Delete the created subscription self.servicebus_client.subscriptions.delete(resource_group_name, namespace_name, topic_name, subscription_name) # delete the Topic self.servicebus_client.topics.delete(resource_group_name, namespace_name, topic_name) # Delete the create namespace deletenamespace = self.servicebus_client.namespaces.delete( resource_group_name, namespace_name).result()