Merge pull request #14450 from saad-ali/issue11391

Add new GCE PD E2E test to verify two PDs attached to one container
This commit is contained in:
Brian Grant 2015-09-25 13:31:30 -07:00
commit 5f55b70976

View File

@ -72,8 +72,9 @@ var _ = Describe("Pod Disks", func() {
diskName, err := createPD() diskName, err := createPD()
expectNoError(err, "Error creating PD") expectNoError(err, "Error creating PD")
host0Pod := testPDPod(diskName, host0Name, false /* readOnly */, 1 /* numContainers */) host0Pod := testPDPod([]string{diskName}, host0Name, false /* readOnly */, 1 /* numContainers */)
host1Pod := testPDPod(diskName, host1Name, false /* readOnly */, 1 /* numContainers */) host1Pod := testPDPod([]string{diskName}, host1Name, false /* readOnly */, 1 /* numContainers */)
containerName := "mycontainer"
defer func() { defer func() {
By("cleaning up PD-RW test environment") By("cleaning up PD-RW test environment")
@ -92,10 +93,10 @@ var _ = Describe("Pod Disks", func() {
expectNoError(framework.WaitForPodRunning(host0Pod.Name)) expectNoError(framework.WaitForPodRunning(host0Pod.Name))
testFile := "/testpd/tracker" testFile := "/testpd1/tracker"
testFileContents := fmt.Sprintf("%v", math_rand.Int()) testFileContents := fmt.Sprintf("%v", math_rand.Int())
expectNoError(framework.WriteFileViaContainer(host0Pod.Name, "testpd" /* containerName */, testFile, testFileContents)) expectNoError(framework.WriteFileViaContainer(host0Pod.Name, containerName, testFile, testFileContents))
Logf("Wrote value: %v", testFileContents) Logf("Wrote value: %v", testFileContents)
By("deleting host0Pod") By("deleting host0Pod")
@ -107,7 +108,7 @@ var _ = Describe("Pod Disks", func() {
expectNoError(framework.WaitForPodRunning(host1Pod.Name)) expectNoError(framework.WaitForPodRunning(host1Pod.Name))
v, err := framework.ReadFileViaContainer(host1Pod.Name, "testpd", testFile) v, err := framework.ReadFileViaContainer(host1Pod.Name, containerName, testFile)
expectNoError(err) expectNoError(err)
Logf("Read value: %v", v) Logf("Read value: %v", v)
@ -129,9 +130,9 @@ var _ = Describe("Pod Disks", func() {
diskName, err := createPD() diskName, err := createPD()
expectNoError(err, "Error creating PD") expectNoError(err, "Error creating PD")
rwPod := testPDPod(diskName, host0Name, false /* readOnly */, 1 /* numContainers */) rwPod := testPDPod([]string{diskName}, host0Name, false /* readOnly */, 1 /* numContainers */)
host0ROPod := testPDPod(diskName, host0Name, true /* readOnly */, 1 /* numContainers */) host0ROPod := testPDPod([]string{diskName}, host0Name, true /* readOnly */, 1 /* numContainers */)
host1ROPod := testPDPod(diskName, host1Name, true /* readOnly */, 1 /* numContainers */) host1ROPod := testPDPod([]string{diskName}, host1Name, true /* readOnly */, 1 /* numContainers */)
defer func() { defer func() {
By("cleaning up PD-RO test environment") By("cleaning up PD-RO test environment")
@ -185,7 +186,7 @@ var _ = Describe("Pod Disks", func() {
expectNoError(err, "Error creating PD") expectNoError(err, "Error creating PD")
numContainers := 4 numContainers := 4
host0Pod := testPDPod(diskName, host0Name, false /* readOnly */, numContainers) host0Pod := testPDPod([]string{diskName}, host0Name, false /* readOnly */, numContainers)
defer func() { defer func() {
By("cleaning up PD-RW test environment") By("cleaning up PD-RW test environment")
@ -206,19 +207,19 @@ var _ = Describe("Pod Disks", func() {
expectNoError(framework.WaitForPodRunning(host0Pod.Name)) expectNoError(framework.WaitForPodRunning(host0Pod.Name))
// randomly select a container and read/verify pd contents from it // randomly select a container and read/verify pd contents from it
containerName := fmt.Sprintf("testpd%v", math_rand.Intn(numContainers)+1) containerName := fmt.Sprintf("mycontainer%v", math_rand.Intn(numContainers)+1)
verifyPDContentsViaContainer(framework, host0Pod.Name, containerName, fileAndContentToVerify) verifyPDContentsViaContainer(framework, host0Pod.Name, containerName, fileAndContentToVerify)
// Randomly select a container to write a file to PD from // Randomly select a container to write a file to PD from
containerName = fmt.Sprintf("testpd%v", math_rand.Intn(numContainers)+1) containerName = fmt.Sprintf("mycontainer%v", math_rand.Intn(numContainers)+1)
testFile := fmt.Sprintf("/testpd/tracker%v", i) testFile := fmt.Sprintf("/testpd1/tracker%v", i)
testFileContents := fmt.Sprintf("%v", math_rand.Int()) testFileContents := fmt.Sprintf("%v", math_rand.Int())
fileAndContentToVerify[testFile] = testFileContents fileAndContentToVerify[testFile] = testFileContents
expectNoError(framework.WriteFileViaContainer(host0Pod.Name, containerName, testFile, testFileContents)) expectNoError(framework.WriteFileViaContainer(host0Pod.Name, containerName, testFile, testFileContents))
Logf("Wrote value: \"%v\" to PD %q from pod %q container %q", testFileContents, diskName, host0Pod.Name, containerName) Logf("Wrote value: \"%v\" to PD %q from pod %q container %q", testFileContents, diskName, host0Pod.Name, containerName)
// Randomly select a container and read/verify pd contents from it // Randomly select a container and read/verify pd contents from it
containerName = fmt.Sprintf("testpd%v", math_rand.Intn(numContainers)+1) containerName = fmt.Sprintf("mycontainer%v", math_rand.Intn(numContainers)+1)
verifyPDContentsViaContainer(framework, host0Pod.Name, containerName, fileAndContentToVerify) verifyPDContentsViaContainer(framework, host0Pod.Name, containerName, fileAndContentToVerify)
By("deleting host0Pod") By("deleting host0Pod")
@ -230,6 +231,69 @@ var _ = Describe("Pod Disks", func() {
return return
}) })
It("should schedule a pod w/two RW PDs both mounted to one container, write to PD, verify contents, delete pod, recreate pod, verify contents, and repeat in rapid succession", func() {
SkipUnlessProviderIs("gce", "gke", "aws")
By("creating PD1")
disk1Name, err := createPD()
expectNoError(err, "Error creating PD1")
By("creating PD2")
disk2Name, err := createPD()
expectNoError(err, "Error creating PD2")
host0Pod := testPDPod([]string{disk1Name, disk2Name}, host0Name, false /* readOnly */, 1 /* numContainers */)
defer func() {
By("cleaning up PD-RW test environment")
// Teardown pods, PD. Ignore errors.
// Teardown should do nothing unless test failed.
podClient.Delete(host0Pod.Name, api.NewDeleteOptions(0))
detachPD(host0Name, disk1Name)
detachPD(host0Name, disk2Name)
deletePD(disk1Name)
deletePD(disk2Name)
}()
containerName := "mycontainer"
fileAndContentToVerify := make(map[string]string)
for i := 0; i < 3; i++ {
Logf("PD Read/Writer Iteration #%v", i)
By("submitting host0Pod to kubernetes")
_, err = podClient.Create(host0Pod)
expectNoError(err, fmt.Sprintf("Failed to create host0Pod: %v", err))
expectNoError(framework.WaitForPodRunning(host0Pod.Name))
// Read/verify pd contents for both disks from container
verifyPDContentsViaContainer(framework, host0Pod.Name, containerName, fileAndContentToVerify)
// Write a file to both PDs from container
testFilePD1 := fmt.Sprintf("/testpd1/tracker%v", i)
testFilePD2 := fmt.Sprintf("/testpd2/tracker%v", i)
testFilePD1Contents := fmt.Sprintf("%v", math_rand.Int())
testFilePD2Contents := fmt.Sprintf("%v", math_rand.Int())
fileAndContentToVerify[testFilePD1] = testFilePD1Contents
fileAndContentToVerify[testFilePD2] = testFilePD2Contents
expectNoError(framework.WriteFileViaContainer(host0Pod.Name, containerName, testFilePD1, testFilePD1Contents))
Logf("Wrote value: \"%v\" to PD1 (%q) from pod %q container %q", testFilePD1Contents, disk1Name, host0Pod.Name, containerName)
expectNoError(framework.WriteFileViaContainer(host0Pod.Name, containerName, testFilePD2, testFilePD2Contents))
Logf("Wrote value: \"%v\" to PD2 (%q) from pod %q container %q", testFilePD2Contents, disk2Name, host0Pod.Name, containerName)
// Read/verify pd contents for both disks from container
verifyPDContentsViaContainer(framework, host0Pod.Name, containerName, fileAndContentToVerify)
By("deleting host0Pod")
expectNoError(podClient.Delete(host0Pod.Name, api.NewDeleteOptions(0)), "Failed to delete host0Pod")
}
By(fmt.Sprintf("deleting PD1 %q", disk1Name))
deletePDWithRetry(disk1Name)
By(fmt.Sprintf("deleting PD2 %q", disk2Name))
deletePDWithRetry(disk2Name)
return
})
}) })
func deletePDWithRetry(diskName string) { func deletePDWithRetry(diskName string) {
@ -316,23 +380,22 @@ func detachPD(hostName, pdName string) error {
} }
} }
func testPDPod(diskName, targetHost string, readOnly bool, numContainers int) *api.Pod { func testPDPod(diskNames []string, targetHost string, readOnly bool, numContainers int) *api.Pod {
containers := make([]api.Container, numContainers) containers := make([]api.Container, numContainers)
for i := range containers { for i := range containers {
containers[i].Name = "testpd" containers[i].Name = "mycontainer"
if numContainers > 1 { if numContainers > 1 {
containers[i].Name = fmt.Sprintf("testpd%v", i+1) containers[i].Name = fmt.Sprintf("mycontainer%v", i+1)
} }
containers[i].Image = "gcr.io/google_containers/busybox" containers[i].Image = "gcr.io/google_containers/busybox"
containers[i].Command = []string{"sleep", "6000"} containers[i].Command = []string{"sleep", "6000"}
containers[i].VolumeMounts = []api.VolumeMount{ containers[i].VolumeMounts = make([]api.VolumeMount, len(diskNames))
{ for k := range diskNames {
Name: "testpd", containers[i].VolumeMounts[k].Name = fmt.Sprintf("testpd%v", k+1)
MountPath: "/testpd", containers[i].VolumeMounts[k].MountPath = fmt.Sprintf("/testpd%v", k+1)
},
} }
containers[i].Resources.Limits = api.ResourceList{} containers[i].Resources.Limits = api.ResourceList{}
@ -355,30 +418,28 @@ func testPDPod(diskName, targetHost string, readOnly bool, numContainers int) *a
} }
if testContext.Provider == "gce" || testContext.Provider == "gke" { if testContext.Provider == "gce" || testContext.Provider == "gke" {
pod.Spec.Volumes = []api.Volume{ pod.Spec.Volumes = make([]api.Volume, len(diskNames))
{ for k, diskName := range diskNames {
Name: "testpd", pod.Spec.Volumes[k].Name = fmt.Sprintf("testpd%v", k+1)
VolumeSource: api.VolumeSource{ pod.Spec.Volumes[k].VolumeSource = api.VolumeSource{
GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{ GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{
PDName: diskName, PDName: diskName,
FSType: "ext4", FSType: "ext4",
ReadOnly: readOnly, ReadOnly: readOnly,
}, },
}, }
},
} }
} else if testContext.Provider == "aws" { } else if testContext.Provider == "aws" {
pod.Spec.Volumes = []api.Volume{ pod.Spec.Volumes = make([]api.Volume, len(diskNames))
{ for k, diskName := range diskNames {
Name: "testpd", pod.Spec.Volumes[k].Name = fmt.Sprintf("testpd%v", k+1)
VolumeSource: api.VolumeSource{ pod.Spec.Volumes[k].VolumeSource = api.VolumeSource{
AWSElasticBlockStore: &api.AWSElasticBlockStoreVolumeSource{ AWSElasticBlockStore: &api.AWSElasticBlockStoreVolumeSource{
VolumeID: diskName, VolumeID: diskName,
FSType: "ext4", FSType: "ext4",
ReadOnly: readOnly, ReadOnly: readOnly,
}, },
}, }
},
} }
} else { } else {
panic("Unknown provider: " + testContext.Provider) panic("Unknown provider: " + testContext.Provider)