-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathzfs.go
237 lines (213 loc) · 6.26 KB
/
zfs.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
// Copyright The Mantle Authors.
// SPDX-License-Identifier: Apache-2.0
package sysext
import (
"fmt"
"net/http"
"github.com/coreos/go-semver/semver"
"github.com/flatcar/mantle/kola"
"github.com/flatcar/mantle/kola/cluster"
"github.com/flatcar/mantle/kola/register"
"github.com/flatcar/mantle/platform"
"github.com/flatcar/mantle/platform/conf"
"github.com/flatcar/mantle/platform/machine/qemu"
"github.com/flatcar/mantle/platform/machine/unprivqemu"
)
var zfsUserData = conf.Butane(`
variant: flatcar
version: 1.0.0
storage:
files:
- path: /etc/flatcar/enabled-sysext.conf
contents:
inline: |
zfs
systemd:
units:
- name: zpool-create.service
enabled: true
contents: |
[Unit]
ConditionFirstBoot=1
Before=first-boot-complete.target
Wants=first-boot-complete.target
[Service]
Type=oneshot
ExecStart=zpool create tank /dev/disk/by-id/virtio-zfs
[Install]
WantedBy=multi-user.target
`)
var zfsDockerUserData = conf.Butane(`
variant: flatcar
version: 1.0.0
storage:
files:
- path: /etc/flatcar/enabled-sysext.conf
contents:
inline: |
zfs
- path: /etc/docker/daemon.json
contents:
inline: |
{
"storage-driver": "zfs"
}
systemd:
units:
- name: docker.service
dropins:
- name: zfs.conf
contents: |
[Unit]
After=zfs.target
- name: zpool-create.service
enabled: true
contents: |
[Unit]
ConditionFirstBoot=1
Before=first-boot-complete.target
Wants=first-boot-complete.target
[Service]
Type=oneshot
ExecStart=zpool create tank /dev/disk/by-id/virtio-zfs
ExecStart=zfs create -o mountpoint=/var/lib/docker tank/docker
[Install]
WantedBy=multi-user.target
`)
var zfsNfsUserData = conf.Butane(`
variant: flatcar
version: 1.0.0
storage:
files:
- path: /etc/flatcar/enabled-sysext.conf
contents:
inline: |
zfs
systemd:
units:
- name: nfs-server.service
enabled: true
- name: zpool-create.service
enabled: true
contents: |
[Unit]
ConditionFirstBoot=1
Before=first-boot-complete.target
Wants=first-boot-complete.target
[Service]
Type=oneshot
ExecStart=zpool create tank /dev/disk/by-id/virtio-zfs
ExecStart=zfs create -o sharenfs=on tank/nfs
[Install]
WantedBy=multi-user.target
`)
var nfsClientUserData = conf.Butane(`
variant: flatcar
version: 1.0.0
systemd:
units:
- name: nfs-client.target
enabled: true
`)
func init() {
register.Register(®ister.Test{
Name: "sysext.zfs.reboot",
Run: checkSysextZfs,
ClusterSize: 0,
Distros: []string{"cl"},
// This test is normally not related to the cloud environment
Platforms: []string{"qemu", "qemu-unpriv"},
MinVersion: semver.Version{Major: 3902},
SkipFunc: skipZfs,
})
register.Register(®ister.Test{
Name: "sysext.zfs.docker",
Run: checkZfsDocker,
ClusterSize: 0,
Distros: []string{"cl"},
// This test is normally not related to the cloud environment
Platforms: []string{"qemu", "qemu-unpriv"},
MinVersion: semver.Version{Major: 3902},
SkipFunc: skipZfs,
})
register.Register(®ister.Test{
Name: "sysext.zfs.nfs",
Run: checkZfsNfs,
ClusterSize: 0,
Distros: []string{"cl"},
// This test is normally not related to the cloud environment
Platforms: []string{"qemu", "qemu-unpriv"},
MinVersion: semver.Version{Major: 3902},
SkipFunc: skipZfs,
})
}
func skipZfs(version semver.Version, channel, arch, platform string) bool {
return kola.SkipSecureboot(version, channel, arch, platform) || skipOnGha(version, channel, arch, platform)
}
func skipOnGha(version semver.Version, channel, arch, platform string) bool {
// Skip for release tests as we don't yet have a sysext signed with the
// prod key, nor is it on the release server.
if len(version.Metadata) == 0 {
return true
}
// GHA doesn't upload to bincache so we won't be able to fetch the sysext :(
reply, err := http.Head(fmt.Sprintf("https://bincache.flatcar-linux.net/images/%s/%s/version.txt", arch, version))
if reply.StatusCode != 200 || err != nil {
return true
}
return false
}
func createZfsMachine(c cluster.TestCluster, userdata *conf.UserData) platform.Machine {
var m platform.Machine
var err error
options := platform.MachineOptions{
AdditionalDisks: []platform.Disk{
{Size: "1G", DeviceOpts: []string{"serial=zfs"}},
},
}
switch pc := c.Cluster.(type) {
// These cases have to be separated because when put together to the same case statement
// the golang compiler no longer checks that the individual types in the case have the
// NewMachineWithOptions function, but rather whether platform.Cluster does which fails
case *qemu.Cluster:
m, err = pc.NewMachineWithOptions(userdata, options)
case *unprivqemu.Cluster:
m, err = pc.NewMachineWithOptions(userdata, options)
default:
c.Fatal("unknown cluster type")
}
if err != nil {
c.Fatalf("creating a machine failed: %v", err)
}
return m
}
func checkSysextZfs(c cluster.TestCluster) {
m := createZfsMachine(c, zfsUserData)
c.AssertCmdOutputContains(m, "findmnt /tank", "zfs")
c.AssertCmdOutputContains(m, "zpool list -H -o name", "tank")
c.AssertCmdOutputContains(m, "zfs list -H -o name", "tank")
c.MustSSH(m, "sudo chown core /tank/ && echo world >/tank/hello")
err := m.Reboot()
if err != nil {
c.Fatalf("could not reboot: %v", err)
}
c.AssertCmdOutputContains(m, "lsmod", "zfs")
c.AssertCmdOutputContains(m, "grep --with-filename . /tank/hello", "hello:world")
}
func checkZfsDocker(c cluster.TestCluster) {
m := createZfsMachine(c, zfsDockerUserData)
c.AssertCmdOutputContains(m, "docker info -f '{{.Driver}}'", "zfs")
c.AssertCmdOutputContains(m, "docker run --rm ghcr.io/flatcar/busybox mount", "zfs")
}
func checkZfsNfs(c cluster.TestCluster) {
m := createZfsMachine(c, zfsNfsUserData)
c.MustSSH(m, "sudo chown core /tank/nfs")
c.MustSSH(m, "echo world >/tank/nfs/hello")
m2, err := c.NewMachine(nfsClientUserData)
if err != nil {
c.Fatalf("Cluster.NewMachine: %s", err)
}
c.MustSSH(m2, "sudo mkdir /mnt/nfs")
c.MustSSH(m2, fmt.Sprintf("sudo mount -t nfs -o nfsvers=4 %s:/tank/nfs /mnt/nfs", m.PrivateIP()))
c.AssertCmdOutputContains(m2, "cat /mnt/nfs/hello", "world")
}