Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests/update: Add test for docker btrfs storage driver #475

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 77 additions & 7 deletions kola/tests/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,25 @@ func init() {
return kola.UpdatePayloadFile == ""
},
})
register.Register(&register.Test{
Name: "cl.update.docker-btrfs-compat",
Run: btrfs_compat,
ClusterSize: 1,
NativeFuncs: map[string]func() error{
"Omaha": Serve,
},
// This test is normally not related to the cloud environment
Platforms: []string{"qemu", "qemu-unpriv"},
// This test verifies preservation of storage driver "btrfs" for docker.
// Docker releases before v23 defaulted to btrfs if the docker can only run if the update payload to test is given.
// The image passed must also be a release lower than or equal to 3760.0.0
// because newer versions ship docker 24.
EndVersion: semver.Version{Major: 3760},
Comment on lines +66 to +70
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we should have a separate test that boots the old release (but new enough to be with docker 24) with a config that forces btrfs storage driver, pulls an image and creates a container, so the storage is used. Then drops the config and updates the OS to see if btrfs driver is still used. Similar to this test, but would make sure nothing breaks after a sequence of [old OS with old docker using btrfs storage] -> [newer OS with new docker using inherited btrfs storage] -> [shiny new OS with new docker still using the inherited btrfs storage] (your test checks the first transition, another would test the second transition). Such test would probably need to be minimum 3760.0.0. Or maybe we could drop the EndVersion and make this test work regardless of the docker version.

Copy link
Member Author

@t-lo t-lo Nov 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think an intermediate update to Docker 24 would make any difference since I don't think docker stores any configuration data, but instead auto-detects whether to use btrfs. The "newest" Docker would need to auto-detect the need to use the btrfs storage driver either way, no matter if it was upgraded from docker 20 or docker 24.

SkipFunc: func(version semver.Version, channel, arch, platform string) bool {
return kola.UpdatePayloadFile == ""
},
Distros: []string{"cl"},
})
register.Register(&register.Test{
Name: "cl.update.oem",
Run: oemPayload,
Expand Down Expand Up @@ -141,13 +160,13 @@ func Serve() error {
return omahawrapper.Serve()
}

func payload(c cluster.TestCluster) {
func payloadPrepareMachine(conf *conf.UserData, c cluster.TestCluster) (string, platform.Machine) {
addr := configureOmahaServer(c, c.Machines()[0])

// create the actual test machine, the machine
// that is created by the test registration is
// used to host the omaha server
m, err := c.NewMachine(nil)
m, err := c.NewMachine(conf)
if err != nil {
c.Fatalf("creating test machine: %v", err)
}
Expand All @@ -156,13 +175,14 @@ func payload(c cluster.TestCluster) {
// via SSH to allow for testing versions which predate
// Ignition
configureMachineForUpdate(c, m, addr)

tutil.AssertBootedUsr(c, m, "USR-A")

updateMachine(c, m)
return addr, m
}

func payloadPerformUpdate(addr string, m platform.Machine, c cluster.TestCluster) {
updateMachine(c, m)
tutil.AssertBootedUsr(c, m, "USR-B")

tutil.InvalidateUsrPartition(c, m, "USR-A")

/*
Expand All @@ -174,12 +194,62 @@ func payload(c cluster.TestCluster) {
We configure again to inject the dev-pub-key to correctly verify the downloaded payload
*/
configureMachineForUpdate(c, m, addr)

updateMachine(c, m)

tutil.AssertBootedUsr(c, m, "USR-A")
}

func payload(c cluster.TestCluster) {
addr, m := payloadPrepareMachine(nil, c)
payloadPerformUpdate(addr, m, c)
}

func btrfs_compat(c cluster.TestCluster) {
conf := conf.ContainerLinuxConfig(`
systemd:
units:
- name: format-var-lib-docker.service
enabled: true
contents: |
[Unit]
Before=docker.service var-lib-docker.mount
ConditionPathExists=!/var/lib/docker.btrfs
[Service]
Type=oneshot
ExecStart=/usr/bin/truncate --size=25G /var/lib/docker.btrfs
ExecStart=/usr/sbin/mkfs.btrfs /var/lib/docker.btrfs
[Install]
WantedBy=multi-user.target
- name: var-lib-docker.mount
enabled: true
contents: |
[Unit]
Before=docker.service
After=format-var-lib-docker.service
Requires=format-var-lib-docker.service
[Install]
RequiredBy=docker.service
[Mount]
What=/var/lib/docker.btrfs
Where=/var/lib/docker
Type=btrfs
Options=loop,discard`)

addr, m := payloadPrepareMachine(conf, c)

// We need to populate the docker storage.
// If empty, docker 23 and above will silently switch to the 'overlay2' driver.
// If populated, docker SHOULD preserve the btrfs driver. That's what we test for later.
c.MustSSH(m, `docker info | grep 'Storage Driver: btrfs' || { echo "ERROR: expected BTRFS storage driver"; docker info; exit 1; }`)
c.MustSSH(m, `docker run -i --name docker_btrfs_driver_test alpine ls /`)

payloadPerformUpdate(addr, m, c)

c.MustSSH(m, `docker info | grep 'Storage Driver: btrfs' || { echo "ERROR: expected BTRFS storage driver"; docker info; exit 1; }`)

c.MustSSH(m, `docker image ls | grep alpine || { echo "ERROR: Container image 'alpine' disappeared after update"; docker image ls; exit 1; } `)
c.MustSSH(m, `docker ps --all | grep docker_btrfs_driver_test || { echo "ERROR: Container 'docker_btrfs_driver_test' disappeared after update"; docker ps --all; exit 1; } `)
}

func configureOmahaServer(c cluster.TestCluster, srv platform.Machine) string {
in, err := os.Open(kola.UpdatePayloadFile)
if err != nil {
Expand Down