Skip to content

Commit b1b655c

Browse files
authored
Merge pull request #146 from mauriciopoppe/smb-api-changes
Changes in the SMB v1beta2 API
2 parents 6d16ceb + f826e46 commit b1b655c

File tree

18 files changed

+465
-218
lines changed

18 files changed

+465
-218
lines changed

client/api/smb/v1beta2/api.pb.go

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

client/api/smb/v1beta2/api.proto

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ message NewSmbGlobalMappingRequest {
3535
}
3636

3737
message NewSmbGlobalMappingResponse {
38-
// Windows error code
39-
// Success is represented as 0
40-
string error = 1;
38+
// Intentionally empty.
4139
}
4240

4341

@@ -55,7 +53,5 @@ message RemoveSmbGlobalMappingRequest {
5553
}
5654

5755
message RemoveSmbGlobalMappingResponse {
58-
// Windows error code
59-
// Success is represented as 0
60-
string error = 1;
56+
// Intentionally empty.
6157
}

integrationtests/smb_test.go

Lines changed: 8 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package integrationtests
22

33
import (
4-
"context"
54
"fmt"
65
"io/ioutil"
76
"math/rand"
@@ -11,11 +10,6 @@ import (
1110
"time"
1211

1312
"testing"
14-
15-
"github.com/stretchr/testify/assert"
16-
17-
"github.com/kubernetes-csi/csi-proxy/client/api/smb/v1beta2"
18-
v1beta2client "github.com/kubernetes-csi/csi-proxy/client/groups/smb/v1beta2"
1913
)
2014

2115
const letterset = "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
@@ -129,69 +123,13 @@ func writeReadFile(path string) error {
129123
}
130124

131125
func TestSmbAPIGroup(t *testing.T) {
132-
t.Run("Smb positive", func(t *testing.T) {
133-
client, err := v1beta2client.NewClient()
134-
if err != nil {
135-
t.Fatalf("Fail to get smb API group client %v", err)
136-
}
137-
defer client.Close()
138-
139-
username := randomString(5)
140-
password := randomString(10) + "!"
141-
sharePath := fmt.Sprintf("C:\\smbshare%s", randomString(5))
142-
smbShare := randomString(6)
143-
144-
localPath := fmt.Sprintf("C:\\localpath%s", randomString(5))
145-
146-
if err = setupUser(username, password); err != nil {
147-
t.Fatalf("TestSmbAPIGroup %v", err)
148-
}
149-
defer removeUser(t, username)
150-
151-
if err = setupSmbShare(smbShare, sharePath, username); err != nil {
152-
t.Fatalf("TestSmbAPIGroup %v", err)
153-
}
154-
defer removeSmbShare(t, smbShare)
155-
156-
hostname, err := os.Hostname()
157-
assert.Nil(t, err)
158-
159-
username = "domain\\" + username
160-
remotePath := "\\\\" + hostname + "\\" + smbShare
161-
// simulate Mount SMB operations around staging a volume on a node
162-
mountSmbShareReq := &v1beta2.NewSmbGlobalMappingRequest{
163-
RemotePath: remotePath,
164-
Username: username,
165-
Password: password,
166-
}
167-
mountSmbShareRsp, err := client.NewSmbGlobalMapping(context.Background(), mountSmbShareReq)
168-
if err != nil {
169-
t.Fatalf("TestSmbAPIGroup %v", err)
170-
}
171-
if !assert.Equal(t, "", mountSmbShareRsp.Error) {
172-
t.Fatalf("TestSmbAPIGroup %v", mountSmbShareRsp.Error)
173-
}
174-
175-
err = getSmbGlobalMapping(remotePath)
176-
assert.Nil(t, err)
177-
178-
err = writeReadFile(remotePath)
179-
assert.Nil(t, err)
180-
181-
unmountSmbShareReq := &v1beta2.RemoveSmbGlobalMappingRequest{
182-
RemotePath: remotePath,
183-
}
184-
unmountSmbShareRsp, err := client.RemoveSmbGlobalMapping(context.Background(), unmountSmbShareReq)
185-
if err != nil {
186-
t.Fatalf("TestSmbAPIGroup %v", err)
187-
}
188-
if !assert.Equal(t, "", unmountSmbShareRsp.Error) {
189-
t.Fatalf("TestSmbAPIGroup %v", mountSmbShareRsp.Error)
190-
}
191-
err = getSmbGlobalMapping(remotePath)
192-
assert.NotNil(t, err)
193-
err = writeReadFile(localPath)
194-
assert.NotNil(t, err)
195-
126+
t.Run("v1alpha1SmbTests", func(t *testing.T) {
127+
v1alpha1SmbTests(t)
128+
})
129+
t.Run("v1beta1SmbTests", func(t *testing.T) {
130+
v1beta1SmbTests(t)
131+
})
132+
t.Run("v1beta2SmbTests", func(t *testing.T) {
133+
v1beta2SmbTests(t)
196134
})
197135
}

integrationtests/smb_v1alpha1_test.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package integrationtests
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"os"
7+
"testing"
8+
9+
"github.com/kubernetes-csi/csi-proxy/client/api/smb/v1alpha1"
10+
client "github.com/kubernetes-csi/csi-proxy/client/groups/smb/v1alpha1"
11+
12+
"github.com/stretchr/testify/assert"
13+
)
14+
15+
func v1alpha1SmbTests(t *testing.T) {
16+
client, err := client.NewClient()
17+
if err != nil {
18+
t.Fatalf("Fail to get smb API group client %v", err)
19+
}
20+
defer client.Close()
21+
22+
username := randomString(5)
23+
password := randomString(10) + "!"
24+
sharePath := fmt.Sprintf("C:\\smbshare%s", randomString(5))
25+
smbShare := randomString(6)
26+
27+
localPath := fmt.Sprintf("C:\\localpath%s", randomString(5))
28+
29+
if err = setupUser(username, password); err != nil {
30+
t.Fatalf("TestSmbAPIGroup %v", err)
31+
}
32+
defer removeUser(t, username)
33+
34+
if err = setupSmbShare(smbShare, sharePath, username); err != nil {
35+
t.Fatalf("TestSmbAPIGroup %v", err)
36+
}
37+
defer removeSmbShare(t, smbShare)
38+
39+
hostname, err := os.Hostname()
40+
assert.Nil(t, err)
41+
42+
username = "domain\\" + username
43+
remotePath := "\\\\" + hostname + "\\" + smbShare
44+
// simulate Mount SMB operations around staging a volume on a node
45+
mountSmbShareReq := &v1alpha1.NewSmbGlobalMappingRequest{
46+
RemotePath: remotePath,
47+
Username: username,
48+
Password: password,
49+
}
50+
_, err = client.NewSmbGlobalMapping(context.Background(), mountSmbShareReq)
51+
if err != nil {
52+
t.Fatalf("TestSmbAPIGroup %v", err)
53+
}
54+
55+
err = getSmbGlobalMapping(remotePath)
56+
assert.Nil(t, err)
57+
58+
err = writeReadFile(remotePath)
59+
assert.Nil(t, err)
60+
61+
unmountSmbShareReq := &v1alpha1.RemoveSmbGlobalMappingRequest{
62+
RemotePath: remotePath,
63+
}
64+
_, err = client.RemoveSmbGlobalMapping(context.Background(), unmountSmbShareReq)
65+
if err != nil {
66+
t.Fatalf("TestSmbAPIGroup %v", err)
67+
}
68+
err = getSmbGlobalMapping(remotePath)
69+
assert.NotNil(t, err)
70+
err = writeReadFile(localPath)
71+
assert.NotNil(t, err)
72+
73+
}

integrationtests/smb_v1beta1_test.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package integrationtests
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"os"
7+
"testing"
8+
9+
"github.com/kubernetes-csi/csi-proxy/client/api/smb/v1beta1"
10+
client "github.com/kubernetes-csi/csi-proxy/client/groups/smb/v1beta1"
11+
12+
"github.com/stretchr/testify/assert"
13+
)
14+
15+
func v1beta1SmbTests(t *testing.T) {
16+
client, err := client.NewClient()
17+
if err != nil {
18+
t.Fatalf("Fail to get smb API group client %v", err)
19+
}
20+
defer client.Close()
21+
22+
username := randomString(5)
23+
password := randomString(10) + "!"
24+
sharePath := fmt.Sprintf("C:\\smbshare%s", randomString(5))
25+
smbShare := randomString(6)
26+
27+
localPath := fmt.Sprintf("C:\\localpath%s", randomString(5))
28+
29+
if err = setupUser(username, password); err != nil {
30+
t.Fatalf("TestSmbAPIGroup %v", err)
31+
}
32+
defer removeUser(t, username)
33+
34+
if err = setupSmbShare(smbShare, sharePath, username); err != nil {
35+
t.Fatalf("TestSmbAPIGroup %v", err)
36+
}
37+
defer removeSmbShare(t, smbShare)
38+
39+
hostname, err := os.Hostname()
40+
assert.Nil(t, err)
41+
42+
username = "domain\\" + username
43+
remotePath := "\\\\" + hostname + "\\" + smbShare
44+
// simulate Mount SMB operations around staging a volume on a node
45+
mountSmbShareReq := &v1beta1.NewSmbGlobalMappingRequest{
46+
RemotePath: remotePath,
47+
Username: username,
48+
Password: password,
49+
}
50+
_, err = client.NewSmbGlobalMapping(context.Background(), mountSmbShareReq)
51+
if err != nil {
52+
t.Fatalf("TestSmbAPIGroup %v", err)
53+
}
54+
55+
err = getSmbGlobalMapping(remotePath)
56+
assert.Nil(t, err)
57+
58+
err = writeReadFile(remotePath)
59+
assert.Nil(t, err)
60+
61+
unmountSmbShareReq := &v1beta1.RemoveSmbGlobalMappingRequest{
62+
RemotePath: remotePath,
63+
}
64+
_, err = client.RemoveSmbGlobalMapping(context.Background(), unmountSmbShareReq)
65+
if err != nil {
66+
t.Fatalf("TestSmbAPIGroup %v", err)
67+
}
68+
err = getSmbGlobalMapping(remotePath)
69+
assert.NotNil(t, err)
70+
err = writeReadFile(localPath)
71+
assert.NotNil(t, err)
72+
73+
}

0 commit comments

Comments
 (0)