mirror of https://github.com/k3s-io/k3s
Extend OpenStack Cloud Provider Volume Tests
Adding test coverage for: getVolume AttachDisk DetachDiskpull/6/head
parent
ce988c8d75
commit
28590781c1
|
@ -28,6 +28,38 @@ import (
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const volumeAvailableStatus = "available"
|
||||||
|
const volumeInUseStatus = "in-use"
|
||||||
|
const volumeCreateTimeoutSeconds = 30
|
||||||
|
|
||||||
|
func WaitForVolumeStatus(t *testing.T, os *OpenStack, volumeName string, status string, timeoutSeconds int) {
|
||||||
|
timeout := timeoutSeconds
|
||||||
|
start := time.Now().Second()
|
||||||
|
for {
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
|
||||||
|
if timeout >= 0 && time.Now().Second()-start >= timeout {
|
||||||
|
t.Logf("Volume (%s) status did not change to %s after %s seconds\n",
|
||||||
|
volumeName,
|
||||||
|
status,
|
||||||
|
timeout)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
getVol, err := os.getVolume(volumeName)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Cannot get existing Cinder volume (%s): %v", volumeName, err)
|
||||||
|
}
|
||||||
|
if getVol.Status == status {
|
||||||
|
t.Logf("Volume (%s) status changed to %s after %s seconds\n",
|
||||||
|
volumeName,
|
||||||
|
status,
|
||||||
|
timeout)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestReadConfig(t *testing.T) {
|
func TestReadConfig(t *testing.T) {
|
||||||
_, err := readConfig(nil)
|
_, err := readConfig(nil)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -220,10 +252,30 @@ func TestVolumes(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Cannot create a new Cinder volume: %v", err)
|
t.Fatalf("Cannot create a new Cinder volume: %v", err)
|
||||||
}
|
}
|
||||||
|
t.Logf("Volume (%s) created\n", vol)
|
||||||
|
|
||||||
|
WaitForVolumeStatus(t, os, vol, volumeAvailableStatus, volumeCreateTimeoutSeconds)
|
||||||
|
|
||||||
|
diskId, err := os.AttachDisk(vol)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Cannot AttachDisk Cinder volume %s: %v", vol, err)
|
||||||
|
}
|
||||||
|
t.Logf("Volume (%s) attached, disk ID: %s\n", vol, diskId)
|
||||||
|
|
||||||
|
WaitForVolumeStatus(t, os, vol, volumeInUseStatus, volumeCreateTimeoutSeconds)
|
||||||
|
|
||||||
|
err = os.DetachDisk(vol)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Cannot DetachDisk Cinder volume %s: %v", vol, err)
|
||||||
|
}
|
||||||
|
t.Logf("Volume (%s) detached\n", vol)
|
||||||
|
|
||||||
|
WaitForVolumeStatus(t, os, vol, volumeAvailableStatus, volumeCreateTimeoutSeconds)
|
||||||
|
|
||||||
err = os.DeleteVolume(vol)
|
err = os.DeleteVolume(vol)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Cannot delete Cinder volume %s: %v", vol, err)
|
t.Fatalf("Cannot delete Cinder volume %s: %v", vol, err)
|
||||||
}
|
}
|
||||||
|
t.Logf("Volume (%s) deleted\n", vol)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue