This repository has been archived by the owner on May 7, 2021. It is now read-only.
/
nfs.go
158 lines (133 loc) · 3.8 KB
/
nfs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// Copyright 2015 CoreOS, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package misc
import (
"fmt"
"path"
"time"
"github.com/coreos/mantle/kola/cluster"
"github.com/coreos/mantle/kola/register"
"github.com/coreos/mantle/platform/conf"
"github.com/coreos/mantle/util"
)
var (
nfsserverconf = conf.ContainerLinuxConfig(`storage:
files:
- filesystem: "root"
path: "/etc/hostname"
contents:
inline: "nfs1"
mode: 0644
- filesystem: "root"
path: "/etc/exports"
contents:
inline: "/tmp *(ro,insecure,all_squash,no_subtree_check,fsid=0)"
mode: 0644
- filesystem: "root"
path: "/var/lib/nfs/etab"
mode: 0644
systemd:
units:
- name: "nfs-server.service"
enabled: true`)
)
func init() {
register.Register(®ister.Test{
Run: NFSv3,
ClusterSize: 0,
Name: "linux.nfs.v3",
Distros: []string{"cl"},
// Disabled on Azure because setting hostname
// is required at the instance creation level
// qemu-unpriv machines cannot communicate
ExcludePlatforms: []string{"azure", "qemu-unpriv"},
})
// TODO: enable FCOS when FCCT exists
register.Register(®ister.Test{
Run: NFSv4,
ClusterSize: 0,
Name: "linux.nfs.v4",
ExcludeDistros: []string{"fcos"},
// Disabled on Azure because setting hostname
// is required at the instance creation level
// qemu-unpriv machines cannot communicate
ExcludePlatforms: []string{"azure", "qemu-unpriv"},
})
}
func testNFS(c cluster.TestCluster, nfsversion int, remotePath string) {
m1, err := c.NewMachine(nfsserverconf)
if err != nil {
c.Fatalf("Cluster.NewMachine: %s", err)
}
defer m1.Destroy()
c.Log("NFS server booted.")
/* poke a file in /tmp */
tmp := c.MustSSH(m1, "mktemp")
c.Logf("Test file %q created on server.", tmp)
nfstype := "nfs"
if nfsversion == 4 {
nfstype = "nfs4"
}
c2 := conf.ContainerLinuxConfig(fmt.Sprintf(`storage:
files:
- filesystem: "root"
path: "/etc/hostname"
contents:
inline: "nfs2"
mode: 0644
systemd:
units:
- name: "var-mnt.mount"
enabled: true
contents: |-
[Unit]
Description=NFS Client
After=network-online.target
Requires=network-online.target
After=rpc-statd.service
Requires=rpc-statd.service
[Mount]
What=%s:%s
Where=/var/mnt
Type=%s
Options=defaults,noexec,nfsvers=%d
[Install]
WantedBy=multi-user.target`, m1.PrivateIP(), remotePath, nfstype, nfsversion))
m2, err := c.NewMachine(c2)
if err != nil {
c.Fatalf("Cluster.NewMachine: %s", err)
}
defer m2.Destroy()
c.Log("NFS client booted.")
checkmount := func() error {
status, err := c.SSH(m2, "systemctl is-active var-mnt.mount")
if err != nil || string(status) != "active" {
return fmt.Errorf("var-mnt.mount status is %q: %v", status, err)
}
c.Log("Got NFS mount.")
return nil
}
if err = util.Retry(10, 3*time.Second, checkmount); err != nil {
c.Fatal(err)
}
c.MustSSH(m2, fmt.Sprintf("stat /var/mnt/%s", path.Base(string(tmp))))
}
// Test that the kernel NFS server and client work within CoreOS.
func NFSv3(c cluster.TestCluster) {
testNFS(c, 3, "/tmp")
}
// Test that NFSv4 without security works.
func NFSv4(c cluster.TestCluster) {
testNFS(c, 4, "/")
}