Skip to content

Commit

Permalink
Merge pull request #240 from alexander-ding/enh/migrate-v2
Browse files Browse the repository at this point in the history
Migrate volume API group to library model
  • Loading branch information
k8s-ci-robot authored Oct 12, 2022
2 parents 0a24a71 + 1e7bd18 commit 1009791
Show file tree
Hide file tree
Showing 7 changed files with 1,323 additions and 54 deletions.
62 changes: 62 additions & 0 deletions integrationtests/utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package integrationtests

import (
"context"
"crypto/md5"
"encoding/hex"
"fmt"
Expand All @@ -23,6 +24,7 @@ import (

"github.com/kubernetes-csi/csi-proxy/pkg/server"
srvtypes "github.com/kubernetes-csi/csi-proxy/pkg/server/types"
"github.com/kubernetes-csi/csi-proxy/pkg/volume"
)

// startServer starts the proxy's GRPC servers, and returns a function to shut them down when done with testing
Expand Down Expand Up @@ -274,6 +276,17 @@ func diskInit(t *testing.T) (*VirtualHardDisk, func()) {
return vhd, cleanup
}

// sizeIsAround returns true if the actual size is around the expected size
// (considers the fact that some bytes were lost)
func sizeIsAround(t *testing.T, actualSize, expectedSize int64) bool {
// An upper bound on the number of bytes that are lost when creating or resizing a partition
var volumeSizeBytesLoss int64 = (20 * 1024 * 1024)
var lowerBound = expectedSize - volumeSizeBytesLoss
var upperBound = expectedSize
t.Logf("Checking that the size is inside the bounds: %d < (actual) %d < %d", lowerBound, actualSize, upperBound)
return lowerBound <= actualSize && actualSize <= upperBound
}

func pathExists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {
Expand All @@ -284,3 +297,52 @@ func pathExists(path string) (bool, error) {
}
return false, err
}

// volumeInit initializes a volume, it creates a VHD, initializes it,
// creates a partition with the max size and formats the volume corresponding to that partition
func volumeInit(volumeClient volume.Interface, t *testing.T) (*VirtualHardDisk, string, func()) {
vhd, vhdCleanup := diskInit(t)

listRequest := &volume.ListVolumesOnDiskRequest{
DiskNumber: vhd.DiskNumber,
}
listResponse, err := volumeClient.ListVolumesOnDisk(context.TODO(), listRequest)
if err != nil {
t.Fatalf("List response: %v", err)
}

volumeIDsLen := len(listResponse.VolumeIds)
if volumeIDsLen != 1 {
t.Fatalf("Number of volumes not equal to 1: %d", volumeIDsLen)
}
volumeID := listResponse.VolumeIds[0]
t.Logf("VolumeId %v", volumeID)

isVolumeFormattedRequest := &volume.IsVolumeFormattedRequest{
VolumeId: volumeID,
}
isVolumeFormattedResponse, err := volumeClient.IsVolumeFormatted(context.TODO(), isVolumeFormattedRequest)
if err != nil {
t.Fatalf("Is volume formatted request error: %v", err)
}
if isVolumeFormattedResponse.Formatted {
t.Fatal("Volume formatted. Unexpected !!")
}

formatVolumeRequest := &volume.FormatVolumeRequest{
VolumeId: volumeID,
}
_, err = volumeClient.FormatVolume(context.TODO(), formatVolumeRequest)
if err != nil {
t.Fatalf("Volume format failed. Error: %v", err)
}

isVolumeFormattedResponse, err = volumeClient.IsVolumeFormatted(context.TODO(), isVolumeFormattedRequest)
if err != nil {
t.Fatalf("Is volume formatted request error: %v", err)
}
if !isVolumeFormattedResponse.Formatted {
t.Fatal("Volume should be formatted. Unexpected !!")
}
return vhd, volumeID, vhdCleanup
}
Loading

0 comments on commit 1009791

Please sign in to comment.