mirror of
https://github.com/containers/podman.git
synced 2025-08-06 19:44:14 +08:00
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:
@ -147,19 +147,19 @@ esac
|
|||||||
# shellcheck disable=SC2154
|
# shellcheck disable=SC2154
|
||||||
case "$CI_DESIRED_DATABASE" in
|
case "$CI_DESIRED_DATABASE" in
|
||||||
sqlite)
|
sqlite)
|
||||||
warn "Forcing PODMAN_DB=sqlite"
|
warn "Forcing PODMAN_DB=sqlite"
|
||||||
echo "PODMAN_DB=sqlite" >> /etc/ci_environment
|
echo "PODMAN_DB=sqlite" >> /etc/ci_environment
|
||||||
;;
|
;;
|
||||||
boltdb)
|
boltdb)
|
||||||
warn "Forcing PODMAN_DB=boltdb"
|
warn "Forcing PODMAN_DB=boltdb"
|
||||||
echo "PODMAN_DB=boltdb" >> /etc/ci_environment
|
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
|
esac
|
||||||
|
|
||||||
# Required to be defined by caller: The environment where primary testing happens
|
# Required to be defined by caller: The environment where primary testing happens
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
goruntime "runtime"
|
goruntime "runtime"
|
||||||
"strings"
|
"strings"
|
||||||
@ -32,7 +33,19 @@ type SQLiteState struct {
|
|||||||
func NewSqliteState(runtime *Runtime) (_ State, defErr error) {
|
func NewSqliteState(runtime *Runtime) (_ State, defErr error) {
|
||||||
state := new(SQLiteState)
|
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 {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("initializing sqlite database: %w", err)
|
return nil, fmt.Errorf("initializing sqlite database: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -134,8 +134,8 @@ func (p *PodmanTestIntegration) StopRemoteService() {
|
|||||||
// MakeOptions assembles all the podman main options
|
// MakeOptions assembles all the podman main options
|
||||||
func getRemoteOptions(p *PodmanTestIntegration, args []string) []string {
|
func getRemoteOptions(p *PodmanTestIntegration, args []string) []string {
|
||||||
networkDir := p.NetworkConfigDir
|
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",
|
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.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, strings.Split(p.StorageOptions, " ")...)
|
||||||
podmanOptions = append(podmanOptions, args...)
|
podmanOptions = append(podmanOptions, args...)
|
||||||
return podmanOptions
|
return podmanOptions
|
||||||
|
@ -563,7 +563,6 @@ var _ = Describe("Podman prune", func() {
|
|||||||
SkipIfRemote("Can't drop database while daemon running")
|
SkipIfRemote("Can't drop database while daemon running")
|
||||||
|
|
||||||
containerStorageDir := filepath.Join(podmanTest.Root, podmanTest.ImageCacheFS+"-containers")
|
containerStorageDir := filepath.Join(podmanTest.Root, podmanTest.ImageCacheFS+"-containers")
|
||||||
dbDir := filepath.Join(podmanTest.Root, "libpod")
|
|
||||||
|
|
||||||
// Create container 1
|
// Create container 1
|
||||||
create := podmanTest.Podman([]string{"create", "--name", "test", BB})
|
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)
|
// Drop podman database and storage, losing track of container 1 (but directory remains)
|
||||||
err = os.Remove(filepath.Join(containerStorageDir, "containers.json"))
|
err = os.Remove(filepath.Join(containerStorageDir, "containers.json"))
|
||||||
Expect(err).ToNot(HaveOccurred())
|
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))
|
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()))
|
Expect(filepath.Join(runContainerStorageDir, "volatile-containers.json")).Should(Not(BeAnExistingFile()))
|
||||||
|
|
||||||
if podmanTest.DatabaseBackend == "sqlite" {
|
if podmanTest.DatabaseBackend == "sqlite" {
|
||||||
Expect(filepath.Join(containerStorageDir, "db.sql")).Should(BeARegularFile())
|
Expect(filepath.Join(podmanTest.Root, "db.sql")).Should(BeARegularFile())
|
||||||
Expect(filepath.Join(runContainerStorageDir, "db.sql")).Should(Not(BeAnExistingFile()))
|
Expect(filepath.Join(podmanTest.RunRoot, "db.sql")).Should(Not(BeAnExistingFile()))
|
||||||
} else {
|
} else {
|
||||||
Expect(filepath.Join(dbDir, "bolt_state.db")).Should(BeARegularFile())
|
Expect(filepath.Join(dbDir, "bolt_state.db")).Should(BeARegularFile())
|
||||||
Expect(filepath.Join(runDBDir, "bolt_state.db")).Should(Not(BeAnExistingFile()))
|
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()))
|
Expect(filepath.Join(runContainerStorageDir, "volatile-containers.json")).Should(Not(BeAnExistingFile()))
|
||||||
|
|
||||||
if podmanTest.DatabaseBackend == "sqlite" {
|
if podmanTest.DatabaseBackend == "sqlite" {
|
||||||
Expect(filepath.Join(containerStorageDir, "db.sql")).Should(BeARegularFile())
|
Expect(filepath.Join(podmanTest.Root, "db.sql")).Should(BeARegularFile())
|
||||||
Expect(filepath.Join(runContainerStorageDir, "db.sql")).Should(Not(BeAnExistingFile()))
|
Expect(filepath.Join(podmanTest.RunRoot, "db.sql")).Should(Not(BeAnExistingFile()))
|
||||||
} else {
|
} else {
|
||||||
Expect(filepath.Join(dbDir, "bolt_state.db")).Should(BeARegularFile())
|
Expect(filepath.Join(dbDir, "bolt_state.db")).Should(BeARegularFile())
|
||||||
Expect(filepath.Join(runDBDir, "bolt_state.db")).Should(Not(BeAnExistingFile()))
|
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())
|
Expect(filepath.Join(runContainerStorageDir, "volatile-containers.json")).Should(BeARegularFile())
|
||||||
|
|
||||||
if podmanTest.DatabaseBackend == "sqlite" {
|
if podmanTest.DatabaseBackend == "sqlite" {
|
||||||
Expect(filepath.Join(containerStorageDir, "db.sql")).Should(Not(BeAnExistingFile()))
|
Expect(filepath.Join(podmanTest.Root, "db.sql")).Should(Not(BeAnExistingFile()))
|
||||||
Expect(filepath.Join(runContainerStorageDir, "db.sql")).Should(BeARegularFile())
|
Expect(filepath.Join(podmanTest.RunRoot, "db.sql")).Should(BeARegularFile())
|
||||||
} else {
|
} else {
|
||||||
Expect(filepath.Join(dbDir, "bolt_state.db")).Should(Not(BeAnExistingFile()))
|
Expect(filepath.Join(dbDir, "bolt_state.db")).Should(Not(BeAnExistingFile()))
|
||||||
Expect(filepath.Join(runDBDir, "bolt_state.db")).Should(BeARegularFile())
|
Expect(filepath.Join(runDBDir, "bolt_state.db")).Should(BeARegularFile())
|
||||||
|
Reference in New Issue
Block a user