Skip to content

Commit

Permalink
reolve issues
Browse files Browse the repository at this point in the history
  • Loading branch information
BarkovBG committed Mar 29, 2024
1 parent d1b09a3 commit ad8204e
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 36 deletions.
2 changes: 1 addition & 1 deletion cloud/disk_manager/internal/pkg/clients/nbs/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ type CheckpointParams struct {

// Used in tests.
type DiskContentInfo struct {
ContentSize uint64
ContentSize uint64 // The coordinate of the last non-zero byte.
StorageSize uint64
Crc32 uint32
BlockCrc32s []uint32
Expand Down
23 changes: 14 additions & 9 deletions cloud/disk_manager/internal/pkg/clients/nbs/mocks/client_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,29 +323,34 @@ func (c *ClientMock) Stat(
////////////////////////////////////////////////////////////////////////////////

func (c *ClientMock) ValidateCrc32(
ctx context.Context,
diskID string,
contentSize uint64,
expectedCrc32 uint32,
expectedDiskContentInfo nbs.DiskContentInfo,
) error {

return c.ValidateCrc32WithEncryption(diskID, contentSize, nil, expectedCrc32)
return c.ValidateCrc32WithEncryption(
ctx,
diskID,
expectedDiskContentInfo,
nil,
)
}

func (c *ClientMock) ValidateCrc32WithEncryption(
ctx context.Context,
diskID string,
contentSize uint64,
expectedDiskContentInfo nbs.DiskContentInfo,
encryption *types.EncryptionDesc,
expectedCrc32 uint32,
) error {

args := c.Called(diskID, contentSize, encryption, expectedCrc32)
args := c.Called(ctx, diskID, expectedDiskContentInfo, encryption)
return args.Error(0)
}

func (c *ClientMock) CalculateCrc32(
diskID string,
contentSize uint64,
) (uint32, error) {
) (nbs.DiskContentInfo, error) {

return c.CalculateCrc32WithEncryption(diskID, contentSize, nil)
}
Expand All @@ -354,10 +359,10 @@ func (c *ClientMock) CalculateCrc32WithEncryption(
diskID string,
contentSize uint64,
encryption *types.EncryptionDesc,
) (uint32, error) {
) (nbs.DiskContentInfo, error) {

args := c.Called(diskID, contentSize, encryption)
return args.Get(0).(uint32), args.Error(1)
return args.Get(0).(nbs.DiskContentInfo), args.Error(1)
}

func (c *ClientMock) MountForReadWrite(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/ydb-platform/nbs/cloud/disk_manager/api/yandex/cloud/priv/disk_manager/v1"
internal_client "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/client"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/clients/nbs"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/facade/testcommon"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/services/disks"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/types"
Expand Down Expand Up @@ -74,7 +75,10 @@ func checkEncryptedSource(
encryption, err := disks.PrepareEncryptionDesc(defaultEncryptionDescWithKey)
require.NoError(t, err)

err = nbsClient.ValidateCrc32WithEncryption(diskID1, uint64(diskSize), encryption, crc32)
err = nbsClient.ValidateCrc32WithEncryption(ctx, diskID1, nbs.DiskContentInfo{
ContentSize: uint64(diskSize),
Crc32: crc32,
}, encryption)
require.NoError(t, err)

diskID2 := t.Name() + "-bad-disk-from-encrypted-" + tag
Expand Down Expand Up @@ -139,7 +143,10 @@ func checkUnencryptedImage(
encryption, err := disks.PrepareEncryptionDesc(defaultEncryptionDescWithKey)
require.NoError(t, err)

err = nbsClient.ValidateCrc32WithEncryption(diskID1, uint64(diskSize), encryption, crc32)
err = nbsClient.ValidateCrc32WithEncryption(ctx, diskID1, nbs.DiskContentInfo{
ContentSize: uint64(diskSize),
Crc32: crc32,
}, encryption)
require.NoError(t, err)

diskID2 := t.Name() + "-bad-enrypted-disk-from-image"
Expand Down Expand Up @@ -179,7 +186,7 @@ func TestImageServiceCreateImageFromImage(t *testing.T) {
imageID1 := t.Name() + "_image1"
imageSize := uint64(40 * 1024 * 1024)

imageCrc32, _ := testcommon.CreateImage(
diskContentInfo := testcommon.CreateImage(
t,
ctx,
imageID1,
Expand Down Expand Up @@ -233,7 +240,7 @@ func TestImageServiceCreateImageFromImage(t *testing.T) {

nbsClient := testcommon.NewNbsClient(t, ctx, "zone-a")

err = nbsClient.ValidateCrc32(diskID2, imageSize, imageCrc32)
err = nbsClient.ValidateCrc32(ctx, diskID2, diskContentInfo)
require.NoError(t, err)

reqCtx = testcommon.GetRequestContext(t, ctx)
Expand Down Expand Up @@ -300,7 +307,7 @@ func TestImageServiceCreateImageFromSnapshot(t *testing.T) {
encryption, err := disks.PrepareEncryptionDesc(defaultEncryptionDescWithKey)
require.NoError(t, err)

crc32, _, err := testcommon.FillEncryptedDisk(nbsClient, diskID, diskSize, encryption)
diskContentInfo, err := testcommon.FillEncryptedDisk(nbsClient, diskID, diskSize, encryption)
require.NoError(t, err)

diskParams, err = nbsClient.Describe(ctx, diskID)
Expand Down Expand Up @@ -335,7 +342,15 @@ func TestImageServiceCreateImageFromSnapshot(t *testing.T) {
SrcSnapshotId: snapshotID,
},
}
checkEncryptedSource(t, client, ctx, snapshotSrc, int64(diskSize), crc32, "snapshot")
checkEncryptedSource(
t,
client,
ctx,
snapshotSrc,
int64(diskSize),
diskContentInfo.Crc32,
"snapshot",
)

imageID := t.Name() + "_image"

Expand Down Expand Up @@ -366,7 +381,15 @@ func TestImageServiceCreateImageFromSnapshot(t *testing.T) {
SrcImageId: imageID,
},
}
checkEncryptedSource(t, client, ctx, imageSrc, int64(diskSize), crc32, "image")
checkEncryptedSource(
t,
client,
ctx,
imageSrc,
int64(diskSize),
diskContentInfo.Crc32,
"image",
)

reqCtx = testcommon.GetRequestContext(t, ctx)
operation1, err := client.DeleteImage(reqCtx, &disk_manager.DeleteImageRequest{
Expand Down Expand Up @@ -453,9 +476,12 @@ func testCreateImageFromURL(

nbsClient := testcommon.NewNbsClient(t, ctx, "zone-a")
err = nbsClient.ValidateCrc32(
ctx,
diskID,
imageSize,
diskCRC32,
nbs.DiskContentInfo{
ContentSize: imageSize,
Crc32: diskCRC32,
},
)
require.NoError(t, err)

Expand Down Expand Up @@ -601,7 +627,14 @@ func TestImageServiceCreateQCOW2ImageFromURLWhichIsOverwrittenInProcess(

nbsClient := testcommon.NewNbsClient(t, ctx, "zone-a")

err = nbsClient.ValidateCrc32(diskID, imageSize, imageCrc32)
err = nbsClient.ValidateCrc32(
ctx,
diskID,
nbs.DiskContentInfo{
ContentSize: imageSize,
Crc32: imageCrc32,
},
)
require.NoError(t, err)

testcommon.CheckConsistency(t, ctx)
Expand Down Expand Up @@ -703,7 +736,7 @@ func TestImageServiceCancelCreateImageFromImage(t *testing.T) {
imageID1 := t.Name() + "1"
imageSize := uint64(64 * 1024 * 1024)

_, _ = testcommon.CreateImage(
_ = testcommon.CreateImage(
t,
ctx,
imageID1,
Expand Down Expand Up @@ -816,7 +849,7 @@ func TestImageServiceCreateImageFromDisk(t *testing.T) {
require.NoError(t, err)

nbsClient := testcommon.NewNbsClient(t, ctx, "zone-a")
crc32, _, err := testcommon.FillDisk(nbsClient, diskID, diskSize)
diskContentInfo, err := testcommon.FillDisk(nbsClient, diskID, diskSize)
require.NoError(t, err)

imageID := t.Name()
Expand Down Expand Up @@ -848,7 +881,14 @@ func TestImageServiceCreateImageFromDisk(t *testing.T) {

testcommon.RequireCheckpointsAreEmpty(t, ctx, diskID)

checkUnencryptedImage(t, client, ctx, imageID, int64(diskSize), crc32)
checkUnencryptedImage(
t,
client,
ctx,
imageID,
int64(diskSize),
diskContentInfo.Crc32,
)

reqCtx = testcommon.GetRequestContext(t, ctx)
operation, err = client.DeleteImage(reqCtx, &disk_manager.DeleteImageRequest{
Expand Down Expand Up @@ -918,7 +958,7 @@ func TestImageServiceDeleteImage(t *testing.T) {
imageID := t.Name()
imageSize := uint64(40 * 1024 * 1024)

_, _ = testcommon.CreateImage(
_ = testcommon.CreateImage(
t,
ctx,
imageID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestPrivateServiceRetireBaseDisks(t *testing.T) {
imageID := t.Name()
imageSize := uint64(64 * 1024 * 1024)

imageCrc32, _ := testcommon.CreateImage(
diskContentInfo := testcommon.CreateImage(
t,
ctx,
imageID,
Expand Down Expand Up @@ -121,7 +121,7 @@ func TestPrivateServiceRetireBaseDisks(t *testing.T) {
return
}

err = nbsClient.ValidateCrc32(diskID, imageSize, imageCrc32)
err = nbsClient.ValidateCrc32(ctx, diskID, diskContentInfo)
errs <- err
}()
}
Expand Down Expand Up @@ -171,7 +171,7 @@ func TestPrivateServiceRetireBaseDisksUsingBaseDiskAsSrc(t *testing.T) {
imageID := t.Name()
imageSize := uint64(64 * 1024 * 1024)

imageCrc32, _ := testcommon.CreateImage(
diskContentInfo := testcommon.CreateImage(
t,
ctx,
imageID,
Expand Down Expand Up @@ -225,7 +225,7 @@ func TestPrivateServiceRetireBaseDisksUsingBaseDiskAsSrc(t *testing.T) {
require.NoError(t, err)

nbsClient := testcommon.NewNbsClient(t, ctx, "zone-a")
err = nbsClient.ValidateCrc32(diskID, imageSize, imageCrc32)
err = nbsClient.ValidateCrc32(ctx, diskID, diskContentInfo)
require.NoError(t, err)

reqCtx = testcommon.GetRequestContext(t, ctx)
Expand All @@ -252,7 +252,7 @@ func TestPrivateServiceOptimizeBaseDisks(t *testing.T) {
imageID := t.Name()
imageSize := uint64(64 * 1024 * 1024)

imageCrc32, _ := testcommon.CreateImage(
diskContentInfo := testcommon.CreateImage(
t,
ctx,
imageID,
Expand Down Expand Up @@ -317,7 +317,7 @@ func TestPrivateServiceOptimizeBaseDisks(t *testing.T) {
return
}

err = nbsClient.ValidateCrc32(diskID, imageSize, imageCrc32)
err = nbsClient.ValidateCrc32(ctx, diskID, diskContentInfo)
errs <- err
}()
}
Expand Down Expand Up @@ -362,7 +362,7 @@ func TestPrivateServiceConfigurePool(t *testing.T) {

imageSize := uint64(4 * 1024 * 1024)

_, _ = testcommon.CreateImage(
_ = testcommon.CreateImage(
t,
ctx,
imageID,
Expand Down Expand Up @@ -406,7 +406,7 @@ func TestPrivateServiceDeletePool(t *testing.T) {
imageID := t.Name()
imageSize := uint64(64 * 1024 * 1024)

_, _ = testcommon.CreateImage(
_ = testcommon.CreateImage(
t,
ctx,
imageID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/ydb-platform/nbs/cloud/disk_manager/api/yandex/cloud/priv/disk_manager/v1"
internal_client "github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/client"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/clients/nbs"
"github.com/ydb-platform/nbs/cloud/disk_manager/internal/pkg/facade/testcommon"
)

Expand Down Expand Up @@ -48,7 +49,7 @@ func testCreateSnapshotFromDisk(
require.NoError(t, err)

nbsClient := testcommon.NewNbsClient(t, ctx, "zone-a")
_, _, err = testcommon.FillDisk(nbsClient, diskID, 64*4096)
_, err = testcommon.FillDisk(nbsClient, diskID, 64*4096)
require.NoError(t, err)

snapshotID := t.Name()
Expand Down Expand Up @@ -280,7 +281,10 @@ func testCreateIncrementalSnapshotFromDisk(
_, err = acc.Write(bytes)
require.NoError(t, err)

err = nbsClient.ValidateCrc32(diskID2, uint64(contentSize), acc.Sum32())
err = nbsClient.ValidateCrc32(ctx, diskID2, nbs.DiskContentInfo{
ContentSize: uint64(contentSize),
Crc32: acc.Sum32(),
})
require.NoError(t, err)

testcommon.CheckConsistency(t, ctx)
Expand Down Expand Up @@ -407,7 +411,10 @@ func TestSnapshotServiceCreateIncrementalSnapshotAfterDeletionOfBaseSnapshot(t *
_, err = acc.Write(bytes)
require.NoError(t, err)

err = nbsClient.ValidateCrc32(diskID2, uint64(diskSize), acc.Sum32())
err = nbsClient.ValidateCrc32(ctx, diskID2, nbs.DiskContentInfo{
ContentSize: uint64(diskSize),
Crc32: acc.Sum32(),
})
require.NoError(t, err)

testcommon.CheckConsistency(t, ctx)
Expand Down Expand Up @@ -516,7 +523,10 @@ func TestSnapshotServiceCreateIncrementalSnapshotWhileDeletingBaseSnapshot(t *te
_, err = acc.Write(bytes)
require.NoError(t, err)

err = nbsClient.ValidateCrc32(diskID2, uint64(diskSize), acc.Sum32())
err = nbsClient.ValidateCrc32(ctx, diskID2, nbs.DiskContentInfo{
ContentSize: uint64(diskSize),
Crc32: acc.Sum32(),
})
require.NoError(t, err)

testcommon.CheckConsistency(t, ctx)
Expand Down

0 comments on commit ad8204e

Please sign in to comment.