def cli_sbtopic_create(client, resource_group_name, namespace_name, topic_name, default_message_time_to_live=None, max_size_in_megabytes=None, requires_duplicate_detection=None, duplicate_detection_history_time_window=None, enable_batched_operations=None, status=None, support_ordering=None, auto_delete_on_idle=None, enable_partitioning=None, enable_express=None): from azure.mgmt.servicebus.models import SBTopic topic_params = SBTopic( default_message_time_to_live=return_valid_duration_create( default_message_time_to_live), max_size_in_megabytes=max_size_in_megabytes, requires_duplicate_detection=requires_duplicate_detection, duplicate_detection_history_time_window=return_valid_duration_create( duplicate_detection_history_time_window), enable_batched_operations=enable_batched_operations, status=status, support_ordering=support_ordering, auto_delete_on_idle=return_valid_duration_create(auto_delete_on_idle), enable_partitioning=enable_partitioning, enable_express=enable_express) return client.create_or_update(resource_group_name=resource_group_name, namespace_name=namespace_name, topic_name=topic_name, parameters=topic_params)
def cli_sbtopic_create(client, resource_group_name, namespace_name, topic_name, default_message_time_to_live=None, max_size_in_megabytes=None, requires_duplicate_detection=None, duplicate_detection_history_time_window=None, enable_batched_operations=None, status=None, support_ordering=None, auto_delete_on_idle=None, enable_partitioning=None, enable_express=None): from azure.mgmt.servicebus.models import SBTopic from knack.util import CLIError if max_size_in_megabytes: getnamespace = client.get(resource_group_name=resource_group_name, namespace_name=namespace_name) if getnamespace.sku.name == 'Standard' and max_size_in_megabytes not in [ 1024, 2048, 3072, 4096, 5120 ]: raise CLIError( '--max-size on Standard sku namespace only supports upto [1024, 2048, 3072, 4096, 5120] GB' ) topic_params = SBTopic( default_message_time_to_live=return_valid_duration_create( default_message_time_to_live), max_size_in_megabytes=max_size_in_megabytes, requires_duplicate_detection=requires_duplicate_detection, duplicate_detection_history_time_window=return_valid_duration_create( duplicate_detection_history_time_window), enable_batched_operations=enable_batched_operations, status=status, support_ordering=support_ordering, auto_delete_on_idle=return_valid_duration_create(auto_delete_on_idle), enable_partitioning=enable_partitioning, enable_express=enable_express) return client.create_or_update(resource_group_name=resource_group_name, namespace_name=namespace_name, topic_name=topic_name, parameters=topic_params)
def test_sb_topic_curd(self, resource_group, location): # List all topic types resource_group_name = resource_group.name # "ardsouza-resourcemovetest-group2" # Create a Namespace namespace_name = "testingpythontestcasetopic" 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'): 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) # Get all the topics listbynamespacetopicresponse = list( self.servicebus_client.topics.list_by_namespace( resource_group_name, namespace_name)) self.assertEqual(len(listbynamespacetopicresponse), 1) self.assertEqual(listbynamespacetopicresponse[0].name, topic_name) # update topic updatetopicresponse = self.servicebus_client.topics.create_or_update( resource_group_name, namespace_name, topic_name, SBTopic(enable_express=True, enable_batched_operations=True, max_size_in_megabytes=1024)) self.assertEqual(updatetopicresponse.name, topic_name) self.assertEqual(updatetopicresponse.enable_batched_operations, True) self.assertEqual(updatetopicresponse.max_size_in_megabytes, 1024) self.assertEqual(updatetopicresponse.enable_express, True) # Create a new authorizationrule authoRule_name = "testingauthrulepy" createtopicauthorule = self.servicebus_client.topics.create_or_update_authorization_rule( resource_group_name, namespace_name, topic_name, authoRule_name, [AccessRights('Send'), AccessRights('Listen')]) self.assertEqual( createtopicauthorule.name, authoRule_name, "Authorization rule name not as created - create_or_update_authorization_rule " ) self.assertEqual(len(createtopicauthorule.rights), 2) # Get the created authorizationrule gettopicauthorule = self.servicebus_client.topics.get_authorization_rule( resource_group_name, namespace_name, topic_name, authoRule_name) self.assertEqual( gettopicauthorule.name, authoRule_name, "Authorization rule name not as passed as parameter - get_authorization_rule" ) self.assertEqual( len(gettopicauthorule.rights), 2, "Access rights mis match as created - get_authorization_rule ") # update the rights of the authorizatiorule gettopicauthorule.rights.append('Manage') updatetopicauthorule = self.servicebus_client.topics.create_or_update_authorization_rule( resource_group_name, namespace_name, topic_name, authoRule_name, gettopicauthorule.rights) self.assertEqual( updatetopicauthorule.name, authoRule_name, "Authorization rule name not as passed as parameter for update call - create_or_update_authorization_rule " ) self.assertEqual( len(updatetopicauthorule.rights), 3, "Access rights mis match as updated - create_or_update_authorization_rule " ) # list all the authorization ruels for the given Topic listtopicauthorule = list( self.servicebus_client.topics.list_authorization_rules( resource_group_name, namespace_name, topic_name)) self.assertEqual( len(listtopicauthorule), 1, "number of authorization rule mismatch, created = 1 - list_authorization_rules" ) # List keys for the authorization rule listkeysauthorizationrule = self.servicebus_client.topics.list_keys( resource_group_name, namespace_name, topic_name, authoRule_name) self.assertIsNotNone(listkeysauthorizationrule) # regenerate Keys for authorizationrule - Primary regenratePrimarykeyauthorizationrule = self.servicebus_client.topics.regenerate_keys( resource_group_name, namespace_name, topic_name, authoRule_name, 'PrimaryKey') self.assertNotEqual(listkeysauthorizationrule.primary_key, regenratePrimarykeyauthorizationrule.primary_key) # regenerate Keys for authorizationrule - Primary regenrateSecondarykeyauthorizationrule = self.servicebus_client.topics.regenerate_keys( resource_group_name, namespace_name, topic_name, authoRule_name, 'SecondaryKey') self.assertNotEqual( listkeysauthorizationrule.secondary_key, regenrateSecondarykeyauthorizationrule.secondary_key) # delete the authorizationrule self.servicebus_client.topics.delete_authorization_rule( resource_group_name, namespace_name, topic_name, authoRule_name) # list all the authorization ruels for the given Topic listtopicauthorule = list( self.servicebus_client.topics.list_authorization_rules( resource_group_name, namespace_name, topic_name)) lenTemp = len(listtopicauthorule) # 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, None, True).output
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_sbtopic_update(instance, default_message_time_to_live=None, max_size_in_megabytes=None, requires_duplicate_detection=None, duplicate_detection_history_time_window=None, enable_batched_operations=None, status=None, support_ordering=None, auto_delete_on_idle=None, enable_partitioning=None, enable_express=None): from azure.mgmt.servicebus.models import SBTopic topic_params = SBTopic() if default_message_time_to_live: topic_params.default_message_time_to_live = return_valid_duration( instance, 'default_message_time_to_live', default_message_time_to_live) if max_size_in_megabytes: topic_params.max_size_in_megabytes = max_size_in_megabytes if requires_duplicate_detection: topic_params.requires_duplicate_detection = requires_duplicate_detection if duplicate_detection_history_time_window: topic_params.duplicate_detection_history_time_window = return_valid_duration( instance, 'duplicate_detection_history_time_window', duplicate_detection_history_time_window) if enable_batched_operations: topic_params.enable_batched_operations = enable_batched_operations if status: topic_params.status = status if support_ordering: topic_params.support_ordering = support_ordering if auto_delete_on_idle: topic_params.auto_delete_on_idle = return_valid_duration( instance, 'auto_delete_on_idle', auto_delete_on_idle) if enable_partitioning: topic_params.enable_partitioning = enable_partitioning if enable_express: topic_params.enable_express = enable_express return topic_params
def cli_sbtopic_update(instance, default_message_time_to_live=None, max_size_in_megabytes=None, requires_duplicate_detection=None, duplicate_detection_history_time_window=None, enable_batched_operations=None, status=None, support_ordering=None, auto_delete_on_idle=None, enable_partitioning=None, enable_express=None): from azure.mgmt.servicebus.models import SBTopic topic_params = SBTopic() if default_message_time_to_live: topic_params.default_message_time_to_live = return_valid_duration(instance, 'default_message_time_to_live', default_message_time_to_live) if max_size_in_megabytes: topic_params.max_size_in_megabytes = max_size_in_megabytes if requires_duplicate_detection: topic_params.requires_duplicate_detection = requires_duplicate_detection if duplicate_detection_history_time_window: topic_params.duplicate_detection_history_time_window = return_valid_duration(instance, 'duplicate_detection_history_time_window', duplicate_detection_history_time_window) if enable_batched_operations: topic_params.enable_batched_operations = enable_batched_operations if status: topic_params.status = status if support_ordering: topic_params.support_ordering = support_ordering if auto_delete_on_idle: topic_params.auto_delete_on_idle = return_valid_duration(instance, 'auto_delete_on_idle', auto_delete_on_idle) if enable_partitioning: topic_params.enable_partitioning = enable_partitioning if enable_express: topic_params.enable_express = enable_express return topic_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()