Skip to content

Commit

Permalink
[Disk Manager] extract disk deletion to testcommon.DeleteDisk (#908)
Browse files Browse the repository at this point in the history
  • Loading branch information
SvartMetal authored Apr 4, 2024
1 parent 23cbede commit 9ad22c5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -610,20 +610,11 @@ func TestDiskServiceMigrateDisk(t *testing.T) {

successfullyMigrateDisk(t, ctx, client, params)

reqCtx := testcommon.GetRequestContext(t, ctx)
operation, err := client.DeleteDisk(reqCtx, &disk_manager.DeleteDiskRequest{
DiskId: &disk_manager.DiskId{
DiskId: diskID,
},
})
require.NoError(t, err)
require.NotEmpty(t, operation)
err = internal_client.WaitOperation(ctx, client, operation.Id)
require.NoError(t, err)
testcommon.DeleteDisk(t, ctx, client, diskID)

// Check that disk is deleted.
srcZoneNBSClient := testcommon.NewNbsClient(t, ctx, params.SrcZoneID)
_, err = srcZoneNBSClient.Describe(ctx, params.DiskID)
_, err := srcZoneNBSClient.Describe(ctx, params.DiskID)
require.Error(t, err)
require.ErrorContains(t, err, "Path not found")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,7 @@ func TestDiskServiceDeleteDiskWhenCreationIsInFlight(t *testing.T) {

<-time.After(time.Second)

reqCtx = testcommon.GetRequestContext(t, ctx)
operation, err := client.DeleteDisk(reqCtx, &disk_manager.DeleteDiskRequest{
DiskId: &disk_manager.DiskId{
DiskId: diskID,
},
})
require.NoError(t, err)
require.NotEmpty(t, operation)
err = internal_client.WaitOperation(ctx, client, operation.Id)
require.NoError(t, err)
testcommon.DeleteDisk(t, ctx, client, diskID)

_ = internal_client.WaitOperation(ctx, client, createOp.Id)

Expand Down Expand Up @@ -448,27 +439,8 @@ func testCreateDiskFromIncrementalSnapshot(
err = nbsClient.ValidateCrc32(ctx, diskID2, diskContentInfo)
require.NoError(t, err)

reqCtx = testcommon.GetRequestContext(t, ctx)
operation, err = client.DeleteDisk(reqCtx, &disk_manager.DeleteDiskRequest{
DiskId: &disk_manager.DiskId{
DiskId: diskID1,
},
})
require.NoError(t, err)
require.NotEmpty(t, operation)
err = internal_client.WaitOperation(ctx, client, operation.Id)
require.NoError(t, err)

reqCtx = testcommon.GetRequestContext(t, ctx)
operation, err = client.DeleteDisk(reqCtx, &disk_manager.DeleteDiskRequest{
DiskId: &disk_manager.DiskId{
DiskId: diskID2,
},
})
require.NoError(t, err)
require.NotEmpty(t, operation)
err = internal_client.WaitOperation(ctx, client, operation.Id)
require.NoError(t, err)
testcommon.DeleteDisk(t, ctx, client, diskID1)
testcommon.DeleteDisk(t, ctx, client, diskID2)

testcommon.CheckConsistency(t, ctx)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,7 @@ func TestPrivateServiceRetireBaseDisksUsingBaseDiskAsSrc(t *testing.T) {
err = nbsClient.ValidateCrc32(ctx, diskID, diskContentInfo)
require.NoError(t, err)

reqCtx = testcommon.GetRequestContext(t, ctx)
operation, err = client.DeleteDisk(reqCtx, &disk_manager.DeleteDiskRequest{
DiskId: &disk_manager.DiskId{
DiskId: diskID,
},
})
require.NoError(t, err)
require.NotEmpty(t, operation)
err = internal_client.WaitOperation(ctx, client, operation.Id)
require.NoError(t, err)
testcommon.DeleteDisk(t, ctx, client, diskID)

testcommon.CheckConsistency(t, ctx)
}
Expand Down Expand Up @@ -492,27 +483,8 @@ func TestPrivateServiceDeletePool(t *testing.T) {
err = internal_client.WaitOperation(ctx, client, operation.Id)
require.NoError(t, err)

reqCtx = testcommon.GetRequestContext(t, ctx)
operation, err = client.DeleteDisk(reqCtx, &disk_manager.DeleteDiskRequest{
DiskId: &disk_manager.DiskId{
DiskId: diskID1,
},
})
require.NoError(t, err)
require.NotEmpty(t, operation)
err = internal_client.WaitOperation(ctx, client, operation.Id)
require.NoError(t, err)

reqCtx = testcommon.GetRequestContext(t, ctx)
operation, err = client.DeleteDisk(reqCtx, &disk_manager.DeleteDiskRequest{
DiskId: &disk_manager.DiskId{
DiskId: diskID2,
},
})
require.NoError(t, err)
require.NotEmpty(t, operation)
err = internal_client.WaitOperation(ctx, client, operation.Id)
require.NoError(t, err)
testcommon.DeleteDisk(t, ctx, client, diskID1)
testcommon.DeleteDisk(t, ctx, client, diskID2)

testcommon.CheckConsistency(t, ctx)
}
Expand Down
20 changes: 20 additions & 0 deletions cloud/disk_manager/internal/pkg/facade/testcommon/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,26 @@ func CreateImage(
return diskContentInfo
}

func DeleteDisk(
t *testing.T,
ctx context.Context,
client sdk_client.Client,
diskID string,
) {

reqCtx := GetRequestContext(t, ctx)
operation, err := client.DeleteDisk(reqCtx, &disk_manager.DeleteDiskRequest{
DiskId: &disk_manager.DiskId{
DiskId: diskID,
},
})
require.NoError(t, err)
require.NotEmpty(t, operation)

err = internal_client.WaitOperation(ctx, client, operation.Id)
require.NoError(t, err)
}

////////////////////////////////////////////////////////////////////////////////

func newYDB(ctx context.Context) (*persistence.YDBClient, error) {
Expand Down

0 comments on commit 9ad22c5

Please sign in to comment.