Skip to content

Commit b69f410

Browse files
committed
e2e_node: consolidated NFSServer APIs.
1 parent 9b56413 commit b69f410

File tree

3 files changed

+22
-41
lines changed

3 files changed

+22
-41
lines changed

test/e2e/framework/volume/fixtures.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,24 @@ func NewNFSServerWithNodeName(ctx context.Context, cs clientset.Interface, names
176176
return config, pod, host
177177
}
178178

179+
// Restart the passed-in nfs-server by issuing a `rpc.nfsd 1` command in the
180+
// pod's (only) container. This command changes the number of nfs server threads from
181+
// (presumably) zero back to 1, and therefore allows nfs to open connections again.
182+
func RestartNFSServer(f *framework.Framework, serverPod *v1.Pod) {
183+
const startcmd = "rpc.nfsd 1"
184+
_, _, err := PodExec(f, serverPod, startcmd)
185+
framework.ExpectNoError(err)
186+
}
187+
188+
// Stop the passed-in nfs-server by issuing a `rpc.nfsd 0` command in the
189+
// pod's (only) container. This command changes the number of nfs server threads to 0,
190+
// thus closing all open nfs connections.
191+
func StopNFSServer(f *framework.Framework, serverPod *v1.Pod) {
192+
const stopcmd = "rpc.nfsd 0 && for i in $(seq 200); do rpcinfo -p | grep -q nfs || break; sleep 1; done"
193+
_, _, err := PodExec(f, serverPod, stopcmd)
194+
framework.ExpectNoError(err)
195+
}
196+
179197
// CreateStorageServer is a wrapper for startVolumeServer(). A storage server config is passed in, and a pod pointer
180198
// and ip address string are returned.
181199
// Note: Expect() is called so no error is returned.

test/e2e/node/kubelet.go

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -109,24 +109,6 @@ func waitTillNPodsRunningOnNodes(ctx context.Context, c clientset.Interface, nod
109109
})
110110
}
111111

112-
// Restart the passed-in nfs-server by issuing a `/usr/sbin/rpc.nfsd 1` command in the
113-
// pod's (only) container. This command changes the number of nfs server threads from
114-
// (presumably) zero back to 1, and therefore allows nfs to open connections again.
115-
func restartNfsServer(serverPod *v1.Pod) {
116-
const startcmd = "/usr/sbin/rpc.nfsd 1"
117-
ns := fmt.Sprintf("--namespace=%v", serverPod.Namespace)
118-
e2ekubectl.RunKubectlOrDie(ns, "exec", ns, serverPod.Name, "--", "/bin/sh", "-c", startcmd)
119-
}
120-
121-
// Stop the passed-in nfs-server by issuing a `/usr/sbin/rpc.nfsd 0` command in the
122-
// pod's (only) container. This command changes the number of nfs server threads to 0,
123-
// thus closing all open nfs connections.
124-
func stopNfsServer(serverPod *v1.Pod) {
125-
const stopcmd = "/usr/sbin/rpc.nfsd 0"
126-
ns := fmt.Sprintf("--namespace=%v", serverPod.Namespace)
127-
e2ekubectl.RunKubectlOrDie(ns, "exec", ns, serverPod.Name, "--", "/bin/sh", "-c", stopcmd)
128-
}
129-
130112
// Creates a pod that mounts an nfs volume that is served by the nfs-server pod. The container
131113
// will execute the passed in shell cmd. Waits for the pod to start.
132114
// Note: the nfs plugin is defined inline, no PV or PVC.
@@ -437,7 +419,7 @@ var _ = SIGDescribe("kubelet", func() {
437419
pod = createPodUsingNfs(ctx, f, c, ns, nfsIP, t.podCmd)
438420

439421
ginkgo.By("Stop the NFS server")
440-
stopNfsServer(nfsServerPod)
422+
e2evolume.StopNFSServer(f, nfsServerPod)
441423

442424
ginkgo.By("Delete the pod mounted to the NFS volume -- expect failure")
443425
err := e2epod.DeletePodWithWait(ctx, c, pod)
@@ -448,7 +430,7 @@ var _ = SIGDescribe("kubelet", func() {
448430
checkPodCleanup(ctx, c, pod, false)
449431

450432
ginkgo.By("Restart the nfs server")
451-
restartNfsServer(nfsServerPod)
433+
e2evolume.RestartNFSServer(f, nfsServerPod)
452434

453435
ginkgo.By("Verify that the deleted client pod is now cleaned up")
454436
checkPodCleanup(ctx, c, pod, true)

test/e2e_node/mirror_pod_test.go

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ var _ = SIGDescribe("MirrorPod", func() {
231231
}
232232

233233
ginkgo.By("Stopping the NFS server")
234-
stopNfsServer(f, nfsServerPod)
234+
e2evolume.StopNFSServer(f, nfsServerPod)
235235

236236
ginkgo.By(fmt.Sprintf("Deleting the static nfs test pod: %s", staticPodName))
237237
err = deleteStaticPod(podPath, staticPodName, ns)
@@ -243,7 +243,7 @@ var _ = SIGDescribe("MirrorPod", func() {
243243
}, 5*time.Minute, 10*time.Second).Should(gomega.BeTrueBecause("pod volume should exist while nfs server is stopped"))
244244

245245
ginkgo.By("Start the NFS server")
246-
restartNfsServer(f, nfsServerPod)
246+
e2evolume.RestartNFSServer(f, nfsServerPod)
247247

248248
ginkgo.By("Waiting for the pod volume to deleted after the NFS server is started")
249249
gomega.Eventually(func() bool {
@@ -286,25 +286,6 @@ func podVolumeDirectoryExists(uid types.UID) bool {
286286
return podVolumeDirectoryExists
287287
}
288288

289-
// Restart the passed-in nfs-server by issuing a `/usr/sbin/rpc.nfsd 1` command in the
290-
// pod's (only) container. This command changes the number of nfs server threads from
291-
// (presumably) zero back to 1, and therefore allows nfs to open connections again.
292-
func restartNfsServer(f *framework.Framework, serverPod *v1.Pod) {
293-
const startcmd = "/usr/sbin/rpc.nfsd 1"
294-
_, _, err := e2evolume.PodExec(f, serverPod, startcmd)
295-
framework.ExpectNoError(err)
296-
297-
}
298-
299-
// Stop the passed-in nfs-server by issuing a `/usr/sbin/rpc.nfsd 0` command in the
300-
// pod's (only) container. This command changes the number of nfs server threads to 0,
301-
// thus closing all open nfs connections.
302-
func stopNfsServer(f *framework.Framework, serverPod *v1.Pod) {
303-
const stopcmd = "rpc.nfsd 0 && for i in $(seq 200); do rpcinfo -p | grep -q nfs || break; sleep 1; done"
304-
_, _, err := e2evolume.PodExec(f, serverPod, stopcmd)
305-
framework.ExpectNoError(err)
306-
}
307-
308289
func createStaticPodUsingNfs(nfsIP string, nodeName string, cmd string, dir string, name string, ns string) error {
309290
ginkgo.By("create pod using nfs volume")
310291

0 commit comments

Comments
 (0)