def _assert_properties_default(self, prop): self.assertIsNotNone(prop) self._assert_logging_equal(prop.logging, QueueAnalyticsLogging()) self._assert_metrics_equal(prop.hour_metrics, Metrics()) self._assert_metrics_equal(prop.minute_metrics, Metrics()) self._assert_cors_equal(prop.cors, list())
def _assert_properties_default(self, prop): self.assertIsNotNone(prop) self._assert_logging_equal(prop['analytics_logging'], QueueAnalyticsLogging()) self._assert_metrics_equal(prop['hour_metrics'], Metrics()) self._assert_metrics_equal(prop['minute_metrics'], Metrics()) self._assert_cors_equal(prop['cors'], list())
def set_service_properties(self, queue_service): try: print('1. Get Queue service properties') props = queue_service.get_service_properties() retention = RetentionPolicy(enabled=True, days=5) logging = QueueAnalyticsLogging(delete=True, read=False, write=True, retention_policy=retention) hour_metrics = Metrics(enabled=True, include_apis=True, retention_policy=retention) minute_metrics = Metrics(enabled=False) print('2. Ovewrite Queue service properties') queue_service.set_service_properties(analytics_logging=logging, hour_metrics=hour_metrics, minute_metrics=minute_metrics) finally: print( '3. Revert Queue service properties back to the original ones') queue_service.set_service_properties( analytics_logging=props['analytics_logging'], hour_metrics=props['hour_metrics'], minute_metrics=props['minute_metrics']) print('4. Set Queue service properties completed')
async def test_queue_service_properties(self, resource_group, location, storage_account, storage_account_key): # Instantiate the QueueServiceClient from a connection string from azure.storage.queue.aio import QueueServiceClient queue_service = QueueServiceClient.from_connection_string( self.connection_string(storage_account, storage_account_key)) # [START async_set_queue_service_properties] # Create service properties from azure.storage.queue import QueueAnalyticsLogging, Metrics, CorsRule, RetentionPolicy # Create logging settings logging = QueueAnalyticsLogging(read=True, write=True, delete=True, retention_policy=RetentionPolicy( enabled=True, days=5)) # Create metrics for requests statistics hour_metrics = Metrics(enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5)) minute_metrics = Metrics(enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5)) # Create CORS rules cors_rule1 = CorsRule(['www.xyz.com'], ['GET']) allowed_origins = ['www.xyz.com', "www.ab.com", "www.bc.com"] allowed_methods = ['GET', 'PUT'] max_age_in_seconds = 500 exposed_headers = [ "x-ms-meta-data*", "x-ms-meta-source*", "x-ms-meta-abc", "x-ms-meta-bcd" ] allowed_headers = [ "x-ms-meta-data*", "x-ms-meta-target*", "x-ms-meta-xyz", "x-ms-meta-foo" ] cors_rule2 = CorsRule(allowed_origins, allowed_methods, max_age_in_seconds=max_age_in_seconds, exposed_headers=exposed_headers, allowed_headers=allowed_headers) cors = [cors_rule1, cors_rule2] # Set the service properties await queue_service.set_service_properties(logging, hour_metrics, minute_metrics, cors) # [END async_set_queue_service_properties] # [START async_get_queue_service_properties] properties = await queue_service.get_service_properties()
def test_set_logging(self, storage_account_name, storage_account_key): # Arrange qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key) logging = QueueAnalyticsLogging(read=True, write=True, delete=True, retention_policy=RetentionPolicy(enabled=True, days=5)) # Act qsc.set_service_properties(analytics_logging=logging) # Assert received_props = qsc.get_service_properties() self._assert_logging_equal(received_props['analytics_logging'], logging)
def test_queue_service_properties(self, storage_account_name, storage_account_key): # Arrange qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key) # Act resp = qsc.set_service_properties( analytics_logging=QueueAnalyticsLogging(), hour_metrics=Metrics(), minute_metrics=Metrics(), cors=list()) # Assert self.assertIsNone(resp) self._assert_properties_default(qsc.get_service_properties())
async def test_set_logging(self, resource_group, location, storage_account, storage_account_key): # Arrange qsc = QueueServiceClient(self._account_url(storage_account.name), storage_account_key, transport=AiohttpTestTransport()) logging = QueueAnalyticsLogging(read=True, write=True, delete=True, retention_policy=RetentionPolicy( enabled=True, days=5)) # Act await qsc.set_service_properties(analytics_logging=logging) # Assert received_props = await qsc.get_service_properties() self._assert_logging_equal(received_props.logging, logging)
async def test_queue_service_properties(self, resource_group, location, storage_account, storage_account_key): # Arrange qsc = QueueServiceClient(self._account_url(storage_account.name), storage_account_key, transport=AiohttpTestTransport()) # Act resp = await qsc.set_service_properties( analytics_logging=QueueAnalyticsLogging(), hour_metrics=Metrics(), minute_metrics=Metrics(), cors=list()) # Assert self.assertIsNone(resp) props = await qsc.get_service_properties() self._assert_properties_default(props)