Skip to content

Commit 22e16c3

Browse files
authored
Merge pull request #138 from mauriciopoppe/volume-api-changes
Update Volume API
2 parents c249530 + 1d02c03 commit 22e16c3

File tree

32 files changed

+2534
-1666
lines changed

32 files changed

+2534
-1666
lines changed

client/api/volume/v1beta3/api.pb.go

Lines changed: 363 additions & 342 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/api/volume/v1beta3/api.proto

Lines changed: 55 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,128 +5,130 @@ package v1beta3;
55
option go_package = "github.com/kubernetes-csi/csi-proxy/client/api/volume/v1beta3";
66

77
service Volume {
8-
// ListVolumesOnDisk returns the volume IDs (in \\.\Volume{GUID} format) for
9-
// all volumes on a Disk device
8+
// ListVolumesOnDisk returns the volume IDs (in \\.\Volume{GUID} format) for all volumes from a
9+
// given disk number and partition number (optional)
1010
rpc ListVolumesOnDisk(ListVolumesOnDiskRequest) returns (ListVolumesOnDiskResponse) {}
11-
// MountVolume mounts the volume at the requested global staging path
11+
// MountVolume mounts the volume at the requested global staging path.
1212
rpc MountVolume(MountVolumeRequest) returns (MountVolumeResponse) {}
13-
// DismountVolume gracefully dismounts a volume
14-
rpc DismountVolume(DismountVolumeRequest) returns (DismountVolumeResponse) {}
15-
// IsVolumeFormatted checks if a volume is formatted with NTFS
13+
// UnmountVolume flushes data cache to disk and removes the global staging path.
14+
rpc UnmountVolume(UnmountVolumeRequest) returns (UnmountVolumeResponse) {}
15+
// IsVolumeFormatted checks if a volume is formatted.
1616
rpc IsVolumeFormatted(IsVolumeFormattedRequest) returns (IsVolumeFormattedResponse) {}
17-
// FormatVolume formats a volume with the provided file system
17+
// FormatVolume formats a volume with NTFS.
1818
rpc FormatVolume(FormatVolumeRequest) returns (FormatVolumeResponse) {}
19-
// ResizeVolume performs resizing of the partition and file system for a block based volume
19+
// ResizeVolume performs resizing of the partition and file system for a block based volume.
2020
rpc ResizeVolume(ResizeVolumeRequest) returns (ResizeVolumeResponse) {}
21-
// VolumeStats gathers DiskSize, VolumeSize and VolumeUsedSize for a volume
22-
rpc VolumeStats(VolumeStatsRequest) returns (VolumeStatsResponse) {}
23-
// GetVolumeDiskNumber gets the disk number of the disk where the volume is located
24-
rpc GetVolumeDiskNumber(VolumeDiskNumberRequest) returns (VolumeDiskNumberResponse) {}
25-
// GetVolumeIDFromMount gets the volume id for a given mount
26-
rpc GetVolumeIDFromMount(VolumeIDFromMountRequest) returns (VolumeIDFromMountResponse) {}
27-
// WriteVolumeCache write volume cache to disk
21+
// GetVolumeStats gathers total bytes and used bytes for a volume.
22+
rpc GetVolumeStats(GetVolumeStatsRequest) returns (GetVolumeStatsResponse) {}
23+
// GetDiskNumberFromVolumeID gets the disk number of the disk where the volume is located.
24+
rpc GetDiskNumberFromVolumeID(GetDiskNumberFromVolumeIDRequest) returns (GetDiskNumberFromVolumeIDResponse ) {}
25+
// GetVolumeIDFromTargetPath gets the volume id for a given target path.
26+
rpc GetVolumeIDFromTargetPath(GetVolumeIDFromTargetPathRequest) returns (GetVolumeIDFromTargetPathResponse) {}
27+
// WriteVolumeCache write volume cache to disk.
2828
rpc WriteVolumeCache(WriteVolumeCacheRequest) returns (WriteVolumeCacheResponse) {}
2929
}
3030

3131
message ListVolumesOnDiskRequest {
32-
// Disk device ID of the disk to query for volumes
33-
string disk_id = 1;
32+
// Disk device number of the disk to query for volumes.
33+
uint32 disk_number = 1;
34+
// The partition number (optional), by default it uses the first partition of the disk.
35+
uint32 partition_number = 2;
3436
}
3537

3638
message ListVolumesOnDiskResponse {
37-
// Volume device IDs of volumes on the specified disk
39+
// Volume device IDs of volumes on the specified disk.
3840
repeated string volume_ids = 1;
3941
}
4042

4143
message MountVolumeRequest {
42-
// Volume device ID of the volume to mount
44+
// Volume device ID of the volume to mount.
4345
string volume_id = 1;
44-
// Path in the host's file system where the volume needs to be mounted
45-
string path = 2;
46+
// Path in the host's file system where the volume needs to be mounted.
47+
string target_path = 2;
4648
}
4749

4850
message MountVolumeResponse {
49-
// Intentionally empty
51+
// Intentionally empty.
5052
}
5153

52-
message DismountVolumeRequest {
53-
// Volume device ID of the volume to dismount
54+
message UnmountVolumeRequest {
55+
// Volume device ID of the volume to dismount.
5456
string volume_id = 1;
5557
// Path where the volume has been mounted.
56-
string path = 2;
58+
string target_path = 2;
5759
}
5860

59-
message DismountVolumeResponse {
60-
// Intentionally empty
61+
message UnmountVolumeResponse {
62+
// Intentionally empty.
6163
}
6264

6365
message IsVolumeFormattedRequest {
64-
// Volume device ID of the volume to check
66+
// Volume device ID of the volume to check.
6567
string volume_id = 1;
6668
}
6769

6870
message IsVolumeFormattedResponse {
69-
// Is the volume formatted with NTFS
71+
// Is the volume formatted with NTFS.
7072
bool formatted = 1;
7173
}
7274

7375
message FormatVolumeRequest {
74-
// Volume device ID of the volume to format
76+
// Volume device ID of the volume to format.
7577
string volume_id = 1;
7678
}
7779

7880
message FormatVolumeResponse {
79-
// Intentionally empty
81+
// Intentionally empty.
8082
}
8183

8284
message ResizeVolumeRequest {
83-
// Volume device ID of the volume to dismount
85+
// Volume device ID of the volume to resize.
8486
string volume_id = 1;
85-
// New size of the volume
86-
int64 size = 2;
87+
// New size in bytes of the volume.
88+
int64 size_bytes = 2;
8789
}
8890

8991
message ResizeVolumeResponse {
90-
// Intentionally empty
92+
// Intentionally empty.
9193
}
9294

93-
message VolumeStatsRequest{
94-
// Volume device Id of the volume to get the stats for
95+
message GetVolumeStatsRequest{
96+
// Volume device Id of the volume to get the stats for.
9597
string volume_id = 1;
9698
}
9799

98-
message VolumeStatsResponse{
99-
// Capacity of the volume
100-
int64 volumeSize = 1;
100+
message GetVolumeStatsResponse{
101+
// Total bytes
102+
int64 total_bytes = 1;
101103
// Used bytes
102-
int64 volumeUsedSize = 2;
104+
int64 used_bytes = 2;
103105
}
104106

105-
message VolumeDiskNumberRequest{
106-
// Volume device Id of the volume to get the disk number for
107+
message GetDiskNumberFromVolumeIDRequest {
108+
// Volume device ID of the volume to get the disk number for.
107109
string volume_id = 1;
108110
}
109111

110-
message VolumeDiskNumberResponse{
111-
// Corresponding disk number
112-
int64 diskNumber = 1;
112+
message GetDiskNumberFromVolumeIDResponse {
113+
// Corresponding disk number.
114+
uint32 disk_number = 1;
113115
}
114116

115-
message VolumeIDFromMountRequest {
116-
// Mount
117-
string mount = 1;
117+
message GetVolumeIDFromTargetPathRequest {
118+
// The target path.
119+
string target_path = 1;
118120
}
119121

120-
message VolumeIDFromMountResponse {
121-
// Mount
122+
message GetVolumeIDFromTargetPathResponse {
123+
// The volume device ID.
122124
string volume_id = 1;
123125
}
124126

125127
message WriteVolumeCacheRequest {
126-
// Volume device ID of the volume to flush the cache
128+
// Volume device ID of the volume to flush the cache.
127129
string volume_id = 1;
128130
}
129131

130132
message WriteVolumeCacheResponse {
131-
// Intentionally empty
133+
// Intentionally empty.
132134
}

client/groups/volume/v1beta3/client_generated.go

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integrationtests/csi_api_gen_test.go

Lines changed: 29 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package integrationtests
22

33
import (
4-
"fmt"
5-
"io/ioutil"
64
"os"
5+
"os/exec"
6+
"path/filepath"
7+
"runtime"
78
"testing"
89

9-
"github.com/kubernetes-csi/csi-proxy/cmd/csi-proxy-api-gen/generators"
1010
"github.com/stretchr/testify/assert"
1111
"github.com/stretchr/testify/require"
1212
)
@@ -18,16 +18,28 @@ import (
1818

1919
// TestNewAPIGroup tests that bootstraping a new group works as intended.
2020
func TestNewAPIGroup(t *testing.T) {
21-
skipTestOnCondition(t, isRunningOnGhActions())
21+
// TODO(mauriciopoppe): this test about the generator isn't working at all
22+
// the generator looks like it's working but the steps to make the diffs between the actual and desired
23+
// aren't correct, on top of that the generator desired files are out of date
24+
t.Skip("Skipping csi-api-generator test (ref 139#)")
25+
2226
// clean slate
2327
require.Nil(t, os.RemoveAll("csiapigen/new_group/actual_output"))
24-
logLevel := "3"
25-
stdout, _ := runGenerator(t, "TestNewAPIGroup",
28+
29+
// check that the csi-proxy-api-gen binary exists
30+
_, b, _, _ := runtime.Caller(0)
31+
csiAPIGenPath := filepath.Join(filepath.Dir(b), "../build/csi-proxy-api-gen")
32+
_, err := os.Lstat(csiAPIGenPath)
33+
require.Truef(t, err == nil, "expected err=nil, instead got err=%+v", err)
34+
35+
// run the generator
36+
stdout := runGenerator(t, csiAPIGenPath, "TestNewAPIGroup",
2637
"--input-dirs", "github.com/kubernetes-csi/csi-proxy/integrationtests/csiapigen/new_group/api",
2738
// might as well check that logging CLI args work as expected
28-
"-v", logLevel)
39+
"-v=3")
2940

30-
assert.Contains(t, stdout, "Verbosity level set to "+logLevel)
41+
assert.Contains(t, stdout, "Verbosity level set to 3")
42+
assert.Contains(t, stdout, "Generation successful!")
3143

3244
// now check the generated files are exactly what we expect
3345
// the files in expected_output have had their `.go` extension changed to `go_code` so that one
@@ -46,64 +58,15 @@ func TestNewAPIGroup(t *testing.T) {
4658
// runGenerator runs csi-proxy-api-gen with the given CLI args, and returns stdout and stderr.
4759
// It will also fail the test immediately if there any panics during the generation (but
4860
// will handle those graciously).
49-
func runGenerator(t *testing.T, testName string, cliArgs ...string) (string, string) {
50-
stdoutFile, err := ioutil.TempFile("", "test-csi-proxy-api-gen-stdout-"+testName)
51-
require.Nil(t, err)
52-
stderrFile, err := ioutil.TempFile("", "test-csi-proxy-api-gen-stderr-"+testName)
53-
require.Nil(t, err)
54-
55-
oldStdout := os.Stdout
56-
oldStderr := os.Stderr
57-
os.Stdout = stdoutFile
58-
os.Stderr = stderrFile
59-
60-
restored := false
61-
62-
restoreStdOutAndErr := func() {
63-
if restored {
64-
return
65-
}
66-
restored = true
67-
68-
os.Stdout = oldStdout
69-
os.Stderr = oldStderr
70-
71-
assert.Nil(t, stdoutFile.Close())
72-
assert.Nil(t, stderrFile.Close())
61+
func runGenerator(t *testing.T, csiAPIGenPath string, testName string, cliArgs ...string) string {
62+
// run generator through powershell
63+
cmd := exec.Command(csiAPIGenPath, cliArgs...)
64+
t.Logf("executing command %q", cmd.String())
65+
out, err := cmd.CombinedOutput()
66+
t.Logf("%s", out)
67+
if err != nil {
68+
t.Fatalf("command %q failed with err=%+v", cmd.String(), err)
7369
}
7470

75-
defer func() {
76-
restoreStdOutAndErr()
77-
78-
panicErr := recover()
79-
failedErrorMsg := ""
80-
if panicErr != nil {
81-
failedErrorMsg = fmt.Sprintf("panic when generating code: %v\n", panicErr)
82-
83-
readLogFile := func(logFile *os.File) string {
84-
contents, err := ioutil.ReadFile(logFile.Name())
85-
if err != nil {
86-
return fmt.Sprintf("<unable to read: %v>", err)
87-
}
88-
return string(contents)
89-
}
90-
91-
failedErrorMsg += fmt.Sprintf("stdout:\n%s\n", readLogFile(stdoutFile))
92-
failedErrorMsg += fmt.Sprintf("stderr:\n%s\n", readLogFile(stderrFile))
93-
}
94-
95-
assert.Nil(t, os.Remove(stdoutFile.Name()))
96-
assert.Nil(t, os.Remove(stderrFile.Name()))
97-
98-
require.Fail(t, failedErrorMsg)
99-
}()
100-
101-
// show time
102-
generators.Execute(testName, cliArgs...)
103-
104-
// to flush & close the log files
105-
restoreStdOutAndErr()
106-
107-
return readFile(t, readFile(t, stdoutFile.Name())),
108-
readFile(t, readFile(t, stderrFile.Name()))
71+
return string(out)
10972
}

0 commit comments

Comments
 (0)