Unverified Commit 450fdc9c authored by k8s-ci-robot's avatar k8s-ci-robot Committed by GitHub

Merge pull request #68608 from andyzhangx/UnmountDevice-windows

fix UnmountDevice failure on Windows
parents 2285a7dd 74f01026
...@@ -458,17 +458,14 @@ func getAllParentLinks(path string) ([]string, error) { ...@@ -458,17 +458,14 @@ func getAllParentLinks(path string) ([]string, error) {
return links, nil return links, nil
} }
// GetMountRefs : empty implementation here since there is no place to query all mount points on Windows
func (mounter *Mounter) GetMountRefs(pathname string) ([]string, error) { func (mounter *Mounter) GetMountRefs(pathname string) ([]string, error) {
if _, err := os.Stat(normalizeWindowsPath(pathname)); os.IsNotExist(err) { if _, err := os.Stat(normalizeWindowsPath(pathname)); os.IsNotExist(err) {
return []string{}, nil return []string{}, nil
} else if err != nil { } else if err != nil {
return nil, err return nil, err
} }
refs, err := getAllParentLinks(normalizeWindowsPath(pathname)) return []string{pathname}, nil
if err != nil {
return nil, err
}
return refs, nil
} }
// Note that on windows, it always returns 0. We actually don't set FSGroup on // Note that on windows, it always returns 0. We actually don't set FSGroup on
......
...@@ -111,30 +111,25 @@ func setEquivalent(set1, set2 []string) bool { ...@@ -111,30 +111,25 @@ func setEquivalent(set1, set2 []string) bool {
// this func must run in admin mode, otherwise it will fail // this func must run in admin mode, otherwise it will fail
func TestGetMountRefs(t *testing.T) { func TestGetMountRefs(t *testing.T) {
fm := &FakeMounter{MountPoints: []MountPoint{}} tests := []struct {
mountPath := `c:\secondmountpath` mountPath string
expectedRefs := []string{`c:\`, `c:\firstmountpath`, mountPath} expectedRefs []string
}{
// remove symbolic links first {
for i := 1; i < len(expectedRefs); i++ { mountPath: `c:\windows`,
removeLink(expectedRefs[i]) expectedRefs: []string{`c:\windows`},
} },
{
// create symbolic links mountPath: `c:\doesnotexist`,
for i := 1; i < len(expectedRefs); i++ { expectedRefs: []string{},
if err := makeLink(expectedRefs[i], expectedRefs[i-1]); err != nil { },
t.Errorf("makeLink failed: %v", err)
}
} }
if refs, err := fm.GetMountRefs(mountPath); err != nil || !setEquivalent(expectedRefs, refs) { mounter := Mounter{"fake/path"}
t.Errorf("getMountRefs(%q) = %v, error: %v; expected %v", mountPath, refs, err, expectedRefs)
}
// remove symbolic links for _, test := range tests {
for i := 1; i < len(expectedRefs); i++ { if refs, err := mounter.GetMountRefs(test.mountPath); err != nil || !setEquivalent(test.expectedRefs, refs) {
if err := removeLink(expectedRefs[i]); err != nil { t.Errorf("getMountRefs(%q) = %v, error: %v; expected %v", test.mountPath, refs, err, test.expectedRefs)
t.Errorf("removeLink failed: %v", err)
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment