diff --git a/cloud/disk_manager/internal/pkg/clients/nbs/interface.go b/cloud/disk_manager/internal/pkg/clients/nbs/interface.go index c757513aaed..2d3f8dcbcb9 100644 --- a/cloud/disk_manager/internal/pkg/clients/nbs/interface.go +++ b/cloud/disk_manager/internal/pkg/clients/nbs/interface.go @@ -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 diff --git a/cloud/disk_manager/internal/pkg/clients/nbs/mocks/client_mock.go b/cloud/disk_manager/internal/pkg/clients/nbs/mocks/client_mock.go index 7548822ba29..ad63fc87a59 100644 --- a/cloud/disk_manager/internal/pkg/clients/nbs/mocks/client_mock.go +++ b/cloud/disk_manager/internal/pkg/clients/nbs/mocks/client_mock.go @@ -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) } @@ -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( diff --git a/cloud/disk_manager/internal/pkg/facade/image_service_test/image_service_test.go b/cloud/disk_manager/internal/pkg/facade/image_service_test/image_service_test.go index fb05c53b0e9..b7765a3d4ab 100644 --- a/cloud/disk_manager/internal/pkg/facade/image_service_test/image_service_test.go +++ b/cloud/disk_manager/internal/pkg/facade/image_service_test/image_service_test.go @@ -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" @@ -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 @@ -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" @@ -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, @@ -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) @@ -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) @@ -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" @@ -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{ @@ -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) @@ -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) @@ -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, @@ -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() @@ -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{ @@ -918,7 +958,7 @@ func TestImageServiceDeleteImage(t *testing.T) { imageID := t.Name() imageSize := uint64(40 * 1024 * 1024) - _, _ = testcommon.CreateImage( + _ = testcommon.CreateImage( t, ctx, imageID, diff --git a/cloud/disk_manager/internal/pkg/facade/private_service_test/private_service_test.go b/cloud/disk_manager/internal/pkg/facade/private_service_test/private_service_test.go index 2b17a6d60b5..a6d9355ddba 100644 --- a/cloud/disk_manager/internal/pkg/facade/private_service_test/private_service_test.go +++ b/cloud/disk_manager/internal/pkg/facade/private_service_test/private_service_test.go @@ -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, @@ -121,7 +121,7 @@ func TestPrivateServiceRetireBaseDisks(t *testing.T) { return } - err = nbsClient.ValidateCrc32(diskID, imageSize, imageCrc32) + err = nbsClient.ValidateCrc32(ctx, diskID, diskContentInfo) errs <- err }() } @@ -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, @@ -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) @@ -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, @@ -317,7 +317,7 @@ func TestPrivateServiceOptimizeBaseDisks(t *testing.T) { return } - err = nbsClient.ValidateCrc32(diskID, imageSize, imageCrc32) + err = nbsClient.ValidateCrc32(ctx, diskID, diskContentInfo) errs <- err }() } @@ -362,7 +362,7 @@ func TestPrivateServiceConfigurePool(t *testing.T) { imageSize := uint64(4 * 1024 * 1024) - _, _ = testcommon.CreateImage( + _ = testcommon.CreateImage( t, ctx, imageID, @@ -406,7 +406,7 @@ func TestPrivateServiceDeletePool(t *testing.T) { imageID := t.Name() imageSize := uint64(64 * 1024 * 1024) - _, _ = testcommon.CreateImage( + _ = testcommon.CreateImage( t, ctx, imageID, diff --git a/cloud/disk_manager/internal/pkg/facade/snapshot_service_test/snapshot_service_test.go b/cloud/disk_manager/internal/pkg/facade/snapshot_service_test/snapshot_service_test.go index e904e9ef627..f57cb7be089 100644 --- a/cloud/disk_manager/internal/pkg/facade/snapshot_service_test/snapshot_service_test.go +++ b/cloud/disk_manager/internal/pkg/facade/snapshot_service_test/snapshot_service_test.go @@ -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" ) @@ -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() @@ -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) @@ -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) @@ -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)