Skip to content

Commit a4d316a

Browse files
committed
integration tests: Add test to confirm that the share path was changed
Signed-off-by: Sachin Prabhu <[email protected]>
1 parent 1951831 commit a4d316a

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed

tests/integration/path_permissions.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// +build integration
2+
3+
package integration
4+
5+
import (
6+
"context"
7+
"strings"
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+
)
15+
16+
type MountPathPermissionsSuite struct {
17+
suite.Suite
18+
19+
commonSources []kube.FileSource
20+
smbshareSources []kube.FileSource
21+
smbShareResource types.NamespacedName
22+
serverLabelPattern string
23+
tc *kube.TestClient
24+
}
25+
26+
func (s *MountPathPermissionsSuite) waitForPods(labelPattern string) {
27+
require := s.Require()
28+
ctx, cancel := context.WithDeadline(
29+
context.TODO(),
30+
time.Now().Add(waitForPodsTime))
31+
defer cancel()
32+
opts := kube.PodFetchOptions{
33+
Namespace: testNamespace,
34+
LabelSelector: labelPattern,
35+
}
36+
require.NoError(
37+
kube.WaitForAnyPodExists(ctx, kube.NewTestClient(""), opts),
38+
"pod does not exist",
39+
)
40+
require.NoError(
41+
kube.WaitForAnyPodReady(ctx, kube.NewTestClient(""), opts),
42+
"pod not ready",
43+
)
44+
}
45+
46+
func (s *MountPathPermissionsSuite) SetupSuite() {
47+
s.tc = kube.NewTestClient("")
48+
require := s.Require()
49+
50+
// Create smbshare with Spec.Storage.PVC.Path specified
51+
createFromFiles(require, s.tc, append(s.commonSources, s.smbshareSources...))
52+
s.waitForPods(s.serverLabelPattern)
53+
}
54+
55+
func (s *MountPathPermissionsSuite) TearDownSuite() {
56+
deleteFromFiles(s.Require(), s.tc, s.smbshareSources)
57+
deleteFromFiles(s.Require(), s.tc, s.commonSources)
58+
}
59+
60+
// The test checks the first directory within /mnt for the xattr.
61+
// We may need to change this if multiple mount paths are supported
62+
func (s *MountPathPermissionsSuite) TestMountPathPermissions() {
63+
require := s.Require()
64+
cmd := []string{
65+
"/bin/python3",
66+
"-c",
67+
"import xattr,os;mp='/mnt/' + os.listdir('/mnt')[0]; print(xattr.get(mp, 'user.share-perms-status'))",
68+
}
69+
70+
pods, err := s.tc.FetchPods(
71+
context.TODO(),
72+
kube.PodFetchOptions{
73+
Namespace: s.smbShareResource.Namespace,
74+
LabelSelector: s.serverLabelPattern,
75+
MaxFound: 1,
76+
})
77+
require.NoError(err)
78+
79+
pc := kube.PodCommand{
80+
Command: cmd,
81+
Namespace: s.smbShareResource.Namespace,
82+
PodName: pods[0].Name,
83+
ContainerName: "samba",
84+
}
85+
bch := kube.NewBufferedCommandHandler()
86+
err = kube.NewTestExec(s.tc).Call(pc, bch)
87+
require.NoError(err)
88+
out := strings.TrimSpace(string(bch.GetStdout()))
89+
s.Require().NotEmpty(out)
90+
}

tests/integration/smb_share_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,27 @@ func allSmbShareSuites() map[string]suite.TestingSuite {
475475
serverLabelPattern: "samba-operator.samba.org/service=tshare1-pvc",
476476
}
477477

478+
m["mountPathPermissions"] = &MountPathPermissionsSuite{
479+
commonSources: []kube.FileSource{
480+
{
481+
Path: path.Join(testFilesDir, "userssecret1.yaml"),
482+
Namespace: testNamespace,
483+
},
484+
{
485+
Path: path.Join(testFilesDir, "smbsecurityconfig1.yaml"),
486+
Namespace: testNamespace,
487+
},
488+
},
489+
smbshareSources: []kube.FileSource{
490+
{
491+
Path: path.Join(testFilesDir, "smbshare1.yaml"),
492+
Namespace: testNamespace,
493+
},
494+
},
495+
smbShareResource: types.NamespacedName{testNamespace, "tshare1"},
496+
serverLabelPattern: "samba-operator.samba.org/service=tshare1",
497+
}
498+
478499
if testClusteredShares {
479500
m["smbShareClustered1"] = &SmbShareSuite{
480501
fileSources: []kube.FileSource{

0 commit comments

Comments
 (0)