Ensure SQLite places uses the runroot in transient mode
Transient mode means the DB should not persist, so instead of using the GraphRoot we should use the RunRoot instead. Signed-off-by: Matt Heon <mheon@redhat.com>
This commit is contained in:
parent
2ec11b16ab
commit
6142c16a9c
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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())
|
||||
|
||||
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))
|
||||
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in New Issue