Skip to content

Commit

Permalink
fixed issues with StageVolume in createVolume
Browse files Browse the repository at this point in the history
  • Loading branch information
boddumanohar committed May 12, 2021
1 parent 92f9581 commit b80ede9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
Binary file modified charts/latest/csi-driver-smb-v0.7.0.tgz
Binary file not shown.
16 changes: 12 additions & 4 deletions pkg/smb/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (d *Driver) ListSnapshots(ctx context.Context, req *csi.ListSnapshotsReques
}

// Given a smbVolume, return a CSI volume id
func (d *Driver) getVolumeIDFromNfsVol(vol *smbVolume) string {
func (d *Driver) getVolumeIDFromSmbVol(vol *smbVolume) string {
idElements := make([]string, totalIDElements)
idElements[idsourceField] = strings.Trim(vol.sourceField, "/")
idElements[idBaseDir] = strings.Trim(vol.baseDir, "/")
Expand Down Expand Up @@ -214,6 +214,10 @@ func (d *Driver) internalMount(ctx context.Context, vol *smbVolume, volCap *csi.
},
VolumeCapability: volCap,
VolumeId: vol.id,
Secrets: map[string]string{
usernameField: "sanity",
passwordField: "sanitytestpassword",
},
})
return err
}
Expand All @@ -238,23 +242,27 @@ func (d *Driver) newSMBVolume(name string, size int64, params map[string]string)
baseDir string
)

trimChar := '"'

// Validate parameters (case-insensitive).
// TODO do more strict validation.
for k, v := range params {
switch strings.ToLower(k) {
case paramSource:
sourceField = v
case paramShare:
baseDir = v
default:
return nil, fmt.Errorf("invalid parameter %q", k)
klog.Warningf("invalid parameter %q", k)
}
}

// Validate required parameters
if sourceField == "" {
return nil, fmt.Errorf("%v is a required parameter", paramSource)
}
// sanitize the sourceField string
sourceField = strings.Trim(sourceField, string(trimChar))

if baseDir == "" {
return nil, fmt.Errorf("%v is a required parameter", paramShare)
}
Expand All @@ -265,7 +273,7 @@ func (d *Driver) newSMBVolume(name string, size int64, params map[string]string)
subDir: name,
size: size,
}
vol.id = d.getVolumeIDFromNfsVol(vol)
vol.id = d.getVolumeIDFromSmbVol(vol)

return vol, nil
}
Expand Down
8 changes: 4 additions & 4 deletions test/integration/run-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ readonly dirname="/tmp/$(date +%s)"

mkdir "$dirname"
export PERMISSIONS=0777
docker run -it --name samba -p 445:445 -v "$dirname":/mount -e ACCOUNT_USERNAME='test' -e SAMBA_VOLUME_CONFIG_username='[share]; path=/mount/; guest ok = yes; read only = no; browseable = yes' -d servercontainers/samba:4.9.4
docker run -e PERMISSIONS=0777 -p 445:445 --name samba -d andyzhangx/samba:win-fix -s "share;/smbshare/;yes;no;no;all;none" -u "sanity;sanitytestpassword" -p
function cleanup {
echo 'stop and delete samba container'
docker stop samba
Expand Down Expand Up @@ -54,8 +54,8 @@ trap cleanup EXIT

sleep 5
# set secret for csc node stage
export X_CSI_SECRETS=username=username,"password=test"
params='source="//0.0.0.0/share",createSubDir="true"'
export X_CSI_SECRETS=username=sanity,"password=sanitytestpassword"
params='source="//0.0.0.0/share",createSubDir=true,share=share'
# Begin to run CSI functions one by one
echo 'Create volume test:'
readonly value=$("$CSC_BIN" controller new --endpoint "$endpoint" --cap 1,block "$volname" --req-bytes 2147483648 --params "$params")
Expand All @@ -76,7 +76,7 @@ echo 'Mount volume test:'
sleep 2

echo "node stats test:"
csc node stats --endpoint "$endpoint" "$volumeid:$target_path:$staging_target_path"
"$CSC_BIN" node stats --endpoint "$endpoint" "$volumeid:$target_path:$staging_target_path"
sleep 2

echo 'Unmount volume test:'
Expand Down

0 comments on commit b80ede9

Please sign in to comment.