From f4232d329960d20aa75a96c71515314f2c2a3c48 Mon Sep 17 00:00:00 2001 From: markturansky Date: Tue, 22 Sep 2015 14:19:12 -0400 Subject: [PATCH] fixed code issues related to hasty test refactor --- test/integration/persistent_volumes_test.go | 80 +++++++-------------- 1 file changed, 26 insertions(+), 54 deletions(-) diff --git a/test/integration/persistent_volumes_test.go b/test/integration/persistent_volumes_test.go index 34783ffc080..1e699d5bfe2 100644 --- a/test/integration/persistent_volumes_test.go +++ b/test/integration/persistent_volumes_test.go @@ -54,59 +54,6 @@ func TestPersistentVolumeRecycler(t *testing.T) { recycler.Run() defer recycler.Stop() - // This PV will be claimed, released, and recycled. - pv := &api.PersistentVolume{ - ObjectMeta: api.ObjectMeta{Name: "fake-pv"}, - Spec: api.PersistentVolumeSpec{ - PersistentVolumeSource: api.PersistentVolumeSource{HostPath: &api.HostPathVolumeSource{Path: "foo"}}, - Capacity: api.ResourceList{api.ResourceName(api.ResourceStorage): resource.MustParse("10G")}, - AccessModes: []api.PersistentVolumeAccessMode{api.ReadWriteOnce}, - PersistentVolumeReclaimPolicy: api.PersistentVolumeReclaimRecycle, - }, - } - - pvc := &api.PersistentVolumeClaim{ - ObjectMeta: api.ObjectMeta{Name: "fake-pvc"}, - Spec: api.PersistentVolumeClaimSpec{ - Resources: api.ResourceRequirements{Requests: api.ResourceList{api.ResourceName(api.ResourceStorage): resource.MustParse("5G")}}, - AccessModes: []api.PersistentVolumeAccessMode{api.ReadWriteOnce}, - }, - } - - watch, _ := testClient.PersistentVolumes().Watch(labels.Everything(), fields.Everything(), "0") - defer watch.Stop() - - _, _ = testClient.PersistentVolumes().Create(pv) - _, _ = testClient.PersistentVolumeClaims(api.NamespaceDefault).Create(pvc) - - // wait until the binder pairs the volume and claim - waitForPersistentVolumePhase(watch, api.VolumeBound) - - // deleting a claim releases the volume, after which it can be recycled - if err := testClient.PersistentVolumeClaims(api.NamespaceDefault).Delete(pvc.Name); err != nil { - t.Errorf("error deleting claim %s", pvc.Name) - } - - waitForPersistentVolumePhase(watch, api.VolumeReleased) - waitForPersistentVolumePhase(watch, api.VolumeAvailable) - - // end of Recycler test. - // Deleter test begins now. - // tests are serial because running masters concurrently that delete keys may cause similar tests to time out - - deleteAllEtcdKeys() - binderClient := client.NewOrDie(&client.Config{Host: s.URL, Version: testapi.Default.Version()}) - recyclerClient := client.NewOrDie(&client.Config{Host: s.URL, Version: testapi.Default.Version()}) - testClient := client.NewOrDie(&client.Config{Host: s.URL, Version: testapi.Default.Version()}) - - binder := volumeclaimbinder.NewPersistentVolumeClaimBinder(binderClient, 1*time.Second) - binder.Run() - defer binder.Stop() - - recycler, _ := volumeclaimbinder.NewPersistentVolumeRecycler(recyclerClient, 1*time.Second, []volume.VolumePlugin{&volume.FakeVolumePlugin{"plugin-name", volume.NewFakeVolumeHost("/tmp/fake", nil, nil)}}) - recycler.Run() - defer recycler.Stop() - // This PV will be claimed, released, and recycled. pv := &api.PersistentVolume{ ObjectMeta: api.ObjectMeta{Name: "fake-pv"}, @@ -114,7 +61,7 @@ func TestPersistentVolumeRecycler(t *testing.T) { PersistentVolumeSource: api.PersistentVolumeSource{HostPath: &api.HostPathVolumeSource{Path: "/tmp/foo"}}, Capacity: api.ResourceList{api.ResourceName(api.ResourceStorage): resource.MustParse("10G")}, AccessModes: []api.PersistentVolumeAccessMode{api.ReadWriteOnce}, - PersistentVolumeReclaimPolicy: api.PersistentVolumeReclaimDelete, + PersistentVolumeReclaimPolicy: api.PersistentVolumeReclaimRecycle, }, } @@ -140,6 +87,31 @@ func TestPersistentVolumeRecycler(t *testing.T) { t.Errorf("error deleting claim %s", pvc.Name) } + waitForPersistentVolumePhase(w, api.VolumeReleased) + waitForPersistentVolumePhase(w, api.VolumeAvailable) + + // end of Recycler test. + // Deleter test begins now. + // tests are serial because running masters concurrently that delete keys may cause similar tests to time out + + deleteAllEtcdKeys() + + // change the reclamation policy of the PV for the next test + pv.Spec.PersistentVolumeReclaimPolicy = api.PersistentVolumeReclaimDelete + + w, _ = testClient.PersistentVolumes().Watch(labels.Everything(), fields.Everything(), "0") + defer w.Stop() + + _, _ = testClient.PersistentVolumes().Create(pv) + _, _ = testClient.PersistentVolumeClaims(api.NamespaceDefault).Create(pvc) + + waitForPersistentVolumePhase(w, api.VolumeBound) + + // deleting a claim releases the volume, after which it can be recycled + if err := testClient.PersistentVolumeClaims(api.NamespaceDefault).Delete(pvc.Name); err != nil { + t.Errorf("error deleting claim %s", pvc.Name) + } + waitForPersistentVolumePhase(w, api.VolumeReleased) for {