Commit ee28e1eb authored by k8s-merge-robot's avatar k8s-merge-robot Committed by GitHub

Merge pull request #27280 from jsafrane/aws-cinder-attach-test

Automatic merge from submit-queue Add AWS volume plugin attach tests. @kubernetes/sig-storage This it a test, it does not really matter if it catches 1.3 train or the next one.
parents 50618ec6 ba63590e
......@@ -24,13 +24,15 @@ import (
"time"
"github.com/golang/glog"
"k8s.io/kubernetes/pkg/cloudprovider/providers/aws"
"k8s.io/kubernetes/pkg/util/exec"
"k8s.io/kubernetes/pkg/util/mount"
"k8s.io/kubernetes/pkg/volume"
)
type awsElasticBlockStoreAttacher struct {
host volume.VolumeHost
host volume.VolumeHost
awsVolumes aws.Volumes
}
var _ volume.Attacher = &awsElasticBlockStoreAttacher{}
......@@ -38,7 +40,15 @@ var _ volume.Attacher = &awsElasticBlockStoreAttacher{}
var _ volume.AttachableVolumePlugin = &awsElasticBlockStorePlugin{}
func (plugin *awsElasticBlockStorePlugin) NewAttacher() (volume.Attacher, error) {
return &awsElasticBlockStoreAttacher{host: plugin.host}, nil
awsCloud, err := getCloudProvider(plugin.host.GetCloudProvider())
if err != nil {
return nil, err
}
return &awsElasticBlockStoreAttacher{
host: plugin.host,
awsVolumes: awsCloud,
}, nil
}
func (attacher *awsElasticBlockStoreAttacher) Attach(spec *volume.Spec, hostName string) (string, error) {
......@@ -49,14 +59,9 @@ func (attacher *awsElasticBlockStoreAttacher) Attach(spec *volume.Spec, hostName
volumeID := volumeSource.VolumeID
awsCloud, err := getCloudProvider(attacher.host.GetCloudProvider())
if err != nil {
return "", err
}
// awsCloud.AttachDisk checks if disk is already attached to node and
// succeeds in that case, so no need to do that separately.
devicePath, err := awsCloud.AttachDisk(volumeID, hostName, readOnly)
devicePath, err := attacher.awsVolumes.AttachDisk(volumeID, hostName, readOnly)
if err != nil {
glog.Errorf("Error attaching volume %q: %+v", volumeID, err)
return "", err
......@@ -156,23 +161,28 @@ func (attacher *awsElasticBlockStoreAttacher) MountDevice(spec *volume.Spec, dev
}
type awsElasticBlockStoreDetacher struct {
host volume.VolumeHost
mounter mount.Interface
awsVolumes aws.Volumes
}
var _ volume.Detacher = &awsElasticBlockStoreDetacher{}
func (plugin *awsElasticBlockStorePlugin) NewDetacher() (volume.Detacher, error) {
return &awsElasticBlockStoreDetacher{host: plugin.host}, nil
awsCloud, err := getCloudProvider(plugin.host.GetCloudProvider())
if err != nil {
return nil, err
}
return &awsElasticBlockStoreDetacher{
mounter: plugin.host.GetMounter(),
awsVolumes: awsCloud,
}, nil
}
func (detacher *awsElasticBlockStoreDetacher) Detach(deviceMountPath string, hostName string) error {
volumeID := path.Base(deviceMountPath)
awsCloud, err := getCloudProvider(detacher.host.GetCloudProvider())
if err != nil {
return err
}
attached, err := awsCloud.DiskIsAttached(volumeID, hostName)
attached, err := detacher.awsVolumes.DiskIsAttached(volumeID, hostName)
if err != nil {
// Log error and continue with detach
glog.Errorf(
......@@ -186,7 +196,7 @@ func (detacher *awsElasticBlockStoreDetacher) Detach(deviceMountPath string, hos
return nil
}
if _, err = awsCloud.DetachDisk(volumeID, hostName); err != nil {
if _, err = detacher.awsVolumes.DetachDisk(volumeID, hostName); err != nil {
glog.Errorf("Error detaching volumeID %q: %v", volumeID, err)
return err
}
......@@ -215,9 +225,8 @@ func (detacher *awsElasticBlockStoreDetacher) WaitForDetach(devicePath string, t
}
func (detacher *awsElasticBlockStoreDetacher) UnmountDevice(deviceMountPath string) error {
mounter := detacher.host.GetMounter()
volume := path.Base(deviceMountPath)
if err := unmountPDAndRemoveGlobalPath(deviceMountPath, mounter); err != nil {
if err := unmountPDAndRemoveGlobalPath(deviceMountPath, detacher.mounter); err != nil {
glog.Errorf("Error unmounting %q: %v", volume, err)
}
......
......@@ -31,7 +31,7 @@ import (
func TestGetDeviceName_Volume(t *testing.T) {
plugin := newPlugin()
name := "my-pd-volume"
spec := createVSpec(name, false)
spec := createVolSpec(name, false)
deviceName, err := plugin.GetVolumeName(spec)
if err != nil {
......@@ -75,7 +75,7 @@ func TestAttachDetach(t *testing.T) {
diskName := "disk"
instanceID := "instance"
readOnly := false
spec := createVSpec(diskName, readOnly)
spec := createVolSpec(diskName, readOnly)
attachError := errors.New("Fake attach error")
detachError := errors.New("Fake detach error")
diskCheckError := errors.New("Fake DiskIsAttached error")
......@@ -222,7 +222,7 @@ func newDetacher(testcase *testcase) *gcePersistentDiskDetacher {
}
}
func createVSpec(name string, readOnly bool) *volume.Spec {
func createVolSpec(name string, readOnly bool) *volume.Spec {
return &volume.Spec{
Volume: &api.Volume{
VolumeSource: api.VolumeSource{
......
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