-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kola/tests: add /var/lib/containers to separate disk test
Customers have requested the ability to use a separate disk for /var/lib/containers as a day two operation. This is a sanity test that makes sure this can be done with systemd units as described in the knowlege base article [0]. [0] https://access.redhat.com/solutions/4952011
- Loading branch information
1 parent
3094bfb
commit ada2087
Showing
1 changed file
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
// Copyright 2020 Red Hat, 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 rhcos | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
ignconverter "github.com/coreos/ign-converter" | ||
ignv3types "github.com/coreos/ignition/v2/config/v3_0/types" | ||
"github.com/coreos/mantle/kola/cluster" | ||
"github.com/coreos/mantle/kola/register" | ||
"github.com/coreos/mantle/platform" | ||
"github.com/coreos/mantle/platform/conf" | ||
"github.com/coreos/mantle/platform/machine/unprivqemu" | ||
"github.com/coreos/mantle/util" | ||
) | ||
|
||
func init() { | ||
register.RegisterTest(®ister.Test{ | ||
Run: varLibContainers, | ||
ClusterSize: 0, | ||
Name: `rhcos.disk.varlibcontainers`, | ||
Flags: []register.Flag{}, | ||
Distros: []string{"rhcos"}, | ||
Platforms: []string{"qemu-unpriv"}, | ||
}) | ||
} | ||
|
||
func varLibContainers(c cluster.TestCluster) { | ||
var m platform.Machine | ||
var err error | ||
disk := "secondary" | ||
varMountName := "var-lib-containers.mount" | ||
mkfsServiceName := fmt.Sprintf("systemd-mkfs@dev-disk-by-id-virtio-%s.service", disk) | ||
|
||
options := platform.MachineOptions{ | ||
AdditionalDisks: []platform.Disk{ | ||
{Size: "1024M", DeviceOpts: []string{"serial=secondary"}}, | ||
}, | ||
} | ||
|
||
mkfsUnit := fmt.Sprintf(`[Unit] | ||
Description=Make File System on /dev/disk/by-id/%[1]s | ||
DefaultDependencies=no | ||
BindsTo=dev-disk-by\x2did-virtio\x2d%[1]s.device | ||
After=dev-disk-by\x2did-virtio\x2d%[1]s.device var.mount | ||
Before=systemd-fsck@dev-disk-by\x2did-virtio\x2d%[1]s.service | ||
Before=shutdown.target | ||
[Service] | ||
Type=oneshot | ||
RemainAfterExit=yes | ||
ExecStart=/bin/bash -c "/bin/rm -rf /var/lib/containers/*" | ||
ExecStart=mkfs.xfs /dev/disk/by-id/virtio-%[1]s | ||
TimeoutSec=0 | ||
[Install] | ||
WantedBy=var-lib-containers.mount`, disk) | ||
|
||
varMountUnit := fmt.Sprintf(`[Unit] | ||
Description=Mount secondary disk to /var/lib/containers | ||
Before=local-fs.target | ||
Requires=%[1]s | ||
After=%[1]s | ||
[Mount] | ||
What=/dev/disk/by-id/virtio-%[2]s | ||
Where=/var/lib/containers | ||
Type=xfs | ||
Options=defaults,prjquota | ||
[Install] | ||
WantedBy=local-fs.target`, mkfsServiceName, disk) | ||
|
||
config := ignv3types.Config{ | ||
Ignition: ignv3types.Ignition{ | ||
Version: "3.0.0", | ||
}, | ||
Systemd: ignv3types.Systemd{ | ||
Units: []ignv3types.Unit{ | ||
{ | ||
Name: mkfsServiceName, | ||
Contents: &mkfsUnit, | ||
Enabled: util.BoolToPtr(true), | ||
}, | ||
{ | ||
Name: varMountName, | ||
Contents: &varMountUnit, | ||
Enabled: util.BoolToPtr(false), | ||
}, | ||
}, | ||
}, | ||
} | ||
convertedConf, err := ignconverter.Translate3to2(config) | ||
buf, err := json.Marshal(convertedConf) | ||
if err != nil { | ||
c.Fatalf("Unable to Marshal config") | ||
} | ||
serializedConfig := buf | ||
|
||
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 *unprivqemu.Cluster: | ||
m, err = pc.NewMachineWithOptions(conf.Ignition(string(serializedConfig)), options, true) | ||
default: | ||
c.Fatal("unknown cluster type") | ||
} | ||
|
||
if err != nil { | ||
c.Fatal(err) | ||
} | ||
|
||
// Verify /var/lib/containers isn't mounted then enable the units to move | ||
// it to the secondary disk | ||
vlc := "/var/lib/containers" | ||
if mount, err := c.SSH(m, fmt.Sprintf("findmnt %s -n -o SOURCE", vlc)); err == nil { | ||
c.Fatalf("%s is already mounted on %s", vlc, string(mount)) | ||
} | ||
c.MustSSH(m, "podman run docker.io/hello-world") | ||
c.MustSSH(m, fmt.Sprintf("sudo systemctl enable %s", mkfsServiceName)) | ||
c.MustSSH(m, fmt.Sprintf("sudo systemctl enable %s", varMountName)) | ||
if err := m.Reboot(); err != nil { | ||
c.Fatal("Unable to reboot") | ||
} | ||
|
||
// Verify /var/lib/containers is now mounted on the secondary disk | ||
secondaryDisk := c.MustSSH(m, fmt.Sprintf("readlink -f /dev/disk/by-id/virtio-%s", disk)) | ||
mount := c.MustSSH(m, fmt.Sprintf("findmnt %s -n -o SOURCE", vlc)) | ||
if string(secondaryDisk) != string(mount) { | ||
c.Fatalf("%s is not mounted on %s", vlc, secondaryDisk) | ||
} | ||
c.MustSSH(m, "podman run docker.io/hello-world") | ||
} |