def cli_namespace_create(client, resource_group_name, namespace_name, location=None, tags=None, sku='Standard', capacity=None, default_action=None): from azure.mgmt.servicebus.models import SBNamespace, SBSku client.create_or_update(resource_group_name=resource_group_name, namespace_name=namespace_name, parameters=SBNamespace( location=location, tags=tags, sku=SBSku(name=sku, tier=sku, capacity=capacity))).result() if default_action: netwrokruleset = client.get_network_rule_set(resource_group_name, namespace_name) netwrokruleset.default_action = default_action client.create_or_update_network_rule_set(resource_group_name, namespace_name, netwrokruleset) return client.get(resource_group_name, namespace_name)
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, {'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 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(None,FilterType.sql_filter,SqlFilter(sql_expression=strSqlExp),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,None,True).output
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 = "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 = "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) # 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()
def cli_namespace_create(client, resource_group_name, namespace_name, location=None, tags=None, sku='Standard', capacity=None): from azure.mgmt.servicebus.models import SBNamespace, SBSku return client.create_or_update( resource_group_name=resource_group_name, namespace_name=namespace_name, parameters=SBNamespace( location=location, tags=tags, sku=SBSku( name=sku, tier=sku, capacity=capacity) ) )
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_queue_curd(self, resource_group, location): # List all topic types resource_group_name = resource_group.name # Create a Namespace namespace_name = self.get_replayable_random_resource_name( "testingpythontestcasequeue") 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 Queue queue_name = self.get_replayable_random_resource_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 = self.get_replayable_random_resource_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).result()
def test_sb_namespace_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( "testingpythontestcasenamespace") 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) # # # Get created Namespace # getnamespaceresponse = self.servicebus_client.namespaces.get( resource_group_name, namespace_name) self.assertEqual(getnamespaceresponse.name, namespace_name) # Get the List of Namespaces under the resourceGroup - list_by_resource_group listbyresourcegroupresponse = list( self.servicebus_client.namespaces.list_by_resource_group( resource_group_name)) self.assertGreater(len(listbyresourcegroupresponse), 0, "No Namespace returned, List is empty") self.assertEqual(listbyresourcegroupresponse[0].name, namespace_name, "Created namespace not found - ListByResourgroup") # Get the List of namespace under the subscription - list listbysubscriptionresponse = list( self.servicebus_client.namespaces.list()) self.assertGreater(len(listbysubscriptionresponse), 0, "No Namespace returned, List is empty") # get the default authorizationrule defaultauthorule_name = self.get_replayable_random_resource_name( "RootManageSharedAccessKey") defaultamespaceauthorule = self.servicebus_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 = self.get_replayable_random_resource_name( "testingauthrulepy") createnamespaceauthorule = self.servicebus_client.namespaces.create_or_update_authorization_rule( resource_group_name, namespace_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.servicebus_client.namespaces.get_authorization_rule( resource_group_name, namespace_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.servicebus_client.namespaces.create_or_update_authorization_rule( resource_group_name, namespace_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.servicebus_client.namespaces.list_authorization_rules( resource_group_name, namespace_name)) self.assertEqual( len(createnamespaceauthorule), 2, "number of authorization rule mismatch with the created + default = 2 - list_authorization_rules" ) #List keys for the authorization rule listkeysauthorizationrule = self.servicebus_client.namespaces.list_keys( resource_group_name, namespace_name, authoRule_name) self.assertIsNotNone(listkeysauthorizationrule) # regenerate Keys for authorizationrule - Primary regenratePrimarykeyauthorizationrule = self.servicebus_client.namespaces.regenerate_keys( resource_group_name, namespace_name, authoRule_name, 'PrimaryKey') self.assertNotEqual(listkeysauthorizationrule.primary_key, regenratePrimarykeyauthorizationrule.primary_key) # regenerate Keys for authorizationrule - Primary regenrateSecondarykeyauthorizationrule = self.servicebus_client.namespaces.regenerate_keys( resource_group_name, namespace_name, authoRule_name, 'SecondaryKey') self.assertNotEqual( listkeysauthorizationrule.secondary_key, regenrateSecondarykeyauthorizationrule.secondary_key) # delete the authorizationrule self.servicebus_client.namespaces.delete_authorization_rule( resource_group_name, namespace_name, authoRule_name) # list all the authorization ruels for the given namespace createnamespaceauthorule = list( self.servicebus_client.namespaces.list_authorization_rules( resource_group_name, namespace_name)) self.assertEqual(len(createnamespaceauthorule), 1) self.assertEqual(createnamespaceauthorule[0].name, defaultauthorule_name) # Delete the create namespace deletenamespace = self.servicebus_client.namespaces.delete( resource_group_name, namespace_name).result()