Skip to content

Commit 6ec2120

Browse files
PeaceRebelHuijingHei
authored andcommitted
test/nfs: Add new test for NFS client on fcos
Sets up a single VM with NFS server running as container. Clients mounts the same export under different mouthpaths for NFS versions 3 and 4, and checks existence of a tempfile This test is added in relation with with the following issue: coreos/fedora-coreos-tracker#1942
1 parent 92fe245 commit 6ec2120

File tree

1 file changed

+163
-0
lines changed

1 file changed

+163
-0
lines changed

mantle/kola/tests/misc/nfs-client.go

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
// Copyright 2025 Red Hat, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package misc
16+
17+
import (
18+
"fmt"
19+
"path"
20+
"time"
21+
22+
"github.com/coreos/coreos-assembler/mantle/kola"
23+
"github.com/coreos/coreos-assembler/mantle/kola/cluster"
24+
"github.com/coreos/coreos-assembler/mantle/kola/register"
25+
"github.com/coreos/coreos-assembler/mantle/platform/conf"
26+
"github.com/coreos/coreos-assembler/mantle/util"
27+
)
28+
29+
const (
30+
machine_conf = `
31+
variant: fcos
32+
version: 1.5.0
33+
storage:
34+
files:
35+
- path: /etc/containers/systemd/nfs.container
36+
overwrite: true
37+
contents:
38+
inline: |
39+
[Container]
40+
Image=quay.io/coreos-assembler/nfs
41+
Volume=/tmp:/export
42+
Network=host
43+
PodmanArgs=--privileged
44+
[Install]
45+
WantedBy=default.target
46+
- path: "/etc/hostname"
47+
contents:
48+
inline: "nfs-client"
49+
mode: 0644
50+
systemd:
51+
units:
52+
- name: "var-mnt-nfsv4.mount"
53+
enabled: true
54+
contents: |-
55+
[Unit]
56+
Description=NFS Client
57+
After=network-online.target
58+
Requires=network-online.target
59+
After=rpc-statd.service nfs.service
60+
Requires=rpc-statd.service
61+
62+
[Mount]
63+
What=127.0.0.1:/
64+
Where=/var/mnt/nfsv4
65+
Type=nfs4
66+
Options=defaults,noexec,nfsvers=4
67+
68+
[Install]
69+
WantedBy=multi-user.target
70+
- name: "var-mnt-nfs.mount"
71+
enabled: true
72+
contents: |-
73+
[Unit]
74+
Description=NFS Client
75+
After=network-online.target
76+
Requires=network-online.target
77+
After=rpc-statd.service nfs.service
78+
Requires=rpc-statd.service
79+
80+
[Mount]
81+
What=127.0.0.1:/export
82+
Where=/var/mnt/nfs
83+
Type=nfs
84+
Options=vers=3
85+
86+
[Install]
87+
WantedBy=multi-user.target`
88+
)
89+
90+
// Test nfs client
91+
92+
func init() {
93+
register.RegisterTest(&register.Test{
94+
Run: nfsClientTest,
95+
ClusterSize: 1,
96+
UserData: conf.Butane(machine_conf),
97+
Name: "linux.nfs.client",
98+
Description: "Verifies NFS client works.",
99+
Tags: []string{kola.NeedsInternetTag},
100+
Platforms: []string{"qemu"},
101+
102+
// RHCOS has a separate test for NFS v4 server and client
103+
ExcludeDistros: []string{"rhcos"},
104+
})
105+
}
106+
107+
func nfsClientTest(c cluster.TestCluster) {
108+
109+
nfs_machine := c.Machines()[0]
110+
111+
// Wait for nfs server to become active
112+
// 1 minutes should be enough to pull the container image
113+
err := util.Retry(4, 15*time.Second, func() error {
114+
115+
nfs_status, err := c.SSH(nfs_machine, "systemctl is-active nfs.service")
116+
117+
if err != nil {
118+
return err
119+
} else if string(nfs_status) == "inactive" {
120+
return fmt.Errorf("nfs.service is not ready: %s.", string(nfs_status))
121+
}
122+
return nil
123+
})
124+
if err != nil {
125+
c.Fatalf("Timed out while waiting for nfs.service to be ready: %v", err)
126+
}
127+
128+
c.Log("NFS server booted")
129+
130+
// poke a file in /tmp
131+
tmp := c.MustSSH(nfs_machine, "mktemp")
132+
133+
checkv4mount := func() error {
134+
status, err := c.SSH(nfs_machine, "systemctl is-active var-mnt-nfsv4.mount")
135+
if err != nil || string(status) != "active" {
136+
return fmt.Errorf("var-mnt-nfsv4.mount status is %q: %v", status, err)
137+
}
138+
139+
c.Log("Got NFSv4 mount.")
140+
return nil
141+
}
142+
143+
if err = util.Retry(10, 3*time.Second, checkv4mount); err != nil {
144+
c.Fatal(err)
145+
}
146+
147+
checkmount := func() error {
148+
status, err := c.SSH(nfs_machine, "systemctl is-active var-mnt-nfs.mount")
149+
if err != nil || string(status) != "active" {
150+
return fmt.Errorf("var-mnt-nfs.mount status is %q: %v", status, err)
151+
}
152+
153+
c.Log("Got NFSv3 mount.")
154+
return nil
155+
}
156+
157+
if err = util.Retry(10, 3*time.Second, checkmount); err != nil {
158+
c.Fatal(err)
159+
}
160+
161+
c.RunCmdSyncf(nfs_machine, "stat /var/mnt/nfsv4/%s", path.Base(string(tmp)))
162+
c.RunCmdSyncf(nfs_machine, "stat /var/mnt/nfs/%s", path.Base(string(tmp)))
163+
}

0 commit comments

Comments
 (0)