Skip to content

Commit

Permalink
update v1beta3 API according to the changes in kubernetes-csi#130
Browse files Browse the repository at this point in the history
  • Loading branch information
mauriciopoppe committed May 12, 2021
1 parent 210de6c commit 46d2f0e
Show file tree
Hide file tree
Showing 18 changed files with 3,158 additions and 1,275 deletions.
1,732 changes: 1,234 additions & 498 deletions client/api/volume/v1beta3/api.pb.go

Large diffs are not rendered by default.

68 changes: 68 additions & 0 deletions client/api/volume/v1beta3/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,29 @@ service Volume {
rpc GetVolumeIDFromTargetPath(GetVolumeIDFromTargetPathRequest) returns (GetVolumeIDFromTargetPathResponse) {}
// WriteVolumeCache write volume cache to disk
rpc WriteVolumeCache(WriteVolumeCacheRequest) returns (WriteVolumeCacheResponse) {}

// Deprecated apis

// DismountVolume dismounts a volume
rpc DismountVolume(DismountVolumeRequest) returns (DismountVolumeResponse) {
// Use UnmountVolume instead
option deprecated = true;
}
// VolumeStats gathers DiskSize, VolumeSize and VolumeUsedSize for a volume
rpc VolumeStats(VolumeStatsRequest) returns (VolumeStatsResponse) {
// Renamed to GetVolumeStats
option deprecated = true;
}
// GetVolumeDiskNumber gets the disk number of the disk where the volume is located
rpc GetVolumeDiskNumber(VolumeDiskNumberRequest) returns (VolumeDiskNumberResponse) {
// Renamed to GetDiskNumberFromVolumeID
option deprecated = true;
}
// GetVolumeIDFromMount gets the volume id for a given mount
rpc GetVolumeIDFromMount(VolumeIDFromMountRequest) returns (VolumeIDFromMountResponse) {
// Renamed to GetVolumeIDFromTargetPath
option deprecated = true;
}
}

message ListVolumesOnDiskRequest {
Expand Down Expand Up @@ -132,3 +155,48 @@ message WriteVolumeCacheRequest {
message WriteVolumeCacheResponse {
// Intentionally empty
}

// deprecated messages

message DismountVolumeRequest {
// Volume device ID of the volume to dismount
string volume_id = 1;
// Path where the volume has been mounted.
string path = 2;
}

message DismountVolumeResponse {
// Intentionally empty
}

message VolumeDiskNumberRequest{
// Volume device Id of the volume to get the disk number for
string volume_id = 1;
}

message VolumeDiskNumberResponse{
// Corresponding disk number
int64 disk_number = 1;
}

message VolumeIDFromMountRequest {
// Mount
string mount = 1;
}

message VolumeIDFromMountResponse {
// Mount
string volume_id = 1;
}

message VolumeStatsRequest{
// Volume device Id of the volume to get the stats for
string volume_id = 1;
}

message VolumeStatsResponse{
// Capacity of the volume
int64 volume_size = 1;
// Used bytes
int64 volume_used_size = 2;
}
16 changes: 16 additions & 0 deletions client/groups/volume/v1beta3/client_generated.go

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

96 changes: 51 additions & 45 deletions integrationtests/volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"math/rand"
"os/exec"
"strconv"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -50,7 +51,7 @@ func diskCleanup(t *testing.T, vhdxPath, mountPath, testPluginPath string) {
}
}

func diskInit(t *testing.T, vhdxPath, mountPath, testPluginPath string) string {
func diskInit(t *testing.T, vhdxPath, mountPath, testPluginPath string) int64 {
var cmd, out string
var err error
const initialSize = 5 * 1024 * 1024 * 1024
Expand All @@ -74,28 +75,32 @@ func diskInit(t *testing.T, vhdxPath, mountPath, testPluginPath string) string {
t.Fatalf("Error: %v. Command: %s. Out: %s", err, cmd, out)
}

var diskNum string
var diskNum int64
var diskNumUnparsed string
cmd = fmt.Sprintf("(Get-VHD -Path %s).DiskNumber", vhdxPath)
if diskNum, err = runPowershellCmd(cmd); err != nil {

if diskNumUnparsed, err = runPowershellCmd(cmd); err != nil {
t.Fatalf("Error: %v. Command: %s", err, cmd)
}
diskNum = strings.TrimRight(diskNum, "\r\n")
if diskNum, err = strconv.ParseInt(strings.TrimRight(diskNumUnparsed, "\r\n"), 10, 64); err != nil {
t.Fatalf("Error: %v", err)
}

cmd = fmt.Sprintf("Initialize-Disk -Number %s -PartitionStyle %s", diskNum, partitionStyle)
cmd = fmt.Sprintf("Initialize-Disk -Number %d -PartitionStyle %s", diskNum, partitionStyle)
if _, err = runPowershellCmd(cmd); err != nil {
t.Fatalf("Error: %v. Command: %s", err, cmd)
}

cmd = fmt.Sprintf("New-Partition -DiskNumber %s -UseMaximumSize", diskNum)
cmd = fmt.Sprintf("New-Partition -DiskNumber %d -UseMaximumSize", diskNum)
if _, err = runPowershellCmd(cmd); err != nil {
t.Fatalf("Error: %v. Command: %s", err, cmd)
}
return diskNum
}

func runNegativeListVolumeRequest(t *testing.T, client *v1beta3client.Client, diskNum string) {
func runNegativeListVolumeRequest(t *testing.T, client *v1beta3client.Client, diskNum int64) {
listRequest := &v1beta3.ListVolumesOnDiskRequest{
DiskId: diskNum,
DiskNumber: diskNum,
}
_, err := client.ListVolumesOnDisk(context.TODO(), listRequest)
if err == nil {
Expand Down Expand Up @@ -125,8 +130,8 @@ func runNegativeFormatVolumeRequest(t *testing.T, client *v1beta3client.Client,

func runNegativeResizeVolumeRequest(t *testing.T, client *v1beta3client.Client, volumeID string, size int64) {
resizeVolumeRequest := &v1beta3.ResizeVolumeRequest{
VolumeId: volumeID,
Size: size,
VolumeId: volumeID,
SizeBytes: size,
}
_, err := client.ResizeVolume(context.TODO(), resizeVolumeRequest)
if err == nil {
Expand All @@ -137,8 +142,8 @@ func runNegativeResizeVolumeRequest(t *testing.T, client *v1beta3client.Client,
func runNegativeMountVolumeRequest(t *testing.T, client *v1beta3client.Client, volumeID, mountPath string) {
// Mount the volume
mountVolumeRequest := &v1beta3.MountVolumeRequest{
VolumeId: volumeID,
Path: mountPath,
VolumeId: volumeID,
TargetPath: mountPath,
}

_, err := client.MountVolume(context.TODO(), mountVolumeRequest)
Expand All @@ -147,24 +152,24 @@ func runNegativeMountVolumeRequest(t *testing.T, client *v1beta3client.Client, v
}
}

func runNegativeDismountVolumeRequest(t *testing.T, client *v1beta3client.Client, volumeID, mountPath string) {
// Dismount the volume
dismountVolumeRequest := &v1beta3.DismountVolumeRequest{
VolumeId: volumeID,
Path: mountPath,
func runNegativeUnmountVolumeRequest(t *testing.T, client *v1beta3client.Client, volumeID, mountPath string) {
// Unmount the volume
unmountVolumeRequest := &v1beta3.UnmountVolumeRequest{
VolumeId: volumeID,
TargetPath: mountPath,
}
_, err := client.DismountVolume(context.TODO(), dismountVolumeRequest)
_, err := client.UnmountVolume(context.TODO(), unmountVolumeRequest)
if err == nil {
t.Fatalf("Empty error. Volume id %s dismount from path %s ", volumeID, mountPath)
}
}

func runNegativeVolumeStatsRequest(t *testing.T, client *v1beta3client.Client, volumeID string) {
// Get VolumeStats
volumeStatsRequest := &v1beta3.VolumeStatsRequest{
volumeStatsRequest := &v1beta3.GetVolumeStatsRequest{
VolumeId: volumeID,
}
_, err := client.VolumeStats(context.TODO(), volumeStatsRequest)
_, err := client.GetVolumeStats(context.TODO(), volumeStatsRequest)
if err == nil {
t.Errorf("Empty error. VolumeStats for id %s", volumeID)
}
Expand Down Expand Up @@ -196,9 +201,9 @@ func negativeVolumeTests(t *testing.T) {
runNegativeMountVolumeRequest(t, client, "", "")
runNegativeMountVolumeRequest(t, client, "-1", "")

// Dismount volume negative tests
runNegativeDismountVolumeRequest(t, client, "", "")
runNegativeDismountVolumeRequest(t, client, "-1", "")
// Unmount volume negative tests
runNegativeUnmountVolumeRequest(t, client, "", "")
runNegativeUnmountVolumeRequest(t, client, "-1", "")

runNegativeVolumeStatsRequest(t, client, "")
runNegativeVolumeStatsRequest(t, client, "-1")
Expand All @@ -214,9 +219,10 @@ func negativeDiskTests(t *testing.T) {
defer client.Close()

// Empty disk Id test
runNegativeListVolumeRequest(t, client, "")
// TODO(mauriciopoppe): changed from an empty string to 0, verify if this is ok
runNegativeListVolumeRequest(t, client, 0)
// Negative disk id test
runNegativeListVolumeRequest(t, client, "-1")
runNegativeListVolumeRequest(t, client, -1)
}

func simpleE2e(t *testing.T) {
Expand Down Expand Up @@ -245,7 +251,7 @@ func simpleE2e(t *testing.T) {
diskNum := diskInit(t, vhdxPath, mountPath, testPluginPath)

listRequest := &v1beta3.ListVolumesOnDiskRequest{
DiskId: diskNum,
DiskNumber: diskNum,
}
listResponse, err := volumeClient.ListVolumesOnDisk(context.TODO(), listRequest)
if err != nil {
Expand Down Expand Up @@ -286,48 +292,48 @@ func simpleE2e(t *testing.T) {
}

t.Logf("VolumeId %v", volumeID)
volumeStatsRequest := &v1beta3.VolumeStatsRequest{
volumeStatsRequest := &v1beta3.GetVolumeStatsRequest{
VolumeId: volumeID,
}

volumeStatsResponse, err := volumeClient.VolumeStats(context.TODO(), volumeStatsRequest)
volumeStatsResponse, err := volumeClient.GetVolumeStats(context.TODO(), volumeStatsRequest)
if err != nil {
t.Fatalf("VolumeStats request error: %v", err)
}

if volumeStatsResponse.VolumeSize == -1 {
t.Fatalf("VolumeSize reported is not valid, it is %v", volumeStatsResponse.VolumeSize)
if volumeStatsResponse.TotalBytes == -1 {
t.Fatalf("volumeStatsResponse.TotalBytes reported is not valid, it is %v", volumeStatsResponse.TotalBytes)
}

oldSize := volumeStatsResponse.VolumeSize
oldSize := volumeStatsResponse.TotalBytes

resizeVolumeRequest := &v1beta3.ResizeVolumeRequest{
VolumeId: volumeID,
// Resize from 5G to 2G
Size: 2 * 1024 * 1024 * 1024,
SizeBytes: 2 * 1024 * 1024 * 1024,
}

_, err = volumeClient.ResizeVolume(context.TODO(), resizeVolumeRequest)
if err != nil {
t.Fatalf("Volume resize request failed. Error: %v", err)
}

volumeStatsResponse, err = volumeClient.VolumeStats(context.TODO(), volumeStatsRequest)
volumeStatsResponse, err = volumeClient.GetVolumeStats(context.TODO(), volumeStatsRequest)
if err != nil {
t.Fatalf("VolumeStats request after resize error: %v", err)
}

if volumeStatsResponse.VolumeSize >= oldSize {
t.Fatalf("VolumeSize reported is not smaller after resize, it is %v", volumeStatsResponse.VolumeSize)
if volumeStatsResponse.TotalBytes >= oldSize {
t.Fatalf("VolumeSize reported is not smaller after resize, it is %v", volumeStatsResponse.TotalBytes)
}

volumeDiskNumberRequest := &v1beta3.VolumeDiskNumberRequest{
volumeDiskNumberRequest := &v1beta3.GetDiskNumberFromVolumeIDRequest{
VolumeId: volumeID,
}

volumeDiskNumberResponse, err := volumeClient.GetVolumeDiskNumber(context.TODO(), volumeDiskNumberRequest)
volumeDiskNumberResponse, err := volumeClient.GetDiskNumberFromVolumeID(context.TODO(), volumeDiskNumberRequest)
if err != nil {
t.Fatalf("GetVolumeDiskNumber failed: %v", err)
t.Fatalf("GetDiskNumberFromVolumeID failed: %v", err)
}

diskNumberString := fmt.Sprintf("%d", volumeDiskNumberResponse.DiskNumber)
Expand All @@ -347,20 +353,20 @@ func simpleE2e(t *testing.T) {

// Mount the volume
mountVolumeRequest := &v1beta3.MountVolumeRequest{
VolumeId: volumeID,
Path: mountPath,
VolumeId: volumeID,
TargetPath: mountPath,
}
_, err = volumeClient.MountVolume(context.TODO(), mountVolumeRequest)
if err != nil {
t.Fatalf("Volume id %s mount to path %s failed. Error: %v", volumeID, mountPath, err)
}

// Dismount the volume
dismountVolumeRequest := &v1beta3.DismountVolumeRequest{
VolumeId: volumeID,
Path: mountPath,
// Unmount the volume
dismountVolumeRequest := &v1beta3.UnmountVolumeRequest{
VolumeId: volumeID,
TargetPath: mountPath,
}
_, err = volumeClient.DismountVolume(context.TODO(), dismountVolumeRequest)
_, err = volumeClient.UnmountVolume(context.TODO(), dismountVolumeRequest)
if err != nil {
t.Fatalf("Volume id %s mount to path %s failed. Error: %v", volumeID, mountPath, err)
}
Expand Down
Loading

0 comments on commit 46d2f0e

Please sign in to comment.