Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating AzBlob to STG 87-90 #21454

Merged
merged 4 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sdk/storage/azblob/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* Added [FilterBlobs by Tags](https://learn.microsoft.com/rest/api/storageservices/find-blobs-by-tags-container) API for container client.
* Added `System` option to `ListContainersInclude` to allow listing of system containers (i.e, $web).
* Updated the SAS Version to `2021-12-02` and added `Encryption Scope` to Account SAS, Service SAS, and User Delegation SAS
* Added `ArchiveStatusRehydratePendingToCold` value to `ArchiveStatus` enum.
* Content length limit for `AppendBlob.AppendBlock()` and `AppendBlob.AppendBlockFromURL()` raised from 4 MB to 100 MB.

### Breaking Changes

Expand Down
30 changes: 30 additions & 0 deletions sdk/storage/azblob/appendblob/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,36 @@ func (s *AppendBlobRecordedTestsSuite) TestAppendBlock() {
_require.Equal(*appendResp.BlobCommittedBlockCount, int32(2))
}

func (s *AppendBlobUnrecordedTestsSuite) TestAppendBlockHighThroughput() {
_require := require.New(s.T())
testName := s.T().Name()
svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil)
_require.NoError(err)

containerName := testcommon.GenerateContainerName(testName)
containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient)
defer testcommon.DeleteContainer(context.Background(), _require, containerClient)

abName := testcommon.GenerateBlobName(testName)
abClient := containerClient.NewAppendBlobClient(testcommon.GenerateBlobName(abName))

// Create AppendBlob with 5MB data
_, err = abClient.Create(context.Background(), nil)
_require.Nil(err)
contentSize := 5 * 1024 * 1024 // 5MB
r, sourceData := testcommon.GetDataAndReader(testName, contentSize)
appendResp, err := abClient.AppendBlock(context.Background(), streaming.NopCloser(r), nil)
_require.Nil(err)
_require.NotNil(appendResp.ETag)

// Check data integrity through downloading.
destBuffer := make([]byte, contentSize)
downloadBufferOptions := blob.DownloadBufferOptions{Range: blob.HTTPRange{Offset: 0, Count: int64(contentSize)}}
_, err = abClient.DownloadBuffer(context.Background(), destBuffer, &downloadBufferOptions)
_require.Nil(err)
_require.Equal(destBuffer, sourceData)
}

func (s *AppendBlobUnrecordedTestsSuite) TestAppendBlockWithAutoGeneratedCRC64() {
_require := require.New(s.T())
testName := s.T().Name()
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/azblob/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "go",
"TagPrefix": "go/storage/azblob",
"Tag": "go/storage/azblob_7a25fb98e8"
"Tag": "go/storage/azblob_c363103941"
}
1 change: 1 addition & 0 deletions sdk/storage/azblob/blob/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ type ArchiveStatus = generated.ArchiveStatus
const (
ArchiveStatusRehydratePendingToCool ArchiveStatus = generated.ArchiveStatusRehydratePendingToCool
ArchiveStatusRehydratePendingToHot ArchiveStatus = generated.ArchiveStatusRehydratePendingToHot
ArchiveStatusRehydratePendingToCold ArchiveStatus = generated.ArchiveStatusRehydratePendingToCold
)

// PossibleArchiveStatusValues returns the possible values for the ArchiveStatus const type.
Expand Down
61 changes: 61 additions & 0 deletions sdk/storage/azblob/blockblob/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"encoding/binary"
"errors"
"fmt"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/internal/generated"
"hash/crc64"
"io"
"math/rand"
Expand Down Expand Up @@ -2735,6 +2736,7 @@ func (s *BlockBlobRecordedTestsSuite) TestRehydrateStatus() {

blobName1 := "rehydration_test_blob_1"
blobName2 := "rehydration_test_blob_2"
blobName3 := "rehydration_test_blob_3"

bbClient1 := testcommon.GetBlockBlobClient(blobName1, containerClient)
reader1, _ := testcommon.GenerateData(1024)
Expand Down Expand Up @@ -2779,6 +2781,22 @@ func (s *BlockBlobRecordedTestsSuite) TestRehydrateStatus() {
_require.Nil(err)
_require.Equal(*getResp2.AccessTier, string(blob.AccessTierArchive))
_require.Equal(*getResp2.ArchiveStatus, string(blob.ArchiveStatusRehydratePendingToHot))

// ------------------------------------------

bbClient3 := testcommon.GetBlockBlobClient(blobName3, containerClient)
reader3, _ := testcommon.GenerateData(1024)
_, err = bbClient3.Upload(context.Background(), reader3, nil)
_require.Nil(err)
_, err = bbClient3.SetTier(context.Background(), blob.AccessTierArchive, nil)
_require.Nil(err)
_, err = bbClient3.SetTier(context.Background(), blob.AccessTierCold, nil)
_require.Nil(err)

getResp3, err := bbClient3.GetProperties(context.Background(), nil)
_require.Nil(err)
_require.Equal(*getResp3.AccessTier, string(blob.AccessTierArchive))
_require.Equal(*getResp3.ArchiveStatus, string(blob.ArchiveStatusRehydratePendingToCold))
}

func (s *BlockBlobRecordedTestsSuite) TestCopyBlobWithRehydratePriority() {
Expand Down Expand Up @@ -5486,3 +5504,46 @@ func TestRequestIDGeneration(t *testing.T) {
require.NoError(t, err)
require.Equal(t, requestIdMatch, true)
}

type serviceVersionTest struct{}

// newServiceVersionTestPolicy returns a policy that checks the x-ms-version header
func newServiceVersionTestPolicy() policy.Policy {
return &serviceVersionTest{}
}

func (m serviceVersionTest) Do(req *policy.Request) (*http.Response, error) {
const versionHeader = "x-ms-version"

currentVersion := map[string][]string(req.Raw().Header)[versionHeader]
if currentVersion[0] != generated.ServiceVersion {
return nil, fmt.Errorf(currentVersion[0] + " service version doesn't match expected version: " + generated.ServiceVersion)
}

return &http.Response{
Request: req.Raw(),
Status: "Created",
StatusCode: http.StatusCreated,
Header: http.Header{},
Body: http.NoBody,
}, nil
}

func TestServiceVersion(t *testing.T) {
fbb := &fakeBlockBlob{}
client, err := blockblob.NewClientWithNoCredential("https://fake/blob/testpath", &blockblob.ClientOptions{
ClientOptions: policy.ClientOptions{
Transport: fbb,
PerCallPolicies: []policy.Policy{newServiceVersionTestPolicy()},
},
})
require.NoError(t, err)
require.NotNil(t, client)

// Upload some data to source
contentSize := 4 * 1024 // 4KB
r, _ := testcommon.GetDataAndReader(t.Name(), contentSize)

_, err = client.Upload(context.Background(), streaming.NopCloser(r), nil)
require.NoError(t, err)
}
19 changes: 18 additions & 1 deletion sdk/storage/azblob/internal/generated/autorest.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ go: true
clear-output-folder: false
version: "^3.0.0"
license-header: MICROSOFT_MIT_NO_VERSION
input-file: "https://raw.githubusercontent.com/Azure/azure-rest-api-specs/080b332b7572514a2e100dd2fa1fb86cb8edcb08/specification/storage/data-plane/Microsoft.BlobStorage/preview/2021-12-02/blob.json"
input-file: "https://raw.githubusercontent.com/Azure/azure-rest-api-specs/a32d0b2423d19835246bb2ef92941503bfd5e734/specification/storage/data-plane/Microsoft.BlobStorage/preview/2021-12-02/blob.json"
credential-scope: "https://storage.azure.com/.default"
output-folder: ../generated
file-prefix: "zz_"
Expand All @@ -22,6 +22,23 @@ export-clients: true
use: "@autorest/[email protected]"
```

### Updating service version to 2023-08-03
```yaml
directive:
- from:
- zz_appendblob_client.go
- zz_blob_client.go
- zz_blockblob_client.go
- zz_container_client.go
- zz_pageblob_client.go
- zz_service_client.go
where: $
transform: >-
return $.
replaceAll(`[]string{"2021-12-02"}`, `[]string{ServiceVersion}`).
replaceAll(`2021-12-02`, `2023-08-03`);
```

### Undo breaking change with BlobName
``` yaml
directive:
Expand Down
9 changes: 9 additions & 0 deletions sdk/storage/azblob/internal/generated/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build go1.18
// +build go1.18

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

package generated

const ServiceVersion = "2023-08-03"
16 changes: 8 additions & 8 deletions sdk/storage/azblob/internal/generated/zz_appendblob_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading