diff --git a/contrib/cirrus/setup_environment.sh b/contrib/cirrus/setup_environment.sh index 01956a1d64..436024ef69 100755 --- a/contrib/cirrus/setup_environment.sh +++ b/contrib/cirrus/setup_environment.sh @@ -147,19 +147,19 @@ esac # shellcheck disable=SC2154 case "$CI_DESIRED_DATABASE" in sqlite) - warn "Forcing PODMAN_DB=sqlite" - echo "PODMAN_DB=sqlite" >> /etc/ci_environment + warn "Forcing PODMAN_DB=sqlite" + echo "PODMAN_DB=sqlite" >> /etc/ci_environment ;; boltdb) - warn "Forcing PODMAN_DB=boltdb" - echo "PODMAN_DB=boltdb" >> /etc/ci_environment + warn "Forcing PODMAN_DB=boltdb" + echo "PODMAN_DB=boltdb" >> /etc/ci_environment ;; "") - warn "Using default Podman database" - ;; + warn "Using default Podman database" + ;; *) - die_unknown CI_DESIRED_DATABASE - ;; + die_unknown CI_DESIRED_DATABASE + ;; esac # Required to be defined by caller: The environment where primary testing happens diff --git a/libpod/sqlite_state.go b/libpod/sqlite_state.go index 72ee89fc35..8317fe4b7c 100644 --- a/libpod/sqlite_state.go +++ b/libpod/sqlite_state.go @@ -4,6 +4,7 @@ import ( "database/sql" "errors" "fmt" + "os" "path/filepath" goruntime "runtime" "strings" @@ -32,7 +33,19 @@ type SQLiteState struct { func NewSqliteState(runtime *Runtime) (_ State, defErr error) { state := new(SQLiteState) - conn, err := sql.Open("sqlite3", filepath.Join(runtime.storageConfig.GraphRoot, "db.sql?_loc=auto")) + basePath := runtime.storageConfig.GraphRoot + if runtime.storageConfig.TransientStore { + basePath = runtime.storageConfig.RunRoot + } + + // c/storage is set up *after* the DB - so even though we use the c/s + // root (or, for transient, runroot) dir, we need to make the dir + // ourselves. + if err := os.MkdirAll(basePath, 0700); err != nil { + return nil, fmt.Errorf("creating root directory: %w", err) + } + + conn, err := sql.Open("sqlite3", filepath.Join(basePath, "db.sql?_loc=auto")) if err != nil { return nil, fmt.Errorf("initializing sqlite database: %w", err) } diff --git a/test/e2e/libpod_suite_remote_test.go b/test/e2e/libpod_suite_remote_test.go index fcdd7496a2..433fa2eab2 100644 --- a/test/e2e/libpod_suite_remote_test.go +++ b/test/e2e/libpod_suite_remote_test.go @@ -134,8 +134,8 @@ func (p *PodmanTestIntegration) StopRemoteService() { // MakeOptions assembles all the podman main options func getRemoteOptions(p *PodmanTestIntegration, args []string) []string { networkDir := p.NetworkConfigDir - podmanOptions := strings.Split(fmt.Sprintf("--root %s --runroot %s --runtime %s --conmon %s --network-config-dir %s --network-backend %s --cgroup-manager %s", - p.Root, p.RunRoot, p.OCIRuntime, p.ConmonBinary, networkDir, p.NetworkBackend.ToString(), p.CgroupManager), " ") + podmanOptions := strings.Split(fmt.Sprintf("--root %s --runroot %s --runtime %s --conmon %s --network-config-dir %s --network-backend %s --cgroup-manager %s --database-backend %s", + p.Root, p.RunRoot, p.OCIRuntime, p.ConmonBinary, networkDir, p.NetworkBackend.ToString(), p.CgroupManager, p.DatabaseBackend), " ") podmanOptions = append(podmanOptions, strings.Split(p.StorageOptions, " ")...) podmanOptions = append(podmanOptions, args...) return podmanOptions diff --git a/test/e2e/prune_test.go b/test/e2e/prune_test.go index 906170b6eb..95a27051d8 100644 --- a/test/e2e/prune_test.go +++ b/test/e2e/prune_test.go @@ -563,7 +563,6 @@ var _ = Describe("Podman prune", func() { SkipIfRemote("Can't drop database while daemon running") containerStorageDir := filepath.Join(podmanTest.Root, podmanTest.ImageCacheFS+"-containers") - dbDir := filepath.Join(podmanTest.Root, "libpod") // Create container 1 create := podmanTest.Podman([]string{"create", "--name", "test", BB}) @@ -580,8 +579,15 @@ var _ = Describe("Podman prune", func() { // Drop podman database and storage, losing track of container 1 (but directory remains) err = os.Remove(filepath.Join(containerStorageDir, "containers.json")) Expect(err).ToNot(HaveOccurred()) - err = os.RemoveAll(dbDir) - Expect(err).ToNot(HaveOccurred()) + + if podmanTest.DatabaseBackend == "sqlite" { + err = os.Remove(filepath.Join(podmanTest.Root, "db.sql")) + Expect(err).ToNot(HaveOccurred()) + } else { + dbDir := filepath.Join(podmanTest.Root, "libpod") + err = os.RemoveAll(dbDir) + Expect(err).ToNot(HaveOccurred()) + } Expect(podmanTest.NumberOfContainers()).To(Equal(0)) diff --git a/test/e2e/run_transient_test.go b/test/e2e/run_transient_test.go index 863963c4cd..f5188682b3 100644 --- a/test/e2e/run_transient_test.go +++ b/test/e2e/run_transient_test.go @@ -56,8 +56,8 @@ var _ = Describe("Podman run with volumes", func() { Expect(filepath.Join(runContainerStorageDir, "volatile-containers.json")).Should(Not(BeAnExistingFile())) if podmanTest.DatabaseBackend == "sqlite" { - Expect(filepath.Join(containerStorageDir, "db.sql")).Should(BeARegularFile()) - Expect(filepath.Join(runContainerStorageDir, "db.sql")).Should(Not(BeAnExistingFile())) + Expect(filepath.Join(podmanTest.Root, "db.sql")).Should(BeARegularFile()) + Expect(filepath.Join(podmanTest.RunRoot, "db.sql")).Should(Not(BeAnExistingFile())) } else { Expect(filepath.Join(dbDir, "bolt_state.db")).Should(BeARegularFile()) Expect(filepath.Join(runDBDir, "bolt_state.db")).Should(Not(BeAnExistingFile())) @@ -76,8 +76,8 @@ var _ = Describe("Podman run with volumes", func() { Expect(filepath.Join(runContainerStorageDir, "volatile-containers.json")).Should(Not(BeAnExistingFile())) if podmanTest.DatabaseBackend == "sqlite" { - Expect(filepath.Join(containerStorageDir, "db.sql")).Should(BeARegularFile()) - Expect(filepath.Join(runContainerStorageDir, "db.sql")).Should(Not(BeAnExistingFile())) + Expect(filepath.Join(podmanTest.Root, "db.sql")).Should(BeARegularFile()) + Expect(filepath.Join(podmanTest.RunRoot, "db.sql")).Should(Not(BeAnExistingFile())) } else { Expect(filepath.Join(dbDir, "bolt_state.db")).Should(BeARegularFile()) Expect(filepath.Join(runDBDir, "bolt_state.db")).Should(Not(BeAnExistingFile())) @@ -97,8 +97,8 @@ var _ = Describe("Podman run with volumes", func() { Expect(filepath.Join(runContainerStorageDir, "volatile-containers.json")).Should(BeARegularFile()) if podmanTest.DatabaseBackend == "sqlite" { - Expect(filepath.Join(containerStorageDir, "db.sql")).Should(Not(BeAnExistingFile())) - Expect(filepath.Join(runContainerStorageDir, "db.sql")).Should(BeARegularFile()) + Expect(filepath.Join(podmanTest.Root, "db.sql")).Should(Not(BeAnExistingFile())) + Expect(filepath.Join(podmanTest.RunRoot, "db.sql")).Should(BeARegularFile()) } else { Expect(filepath.Join(dbDir, "bolt_state.db")).Should(Not(BeAnExistingFile())) Expect(filepath.Join(runDBDir, "bolt_state.db")).Should(BeARegularFile())