Skip to content

Commit

Permalink
test/e2e: improve write/removeConf()
Browse files Browse the repository at this point in the history
First use proper ginkgo error handling to ensure errors are actually
reported and fail the test. Mark it as helper function to have better
stack traces.

Then use a atomic write function to prevent issues with partial written
files. I think this is causing CI flakes[1].

Lastly fix the file permissions, do not make it world writable and do
not set the executable bit on the file.

[1] https://api.cirrus-ci.com/v1/artifact/task/5985244932734976/html/int-podman-fedora-41-root-host-sqlite.log.html#t--Podman-network-podman-network-ID-test--1

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
  • Loading branch information
Luap99 committed Feb 3, 2025
1 parent e300f5c commit dcdf82e
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions test/e2e/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/containers/podman/v5/pkg/inspect"
. "github.com/containers/podman/v5/test/utils"
"github.com/containers/podman/v5/utils"
"github.com/containers/storage/pkg/ioutils"
"github.com/containers/storage/pkg/lockfile"
"github.com/containers/storage/pkg/reexec"
"github.com/containers/storage/pkg/stringid"
Expand Down Expand Up @@ -1187,19 +1188,21 @@ func (p *PodmanTestIntegration) makeOptions(args []string, options PodmanExecOpt
}

func writeConf(conf []byte, confPath string) {
if _, err := os.Stat(filepath.Dir(confPath)); os.IsNotExist(err) {
if err := os.MkdirAll(filepath.Dir(confPath), 0o777); err != nil {
GinkgoWriter.Println(err)
}
}
if err := os.WriteFile(confPath, conf, 0o777); err != nil {
GinkgoWriter.Println(err)
}
GinkgoHelper()
err := os.MkdirAll(filepath.Dir(confPath), 0o755)
Expect(err).ToNot(HaveOccurred())

err = ioutils.AtomicWriteFile(confPath, conf, 0o644)
Expect(err).ToNot(HaveOccurred())
}

func removeConf(confPath string) {
if err := os.Remove(confPath); err != nil {
GinkgoWriter.Println(err)
GinkgoHelper()
err := os.Remove(confPath)
// Network remove test will remove the config and then this can fail.
// If the config does not exists no reason to hard error here.
if !errors.Is(err, os.ErrNotExist) {
Expect(err).ToNot(HaveOccurred())
}
}

Expand Down

0 comments on commit dcdf82e

Please sign in to comment.