Fix local PV node affinity tests and only run once

pull/6/head
Michelle Au 2018-02-05 13:53:29 -08:00
parent b80ee8c02c
commit 95f04eebee
1 changed files with 87 additions and 70 deletions

View File

@ -168,6 +168,7 @@ var _ = utils.SIGDescribe("PersistentVolumes-local [Feature:LocalPersistentVolum
} }
}) })
// TODO: move this under volumeType loop
Context("when one pod requests one prebound PVC", func() { Context("when one pod requests one prebound PVC", func() {
var testVol *localTestVolume var testVol *localTestVolume
@ -257,61 +258,38 @@ var _ = utils.SIGDescribe("PersistentVolumes-local [Feature:LocalPersistentVolum
}) })
}) })
Context("when pod using local volume with non-existant path", func() { })
}
Context("when local volume cannot be mounted [Slow]", func() {
// TODO:
// - make the pod create timeout shorter
// - check for these errors in unit tests intead
It("should fail mount due to non-existant path", func() {
ep := &eventPatterns{ ep := &eventPatterns{
reason: "FailedMount", reason: "FailedMount",
pattern: make([]string, 2)} pattern: make([]string, 2)}
ep.pattern = append(ep.pattern, "MountVolume.SetUp failed") ep.pattern = append(ep.pattern, "MountVolume.SetUp failed")
ep.pattern = append(ep.pattern, "does not exist") ep.pattern = append(ep.pattern, "does not exist")
It("should not be able to mount", func() {
testVol := &localTestVolume{ testVol := &localTestVolume{
node: config.node0, node: config.node0,
hostDir: "/non-existent/location/nowhere", hostDir: "/non-existent/location/nowhere",
localVolumeType: testVolType, localVolumeType: DirectoryLocalVolumeType,
} }
By("Creating local PVC and PV") By("Creating local PVC and PV")
createLocalPVCsPVs(config, []*localTestVolume{testVol}, testMode) createLocalPVCsPVs(config, []*localTestVolume{testVol}, immediateMode)
pod, err := createLocalPod(config, testVol) pod, err := createLocalPod(config, testVol)
Expect(err).To(HaveOccurred()) Expect(err).To(HaveOccurred())
checkPodEvents(config, pod.Name, ep) checkPodEvents(config, pod.Name, ep)
verifyLocalVolume(config, testVol) verifyLocalVolume(config, testVol)
cleanupLocalPVCsPVs(config, []*localTestVolume{testVol}) cleanupLocalPVCsPVs(config, []*localTestVolume{testVol})
}) })
})
Context("when pod's node is different from PV's NodeAffinity", func() { It("should fail mount due to wrong node", func() {
BeforeEach(func() {
if len(config.nodes) < 2 { if len(config.nodes) < 2 {
framework.Skipf("Runs only when number of nodes >= 2") framework.Skipf("Runs only when number of nodes >= 2")
} }
})
ep := &eventPatterns{
reason: "FailedScheduling",
pattern: make([]string, 2)}
ep.pattern = append(ep.pattern, "MatchNodeSelector")
ep.pattern = append(ep.pattern, "VolumeNodeAffinityConflict")
It("should not be able to mount due to different NodeAffinity", func() {
testPodWithNodeName(config, testVolType, ep, config.nodes[1].Name, makeLocalPodWithNodeAffinity, testMode)
})
It("should not be able to mount due to different NodeSelector", func() {
testPodWithNodeName(config, testVolType, ep, config.nodes[1].Name, makeLocalPodWithNodeSelector, testMode)
})
})
Context("when pod's node is different from PV's NodeName", func() {
BeforeEach(func() {
if len(config.nodes) < 2 {
framework.Skipf("Runs only when number of nodes >= 2")
}
})
ep := &eventPatterns{ ep := &eventPatterns{
reason: "FailedMount", reason: "FailedMount",
@ -319,13 +297,52 @@ var _ = utils.SIGDescribe("PersistentVolumes-local [Feature:LocalPersistentVolum
ep.pattern = append(ep.pattern, "NodeSelectorTerm") ep.pattern = append(ep.pattern, "NodeSelectorTerm")
ep.pattern = append(ep.pattern, "MountVolume.NodeAffinity check failed") ep.pattern = append(ep.pattern, "MountVolume.NodeAffinity check failed")
It("should not be able to mount due to different NodeName", func() { testVols := setupLocalVolumesPVCsPVs(config, DirectoryLocalVolumeType, config.node0, 1, immediateMode)
testPodWithNodeName(config, testVolType, ep, config.nodes[1].Name, makeLocalPodWithNodeName, testMode) testVol := testVols[0]
})
pod := makeLocalPodWithNodeName(config, testVol, config.nodes[1].Name)
pod, err := config.client.CoreV1().Pods(config.ns).Create(pod)
Expect(err).NotTo(HaveOccurred())
err = framework.WaitForPodNameRunningInNamespace(config.client, pod.Name, pod.Namespace)
Expect(err).To(HaveOccurred())
checkPodEvents(config, pod.Name, ep)
cleanupLocalVolumes(config, []*localTestVolume{testVol})
}) })
}) })
Context("when pod's node is different from PV's NodeAffinity", func() {
var (
testVol *localTestVolume
volumeType localVolumeType
)
BeforeEach(func() {
if len(config.nodes) < 2 {
framework.Skipf("Runs only when number of nodes >= 2")
} }
volumeType = DirectoryLocalVolumeType
setupStorageClass(config, &immediateMode)
testVols := setupLocalVolumesPVCsPVs(config, volumeType, config.node0, 1, immediateMode)
testVol = testVols[0]
})
AfterEach(func() {
cleanupLocalVolumes(config, []*localTestVolume{testVol})
cleanupStorageClass(config)
})
It("should not be able to mount due to different NodeAffinity", func() {
testPodWithNodeConflict(config, volumeType, config.nodes[1].Name, makeLocalPodWithNodeAffinity, immediateMode)
})
It("should not be able to mount due to different NodeSelector", func() {
testPodWithNodeConflict(config, volumeType, config.nodes[1].Name, makeLocalPodWithNodeSelector, immediateMode)
})
})
Context("when using local volume provisioner", func() { Context("when using local volume provisioner", func() {
var volumePath string var volumePath string
@ -424,7 +441,7 @@ var _ = utils.SIGDescribe("PersistentVolumes-local [Feature:LocalPersistentVolum
type makeLocalPodWith func(config *localTestConfig, volume *localTestVolume, nodeName string) *v1.Pod type makeLocalPodWith func(config *localTestConfig, volume *localTestVolume, nodeName string) *v1.Pod
func testPodWithNodeName(config *localTestConfig, testVolType localVolumeType, ep *eventPatterns, nodeName string, makeLocalPodFunc makeLocalPodWith, bindingMode storagev1.VolumeBindingMode) { func testPodWithNodeConflict(config *localTestConfig, testVolType localVolumeType, nodeName string, makeLocalPodFunc makeLocalPodWith, bindingMode storagev1.VolumeBindingMode) {
By(fmt.Sprintf("local-volume-type: %s", testVolType)) By(fmt.Sprintf("local-volume-type: %s", testVolType))
testVols := setupLocalVolumesPVCsPVs(config, testVolType, config.node0, 1, bindingMode) testVols := setupLocalVolumesPVCsPVs(config, testVolType, config.node0, 1, bindingMode)
testVol := testVols[0] testVol := testVols[0]
@ -432,9 +449,9 @@ func testPodWithNodeName(config *localTestConfig, testVolType localVolumeType, e
pod := makeLocalPodFunc(config, testVol, nodeName) pod := makeLocalPodFunc(config, testVol, nodeName)
pod, err := config.client.CoreV1().Pods(config.ns).Create(pod) pod, err := config.client.CoreV1().Pods(config.ns).Create(pod)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
err = framework.WaitForPodRunningInNamespace(config.client, pod)
Expect(err).To(HaveOccurred()) err = framework.WaitForPodNameUnschedulableInNamespace(config.client, pod.Name, pod.Namespace)
checkPodEvents(config, pod.Name, ep) Expect(err).NotTo(HaveOccurred())
cleanupLocalVolumes(config, []*localTestVolume{testVol}) cleanupLocalVolumes(config, []*localTestVolume{testVol})
} }