Skip to content
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
42 changes: 42 additions & 0 deletions test/e2e/info_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package integration

import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"

"github.com/containers/libpod/pkg/rootless"
. "github.com/containers/libpod/test/utils"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -50,4 +55,41 @@ var _ = Describe("Podman Info", func() {
Expect(session.ExitCode()).To(Equal(0))
Expect(session.OutputToString()).To(ContainSubstring("registry"))
})

It("podman info rootless storage path", func() {
if !rootless.IsRootless() {
Skip("test of rootless_storage_path is only meaningful as rootless")
}
SkipIfRemote()
oldHOME, hasHOME := os.LookupEnv("HOME")
defer func() {
if hasHOME {
os.Setenv("HOME", oldHOME)
} else {
os.Unsetenv("HOME")
}
}()
os.Setenv("HOME", podmanTest.TempDir)
configPath := filepath.Join(os.Getenv("HOME"), ".config", "containers", "storage.conf")
err := os.RemoveAll(filepath.Dir(configPath))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This makes me uncomfortable. I think these tests run only in CI, and can't be run by developers, but if that ever changes this could be catastrophic for regular users: it would destroy their existing storage.conf.

Did you consider something such as this instead?

    preserved_home := getenv("HOME")
    (add magic fail-safe such that HOME is restored on exit or failure)
    setenv("HOME", random-tmpdir)
    ...then create the storage.conf, etc

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Lets try that.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fixed

Expect(err).To(BeNil())

err = os.MkdirAll(filepath.Dir(configPath), os.ModePerm)
Expect(err).To(BeNil())

rootlessStoragePath := `"/tmp/$HOME/$USER/$UID"`
driver := `"overlay"`
storageOpt := `"/usr/bin/fuse-overlayfs"`
storageConf := []byte(fmt.Sprintf("[storage]\ndriver=%s\nrootless_storage_path=%s\n[storage.options]\nmount_program=%s", driver, rootlessStoragePath, storageOpt))
err = ioutil.WriteFile(configPath, storageConf, os.ModePerm)
Expect(err).To(BeNil())

expect := filepath.Join("/tmp", os.Getenv("HOME"), os.Getenv("USER"), os.Getenv("UID"))
podmanPath := podmanTest.PodmanTest.PodmanBinary
cmd := exec.Command(podmanPath, "info", "--format", "{{.Store.GraphRoot}}")
out, err := cmd.CombinedOutput()
fmt.Println(string(out))
Expect(err).To(BeNil())
Expect(string(out)).To(ContainSubstring(expect))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It'd be better to compare the string exactly, not substring, but I'm OK with this as it is. Just make a note for future work: exact comparisons are better than substring.

})
})