Пример #1
0
    def test_create_properties(self, tables_storage_account_name, tables_primary_storage_account_key):
        # # Arrange
        account_url = self.account_url(tables_storage_account_name, "table")
        ts = TableServiceClient(credential=tables_primary_storage_account_key, endpoint=account_url)
        table_name = self._get_table_reference()
        # Act
        created = ts.create_table(table_name)

        # Assert
        assert created.table_name == table_name

        properties = ts.get_service_properties()
        ts.set_service_properties(analytics_logging=TableAnalyticsLogging(write=True))
        # have to wait for return to service
        p = ts.get_service_properties()
        # have to wait for return to service
        ts.set_service_properties(
            minute_metrics=TableMetrics(
                enabled=True,
                include_apis=True,
                retention_policy=TableRetentionPolicy(enabled=True, days=5)
            )
        )

        ps = ts.get_service_properties()
        ts.delete_table(table_name)
Пример #2
0
    def test_create_properties(self, resource_group, location, storage_account,
                               storage_account_key):
        # # Arrange
        ts = TableServiceClient(self.account_url(storage_account, "table"),
                                storage_account_key)
        table_name = self._get_table_reference()
        # Act
        created = ts.create_table(table_name)

        # Assert
        assert created.table_name == table_name

        properties = ts.get_service_properties()
        print(properties)
        ts.set_service_properties(analytics_logging=TableAnalyticsLogging(
            write=True))
        # have to wait for return to service
        p = ts.get_service_properties()
        # have to wait for return to service
        ts.set_service_properties(minute_metrics=Metrics(
            enabled=True,
            include_apis=True,
            retention_policy=RetentionPolicy(enabled=True, days=5)))

        ps = ts.get_service_properties()
        print(ps)
        print(p)
        ts.delete_table(table_name)
    def test_create_properties(self, tables_cosmos_account_name,
                               tables_primary_cosmos_account_key):
        # # Arrange
        ts = TableServiceClient(
            self.account_url(tables_cosmos_account_name, "cosmos"),
            tables_primary_cosmos_account_key)
        table_name = self._get_table_reference()
        # Act
        created = ts.create_table(table_name)

        # Assert
        assert created.table_name == table_name

        # properties = ts.get_service_properties()
        ts.set_service_properties(analytics_logging=TableAnalyticsLogging(
            write=True))

        p = ts.get_service_properties()

        ts.set_service_properties(minute_metrics=Metrics(
            enabled=True,
            include_apis=True,
            retention_policy=RetentionPolicy(enabled=True, days=5)))

        ps = ts.get_service_properties()
        ts.delete_table(table_name)

        if self.is_live:
            sleep(SLEEP_DELAY)
Пример #4
0
    def test_set_cors(self, resource_group, location, storage_account, storage_account_key):
        # Arrange
        url = self.account_url(storage_account, "table")
        if 'cosmos' in url:
            pytest.skip("Cosmos Tables does not yet support service properties")
        tsc = TableServiceClient(url, storage_account_key)
        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]

        # Act
        tsc.set_service_properties(cors=cors)

        # Assert
        if self.is_live:
            time.sleep(30)
        received_props = tsc.get_service_properties()
        self._assert_cors_equal(received_props['cors'], cors)
Пример #5
0
    def test_set_cors(self, tables_storage_account_name,
                      tables_primary_storage_account_key):
        # Arrange
        url = self.account_url(tables_storage_account_name, "table")
        tsc = TableServiceClient(url,
                                 credential=tables_primary_storage_account_key)
        cors_rule1 = TableCorsRule(['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 = TableCorsRule(allowed_origins, allowed_methods)
        cors_rule2.max_age_in_seconds = max_age_in_seconds
        cors_rule2.exposed_headers = exposed_headers
        cors_rule2.allowed_headers = allowed_headers

        cors = [cors_rule1, cors_rule2]

        # Act
        tsc.set_service_properties(cors=cors)

        # Assert
        if self.is_live:
            time.sleep(45)
        received_props = tsc.get_service_properties()
        self._assert_cors_equal(received_props['cors'], cors)
Пример #6
0
 def authentication_by_shared_key(self):
     # Instantiate a TableServiceClient using a shared access key
     # [START auth_from_shared_key]
     from azure.data.tables import TableServiceClient
     table_service = TableServiceClient(account_url=self.account_url,
                                        credential=self.access_key)
     properties = table_service.get_service_properties()
     print("Shared Key: {}".format(properties))
Пример #7
0
 def create_table_service_client(self):
     # Instantiate a TableServiceClient using a shared access key
     # [START create_table_service_client]
     from azure.data.tables import TableServiceClient
     table_service = TableServiceClient(account_url=self.account_url,
                                        credential=self.access_key)
     properties = table_service.get_service_properties()
     print("Properties: {}".format(properties))
Пример #8
0
    def authentication_by_shared_key(self):
        # Instantiate a TableServiceClient using a shared access key
        # [START create_Table_service_client]
        from azure.data.tables import TableServiceClient
        table_service = TableServiceClient(account_url=self.account_url, credential=self.access_key)
        # [END create_table_service_client]

        # Get information for the Table Service
        properties = table_service.get_service_properties()
Пример #9
0
    def test_set_hour_metrics(self, tables_cosmos_account_name, tables_primary_cosmos_account_key):
        # Arrange
        url = self.account_url(tables_cosmos_account_name, "cosmos")
        tsc = TableServiceClient(url, tables_primary_cosmos_account_key)
        hour_metrics = Metrics(enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5))

        # Act
        tsc.set_service_properties(hour_metrics=hour_metrics)

        # Assert
        received_props = tsc.get_service_properties()
        self._assert_metrics_equal(received_props['hour_metrics'], hour_metrics)
        if self.is_live:
            sleep(SLEEP_DELAY)
Пример #10
0
    def test_set_logging(self, tables_cosmos_account_name, tables_primary_cosmos_account_key):
        # Arrange
        url = self.account_url(tables_cosmos_account_name, "cosmos")
        tsc = TableServiceClient(url, tables_primary_cosmos_account_key)
        logging = TableAnalyticsLogging(read=True, write=True, delete=True, retention_policy=RetentionPolicy(enabled=True, days=5))

        # Act
        tsc.set_service_properties(analytics_logging=logging)

        # Assert
        received_props = tsc.get_service_properties()
        self._assert_logging_equal(received_props['analytics_logging'], logging)
        if self.is_live:
            time.sleep(30)
    def test_set_minute_metrics(self, tables_storage_account_name, tables_primary_storage_account_key):
        # Arrange
        url = self.account_url(tables_storage_account_name, "table")
        tsc = TableServiceClient(url, tables_primary_storage_account_key)
        minute_metrics = Metrics(enabled=True, include_apis=True,
                                 retention_policy=RetentionPolicy(enabled=True, days=5))

        # Act
        tsc.set_service_properties(minute_metrics=minute_metrics)

        # Assert
        if self.is_live:
            time.sleep(30)
        received_props = tsc.get_service_properties()
        self._assert_metrics_equal(received_props['minute_metrics'], minute_metrics)
Пример #12
0
    def test_table_service_properties(self, tables_cosmos_account_name, tables_primary_cosmos_account_key):
        # Arrange
        url = self.account_url(tables_cosmos_account_name, "cosmos")
        tsc = TableServiceClient(url, tables_primary_cosmos_account_key)
        # Act
        resp = tsc.set_service_properties(
            analytics_logging=TableAnalyticsLogging(),
            hour_metrics=Metrics(),
            minute_metrics=Metrics(),
            cors=list())

        # Assert
        assert resp is None
        self._assert_properties_default(tsc.get_service_properties())
        if self.is_live:
            sleep(SLEEP_DELAY)
    def test_table_service_properties(self, tables_storage_account_name, tables_primary_storage_account_key):
        # Arrange
        url = self.account_url(tables_storage_account_name, "table")
        tsc = TableServiceClient(url, tables_primary_storage_account_key)
        # Act
        resp = tsc.set_service_properties(
            analytics_logging=TableAnalyticsLogging(),
            hour_metrics=Metrics(),
            minute_metrics=Metrics(),
            cors=list())

        # Assert
        assert resp is None
        if self.is_live:
            time.sleep(30)
        self._assert_properties_default(tsc.get_service_properties())
Пример #14
0
    def test_set_hour_metrics(self, resource_group, location, storage_account, storage_account_key):
        # Arrange
        url = self.account_url(storage_account, "table")
        if 'cosmos' in url:
            pytest.skip("Cosmos Tables does not yet support service properties")
        tsc = TableServiceClient(url, storage_account_key)
        hour_metrics = Metrics(enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5))

        # Act
        tsc.set_service_properties(hour_metrics=hour_metrics)

        # Assert
        if self.is_live:
            time.sleep(30)
        received_props = tsc.get_service_properties()
        self._assert_metrics_equal(received_props['hour_metrics'], hour_metrics)
Пример #15
0
    def test_set_logging(self, resource_group, location, storage_account, storage_account_key):
        # Arrange
        url = self.account_url(storage_account, "table")
        if 'cosmos' in url:
            pytest.skip("Cosmos Tables does not yet support service properties")
        tsc = TableServiceClient(url, storage_account_key)
        logging = TableAnalyticsLogging(read=True, write=True, delete=True, retention_policy=RetentionPolicy(enabled=True, days=5))

        # Act
        tsc.set_service_properties(analytics_logging=logging)

        # Assert
        if self.is_live:
            time.sleep(30)
        received_props = tsc.get_service_properties()
        self._assert_logging_equal(received_props['analytics_logging'], logging)
    def test_table_service_properties(self, resource_group, location,
                                      storage_account, storage_account_key):
        # Arrange
        url = self.account_url(storage_account, "cosmos")
        tsc = TableServiceClient(url, storage_account_key)
        # Act
        resp = tsc.set_service_properties(
            analytics_logging=TableAnalyticsLogging(),
            hour_metrics=Metrics(),
            minute_metrics=Metrics(),
            cors=list())

        # Assert
        assert resp is None
        self._assert_properties_default(tsc.get_service_properties())
        if self.is_live:
            sleep(SLEEP_DELAY)
Пример #17
0
    def test_table_service_properties(self, resource_group, location, storage_account, storage_account_key):
        # Arrange
        url = self.account_url(storage_account, "table")
        if 'cosmos' in url:
            pytest.skip("Cosmos Tables does not yet support service properties")
        tsc = TableServiceClient(url, storage_account_key)
        # Act
        resp = tsc.set_service_properties(
            analytics_logging=TableAnalyticsLogging(),
            hour_metrics=Metrics(),
            minute_metrics=Metrics(),
            cors=list())

        # Assert
        self.assertIsNone(resp)
        if self.is_live:
            time.sleep(30)
        self._assert_properties_default(tsc.get_service_properties())
    def test_set_minute_metrics(self, resource_group, location,
                                storage_account, storage_account_key):
        # Arrange
        url = self.account_url(storage_account, "cosmos")
        tsc = TableServiceClient(url, storage_account_key)
        minute_metrics = Metrics(enabled=True,
                                 include_apis=True,
                                 retention_policy=RetentionPolicy(enabled=True,
                                                                  days=5))

        # Act
        tsc.set_service_properties(minute_metrics=minute_metrics)

        # Assert
        received_props = tsc.get_service_properties()
        self._assert_metrics_equal(received_props['minute_metrics'],
                                   minute_metrics)
        if self.is_live:
            sleep(SLEEP_DELAY)
Пример #19
0
    def authentication_by_shared_access_signature(self):
        # Instantiate a TableServiceClient using a connection string
        from azure.data.tables import TableServiceClient

        # [START auth_from_sas]
        # Create a SAS token to use for authentication of a client
        from azure.data.tables import generate_account_sas, ResourceTypes, AccountSasPermissions
        print(self.account_name)
        sas_token = generate_account_sas(
            self.account_name,
            self.access_key,
            resource_types=ResourceTypes(service=True),
            permission=AccountSasPermissions(read=True),
            expiry=datetime.utcnow() + timedelta(hours=1))

        token_auth_table_service = TableServiceClient(
            account_url=self.account_url, credential=sas_token)

        properties = token_auth_table_service.get_service_properties()
        print("Shared Access Signature: {}".format(properties))
Пример #20
0
class TestStorageRetry(AzureRecordedTestCase, TableTestCase):
    def _set_up(self,
                tables_storage_account_name,
                tables_primary_storage_account_key,
                url='table',
                default_table=True,
                **kwargs):
        self.table_name = self.get_resource_name('uttable')
        self.ts = TableServiceClient(
            self.account_url(tables_storage_account_name, url),
            credential=tables_primary_storage_account_key,
            **kwargs)
        self.table = self.ts.get_table_client(self.table_name)
        if self.is_live and default_table:
            try:
                self.ts.create_table(self.table_name)
            except ResourceExistsError:
                pass

        self.query_tables = []

    # TODO: Figure out why this is needed by the "test_retry_on_socket_timeout" test
    def _tear_down(self, **kwargs):
        if self.is_live:
            try:
                self.ts.delete_table(self.table_name, **kwargs)
            except:
                pass

            try:
                for table_name in self.query_tables:
                    try:
                        self.ts.delete_table(table_name, **kwargs)
                    except:
                        pass
            except AttributeError:
                pass

    # --Test Cases --------------------------------------------
    @tables_decorator
    @recorded_by_proxy
    def test_retry_on_server_error(self, tables_storage_account_name,
                                   tables_primary_storage_account_key):
        self._set_up(tables_storage_account_name,
                     tables_primary_storage_account_key,
                     default_table=False)
        try:
            callback = ResponseCallback(status=201,
                                        new_status=500).override_status

            new_table_name = self.get_resource_name('uttable')
            # The initial create will return 201, but we overwrite it with 500 and retry.
            # The retry will then get a 409 conflict.
            with pytest.raises(ResourceExistsError):
                self.ts.create_table(new_table_name,
                                     raw_response_hook=callback)
        finally:
            self.ts.delete_table(new_table_name)
            self._tear_down()

    @tables_decorator
    @recorded_by_proxy
    def test_retry_on_timeout(self, tables_storage_account_name,
                              tables_primary_storage_account_key):
        self._set_up(tables_storage_account_name,
                     tables_primary_storage_account_key,
                     default_table=False,
                     retry_mode=RetryMode.Exponential,
                     retry_backoff_factor=1)

        callback = ResponseCallback(status=200,
                                    new_status=408).override_first_status
        try:
            # The initial get will return 200, but we overwrite it with 408 and retry.
            # The retry will then succeed.
            self.ts.get_service_properties(raw_response_hook=callback)
        finally:
            self._tear_down()

    @pytest.mark.live_test_only
    @tables_decorator
    def test_retry_on_socket_timeout(self, tables_storage_account_name,
                                     tables_primary_storage_account_key):
        retry_transport = RetryRequestTransport(connection_timeout=11,
                                                read_timeout=0.000000000001)
        self._set_up(tables_storage_account_name,
                     tables_primary_storage_account_key,
                     transport=retry_transport,
                     default_table=False,
                     retry_mode=RetryMode.Fixed,
                     retry_backoff_factor=1)

        with pytest.raises(AzureError) as error:
            self.ts.get_service_properties()

        # 3 retries + 1 original == 4
        assert retry_transport.count == 4
        # This call should succeed on the server side, but fail on the client side due to socket timeout
        assert 'read timeout' in str(
            error.value
        ), 'Expected socket timeout but got different exception.'

    @tables_decorator
    @recorded_by_proxy
    def test_no_retry(self, tables_storage_account_name,
                      tables_primary_storage_account_key):
        self._set_up(tables_storage_account_name,
                     tables_primary_storage_account_key,
                     retry_total=0,
                     default_table=False)

        new_table_name = self.get_resource_name('uttable')

        # Force the create call to 'timeout' with a 408
        callback = ResponseCallback(status=201, new_status=500).override_status

        try:
            with pytest.raises(HttpResponseError) as error:
                self.ts.create_table(new_table_name,
                                     raw_response_hook=callback)
            assert error.value.response.status_code == 500
            assert error.value.reason == 'Created'

        finally:
            self.ts.delete_table(new_table_name)
            self._tear_down()