Merge pull request #207 from jbw976/rook-168

Look for devices using a cleaned mount point
This commit is contained in:
Jared Watts authored and GitHub committed 2016-11-16 16:57:44 -08:00
commit 23dacdda98
2 files changed
+34

No files matched your search

+2
View File
@@ -19,6 +19,7 @@ import (
"fmt"
"os"
"os/user"
"path/filepath"
"strings"
"github.com/google/uuid"
@@ -103,6 +104,7 @@ func GetDeviceMountPoint(deviceName string, executor exec.Executor) (string, err
}
func GetDeviceFromMountPoint(mountPoint string, executor exec.Executor) (string, error) {
mountPoint = filepath.Clean(mountPoint)
cmd := fmt.Sprintf("get device from mount point %s", mountPoint)
device, err := executor.ExecuteCommandPipeline(
cmd,
+32
View File
@@ -16,8 +16,10 @@ limitations under the License.
package sys
import (
"strings"
"testing"
exectest "github.com/rook/rook/pkg/util/exec/test"
"github.com/stretchr/testify/assert"
)
@@ -55,3 +57,33 @@ sdc tmpfs`
result = parseDFOutput("sdc", output)
assert.Equal(t, "", result)
}
func TestGetDeviceFromMountPoint(t *testing.T) {
const device = "/dev/rbd3"
e := &exectest.MockExecutor{
MockExecuteCommandPipeline: func(actionName string, command string) (string, error) {
switch {
case strings.HasPrefix(actionName, "get device from mount point"):
// verify that the mount path being searched for has been cleaned
assert.Contains(t, command, " /tmp/mymountpath ")
return device, nil
}
return "", nil
},
}
// no trailing slash should work OK
d, err := GetDeviceFromMountPoint("/tmp/mymountpath", e)
assert.Nil(t, err)
assert.Equal(t, device, d)
// a trailing slash should be cleaned and work OK
d, err = GetDeviceFromMountPoint("/tmp/mymountpath/", e)
assert.Nil(t, err)
assert.Equal(t, device, d)
// a parent directory '..' in the middle of the path should work OK
d, err = GetDeviceFromMountPoint("/tmp/somedir/../mymountpath/", e)
assert.Nil(t, err)
assert.Equal(t, device, d)
}