Beispiel #1
0
    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 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')
Beispiel #3
0
    def test_retention_too_long(self):
        # Arrange
        minute_metrics = Metrics(enabled=True, include_apis=True,
                                 retention_policy=RetentionPolicy(enabled=True, days=366))

        # Assert
        self.assertRaises(HttpResponseError,
                          self.qsc.set_service_properties,
                          None, None, minute_metrics)
Beispiel #4
0
    async def test_retention_too_long(self, storage_account_name, storage_account_key):
        # Arrange
        qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key, transport=AiohttpTestTransport())
        minute_metrics = Metrics(enabled=True, include_apis=True,
                                 retention_policy=RetentionPolicy(enabled=True, days=366))

        # Assert
        with self.assertRaises(HttpResponseError):
            await qsc.set_service_properties()
Beispiel #5
0
    def test_set_hour_metrics(self):
        # Arrange
        hour_metrics = Metrics(enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5))

        # Act
        self.qsc.set_service_properties(hour_metrics=hour_metrics)

        # Assert
        received_props = self.qsc.get_service_properties()
        self._assert_metrics_equal(received_props.hour_metrics, hour_metrics)
Beispiel #6
0
    def test_set_logging(self):
        # Arrange
        logging = Logging(read=True, write=True, delete=True, retention_policy=RetentionPolicy(enabled=True, days=5))

        # Act
        self.qsc.set_service_properties(logging=logging)

        # Assert
        received_props = self.qsc.get_service_properties()
        self._assert_logging_equal(received_props.logging, logging)
Beispiel #7
0
    def test_retention_too_long(self, storage_account_name, storage_account_key):
        # Arrange
        qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key)
        minute_metrics = Metrics(enabled=True, include_apis=True,
                                 retention_policy=RetentionPolicy(enabled=True, days=366))

        # Assert
        self.assertRaises(HttpResponseError,
                          qsc.set_service_properties,
                          None, None, minute_metrics)
Beispiel #8
0
    def test_set_hour_metrics(self, storage_account_name, storage_account_key):
        # Arrange
        qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key)
        hour_metrics = Metrics(enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5))

        # Act
        qsc.set_service_properties(hour_metrics=hour_metrics)

        # Assert
        received_props = qsc.get_service_properties()
        self._assert_metrics_equal(received_props['hour_metrics'], hour_metrics)
    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)
        logging = Logging(read=True, write=True, delete=True, retention_policy=RetentionPolicy(enabled=True, days=5))

        # Act
        qsc.set_service_properties(logging=logging)

        # Assert
        received_props = qsc.get_service_properties()
        self._assert_logging_equal(received_props.logging, logging)
    def test_set_minute_metrics(self, resource_group, location, storage_account, storage_account_key):
        # Arrange
        qsc = QueueServiceClient(self._account_url(storage_account.name), storage_account_key)
        minute_metrics = Metrics(enabled=True, include_apis=True,
                                 retention_policy=RetentionPolicy(enabled=True, days=5))

        # Act
        qsc.set_service_properties(minute_metrics=minute_metrics)

        # Assert
        received_props = qsc.get_service_properties()
        self._assert_metrics_equal(received_props.minute_metrics, minute_metrics)
Beispiel #11
0
    async def test_set_minute_metrics(self, storage_account_name, storage_account_key):
        # Arrange
        qsc = QueueServiceClient(self.account_url(storage_account_name, "queue"), storage_account_key, transport=AiohttpTestTransport())
        minute_metrics = Metrics(enabled=True, include_apis=True,
                                 retention_policy=RetentionPolicy(enabled=True, days=5))

        # Act
        await qsc.set_service_properties(minute_metrics=minute_metrics)

        # Assert
        received_props = await qsc.get_service_properties()
        self._assert_metrics_equal(received_props['minute_metrics'], minute_metrics)
Beispiel #12
0
    async def test_set_hour_metrics(self, resource_group, location,
                                    storage_account, storage_account_key):
        # Arrange
        qsc = QueueServiceClient(self._account_url(storage_account.name),
                                 storage_account_key,
                                 transport=AiohttpTestTransport())
        hour_metrics = Metrics(enabled=True,
                               include_apis=True,
                               retention_policy=RetentionPolicy(enabled=True,
                                                                days=5))

        # Act
        await qsc.set_service_properties(hour_metrics=hour_metrics)

        # Assert
        received_props = await qsc.get_service_properties()
        self._assert_metrics_equal(received_props.hour_metrics, hour_metrics)
Beispiel #13
0
    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)
Beispiel #14
0
    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)