forked from ceph/ceph-csi
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #217 from red-hat-storage/sync_us--devel
Syncing latest changes from devel for ceph-csi
- Loading branch information
Showing
8 changed files
with
401 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
name: Security scanning | ||
# yamllint disable-line rule:truthy | ||
on: | ||
schedule: | ||
# Run weekly on every Monday | ||
- cron: '0 0 * * 1' | ||
push: | ||
tags: | ||
- v* | ||
branches: | ||
- release-* | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
security: | ||
if: github.repository == 'ceph/ceph-csi' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: run Snyk to check for code vulnerabilities | ||
uses: snyk/actions/golang@master | ||
env: | ||
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
/* | ||
Copyright 2023 The Ceph-CSI Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package cephfs | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/container-storage-interface/spec/lib/go/csi" | ||
|
||
"github.com/ceph/ceph-csi/internal/cephfs/mounter" | ||
"github.com/ceph/ceph-csi/internal/cephfs/store" | ||
"github.com/ceph/ceph-csi/internal/util" | ||
) | ||
|
||
func Test_setMountOptions(t *testing.T) { | ||
t.Parallel() | ||
|
||
cliKernelMountOptions := "noexec,nodev" | ||
cliFuseMountOptions := "default_permissions,auto_cache" | ||
|
||
configKernelMountOptions := "crc" | ||
configFuseMountOptions := "allow_other" | ||
|
||
csiConfig := []util.ClusterInfo{ | ||
{ | ||
ClusterID: "cluster-1", | ||
CephFS: util.CephFS{ | ||
KernelMountOptions: configKernelMountOptions, | ||
FuseMountOptions: configFuseMountOptions, | ||
}, | ||
}, | ||
{ | ||
ClusterID: "cluster-2", | ||
CephFS: util.CephFS{ | ||
KernelMountOptions: "", | ||
FuseMountOptions: "", | ||
}, | ||
}, | ||
} | ||
|
||
csiConfigFileContent, err := json.Marshal(csiConfig) | ||
if err != nil { | ||
t.Errorf("failed to marshal csi config info %v", err) | ||
} | ||
tmpConfPath := t.TempDir() + "/ceph-csi.json" | ||
t.Logf("path = %s", tmpConfPath) | ||
err = os.WriteFile(tmpConfPath, csiConfigFileContent, 0o600) | ||
if err != nil { | ||
t.Errorf("failed to write %s file content: %v", util.CsiConfigFile, err) | ||
} | ||
|
||
tests := []struct { | ||
name string | ||
ns NodeServer | ||
mnt mounter.VolumeMounter | ||
volOptions *store.VolumeOptions | ||
want string | ||
}{ | ||
{ | ||
name: "KernelMountOptions set in cluster-1 config and not set in CLI", | ||
ns: NodeServer{}, | ||
mnt: mounter.VolumeMounter(&mounter.KernelMounter{}), | ||
volOptions: &store.VolumeOptions{ | ||
ClusterID: "cluster-1", | ||
}, | ||
want: configKernelMountOptions, | ||
}, | ||
{ | ||
name: "FuseMountOptions set in cluster-1 config and not set in CLI", | ||
ns: NodeServer{}, | ||
mnt: mounter.VolumeMounter(&mounter.FuseMounter{}), | ||
volOptions: &store.VolumeOptions{ | ||
ClusterID: "cluster-1", | ||
}, | ||
want: configFuseMountOptions, | ||
}, | ||
{ | ||
name: "KernelMountOptions set in cluster-1 config and set in CLI", | ||
ns: NodeServer{ | ||
kernelMountOptions: cliKernelMountOptions, | ||
}, | ||
mnt: mounter.VolumeMounter(&mounter.KernelMounter{}), | ||
volOptions: &store.VolumeOptions{ | ||
ClusterID: "cluster-1", | ||
}, | ||
want: configKernelMountOptions, | ||
}, | ||
{ | ||
name: "FuseMountOptions not set in cluster-2 config and set in CLI", | ||
ns: NodeServer{ | ||
fuseMountOptions: cliFuseMountOptions, | ||
}, | ||
mnt: mounter.VolumeMounter(&mounter.FuseMounter{}), | ||
volOptions: &store.VolumeOptions{ | ||
ClusterID: "cluster-1", | ||
}, | ||
want: configFuseMountOptions, | ||
}, | ||
{ | ||
name: "KernelMountOptions not set in cluster-2 config and set in CLI", | ||
ns: NodeServer{ | ||
kernelMountOptions: cliKernelMountOptions, | ||
}, | ||
mnt: mounter.VolumeMounter(&mounter.KernelMounter{}), | ||
volOptions: &store.VolumeOptions{ | ||
ClusterID: "cluster-2", | ||
}, | ||
want: cliKernelMountOptions, | ||
}, | ||
{ | ||
name: "FuseMountOptions not set in cluster-1 config and set in CLI", | ||
ns: NodeServer{ | ||
fuseMountOptions: cliFuseMountOptions, | ||
}, | ||
mnt: mounter.VolumeMounter(&mounter.FuseMounter{}), | ||
volOptions: &store.VolumeOptions{ | ||
ClusterID: "cluster-2", | ||
}, | ||
want: cliFuseMountOptions, | ||
}, | ||
} | ||
|
||
volCap := &csi.VolumeCapability{ | ||
AccessMode: &csi.VolumeCapability_AccessMode{}, | ||
} | ||
|
||
for _, tt := range tests { | ||
tc := tt | ||
t.Run(tc.name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
err := tc.ns.setMountOptions(tc.mnt, tc.volOptions, volCap, tmpConfPath) | ||
if err != nil { | ||
t.Errorf("setMountOptions() = %v", err) | ||
} | ||
|
||
switch tc.mnt.(type) { | ||
case *mounter.FuseMounter: | ||
if !strings.Contains(tc.volOptions.FuseMountOptions, tc.want) { | ||
t.Errorf("Set FuseMountOptions = %v Required FuseMountOptions = %v", tc.volOptions.FuseMountOptions, tc.want) | ||
} | ||
case *mounter.KernelMounter: | ||
if !strings.Contains(tc.volOptions.KernelMountOptions, tc.want) { | ||
t.Errorf("Set KernelMountOptions = %v Required KernelMountOptions = %v", tc.volOptions.KernelMountOptions, tc.want) | ||
} | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.