github.com/coreos/mantle@v0.13.0/kola/tests/ignition/filesystem.go (about) 1 // Copyright 2016 CoreOS, 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 ignition 16 17 import ( 18 "strings" 19 20 "github.com/coreos/mantle/kola/cluster" 21 "github.com/coreos/mantle/kola/register" 22 "github.com/coreos/mantle/platform/conf" 23 ) 24 25 const ( 26 targetUUID = "9aa5237a-ab6b-458b-a7e8-f25e2baef1a3" 27 targetVfatID = "1A37-8FA3" 28 ) 29 30 func init() { 31 // Reformat the root as btrfs 32 btrfsConfigV1 := conf.Ignition(`{ 33 "ignitionVersion": 1, 34 "storage": { 35 "filesystems": [ 36 { 37 "device": "/dev/disk/by-partlabel/ROOT", 38 "format": "btrfs", 39 "create": { 40 "force": true, 41 "options": [ 42 "--label=ROOT", 43 "--uuid=` + targetUUID + `" 44 ] 45 } 46 } 47 ] 48 } 49 }`) 50 btrfsConfigV2 := conf.Ignition(`{ 51 "ignition": { 52 "version": "2.0.0" 53 }, 54 "storage": { 55 "filesystems": [ 56 { 57 "mount": { 58 "device": "/dev/disk/by-label/ROOT", 59 "format": "btrfs", 60 "create": { 61 "force": true, 62 "options": [ 63 "--label=ROOT", 64 "--uuid=` + targetUUID + `" 65 ] 66 } 67 } 68 } 69 ] 70 } 71 }`) 72 register.Register(®ister.Test{ 73 Name: "cl.ignition.v1.btrfsroot", 74 Run: btrfsRoot, 75 ClusterSize: 1, 76 UserData: btrfsConfigV1, 77 Distros: []string{"cl"}, 78 }) 79 register.Register(®ister.Test{ 80 Name: "cl.ignition.v2.btrfsroot", 81 Run: btrfsRoot, 82 ClusterSize: 1, 83 UserData: btrfsConfigV2, 84 Distros: []string{"cl"}, 85 }) 86 87 // Reformat the root as xfs 88 xfsConfigV1 := conf.Ignition(`{ 89 "ignitionVersion": 1, 90 "storage": { 91 "filesystems": [ 92 { 93 "device": "/dev/disk/by-partlabel/ROOT", 94 "format": "xfs", 95 "create": { 96 "force": true, 97 "options": [ 98 "-L", "ROOT", 99 "-m", "uuid=` + targetUUID + `" 100 ] 101 } 102 } 103 ] 104 } 105 }`) 106 xfsConfigV2 := conf.Ignition(`{ 107 "ignition": { 108 "version": "2.0.0" 109 }, 110 "storage": { 111 "filesystems": [ 112 { 113 "mount": { 114 "device": "/dev/disk/by-partlabel/ROOT", 115 "format": "xfs", 116 "create": { 117 "force": true, 118 "options": [ 119 "-L", "ROOT", 120 "-m", "uuid=` + targetUUID + `" 121 ] 122 } 123 } 124 } 125 ] 126 } 127 }`) 128 register.Register(®ister.Test{ 129 Name: "cl.ignition.v1.xfsroot", 130 Run: xfsRoot, 131 ClusterSize: 1, 132 UserData: xfsConfigV1, 133 Distros: []string{"cl"}, 134 }) 135 register.Register(®ister.Test{ 136 Name: "cl.ignition.v2.xfsroot", 137 Run: xfsRoot, 138 ClusterSize: 1, 139 UserData: xfsConfigV2, 140 Distros: []string{"cl"}, 141 }) 142 143 // Reformat the root as ext4 144 ext4ConfigV1 := conf.Ignition(`{ 145 "ignitionVersion": 1, 146 "storage": { 147 "filesystems": [ 148 { 149 "device": "/dev/disk/by-partlabel/ROOT", 150 "format": "ext4", 151 "create": { 152 "force": true, 153 "options": [ 154 "-L", "ROOT", 155 "-U", "` + targetUUID + `" 156 ] 157 } 158 } 159 ] 160 } 161 }`) 162 ext4ConfigV2 := conf.Ignition(`{ 163 "ignition": { 164 "version": "2.0.0" 165 }, 166 "storage": { 167 "filesystems": [ 168 { 169 "mount": { 170 "device": "/dev/disk/by-partlabel/ROOT", 171 "format": "ext4", 172 "create": { 173 "force": true, 174 "options": [ 175 "-L", "ROOT", 176 "-U", "` + targetUUID + `" 177 ] 178 } 179 } 180 } 181 ] 182 } 183 }`) 184 register.Register(®ister.Test{ 185 Name: "cl.ignition.v1.ext4root", 186 Run: ext4Root, 187 ClusterSize: 1, 188 UserData: ext4ConfigV1, 189 Distros: []string{"cl"}, 190 }) 191 register.Register(®ister.Test{ 192 Name: "cl.ignition.v2.ext4root", 193 Run: ext4Root, 194 ClusterSize: 1, 195 UserData: ext4ConfigV2, 196 Distros: []string{"cl"}, 197 }) 198 register.Register(®ister.Test{ 199 Name: "cl.ignition.v2_1.ext4checkexisting", 200 Run: ext4CheckExisting, 201 ClusterSize: 1, 202 Distros: []string{"cl"}, 203 }) 204 205 vfatConfigV2_1 := conf.Ignition(`{ 206 "ignition": { 207 "version": "2.1.0" 208 }, 209 "storage": { 210 "filesystems": [ 211 { 212 "mount": { 213 "device": "/dev/disk/by-partlabel/USR-B", 214 "format": "vfat", 215 "wipeFilesystem": true, 216 "label": "USR-B", 217 "uuid": "` + targetVfatID + `" 218 } 219 } 220 ] 221 } 222 }`) 223 register.Register(®ister.Test{ 224 Name: "cl.ignition.v2_1.vfat", 225 Run: vfatUsrB, 226 ClusterSize: 1, 227 UserData: vfatConfigV2_1, 228 Distros: []string{"cl"}, 229 }) 230 231 swapConfigV2_1 := conf.Ignition(`{ 232 "ignition": { 233 "version": "2.1.0" 234 }, 235 "storage": { 236 "filesystems": [ 237 { 238 "mount": { 239 "device": "/dev/disk/by-partlabel/USR-B", 240 "format": "swap", 241 "wipeFilesystem": true, 242 "label": "USR-B", 243 "uuid": "` + targetUUID + `" 244 } 245 } 246 ] 247 } 248 }`) 249 register.Register(®ister.Test{ 250 Name: "cl.ignition.v2_1.swap", 251 Run: swapUsrB, 252 ClusterSize: 1, 253 UserData: swapConfigV2_1, 254 Distros: []string{"cl"}, 255 }) 256 } 257 258 var ext4NoClobberV2_1 = conf.Ignition(`{ 259 "ignition": { 260 "version": "2.1.0" 261 }, 262 "storage": { 263 "filesystems": [ 264 { 265 "mount": { 266 "device": "/dev/disk/by-partlabel/ROOT", 267 "format": "ext4", 268 "label": "ROOT" 269 } 270 } 271 ] 272 } 273 }`) 274 275 func btrfsRoot(c cluster.TestCluster) { 276 testRoot(c, "btrfs") 277 } 278 279 func xfsRoot(c cluster.TestCluster) { 280 testRoot(c, "xfs") 281 } 282 283 func ext4Root(c cluster.TestCluster) { 284 testRoot(c, "ext4") 285 } 286 287 func vfatUsrB(c cluster.TestCluster) { 288 testFormatted(c, "vfat", "USR-B") 289 } 290 291 func swapUsrB(c cluster.TestCluster) { 292 testFormatted(c, "swap", "USR-B") 293 } 294 295 func testFormatted(c cluster.TestCluster, fs, label string) { 296 m := c.Machines()[0] 297 298 out := c.MustSSH(m, "sudo blkid -s UUID -o value /dev/disk/by-label/"+label) 299 target := targetUUID 300 if fs == "vfat" { 301 target = targetVfatID 302 } 303 if strings.TrimRight(string(out), "\n") != target { 304 c.Fatalf("filesystem wasn't correctly formatted:\n%s", out) 305 } 306 307 out = c.MustSSH(m, "sudo blkid -s TYPE -o value /dev/disk/by-label/"+label) 308 if strings.TrimRight(string(out), "\n") != fs { 309 c.Fatalf("filesystem has incorrect type:\n%s", out) 310 } 311 } 312 313 func testRoot(c cluster.TestCluster, fs string) { 314 m := c.Machines()[0] 315 316 testFormatted(c, fs, "ROOT") 317 318 out := c.MustSSH(m, "findmnt --noheadings --output FSTYPE --target /") 319 if string(out) != fs { 320 c.Fatalf("root wasn't correctly reformatted:\n%s", out) 321 } 322 } 323 324 func ext4CheckExisting(c cluster.TestCluster) { 325 m1 := c.Machines()[0] 326 327 // Get root filesystem UUID 328 out := c.MustSSH(m1, "sudo blkid /dev/disk/by-partlabel/ROOT -s UUID -o value") 329 uuid1 := strings.TrimRight(string(out), "\n") 330 331 // Start a machine with config that conditionally recreates the FS 332 m2, err := c.NewMachine(ext4NoClobberV2_1) 333 if err != nil { 334 c.Fatalf("Couldn't start machine: %v", err) 335 } 336 337 // Verify UUID hasn't changed 338 out = c.MustSSH(m2, "sudo blkid /dev/disk/by-partlabel/ROOT -s UUID -o value") 339 uuid2 := strings.TrimRight(string(out), "\n") 340 if uuid1 != uuid2 { 341 c.Fatalf("Filesystem was reformatted: %s != %s", uuid1, uuid2) 342 } 343 }