Skip to content

Commit d1c86d0

Browse files
spuiukphlogistonjohn
authored andcommitted
integration tests: Add mount path tests
Add tests for the Spec.Storage.Pvc.Path component. Signed-off-by: Sachin Prabhu <[email protected]>
1 parent f4ed47e commit d1c86d0

File tree

5 files changed

+218
-0
lines changed

5 files changed

+218
-0
lines changed

tests/files/smbsharepvc1.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
apiVersion: samba-operator.samba.org/v1alpha1
3+
kind: SmbShare
4+
metadata:
5+
name: tshare1-setup-pvc
6+
labels:
7+
app: samba-operator-test-smbshare-withpvc
8+
spec:
9+
readOnly: false
10+
browseable: false
11+
securityConfig: sharesec1
12+
storage:
13+
pvc:
14+
name: "userpvc"

tests/files/smbsharepvc2.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
apiVersion: samba-operator.samba.org/v1alpha1
3+
kind: SmbShare
4+
metadata:
5+
name: tshare1-pvc
6+
labels:
7+
app: samba-operator-test-smbshare-withpvc
8+
spec:
9+
readOnly: false
10+
browseable: false
11+
securityConfig: sharesec1
12+
storage:
13+
pvc:
14+
name: "userpvc"
15+
path: "testmnt1"

tests/files/userpvc.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: PersistentVolumeClaim
3+
metadata:
4+
name: userpvc
5+
spec:
6+
accessModes:
7+
- ReadWriteOnce
8+
resources:
9+
requests:
10+
storage: 100Mi
11+
volumeMode: Filesystem

tests/integration/mount_path_test.go

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
// +build integration
2+
3+
package integration
4+
5+
import (
6+
"context"
7+
"fmt"
8+
"time"
9+
10+
"github.com/stretchr/testify/suite"
11+
"k8s.io/apimachinery/pkg/types"
12+
13+
"github.com/samba-in-kubernetes/samba-operator/tests/utils/kube"
14+
"github.com/samba-in-kubernetes/samba-operator/tests/utils/smbclient"
15+
)
16+
17+
type MountPathSuite struct {
18+
suite.Suite
19+
20+
auths []smbclient.Auth
21+
commonSources []kube.FileSource
22+
smbshareSetupSources []kube.FileSource
23+
smbshareSources []kube.FileSource
24+
smbShareSetupResource types.NamespacedName
25+
setupServerLabelPattern string
26+
smbShareResource types.NamespacedName
27+
serverLabelPattern string
28+
tc *kube.TestClient
29+
}
30+
31+
func (s *MountPathSuite) getPodIP(labelPattern string) (string, error) {
32+
pods, err := s.tc.FetchPods(
33+
context.TODO(),
34+
kube.PodFetchOptions{
35+
Namespace: testNamespace,
36+
LabelSelector: labelPattern,
37+
MaxFound: 1,
38+
})
39+
if err != nil {
40+
return "", err
41+
}
42+
for _, pod := range pods {
43+
if kube.PodIsReady(&pod) {
44+
return pod.Status.PodIP, nil
45+
}
46+
}
47+
return "", fmt.Errorf("no pods ready when fetching IP")
48+
}
49+
50+
func (s *MountPathSuite) waitForPods(labelPattern string) {
51+
require := s.Require()
52+
ctx, cancel := context.WithDeadline(
53+
context.TODO(),
54+
time.Now().Add(waitForPodsTime))
55+
defer cancel()
56+
opts := kube.PodFetchOptions{
57+
Namespace: testNamespace,
58+
LabelSelector: labelPattern,
59+
}
60+
require.NoError(
61+
kube.WaitForAnyPodExists(ctx, kube.NewTestClient(""), opts),
62+
"pod does not exist",
63+
)
64+
require.NoError(
65+
kube.WaitForAnyPodReady(ctx, kube.NewTestClient(""), opts),
66+
"pod not ready",
67+
)
68+
}
69+
70+
func (s *MountPathSuite) SetupSuite() {
71+
s.tc = kube.NewTestClient("")
72+
require := s.Require()
73+
createFromFiles(require, s.tc, append(s.commonSources, s.smbshareSetupSources...))
74+
// ensure the smbserver test pod exists and is ready
75+
s.waitForPods(s.setupServerLabelPattern)
76+
serverIP, err := s.getPodIP(s.setupServerLabelPattern)
77+
require.NoError(err)
78+
share := smbclient.Share{
79+
Host: smbclient.Host(serverIP),
80+
Name: s.smbShareSetupResource.Name,
81+
}
82+
83+
// Create folders over smbclient
84+
smbclient := smbclient.MustPodExec(s.tc, testNamespace,
85+
"smbclient", "client")
86+
err = smbclient.CacheFlush(context.TODO())
87+
require.NoError(err)
88+
auth := s.auths[0]
89+
cmds := []string{
90+
"mkdir testmnt1",
91+
"mkdir testmnt2",
92+
"mkdir testmnt1/mnt1",
93+
"mkdir testmnt2/mnt2",
94+
}
95+
err = smbclient.Command(
96+
context.TODO(),
97+
share,
98+
auth,
99+
cmds)
100+
require.NoError(err)
101+
102+
// Delete the smbshare created
103+
deleteFromFiles(require, s.tc, s.smbshareSetupSources)
104+
105+
// Create smbshare with Spec.Storage.PVC.Path specified
106+
createFromFiles(require, s.tc, append(s.commonSources, s.smbshareSources...))
107+
s.waitForPods(s.serverLabelPattern)
108+
}
109+
110+
func (s *MountPathSuite) TearDownSuite() {
111+
deleteFromFiles(s.Require(), s.tc, s.smbshareSetupSources)
112+
deleteFromFiles(s.Require(), s.tc, s.smbshareSources)
113+
deleteFromFiles(s.Require(), s.tc, s.commonSources)
114+
}
115+
116+
func (s *MountPathSuite) TestMountPath() {
117+
require := s.Require()
118+
119+
serverIP, err := s.getPodIP(s.serverLabelPattern)
120+
require.NoError(err)
121+
share := smbclient.Share{
122+
Host: smbclient.Host(serverIP),
123+
Name: s.smbShareResource.Name,
124+
}
125+
126+
// Test if correct path mounted using smbclient
127+
smbclient := smbclient.MustPodExec(s.tc, testNamespace,
128+
"smbclient", "client")
129+
err = smbclient.CacheFlush(context.TODO())
130+
require.NoError(err)
131+
auth := s.auths[0]
132+
out, err := smbclient.CommandOutput(
133+
context.TODO(),
134+
share,
135+
auth,
136+
[]string{"ls"})
137+
require.NoError(err)
138+
require.Contains(string(out), "mnt1")
139+
}

tests/integration/smb_share_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,45 @@ func allSmbShareSuites() map[string]suite.TestingSuite {
374374
}},
375375
}}
376376

377+
m["mountPath"] = &MountPathSuite{
378+
auths: []smbclient.Auth{
379+
{
380+
Username: "sambauser",
381+
Password: "1nsecurely",
382+
},
383+
},
384+
commonSources: []kube.FileSource{
385+
{
386+
Path: path.Join(testFilesDir, "userpvc.yaml"),
387+
Namespace: testNamespace,
388+
},
389+
{
390+
Path: path.Join(testFilesDir, "userssecret1.yaml"),
391+
Namespace: testNamespace,
392+
},
393+
{
394+
Path: path.Join(testFilesDir, "smbsecurityconfig1.yaml"),
395+
Namespace: testNamespace,
396+
},
397+
},
398+
smbshareSetupSources: []kube.FileSource{
399+
{
400+
Path: path.Join(testFilesDir, "smbsharepvc1.yaml"),
401+
Namespace: testNamespace,
402+
},
403+
},
404+
smbshareSources: []kube.FileSource{
405+
{
406+
Path: path.Join(testFilesDir, "smbsharepvc2.yaml"),
407+
Namespace: testNamespace,
408+
},
409+
},
410+
smbShareSetupResource: types.NamespacedName{testNamespace, "tshare1-setup-pvc"},
411+
setupServerLabelPattern: "samba-operator.samba.org/service=tshare1-setup-pvc",
412+
smbShareResource: types.NamespacedName{testNamespace, "tshare1-pvc"},
413+
serverLabelPattern: "samba-operator.samba.org/service=tshare1-pvc",
414+
}
415+
377416
if testClusteredShares {
378417
m["smbShareClustered1"] = &SmbShareSuite{
379418
fileSources: []kube.FileSource{

0 commit comments

Comments
 (0)