Abstract node side functionality of attachable plugins

- Expand Attacher/Detacher interfaces to break up work more
  explicitly.
- Add arguments to all functions to avoid having implementers store
  the data needed for operations.
- Expand unit tests to check that Attach, Detach, WaitForAttach,
  WaitForDetach, MountDevice, and UnmountDevice get call where
  appropriet.
This commit is contained in:
Sami Wagiaalla
2016-04-29 15:29:59 -04:00
parent ad86986c87
commit 71e7dba845
6 changed files with 190 additions and 17 deletions

View File

@@ -23,6 +23,7 @@ import (
"os/exec"
"path"
"strings"
"time"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/resource"
@@ -137,6 +138,11 @@ type FakeVolumePlugin struct {
LastProvisionerOptions VolumeOptions
NewAttacherCallCount int
NewDetacherCallCount int
Mounters []*FakeVolume
Unmounters []*FakeVolume
Attachers []*FakeVolume
Detachers []*FakeVolume
}
var _ VolumePlugin = &FakeVolumePlugin{}
@@ -145,6 +151,12 @@ var _ DeletableVolumePlugin = &FakeVolumePlugin{}
var _ ProvisionableVolumePlugin = &FakeVolumePlugin{}
var _ AttachableVolumePlugin = &FakeVolumePlugin{}
func (plugin *FakeVolumePlugin) getFakeVolume(list *[]*FakeVolume) *FakeVolume {
volume := &FakeVolume{}
*list = append(*list, volume)
return volume
}
func (plugin *FakeVolumePlugin) Init(host VolumeHost) error {
plugin.Host = host
return nil
@@ -160,21 +172,31 @@ func (plugin *FakeVolumePlugin) CanSupport(spec *Spec) bool {
}
func (plugin *FakeVolumePlugin) NewMounter(spec *Spec, pod *api.Pod, opts VolumeOptions) (Mounter, error) {
return &FakeVolume{pod.UID, spec.Name(), plugin, MetricsNil{}}, nil
volume := plugin.getFakeVolume(&plugin.Mounters)
volume.PodUID = pod.UID
volume.VolName = spec.Name()
volume.Plugin = plugin
volume.MetricsNil = MetricsNil{}
return volume, nil
}
func (plugin *FakeVolumePlugin) NewUnmounter(volName string, podUID types.UID) (Unmounter, error) {
return &FakeVolume{podUID, volName, plugin, MetricsNil{}}, nil
volume := plugin.getFakeVolume(&plugin.Unmounters)
volume.PodUID = podUID
volume.VolName = volName
volume.Plugin = plugin
volume.MetricsNil = MetricsNil{}
return volume, nil
}
func (plugin *FakeVolumePlugin) NewAttacher(spec *Spec) (Attacher, error) {
plugin.NewAttacherCallCount = plugin.NewAttacherCallCount + 1
return &FakeVolume{}, nil
return plugin.getFakeVolume(&plugin.Attachers), nil
}
func (plugin *FakeVolumePlugin) NewDetacher(name string, podUID types.UID) (Detacher, error) {
plugin.NewDetacherCallCount = plugin.NewDetacherCallCount + 1
return &FakeVolume{}, nil
return plugin.getFakeVolume(&plugin.Detachers), nil
}
func (plugin *FakeVolumePlugin) NewRecycler(spec *Spec) (Recycler, error) {
@@ -199,6 +221,16 @@ type FakeVolume struct {
VolName string
Plugin *FakeVolumePlugin
MetricsNil
SetUpCallCount int
TearDownCallCount int
AttachCallCount int
DetachCallCount int
WaitForAttachCallCount int
WaitForDetachCallCount int
MountDeviceCallCount int
UnmountDeviceCallCount int
GetDeviceMountPathCallCount int
}
func (_ *FakeVolume) GetAttributes() Attributes {
@@ -210,6 +242,7 @@ func (_ *FakeVolume) GetAttributes() Attributes {
}
func (fv *FakeVolume) SetUp(fsGroup *int64) error {
fv.SetUpCallCount++
return fv.SetUpAt(fv.GetPath(), fsGroup)
}
@@ -222,6 +255,7 @@ func (fv *FakeVolume) GetPath() string {
}
func (fv *FakeVolume) TearDown() error {
fv.TearDownCallCount++
return fv.TearDownAt(fv.GetPath())
}
@@ -229,11 +263,38 @@ func (fv *FakeVolume) TearDownAt(dir string) error {
return os.RemoveAll(dir)
}
func (fv *FakeVolume) Attach() error {
func (fv *FakeVolume) Attach(spec *Spec, hostName string) error {
fv.AttachCallCount++
return nil
}
func (fv *FakeVolume) Detach() error {
func (fv *FakeVolume) WaitForAttach(spec *Spec, spectimeout time.Duration) (string, error) {
fv.WaitForAttachCallCount++
return "", nil
}
func (fv *FakeVolume) GetDeviceMountPath(spec *Spec) string {
fv.GetDeviceMountPathCallCount++
return ""
}
func (fv *FakeVolume) MountDevice(devicePath string, deviceMountPath string, mounter mount.Interface) error {
fv.MountDeviceCallCount++
return nil
}
func (fv *FakeVolume) Detach(deviceMountPath string, hostName string) error {
fv.DetachCallCount++
return nil
}
func (fv *FakeVolume) WaitForDetach(devicePath string, timeout time.Duration) error {
fv.WaitForDetachCallCount++
return nil
}
func (fv *FakeVolume) UnmountDevice(globalMountPath string, mounter mount.Interface) error {
fv.UnmountDeviceCallCount++
return nil
}