mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-26 07:22:20 +00:00
persist: remove all usage of VCStore
Remove VCStore usage from all modules Signed-off-by: Wei Zhang <weizhang555.zw@gmail.com>
This commit is contained in:
parent
01b4a64be2
commit
8e88859ee4
@ -24,8 +24,8 @@ import (
|
|||||||
"github.com/kata-containers/runtime/pkg/rootless"
|
"github.com/kata-containers/runtime/pkg/rootless"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/device/config"
|
"github.com/kata-containers/runtime/virtcontainers/device/config"
|
||||||
persistapi "github.com/kata-containers/runtime/virtcontainers/persist/api"
|
persistapi "github.com/kata-containers/runtime/virtcontainers/persist/api"
|
||||||
|
"github.com/kata-containers/runtime/virtcontainers/persist/fs"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/pkg/uuid"
|
"github.com/kata-containers/runtime/virtcontainers/pkg/uuid"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/store"
|
|
||||||
"github.com/kata-containers/runtime/virtcontainers/types"
|
"github.com/kata-containers/runtime/virtcontainers/types"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/utils"
|
"github.com/kata-containers/runtime/virtcontainers/utils"
|
||||||
)
|
)
|
||||||
@ -327,7 +327,7 @@ func (a *Acrn) setup(id string, hypervisorConfig *HypervisorConfig) error {
|
|||||||
|
|
||||||
// The path might already exist, but in case of VM templating,
|
// The path might already exist, but in case of VM templating,
|
||||||
// we have to create it since the sandbox has not created it yet.
|
// we have to create it since the sandbox has not created it yet.
|
||||||
if err = os.MkdirAll(store.SandboxRuntimeRootPath(id), store.DirMode); err != nil {
|
if err = os.MkdirAll(filepath.Join(fs.RunStoragePath(), id), DirMode); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -443,8 +443,8 @@ func (a *Acrn) startSandbox(timeoutSecs int) error {
|
|||||||
a.Logger().WithField("default-kernel-parameters", formatted).Debug()
|
a.Logger().WithField("default-kernel-parameters", formatted).Debug()
|
||||||
}
|
}
|
||||||
|
|
||||||
vmPath := filepath.Join(store.RunVMStoragePath(), a.id)
|
vmPath := filepath.Join(fs.RunVMStoragePath(), a.id)
|
||||||
err := os.MkdirAll(vmPath, store.DirMode)
|
err := os.MkdirAll(vmPath, DirMode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -657,7 +657,7 @@ func (a *Acrn) getSandboxConsole(id string) (string, error) {
|
|||||||
span, _ := a.trace("getSandboxConsole")
|
span, _ := a.trace("getSandboxConsole")
|
||||||
defer span.Finish()
|
defer span.Finish()
|
||||||
|
|
||||||
return utils.BuildSocketPath(store.RunVMStoragePath(), id, acrnConsoleSocket)
|
return utils.BuildSocketPath(fs.RunVMStoragePath(), id, acrnConsoleSocket)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Acrn) saveSandbox() error {
|
func (a *Acrn) saveSandbox() error {
|
||||||
@ -802,7 +802,7 @@ func (a *Acrn) storeInfo() error {
|
|||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
// Root directory
|
// Root directory
|
||||||
a.Logger().WithField("path", dirPath).Debugf("Creating UUID directory")
|
a.Logger().WithField("path", dirPath).Debugf("Creating UUID directory")
|
||||||
if err := os.MkdirAll(dirPath, store.DirMode); err != nil {
|
if err := os.MkdirAll(dirPath, DirMode); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/kata-containers/runtime/virtcontainers/device/config"
|
"github.com/kata-containers/runtime/virtcontainers/device/config"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/store"
|
"github.com/kata-containers/runtime/virtcontainers/persist/fs"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/types"
|
"github.com/kata-containers/runtime/virtcontainers/types"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
@ -106,7 +106,7 @@ func TestAcrnArchBaseAppendConsoles(t *testing.T) {
|
|||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
acrnArchBase := newAcrnArchBase()
|
acrnArchBase := newAcrnArchBase()
|
||||||
|
|
||||||
path := filepath.Join(store.SandboxRuntimeRootPath(sandboxID), consoleSocket)
|
path := filepath.Join(filepath.Join(fs.RunStoragePath(), sandboxID), consoleSocket)
|
||||||
|
|
||||||
expectedOut := []Device{
|
expectedOut := []Device{
|
||||||
ConsoleDevice{
|
ConsoleDevice{
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/kata-containers/runtime/virtcontainers/device/config"
|
"github.com/kata-containers/runtime/virtcontainers/device/config"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/store"
|
"github.com/kata-containers/runtime/virtcontainers/persist/fs"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/types"
|
"github.com/kata-containers/runtime/virtcontainers/types"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
@ -198,7 +198,7 @@ func TestAcrnGetSandboxConsole(t *testing.T) {
|
|||||||
ctx: context.Background(),
|
ctx: context.Background(),
|
||||||
}
|
}
|
||||||
sandboxID := "testSandboxID"
|
sandboxID := "testSandboxID"
|
||||||
expected := filepath.Join(store.RunVMStoragePath(), sandboxID, consoleSocket)
|
expected := filepath.Join(fs.RunVMStoragePath(), sandboxID, consoleSocket)
|
||||||
|
|
||||||
result, err := a.getSandboxConsole(sandboxID)
|
result, err := a.getSandboxConsole(sandboxID)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
@ -16,7 +16,6 @@ import (
|
|||||||
"github.com/kata-containers/runtime/virtcontainers/persist/fs"
|
"github.com/kata-containers/runtime/virtcontainers/persist/fs"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/pkg/compatoci"
|
"github.com/kata-containers/runtime/virtcontainers/pkg/compatoci"
|
||||||
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
|
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/store"
|
|
||||||
"github.com/kata-containers/runtime/virtcontainers/types"
|
"github.com/kata-containers/runtime/virtcontainers/types"
|
||||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
opentracing "github.com/opentracing/opentracing-go"
|
opentracing "github.com/opentracing/opentracing-go"
|
||||||
@ -50,7 +49,6 @@ func SetLogger(ctx context.Context, logger *logrus.Entry) {
|
|||||||
virtLog = logger.WithFields(fields)
|
virtLog = logger.WithFields(fields)
|
||||||
|
|
||||||
deviceApi.SetLogger(virtLog)
|
deviceApi.SetLogger(virtLog)
|
||||||
store.SetLogger(virtLog)
|
|
||||||
compatoci.SetLogger(virtLog)
|
compatoci.SetLogger(virtLog)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,11 +16,11 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
ktu "github.com/kata-containers/runtime/pkg/katatestutils"
|
ktu "github.com/kata-containers/runtime/pkg/katatestutils"
|
||||||
|
"github.com/kata-containers/runtime/virtcontainers/persist"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/persist/fs"
|
"github.com/kata-containers/runtime/virtcontainers/persist/fs"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
|
"github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/pkg/mock"
|
"github.com/kata-containers/runtime/virtcontainers/pkg/mock"
|
||||||
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
|
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/store"
|
|
||||||
"github.com/kata-containers/runtime/virtcontainers/types"
|
"github.com/kata-containers/runtime/virtcontainers/types"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/utils"
|
"github.com/kata-containers/runtime/virtcontainers/utils"
|
||||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
@ -69,6 +69,16 @@ func newBasicTestCmd() types.Cmd {
|
|||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func rmSandboxDir(sid string) error {
|
||||||
|
store, err := persist.GetDriver("fs")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to get fs persist driver: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
store.Destroy(sid)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func newTestSandboxConfigNoop() SandboxConfig {
|
func newTestSandboxConfigNoop() SandboxConfig {
|
||||||
bundlePath := filepath.Join(testDir, testBundle)
|
bundlePath := filepath.Join(testDir, testBundle)
|
||||||
containerAnnotations[annotations.BundlePathKey] = bundlePath
|
containerAnnotations[annotations.BundlePathKey] = bundlePath
|
||||||
@ -139,7 +149,7 @@ func TestCreateSandboxNoopAgentSuccessful(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
sandboxDir := store.SandboxRuntimeRootPath(p.ID())
|
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
}
|
}
|
||||||
@ -176,7 +186,7 @@ func TestCreateSandboxKataAgentSuccessful(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
sandboxDir := store.SandboxRuntimeRootPath(p.ID())
|
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
}
|
}
|
||||||
@ -203,7 +213,7 @@ func TestDeleteSandboxNoopAgentSuccessful(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
sandboxDir := store.SandboxRuntimeRootPath(p.ID())
|
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
@ -248,7 +258,7 @@ func TestDeleteSandboxKataAgentSuccessful(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
sandboxDir := store.SandboxRuntimeRootPath(p.ID())
|
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
@ -264,7 +274,7 @@ func TestDeleteSandboxFailing(t *testing.T) {
|
|||||||
defer cleanUp()
|
defer cleanUp()
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
sandboxDir := store.SandboxRuntimeRootPath(testSandboxID)
|
sandboxDir := filepath.Join(fs.RunStoragePath(), testSandboxID)
|
||||||
os.Remove(sandboxDir)
|
os.Remove(sandboxDir)
|
||||||
|
|
||||||
p, err := DeleteSandbox(context.Background(), testSandboxID)
|
p, err := DeleteSandbox(context.Background(), testSandboxID)
|
||||||
@ -328,7 +338,7 @@ func TestStartSandboxFailing(t *testing.T) {
|
|||||||
defer cleanUp()
|
defer cleanUp()
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
sandboxDir := store.SandboxRuntimeRootPath(testSandboxID)
|
sandboxDir := filepath.Join(fs.RunStoragePath(), testSandboxID)
|
||||||
os.Remove(sandboxDir)
|
os.Remove(sandboxDir)
|
||||||
|
|
||||||
p, err := StartSandbox(context.Background(), testSandboxID)
|
p, err := StartSandbox(context.Background(), testSandboxID)
|
||||||
@ -395,7 +405,7 @@ func TestStopSandboxKataAgentSuccessful(t *testing.T) {
|
|||||||
func TestStopSandboxFailing(t *testing.T) {
|
func TestStopSandboxFailing(t *testing.T) {
|
||||||
defer cleanUp()
|
defer cleanUp()
|
||||||
|
|
||||||
sandboxDir := store.SandboxRuntimeRootPath(testSandboxID)
|
sandboxDir := filepath.Join(fs.RunStoragePath(), testSandboxID)
|
||||||
os.Remove(sandboxDir)
|
os.Remove(sandboxDir)
|
||||||
|
|
||||||
p, err := StopSandbox(context.Background(), testSandboxID, false)
|
p, err := StopSandbox(context.Background(), testSandboxID, false)
|
||||||
@ -413,7 +423,7 @@ func TestRunSandboxNoopAgentSuccessful(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
sandboxDir := store.SandboxRuntimeRootPath(p.ID())
|
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
}
|
}
|
||||||
@ -451,7 +461,7 @@ func TestRunSandboxKataAgentSuccessful(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
sandboxDir := store.SandboxRuntimeRootPath(p.ID())
|
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
@ -617,8 +627,6 @@ func TestStatusSandboxSuccessfulStateRunning(t *testing.T) {
|
|||||||
assert.Exactly(status, expectedStatus)
|
assert.Exactly(status, expectedStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*FIXME: replace DeleteAll with newstore.Destroy
|
|
||||||
|
|
||||||
func TestStatusSandboxFailingFetchSandboxConfig(t *testing.T) {
|
func TestStatusSandboxFailingFetchSandboxConfig(t *testing.T) {
|
||||||
defer cleanUp()
|
defer cleanUp()
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
@ -630,7 +638,7 @@ func TestStatusSandboxFailingFetchSandboxConfig(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
store.DeleteAll()
|
rmSandboxDir(p.ID())
|
||||||
globalSandboxList.removeSandbox(p.ID())
|
globalSandboxList.removeSandbox(p.ID())
|
||||||
|
|
||||||
_, err = StatusSandbox(ctx, p.ID())
|
_, err = StatusSandbox(ctx, p.ID())
|
||||||
@ -648,12 +656,12 @@ func TestStatusPodSandboxFailingFetchSandboxState(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
store.DeleteAll()
|
rmSandboxDir(p.ID())
|
||||||
globalSandboxList.removeSandbox(p.ID())
|
globalSandboxList.removeSandbox(p.ID())
|
||||||
|
|
||||||
_, err = StatusSandbox(ctx, p.ID())
|
_, err = StatusSandbox(ctx, p.ID())
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
}*/
|
}
|
||||||
|
|
||||||
func newTestContainerConfigNoop(contID string) ContainerConfig {
|
func newTestContainerConfigNoop(contID string) ContainerConfig {
|
||||||
// Define the container command and bundle.
|
// Define the container command and bundle.
|
||||||
@ -680,7 +688,7 @@ func TestCreateContainerSuccessful(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
sandboxDir := store.SandboxRuntimeRootPath(p.ID())
|
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
@ -734,7 +742,7 @@ func TestDeleteContainerSuccessful(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
sandboxDir := store.SandboxRuntimeRootPath(p.ID())
|
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
@ -778,7 +786,7 @@ func TestDeleteContainerFailingNoContainer(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
sandboxDir := store.SandboxRuntimeRootPath(p.ID())
|
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
@ -835,7 +843,7 @@ func TestStartContainerFailingNoContainer(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
sandboxDir := store.SandboxRuntimeRootPath(p.ID())
|
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
@ -856,7 +864,7 @@ func TestStartContainerFailingSandboxNotStarted(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
sandboxDir := store.SandboxRuntimeRootPath(p.ID())
|
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
@ -936,7 +944,7 @@ func TestStopContainerFailingNoContainer(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
sandboxDir := store.SandboxRuntimeRootPath(p.ID())
|
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
@ -1040,7 +1048,7 @@ func TestEnterContainerFailingNoContainer(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
sandboxDir := store.SandboxRuntimeRootPath(p.ID())
|
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
@ -1093,7 +1101,7 @@ func TestStatusContainerSuccessful(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
sandboxDir := store.SandboxRuntimeRootPath(p.ID())
|
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
@ -1136,7 +1144,7 @@ func TestStatusContainerStateReady(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
sandboxDir := store.SandboxRuntimeRootPath(p.ID())
|
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
@ -1199,7 +1207,7 @@ func TestStatusContainerStateRunning(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
sandboxDir := store.SandboxRuntimeRootPath(p.ID())
|
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
@ -1246,7 +1254,6 @@ func TestStatusContainerStateRunning(t *testing.T) {
|
|||||||
assert.Exactly(status, expectedStatus)
|
assert.Exactly(status, expectedStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME: replace DeleteAll with newstore.Destroy
|
|
||||||
func TestStatusContainerFailing(t *testing.T) {
|
func TestStatusContainerFailing(t *testing.T) {
|
||||||
defer cleanUp()
|
defer cleanUp()
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
@ -1259,12 +1266,12 @@ func TestStatusContainerFailing(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
store.DeleteAll()
|
rmSandboxDir(p.ID())
|
||||||
globalSandboxList.removeSandbox(p.ID())
|
globalSandboxList.removeSandbox(p.ID())
|
||||||
|
|
||||||
_, err = StatusContainer(ctx, p.ID(), contID)
|
_, err = StatusContainer(ctx, p.ID(), contID)
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
}*/
|
}
|
||||||
|
|
||||||
func TestStatsContainerFailing(t *testing.T) {
|
func TestStatsContainerFailing(t *testing.T) {
|
||||||
defer cleanUp()
|
defer cleanUp()
|
||||||
@ -1278,7 +1285,7 @@ func TestStatsContainerFailing(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
store.DeleteAll()
|
rmSandboxDir(p.ID())
|
||||||
globalSandboxList.removeSandbox(p.ID())
|
globalSandboxList.removeSandbox(p.ID())
|
||||||
|
|
||||||
_, err = StatsContainer(ctx, p.ID(), contID)
|
_, err = StatsContainer(ctx, p.ID(), contID)
|
||||||
@ -1312,7 +1319,6 @@ func TestStatsContainer(t *testing.T) {
|
|||||||
|
|
||||||
pImpl, ok := p.(*Sandbox)
|
pImpl, ok := p.(*Sandbox)
|
||||||
assert.True(ok)
|
assert.True(ok)
|
||||||
defer store.DeleteAll()
|
|
||||||
|
|
||||||
contConfig := newTestContainerConfigNoop(contID)
|
contConfig := newTestContainerConfigNoop(contID)
|
||||||
_, c, err := CreateContainer(ctx, p.ID(), contConfig)
|
_, c, err := CreateContainer(ctx, p.ID(), contConfig)
|
||||||
@ -1358,7 +1364,7 @@ func TestProcessListContainer(t *testing.T) {
|
|||||||
|
|
||||||
pImpl, ok := p.(*Sandbox)
|
pImpl, ok := p.(*Sandbox)
|
||||||
assert.True(ok)
|
assert.True(ok)
|
||||||
defer store.DeleteAll()
|
// defer store.DeleteAll()
|
||||||
|
|
||||||
contConfig := newTestContainerConfigNoop(contID)
|
contConfig := newTestContainerConfigNoop(contID)
|
||||||
_, c, err := CreateContainer(ctx, p.ID(), contConfig)
|
_, c, err := CreateContainer(ctx, p.ID(), contConfig)
|
||||||
@ -1414,7 +1420,7 @@ func createAndStartSandbox(ctx context.Context, config SandboxConfig) (sandbox V
|
|||||||
return nil, "", err
|
return nil, "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
sandboxDir = store.SandboxRuntimeRootPath(sandbox.ID())
|
sandboxDir = filepath.Join(fs.RunStoragePath(), sandbox.ID())
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
@ -1699,7 +1705,7 @@ func TestCleanupContainer(t *testing.T) {
|
|||||||
CleanupContainer(ctx, p.ID(), c.ID(), true)
|
CleanupContainer(ctx, p.ID(), c.ID(), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
sandboxDir := store.SandboxRuntimeRootPath(p.ID())
|
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
||||||
|
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -21,13 +21,13 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
persistapi "github.com/kata-containers/runtime/virtcontainers/persist/api"
|
persistapi "github.com/kata-containers/runtime/virtcontainers/persist/api"
|
||||||
|
"github.com/kata-containers/runtime/virtcontainers/persist/fs"
|
||||||
chclient "github.com/kata-containers/runtime/virtcontainers/pkg/cloud-hypervisor/client"
|
chclient "github.com/kata-containers/runtime/virtcontainers/pkg/cloud-hypervisor/client"
|
||||||
opentracing "github.com/opentracing/opentracing-go"
|
opentracing "github.com/opentracing/opentracing-go"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/kata-containers/runtime/virtcontainers/device/config"
|
"github.com/kata-containers/runtime/virtcontainers/device/config"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/store"
|
|
||||||
"github.com/kata-containers/runtime/virtcontainers/types"
|
"github.com/kata-containers/runtime/virtcontainers/types"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/utils"
|
"github.com/kata-containers/runtime/virtcontainers/utils"
|
||||||
)
|
)
|
||||||
@ -303,8 +303,8 @@ func (clh *cloudHypervisor) startSandbox(timeout int) error {
|
|||||||
|
|
||||||
clh.Logger().WithField("function", "startSandbox").Info("starting Sandbox")
|
clh.Logger().WithField("function", "startSandbox").Info("starting Sandbox")
|
||||||
|
|
||||||
vmPath := filepath.Join(store.RunVMStoragePath(), clh.id)
|
vmPath := filepath.Join(fs.RunVMStoragePath(), clh.id)
|
||||||
err := os.MkdirAll(vmPath, store.DirMode)
|
err := os.MkdirAll(vmPath, DirMode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -604,23 +604,23 @@ func (clh *cloudHypervisor) generateSocket(id string, useVsock bool) (interface{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (clh *cloudHypervisor) virtioFsSocketPath(id string) (string, error) {
|
func (clh *cloudHypervisor) virtioFsSocketPath(id string) (string, error) {
|
||||||
return utils.BuildSocketPath(store.RunVMStoragePath(), id, virtioFsSocket)
|
return utils.BuildSocketPath(fs.RunVMStoragePath(), id, virtioFsSocket)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (clh *cloudHypervisor) vsockSocketPath(id string) (string, error) {
|
func (clh *cloudHypervisor) vsockSocketPath(id string) (string, error) {
|
||||||
return utils.BuildSocketPath(store.RunVMStoragePath(), id, clhSocket)
|
return utils.BuildSocketPath(fs.RunVMStoragePath(), id, clhSocket)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (clh *cloudHypervisor) serialPath(id string) (string, error) {
|
func (clh *cloudHypervisor) serialPath(id string) (string, error) {
|
||||||
return utils.BuildSocketPath(store.RunVMStoragePath(), id, clhSerial)
|
return utils.BuildSocketPath(fs.RunVMStoragePath(), id, clhSerial)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (clh *cloudHypervisor) apiSocketPath(id string) (string, error) {
|
func (clh *cloudHypervisor) apiSocketPath(id string) (string, error) {
|
||||||
return utils.BuildSocketPath(store.RunVMStoragePath(), id, clhAPISocket)
|
return utils.BuildSocketPath(fs.RunVMStoragePath(), id, clhAPISocket)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (clh *cloudHypervisor) logFilePath(id string) (string, error) {
|
func (clh *cloudHypervisor) logFilePath(id string) (string, error) {
|
||||||
return utils.BuildSocketPath(store.RunVMStoragePath(), id, clhLogFile)
|
return utils.BuildSocketPath(fs.RunVMStoragePath(), id, clhLogFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (clh *cloudHypervisor) waitVMM(timeout uint) error {
|
func (clh *cloudHypervisor) waitVMM(timeout uint) error {
|
||||||
@ -998,7 +998,7 @@ func (clh *cloudHypervisor) cleanupVM(force bool) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// cleanup vm path
|
// cleanup vm path
|
||||||
dir := filepath.Join(store.RunVMStoragePath(), clh.id)
|
dir := filepath.Join(fs.RunVMStoragePath(), clh.id)
|
||||||
|
|
||||||
// If it's a symlink, remove both dir and the target.
|
// If it's a symlink, remove both dir and the target.
|
||||||
link, err := filepath.EvalSymlinks(dir)
|
link, err := filepath.EvalSymlinks(dir)
|
||||||
@ -1027,14 +1027,7 @@ func (clh *cloudHypervisor) cleanupVM(force bool) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if clh.config.VMid != "" {
|
if clh.config.VMid != "" {
|
||||||
dir = store.SandboxConfigurationRootPath(clh.config.VMid)
|
dir = filepath.Join(fs.RunStoragePath(), clh.config.VMid)
|
||||||
if err := os.RemoveAll(dir); err != nil {
|
|
||||||
if !force {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
clh.Logger().WithError(err).WithField("path", dir).Warnf("failed to remove vm path")
|
|
||||||
}
|
|
||||||
dir = store.SandboxRuntimeRootPath(clh.config.VMid)
|
|
||||||
if err := os.RemoveAll(dir); err != nil {
|
if err := os.RemoveAll(dir); err != nil {
|
||||||
if !force {
|
if !force {
|
||||||
return err
|
return err
|
||||||
|
@ -219,18 +219,8 @@ func TestClhCreateSandbox(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
vcStore, err := store.NewVCSandboxStore(sandbox.ctx, sandbox.id)
|
err = clh.createSandbox(context.Background(), sandbox.id, NetworkNamespace{}, &sandbox.config.HypervisorConfig, false)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
sandbox.store = vcStore
|
|
||||||
|
|
||||||
// Create parent dir path for hypervisor.json
|
|
||||||
parentDir := store.SandboxConfigurationRootPath(sandbox.id)
|
|
||||||
assert.NoError(os.MkdirAll(parentDir, store.DirMode))
|
|
||||||
|
|
||||||
err = clh.createSandbox(context.Background(), sandbox.id, NetworkNamespace{}, &sandbox.config.HypervisorConfig, sandbox.store, false)
|
|
||||||
assert.NoError(err)
|
|
||||||
assert.NoError(os.RemoveAll(parentDir))
|
|
||||||
assert.Exactly(clhConfig, clh.config)
|
assert.Exactly(clhConfig, clh.config)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,23 +235,6 @@ func TestClooudHypervisorStartSandbox(t *testing.T) {
|
|||||||
virtiofsd: &virtiofsdMock{},
|
virtiofsd: &virtiofsdMock{},
|
||||||
}
|
}
|
||||||
|
|
||||||
sandbox := &Sandbox{
|
|
||||||
ctx: context.Background(),
|
|
||||||
id: "testSandbox",
|
|
||||||
config: &SandboxConfig{
|
|
||||||
HypervisorConfig: clhConfig,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
vcStore, err := store.NewVCSandboxStore(sandbox.ctx, sandbox.id)
|
|
||||||
assert.NoError(err)
|
|
||||||
|
|
||||||
sandbox.store = vcStore
|
|
||||||
|
|
||||||
// Create parent dir path for hypervisor.json
|
|
||||||
parentDir := store.SandboxConfigurationRootPath(sandbox.id)
|
|
||||||
assert.NoError(os.MkdirAll(parentDir, store.DirMode))
|
|
||||||
|
|
||||||
err = clh.startSandbox(10)
|
err = clh.startSandbox(10)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,6 @@ import (
|
|||||||
"github.com/kata-containers/runtime/pkg/rootless"
|
"github.com/kata-containers/runtime/pkg/rootless"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/device/config"
|
"github.com/kata-containers/runtime/virtcontainers/device/config"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/device/manager"
|
"github.com/kata-containers/runtime/virtcontainers/device/manager"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/store"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// https://github.com/torvalds/linux/blob/master/include/uapi/linux/major.h
|
// https://github.com/torvalds/linux/blob/master/include/uapi/linux/major.h
|
||||||
@ -322,8 +321,6 @@ type Container struct {
|
|||||||
|
|
||||||
sandbox *Sandbox
|
sandbox *Sandbox
|
||||||
|
|
||||||
runPath string
|
|
||||||
configPath string
|
|
||||||
containerPath string
|
containerPath string
|
||||||
rootfsSuffix string
|
rootfsSuffix string
|
||||||
|
|
||||||
@ -673,8 +670,6 @@ func newContainer(sandbox *Sandbox, contConfig *ContainerConfig) (*Container, er
|
|||||||
rootFs: contConfig.RootFs,
|
rootFs: contConfig.RootFs,
|
||||||
config: contConfig,
|
config: contConfig,
|
||||||
sandbox: sandbox,
|
sandbox: sandbox,
|
||||||
runPath: store.ContainerRuntimeRootPath(sandbox.id, contConfig.ID),
|
|
||||||
configPath: store.ContainerConfigurationRootPath(sandbox.id, contConfig.ID),
|
|
||||||
containerPath: filepath.Join(sandbox.id, contConfig.ID),
|
containerPath: filepath.Join(sandbox.id, contConfig.ID),
|
||||||
rootfsSuffix: "rootfs",
|
rootfsSuffix: "rootfs",
|
||||||
state: types.ContainerState{},
|
state: types.ContainerState{},
|
||||||
|
@ -21,7 +21,6 @@ import (
|
|||||||
"github.com/kata-containers/runtime/virtcontainers/device/drivers"
|
"github.com/kata-containers/runtime/virtcontainers/device/drivers"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/device/manager"
|
"github.com/kata-containers/runtime/virtcontainers/device/manager"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/persist"
|
"github.com/kata-containers/runtime/virtcontainers/persist"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/store"
|
|
||||||
"github.com/kata-containers/runtime/virtcontainers/types"
|
"github.com/kata-containers/runtime/virtcontainers/types"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
@ -267,7 +266,7 @@ func testSetupFakeRootfs(t *testing.T) (testRawFile, loopDev, mntDir string, err
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
mntDir = filepath.Join(tmpDir, "rootfs")
|
mntDir = filepath.Join(tmpDir, "rootfs")
|
||||||
err = os.Mkdir(mntDir, store.DirMode)
|
err = os.Mkdir(mntDir, DirMode)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
err = syscall.Mount(loopDev, mntDir, "ext4", uintptr(0), "")
|
err = syscall.Mount(loopDev, mntDir, "ext4", uintptr(0), "")
|
||||||
|
11
virtcontainers/factory/cache/cache_test.go
vendored
11
virtcontainers/factory/cache/cache_test.go
vendored
@ -15,7 +15,7 @@ import (
|
|||||||
|
|
||||||
vc "github.com/kata-containers/runtime/virtcontainers"
|
vc "github.com/kata-containers/runtime/virtcontainers"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/factory/direct"
|
"github.com/kata-containers/runtime/virtcontainers/factory/direct"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/store"
|
"github.com/kata-containers/runtime/virtcontainers/persist/fs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTemplateFactory(t *testing.T) {
|
func TestTemplateFactory(t *testing.T) {
|
||||||
@ -35,14 +35,11 @@ func TestTemplateFactory(t *testing.T) {
|
|||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
ConfigStoragePathSaved := store.ConfigStoragePath
|
runPathSave := fs.RunStoragePath()
|
||||||
RunStoragePathSaved := store.RunStoragePath
|
fs.TestSetRunStoragePath(filepath.Join(testDir, "vc", "run"))
|
||||||
// allow the tests to run without affecting the host system.
|
// allow the tests to run without affecting the host system.
|
||||||
store.ConfigStoragePath = func() string { return filepath.Join(testDir, store.StoragePathSuffix, "config") }
|
|
||||||
store.RunStoragePath = func() string { return filepath.Join(testDir, store.StoragePathSuffix, "run") }
|
|
||||||
defer func() {
|
defer func() {
|
||||||
store.ConfigStoragePath = ConfigStoragePathSaved
|
fs.TestSetRunStoragePath(runPathSave)
|
||||||
store.RunStoragePath = RunStoragePathSaved
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// New
|
// New
|
||||||
|
@ -38,7 +38,6 @@ import (
|
|||||||
"github.com/blang/semver"
|
"github.com/blang/semver"
|
||||||
"github.com/containerd/console"
|
"github.com/containerd/console"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/device/config"
|
"github.com/kata-containers/runtime/virtcontainers/device/config"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/store"
|
|
||||||
"github.com/kata-containers/runtime/virtcontainers/types"
|
"github.com/kata-containers/runtime/virtcontainers/types"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/utils"
|
"github.com/kata-containers/runtime/virtcontainers/utils"
|
||||||
)
|
)
|
||||||
@ -76,6 +75,8 @@ const (
|
|||||||
fcMetricsFifo = "metrics.fifo"
|
fcMetricsFifo = "metrics.fifo"
|
||||||
|
|
||||||
defaultFcConfig = "fcConfig.json"
|
defaultFcConfig = "fcConfig.json"
|
||||||
|
// storagePathSuffix mirrors persist/fs/fs.go:storagePathSuffix
|
||||||
|
storagePathSuffix = "vc"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Specify the minimum version of firecracker supported
|
// Specify the minimum version of firecracker supported
|
||||||
@ -244,8 +245,8 @@ func (fc *firecracker) createSandbox(ctx context.Context, id string, networkNS N
|
|||||||
// Also jailer based on the id implicitly sets up cgroups under
|
// Also jailer based on the id implicitly sets up cgroups under
|
||||||
// <cgroups_base>/<exec_file_name>/<id>/
|
// <cgroups_base>/<exec_file_name>/<id>/
|
||||||
hypervisorName := filepath.Base(hypervisorConfig.HypervisorPath)
|
hypervisorName := filepath.Base(hypervisorConfig.HypervisorPath)
|
||||||
//store.ConfigStoragePath cannot be used as we need exec perms
|
//fs.RunStoragePath cannot be used as we need exec perms
|
||||||
fc.chrootBaseDir = filepath.Join("/var/lib/", store.StoragePathSuffix)
|
fc.chrootBaseDir = filepath.Join("/run", storagePathSuffix)
|
||||||
|
|
||||||
fc.vmPath = filepath.Join(fc.chrootBaseDir, hypervisorName, fc.id)
|
fc.vmPath = filepath.Join(fc.chrootBaseDir, hypervisorName, fc.id)
|
||||||
fc.jailerRoot = filepath.Join(fc.vmPath, "root") // auto created by jailer
|
fc.jailerRoot = filepath.Join(fc.vmPath, "root") // auto created by jailer
|
||||||
@ -374,7 +375,7 @@ func (fc *firecracker) fcInit(timeout int) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fetch sandbox network to be able to access it from the sandbox structure.
|
// Fetch sandbox network to be able to access it from the sandbox structure.
|
||||||
err := os.MkdirAll(fc.jailerRoot, store.DirMode)
|
err := os.MkdirAll(fc.jailerRoot, DirMode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ import (
|
|||||||
|
|
||||||
"github.com/kata-containers/runtime/virtcontainers/device/config"
|
"github.com/kata-containers/runtime/virtcontainers/device/config"
|
||||||
persistapi "github.com/kata-containers/runtime/virtcontainers/persist/api"
|
persistapi "github.com/kata-containers/runtime/virtcontainers/persist/api"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/store"
|
"github.com/kata-containers/runtime/virtcontainers/persist/fs"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/types"
|
"github.com/kata-containers/runtime/virtcontainers/types"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/utils"
|
"github.com/kata-containers/runtime/virtcontainers/utils"
|
||||||
)
|
)
|
||||||
@ -720,7 +720,7 @@ func generateVMSocket(id string, useVsock bool) (interface{}, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
path, err := utils.BuildSocketPath(filepath.Join(store.RunVMStoragePath(), id), defaultSocketName)
|
path, err := utils.BuildSocketPath(filepath.Join(fs.RunVMStoragePath(), id), defaultSocketName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -26,11 +26,11 @@ import (
|
|||||||
"github.com/kata-containers/runtime/pkg/rootless"
|
"github.com/kata-containers/runtime/pkg/rootless"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/device/config"
|
"github.com/kata-containers/runtime/virtcontainers/device/config"
|
||||||
persistapi "github.com/kata-containers/runtime/virtcontainers/persist/api"
|
persistapi "github.com/kata-containers/runtime/virtcontainers/persist/api"
|
||||||
|
"github.com/kata-containers/runtime/virtcontainers/persist/fs"
|
||||||
vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
|
vcAnnotations "github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
|
||||||
ns "github.com/kata-containers/runtime/virtcontainers/pkg/nsenter"
|
ns "github.com/kata-containers/runtime/virtcontainers/pkg/nsenter"
|
||||||
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
|
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/pkg/uuid"
|
"github.com/kata-containers/runtime/virtcontainers/pkg/uuid"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/store"
|
|
||||||
"github.com/kata-containers/runtime/virtcontainers/types"
|
"github.com/kata-containers/runtime/virtcontainers/types"
|
||||||
"github.com/opencontainers/runtime-spec/specs-go"
|
"github.com/opencontainers/runtime-spec/specs-go"
|
||||||
opentracing "github.com/opentracing/opentracing-go"
|
opentracing "github.com/opentracing/opentracing-go"
|
||||||
@ -217,7 +217,7 @@ func (k *kataAgent) Logger() *logrus.Entry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (k *kataAgent) getVMPath(id string) string {
|
func (k *kataAgent) getVMPath(id string) string {
|
||||||
return filepath.Join(store.RunVMStoragePath(), id)
|
return filepath.Join(fs.RunVMStoragePath(), id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k *kataAgent) getSharePath(id string) string {
|
func (k *kataAgent) getSharePath(id string) string {
|
||||||
@ -402,7 +402,7 @@ func (k *kataAgent) configure(h hypervisor, id, sharePath string, builtin bool,
|
|||||||
HostPath: sharePath,
|
HostPath: sharePath,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = os.MkdirAll(sharedVolume.HostPath, store.DirMode); err != nil {
|
if err = os.MkdirAll(sharedVolume.HostPath, DirMode); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2126,7 +2126,7 @@ func (k *kataAgent) copyFile(src, dst string) error {
|
|||||||
|
|
||||||
cpReq := &grpc.CopyFileRequest{
|
cpReq := &grpc.CopyFileRequest{
|
||||||
Path: dst,
|
Path: dst,
|
||||||
DirMode: uint32(store.DirMode),
|
DirMode: uint32(DirMode),
|
||||||
FileMode: st.Mode,
|
FileMode: st.Mode,
|
||||||
FileSize: fileSize,
|
FileSize: fileSize,
|
||||||
Uid: int32(st.Uid),
|
Uid: int32(st.Uid),
|
||||||
|
@ -37,6 +37,9 @@ const storagePathSuffix = "vc"
|
|||||||
// sandboxPathSuffix is the suffix used for sandbox storage
|
// sandboxPathSuffix is the suffix used for sandbox storage
|
||||||
const sandboxPathSuffix = "sbs"
|
const sandboxPathSuffix = "sbs"
|
||||||
|
|
||||||
|
// vmPathSuffix is the suffix used for guest VMs.
|
||||||
|
const vmPathSuffix = "vm"
|
||||||
|
|
||||||
// RunStoragePath is the sandbox runtime directory.
|
// RunStoragePath is the sandbox runtime directory.
|
||||||
// It will contain one state.json and one lock file for each created sandbox.
|
// It will contain one state.json and one lock file for each created sandbox.
|
||||||
var RunStoragePath = func() string {
|
var RunStoragePath = func() string {
|
||||||
@ -47,6 +50,17 @@ var RunStoragePath = func() string {
|
|||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RunVMStoragePath is the vm directory.
|
||||||
|
// It will contain all guest vm sockets and shared mountpoints.
|
||||||
|
// The function is declared this way for mocking in unit tests
|
||||||
|
var RunVMStoragePath = func() string {
|
||||||
|
path := filepath.Join("/run", storagePathSuffix, vmPathSuffix)
|
||||||
|
if rootless.IsRootless() {
|
||||||
|
return filepath.Join(rootless.GetRootlessDir(), path)
|
||||||
|
}
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
|
||||||
// FS storage driver implementation
|
// FS storage driver implementation
|
||||||
type FS struct {
|
type FS struct {
|
||||||
sandboxState *persistapi.SandboxState
|
sandboxState *persistapi.SandboxState
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
kataclient "github.com/kata-containers/agent/protocols/client"
|
kataclient "github.com/kata-containers/agent/protocols/client"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/store"
|
"github.com/kata-containers/runtime/virtcontainers/persist/fs"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -146,7 +146,7 @@ func validateProxyConfig(proxyConfig ProxyConfig) error {
|
|||||||
func defaultProxyURL(id, socketType string) (string, error) {
|
func defaultProxyURL(id, socketType string) (string, error) {
|
||||||
switch socketType {
|
switch socketType {
|
||||||
case SocketTypeUNIX:
|
case SocketTypeUNIX:
|
||||||
socketPath := filepath.Join(store.SandboxRuntimeRootPath(id), "proxy.sock")
|
socketPath := filepath.Join(filepath.Join(fs.RunStoragePath(), id), "proxy.sock")
|
||||||
return fmt.Sprintf("unix://%s", socketPath), nil
|
return fmt.Sprintf("unix://%s", socketPath), nil
|
||||||
case SocketTypeVSOCK:
|
case SocketTypeVSOCK:
|
||||||
// TODO Build the VSOCK default URL
|
// TODO Build the VSOCK default URL
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/kata-containers/runtime/virtcontainers/store"
|
"github.com/kata-containers/runtime/virtcontainers/persist/fs"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
@ -173,7 +173,7 @@ func testDefaultProxyURL(expectedURL string, socketType string, sandboxID string
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultProxyURLUnix(t *testing.T) {
|
func TestDefaultProxyURLUnix(t *testing.T) {
|
||||||
path := filepath.Join(store.SandboxRuntimeRootPath(sandboxID), "proxy.sock")
|
path := filepath.Join(filepath.Join(fs.RunStoragePath(), sandboxID), "proxy.sock")
|
||||||
socketPath := fmt.Sprintf("unix://%s", path)
|
socketPath := fmt.Sprintf("unix://%s", path)
|
||||||
assert.NoError(t, testDefaultProxyURL(socketPath, SocketTypeUNIX, sandboxID))
|
assert.NoError(t, testDefaultProxyURL(socketPath, SocketTypeUNIX, sandboxID))
|
||||||
}
|
}
|
||||||
@ -183,7 +183,7 @@ func TestDefaultProxyURLVSock(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultProxyURLUnknown(t *testing.T) {
|
func TestDefaultProxyURLUnknown(t *testing.T) {
|
||||||
path := filepath.Join(store.SandboxRuntimeRootPath(sandboxID), "proxy.sock")
|
path := filepath.Join(filepath.Join(fs.RunStoragePath(), sandboxID), "proxy.sock")
|
||||||
socketPath := fmt.Sprintf("unix://%s", path)
|
socketPath := fmt.Sprintf("unix://%s", path)
|
||||||
assert.Error(t, testDefaultProxyURL(socketPath, "foobar", sandboxID))
|
assert.Error(t, testDefaultProxyURL(socketPath, "foobar", sandboxID))
|
||||||
}
|
}
|
||||||
@ -204,7 +204,7 @@ func testProxyStart(t *testing.T, agent agent, proxy proxy) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
invalidPath := filepath.Join(tmpdir, "enoent")
|
invalidPath := filepath.Join(tmpdir, "enoent")
|
||||||
expectedSocketPath := filepath.Join(store.SandboxRuntimeRootPath(testSandboxID), "proxy.sock")
|
expectedSocketPath := filepath.Join(filepath.Join(fs.RunStoragePath(), testSandboxID), "proxy.sock")
|
||||||
expectedURI := fmt.Sprintf("unix://%s", expectedSocketPath)
|
expectedURI := fmt.Sprintf("unix://%s", expectedSocketPath)
|
||||||
|
|
||||||
data := []testData{
|
data := []testData{
|
||||||
|
@ -32,8 +32,8 @@ import (
|
|||||||
|
|
||||||
"github.com/kata-containers/runtime/virtcontainers/device/config"
|
"github.com/kata-containers/runtime/virtcontainers/device/config"
|
||||||
persistapi "github.com/kata-containers/runtime/virtcontainers/persist/api"
|
persistapi "github.com/kata-containers/runtime/virtcontainers/persist/api"
|
||||||
|
"github.com/kata-containers/runtime/virtcontainers/persist/fs"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/pkg/uuid"
|
"github.com/kata-containers/runtime/virtcontainers/pkg/uuid"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/store"
|
|
||||||
"github.com/kata-containers/runtime/virtcontainers/types"
|
"github.com/kata-containers/runtime/virtcontainers/types"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/utils"
|
"github.com/kata-containers/runtime/virtcontainers/utils"
|
||||||
)
|
)
|
||||||
@ -269,7 +269,7 @@ func (q *qemu) setup(id string, hypervisorConfig *HypervisorConfig) error {
|
|||||||
|
|
||||||
// The path might already exist, but in case of VM templating,
|
// The path might already exist, but in case of VM templating,
|
||||||
// we have to create it since the sandbox has not created it yet.
|
// we have to create it since the sandbox has not created it yet.
|
||||||
if err = os.MkdirAll(store.SandboxRuntimeRootPath(id), store.DirMode); err != nil {
|
if err = os.MkdirAll(filepath.Join(fs.RunStoragePath(), id), DirMode); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -324,7 +324,7 @@ func (q *qemu) memoryTopology() (govmmQemu.Memory, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (q *qemu) qmpSocketPath(id string) (string, error) {
|
func (q *qemu) qmpSocketPath(id string) (string, error) {
|
||||||
return utils.BuildSocketPath(store.RunVMStoragePath(), id, qmpSocket)
|
return utils.BuildSocketPath(fs.RunVMStoragePath(), id, qmpSocket)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *qemu) getQemuMachine() (govmmQemu.Machine, error) {
|
func (q *qemu) getQemuMachine() (govmmQemu.Machine, error) {
|
||||||
@ -568,7 +568,7 @@ func (q *qemu) createSandbox(ctx context.Context, id string, networkNS NetworkNa
|
|||||||
VGA: "none",
|
VGA: "none",
|
||||||
GlobalParam: "kvm-pit.lost_tick_policy=discard",
|
GlobalParam: "kvm-pit.lost_tick_policy=discard",
|
||||||
Bios: firmwarePath,
|
Bios: firmwarePath,
|
||||||
PidFile: filepath.Join(store.RunVMStoragePath(), q.id, "pid"),
|
PidFile: filepath.Join(fs.RunVMStoragePath(), q.id, "pid"),
|
||||||
}
|
}
|
||||||
|
|
||||||
if ioThread != nil {
|
if ioThread != nil {
|
||||||
@ -590,7 +590,7 @@ func (q *qemu) createSandbox(ctx context.Context, id string, networkNS NetworkNa
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (q *qemu) vhostFSSocketPath(id string) (string, error) {
|
func (q *qemu) vhostFSSocketPath(id string) (string, error) {
|
||||||
return utils.BuildSocketPath(store.RunVMStoragePath(), id, vhostFSSocket)
|
return utils.BuildSocketPath(fs.RunVMStoragePath(), id, vhostFSSocket)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *qemu) virtiofsdArgs(fd uintptr) []string {
|
func (q *qemu) virtiofsdArgs(fd uintptr) []string {
|
||||||
@ -694,8 +694,8 @@ func (q *qemu) startSandbox(timeout int) error {
|
|||||||
q.fds = []*os.File{}
|
q.fds = []*os.File{}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
vmPath := filepath.Join(store.RunVMStoragePath(), q.id)
|
vmPath := filepath.Join(fs.RunVMStoragePath(), q.id)
|
||||||
err := os.MkdirAll(vmPath, store.DirMode)
|
err := os.MkdirAll(vmPath, DirMode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -867,7 +867,7 @@ func (q *qemu) stopSandbox() error {
|
|||||||
func (q *qemu) cleanupVM() error {
|
func (q *qemu) cleanupVM() error {
|
||||||
|
|
||||||
// cleanup vm path
|
// cleanup vm path
|
||||||
dir := filepath.Join(store.RunVMStoragePath(), q.id)
|
dir := filepath.Join(fs.RunVMStoragePath(), q.id)
|
||||||
|
|
||||||
// If it's a symlink, remove both dir and the target.
|
// If it's a symlink, remove both dir and the target.
|
||||||
// This can happen when vm template links a sandbox to a vm.
|
// This can happen when vm template links a sandbox to a vm.
|
||||||
@ -888,11 +888,7 @@ func (q *qemu) cleanupVM() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if q.config.VMid != "" {
|
if q.config.VMid != "" {
|
||||||
dir = store.SandboxConfigurationRootPath(q.config.VMid)
|
dir = filepath.Join(fs.RunStoragePath(), q.config.VMid)
|
||||||
if err := os.RemoveAll(dir); err != nil {
|
|
||||||
q.Logger().WithError(err).WithField("path", dir).Warnf("failed to remove vm path")
|
|
||||||
}
|
|
||||||
dir = store.SandboxRuntimeRootPath(q.config.VMid)
|
|
||||||
if err := os.RemoveAll(dir); err != nil {
|
if err := os.RemoveAll(dir); err != nil {
|
||||||
q.Logger().WithError(err).WithField("path", dir).Warnf("failed to remove vm path")
|
q.Logger().WithError(err).WithField("path", dir).Warnf("failed to remove vm path")
|
||||||
}
|
}
|
||||||
@ -1582,7 +1578,7 @@ func (q *qemu) getSandboxConsole(id string) (string, error) {
|
|||||||
span, _ := q.trace("getSandboxConsole")
|
span, _ := q.trace("getSandboxConsole")
|
||||||
defer span.Finish()
|
defer span.Finish()
|
||||||
|
|
||||||
return utils.BuildSocketPath(store.RunVMStoragePath(), id, consoleSocket)
|
return utils.BuildSocketPath(fs.RunVMStoragePath(), id, consoleSocket)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *qemu) saveSandbox() error {
|
func (q *qemu) saveSandbox() error {
|
||||||
|
@ -16,7 +16,7 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"github.com/kata-containers/runtime/virtcontainers/device/config"
|
"github.com/kata-containers/runtime/virtcontainers/device/config"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/store"
|
"github.com/kata-containers/runtime/virtcontainers/persist/fs"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/types"
|
"github.com/kata-containers/runtime/virtcontainers/types"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
@ -259,7 +259,7 @@ func TestQemuArchBaseAppendConsoles(t *testing.T) {
|
|||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
qemuArchBase := newQemuArchBase()
|
qemuArchBase := newQemuArchBase()
|
||||||
|
|
||||||
path := filepath.Join(store.SandboxRuntimeRootPath(sandboxID), consoleSocket)
|
path := filepath.Join(filepath.Join(fs.RunStoragePath(), sandboxID), consoleSocket)
|
||||||
|
|
||||||
expectedOut := []govmmQemu.Device{
|
expectedOut := []govmmQemu.Device{
|
||||||
govmmQemu.SerialDevice{
|
govmmQemu.SerialDevice{
|
||||||
|
@ -17,7 +17,7 @@ import (
|
|||||||
govmmQemu "github.com/intel/govmm/qemu"
|
govmmQemu "github.com/intel/govmm/qemu"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/device/config"
|
"github.com/kata-containers/runtime/virtcontainers/device/config"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/persist"
|
"github.com/kata-containers/runtime/virtcontainers/persist"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/store"
|
"github.com/kata-containers/runtime/virtcontainers/persist/fs"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/types"
|
"github.com/kata-containers/runtime/virtcontainers/types"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@ -92,8 +92,8 @@ func TestQemuCreateSandbox(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
// Create parent dir path for hypervisor.json
|
// Create parent dir path for hypervisor.json
|
||||||
parentDir := store.SandboxRuntimeRootPath(sandbox.id)
|
parentDir := filepath.Join(fs.RunStoragePath(), sandbox.id)
|
||||||
assert.NoError(os.MkdirAll(parentDir, store.DirMode))
|
assert.NoError(os.MkdirAll(parentDir, DirMode))
|
||||||
|
|
||||||
err = q.createSandbox(context.Background(), sandbox.id, NetworkNamespace{}, &sandbox.config.HypervisorConfig, false)
|
err = q.createSandbox(context.Background(), sandbox.id, NetworkNamespace{}, &sandbox.config.HypervisorConfig, false)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
@ -120,7 +120,7 @@ func TestQemuCreateSandboxMissingParentDirFail(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
// Ensure parent dir path for hypervisor.json does not exist.
|
// Ensure parent dir path for hypervisor.json does not exist.
|
||||||
parentDir := store.SandboxRuntimeRootPath(sandbox.id)
|
parentDir := filepath.Join(fs.RunStoragePath(), sandbox.id)
|
||||||
assert.NoError(os.RemoveAll(parentDir))
|
assert.NoError(os.RemoveAll(parentDir))
|
||||||
|
|
||||||
err = q.createSandbox(context.Background(), sandbox.id, NetworkNamespace{}, &sandbox.config.HypervisorConfig, false)
|
err = q.createSandbox(context.Background(), sandbox.id, NetworkNamespace{}, &sandbox.config.HypervisorConfig, false)
|
||||||
@ -280,7 +280,7 @@ func TestQemuGetSandboxConsole(t *testing.T) {
|
|||||||
ctx: context.Background(),
|
ctx: context.Background(),
|
||||||
}
|
}
|
||||||
sandboxID := "testSandboxID"
|
sandboxID := "testSandboxID"
|
||||||
expected := filepath.Join(store.RunVMStoragePath(), sandboxID, consoleSocket)
|
expected := filepath.Join(fs.RunVMStoragePath(), sandboxID, consoleSocket)
|
||||||
|
|
||||||
result, err := q.getSandboxConsole(sandboxID)
|
result, err := q.getSandboxConsole(sandboxID)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
@ -37,7 +37,6 @@ import (
|
|||||||
"github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
|
"github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/pkg/compatoci"
|
"github.com/kata-containers/runtime/virtcontainers/pkg/compatoci"
|
||||||
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
|
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/store"
|
|
||||||
"github.com/kata-containers/runtime/virtcontainers/types"
|
"github.com/kata-containers/runtime/virtcontainers/types"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/utils"
|
"github.com/kata-containers/runtime/virtcontainers/utils"
|
||||||
)
|
)
|
||||||
@ -46,6 +45,9 @@ const (
|
|||||||
// vmStartTimeout represents the time in seconds a sandbox can wait before
|
// vmStartTimeout represents the time in seconds a sandbox can wait before
|
||||||
// to consider the VM starting operation failed.
|
// to consider the VM starting operation failed.
|
||||||
vmStartTimeout = 10
|
vmStartTimeout = 10
|
||||||
|
|
||||||
|
// DirMode is the permission bits used for creating a directory
|
||||||
|
DirMode = os.FileMode(0750) | os.ModeDir
|
||||||
)
|
)
|
||||||
|
|
||||||
// SandboxStatus describes a sandbox status.
|
// SandboxStatus describes a sandbox status.
|
||||||
@ -188,9 +190,6 @@ type Sandbox struct {
|
|||||||
|
|
||||||
containers map[string]*Container
|
containers map[string]*Container
|
||||||
|
|
||||||
runPath string
|
|
||||||
configPath string
|
|
||||||
|
|
||||||
state types.SandboxState
|
state types.SandboxState
|
||||||
|
|
||||||
networkNS NetworkNamespace
|
networkNS NetworkNamespace
|
||||||
@ -519,8 +518,6 @@ func newSandbox(ctx context.Context, sandboxConfig SandboxConfig, factory Factor
|
|||||||
config: &sandboxConfig,
|
config: &sandboxConfig,
|
||||||
volumes: sandboxConfig.Volumes,
|
volumes: sandboxConfig.Volumes,
|
||||||
containers: map[string]*Container{},
|
containers: map[string]*Container{},
|
||||||
runPath: store.SandboxRuntimeRootPath(sandboxConfig.ID),
|
|
||||||
configPath: store.SandboxConfigurationRootPath(sandboxConfig.ID),
|
|
||||||
state: types.SandboxState{},
|
state: types.SandboxState{},
|
||||||
annotationsLock: &sync.RWMutex{},
|
annotationsLock: &sync.RWMutex{},
|
||||||
wg: &sync.WaitGroup{},
|
wg: &sync.WaitGroup{},
|
||||||
|
@ -21,8 +21,8 @@ import (
|
|||||||
"github.com/kata-containers/runtime/virtcontainers/device/drivers"
|
"github.com/kata-containers/runtime/virtcontainers/device/drivers"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/device/manager"
|
"github.com/kata-containers/runtime/virtcontainers/device/manager"
|
||||||
exp "github.com/kata-containers/runtime/virtcontainers/experimental"
|
exp "github.com/kata-containers/runtime/virtcontainers/experimental"
|
||||||
|
"github.com/kata-containers/runtime/virtcontainers/persist/fs"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
|
"github.com/kata-containers/runtime/virtcontainers/pkg/annotations"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/store"
|
|
||||||
"github.com/kata-containers/runtime/virtcontainers/types"
|
"github.com/kata-containers/runtime/virtcontainers/types"
|
||||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@ -682,7 +682,7 @@ func TestSandboxAttachDevicesVFIO(t *testing.T) {
|
|||||||
testDeviceBDFPath := "0000:00:1c.0"
|
testDeviceBDFPath := "0000:00:1c.0"
|
||||||
|
|
||||||
devicesDir := filepath.Join(tmpDir, testFDIOGroup, "devices")
|
devicesDir := filepath.Join(tmpDir, testFDIOGroup, "devices")
|
||||||
err = os.MkdirAll(devicesDir, store.DirMode)
|
err = os.MkdirAll(devicesDir, DirMode)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
deviceFile := filepath.Join(devicesDir, testDeviceBDFPath)
|
deviceFile := filepath.Join(devicesDir, testDeviceBDFPath)
|
||||||
@ -990,7 +990,7 @@ func TestDeleteStoreWhenNewContainerFail(t *testing.T) {
|
|||||||
}
|
}
|
||||||
_, err = newContainer(p, &contConfig)
|
_, err = newContainer(p, &contConfig)
|
||||||
assert.NotNil(t, err, "New container with invalid device info should fail")
|
assert.NotNil(t, err, "New container with invalid device info should fail")
|
||||||
storePath := store.ContainerRuntimeRootPath(testSandboxID, contID)
|
storePath := filepath.Join(fs.RunStoragePath(), testSandboxID, contID)
|
||||||
_, err = os.Stat(storePath)
|
_, err = os.Stat(storePath)
|
||||||
assert.NotNil(t, err, "Should delete configuration root after failed to create a container")
|
assert.NotNil(t, err, "Should delete configuration root after failed to create a container")
|
||||||
}
|
}
|
||||||
@ -1160,8 +1160,8 @@ func TestAttachBlockDevice(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create state file
|
// create state file
|
||||||
path := store.ContainerRuntimeRootPath(testSandboxID, container.ID())
|
path := filepath.Join(fs.RunStoragePath(), testSandboxID, container.ID())
|
||||||
err := os.MkdirAll(path, store.DirMode)
|
err := os.MkdirAll(path, DirMode)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
defer os.RemoveAll(path)
|
defer os.RemoveAll(path)
|
||||||
@ -1238,8 +1238,8 @@ func TestPreAddDevice(t *testing.T) {
|
|||||||
container.state.State = types.StateReady
|
container.state.State = types.StateReady
|
||||||
|
|
||||||
// create state file
|
// create state file
|
||||||
path := store.ContainerRuntimeRootPath(testSandboxID, container.ID())
|
path := filepath.Join(fs.RunStoragePath(), testSandboxID, container.ID())
|
||||||
err := os.MkdirAll(path, store.DirMode)
|
err := os.MkdirAll(path, DirMode)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
defer os.RemoveAll(path)
|
defer os.RemoveAll(path)
|
||||||
@ -1336,9 +1336,6 @@ func checkDirNotExist(path string) error {
|
|||||||
|
|
||||||
func checkSandboxRemains() error {
|
func checkSandboxRemains() error {
|
||||||
var err error
|
var err error
|
||||||
if err = checkDirNotExist(sandboxDirConfig); err != nil {
|
|
||||||
return fmt.Errorf("%s still exists", sandboxDirConfig)
|
|
||||||
}
|
|
||||||
if err = checkDirNotExist(sandboxDirState); err != nil {
|
if err = checkDirNotExist(sandboxDirState); err != nil {
|
||||||
return fmt.Errorf("%s still exists", sandboxDirState)
|
return fmt.Errorf("%s still exists", sandboxDirState)
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/kata-containers/runtime/virtcontainers/persist/fs"
|
"github.com/kata-containers/runtime/virtcontainers/persist/fs"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/store"
|
|
||||||
"github.com/kata-containers/runtime/virtcontainers/utils"
|
"github.com/kata-containers/runtime/virtcontainers/utils"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
@ -35,12 +34,7 @@ const testDisabledAsNonRoot = "Test disabled as requires root privileges"
|
|||||||
|
|
||||||
// package variables set in TestMain
|
// package variables set in TestMain
|
||||||
var testDir = ""
|
var testDir = ""
|
||||||
var sandboxDirConfig = ""
|
|
||||||
var sandboxFileConfig = ""
|
|
||||||
var sandboxDirState = ""
|
var sandboxDirState = ""
|
||||||
var sandboxDirLock = ""
|
|
||||||
var sandboxFileState = ""
|
|
||||||
var sandboxFileLock = ""
|
|
||||||
var testQemuKernelPath = ""
|
var testQemuKernelPath = ""
|
||||||
var testQemuInitrdPath = ""
|
var testQemuInitrdPath = ""
|
||||||
var testQemuImagePath = ""
|
var testQemuImagePath = ""
|
||||||
@ -63,22 +57,16 @@ var savedRunVMStoragePathFunc func() string
|
|||||||
// the next test to run.
|
// the next test to run.
|
||||||
func cleanUp() {
|
func cleanUp() {
|
||||||
globalSandboxList.removeSandbox(testSandboxID)
|
globalSandboxList.removeSandbox(testSandboxID)
|
||||||
store.DeleteAll()
|
os.RemoveAll(fs.RunStoragePath())
|
||||||
|
os.RemoveAll(fs.RunVMStoragePath())
|
||||||
os.RemoveAll(testDir)
|
os.RemoveAll(testDir)
|
||||||
store.VCStorePrefix = ""
|
os.MkdirAll(testDir, DirMode)
|
||||||
store.RunVMStoragePath = savedRunVMStoragePathFunc
|
|
||||||
|
|
||||||
setup()
|
setup()
|
||||||
}
|
}
|
||||||
|
|
||||||
func setup() {
|
func setup() {
|
||||||
store.VCStorePrefix = testDir
|
os.Mkdir(filepath.Join(testDir, testBundle), DirMode)
|
||||||
savedRunVMStoragePathFunc = store.RunVMStoragePath
|
|
||||||
store.RunVMStoragePath = func() string {
|
|
||||||
return filepath.Join("testDir", "vm")
|
|
||||||
}
|
|
||||||
os.MkdirAll(store.RunVMStoragePath(), store.DirMode)
|
|
||||||
os.MkdirAll(filepath.Join(testDir, testBundle), store.DirMode)
|
|
||||||
|
|
||||||
for _, filename := range []string{testQemuKernelPath, testQemuInitrdPath, testQemuImagePath, testQemuPath} {
|
for _, filename := range []string{testQemuKernelPath, testQemuInitrdPath, testQemuImagePath, testQemuPath} {
|
||||||
_, err := os.Create(filename)
|
_, err := os.Create(filename)
|
||||||
@ -90,7 +78,7 @@ func setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setupAcrn() {
|
func setupAcrn() {
|
||||||
os.Mkdir(filepath.Join(testDir, testBundle), store.DirMode)
|
os.Mkdir(filepath.Join(testDir, testBundle), DirMode)
|
||||||
|
|
||||||
for _, filename := range []string{testAcrnKernelPath, testAcrnImagePath, testAcrnPath, testAcrnCtlPath} {
|
for _, filename := range []string{testAcrnKernelPath, testAcrnImagePath, testAcrnPath, testAcrnCtlPath} {
|
||||||
_, err := os.Create(filename)
|
_, err := os.Create(filename)
|
||||||
@ -102,7 +90,7 @@ func setupAcrn() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setupClh() {
|
func setupClh() {
|
||||||
os.Mkdir(filepath.Join(testDir, testBundle), store.DirMode)
|
os.Mkdir(filepath.Join(testDir, testBundle), DirMode)
|
||||||
|
|
||||||
for _, filename := range []string{testClhKernelPath, testClhImagePath, testClhPath, testVirtiofsdPath} {
|
for _, filename := range []string{testClhKernelPath, testClhImagePath, testClhPath, testVirtiofsdPath} {
|
||||||
_, err := os.Create(filename)
|
_, err := os.Create(filename)
|
||||||
@ -135,7 +123,7 @@ func TestMain(m *testing.M) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("INFO: Creating virtcontainers test directory %s\n", testDir)
|
fmt.Printf("INFO: Creating virtcontainers test directory %s\n", testDir)
|
||||||
err = os.MkdirAll(testDir, store.DirMode)
|
err = os.MkdirAll(testDir, DirMode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Could not create test directories:", err)
|
fmt.Println("Could not create test directories:", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@ -170,25 +158,16 @@ func TestMain(m *testing.M) {
|
|||||||
|
|
||||||
setupClh()
|
setupClh()
|
||||||
|
|
||||||
ConfigStoragePathSaved := store.ConfigStoragePath
|
|
||||||
RunStoragePathSaved := store.RunStoragePath
|
|
||||||
// allow the tests to run without affecting the host system.
|
// allow the tests to run without affecting the host system.
|
||||||
store.ConfigStoragePath = func() string { return filepath.Join(testDir, store.StoragePathSuffix, "config") }
|
runPathSave := fs.RunStoragePath()
|
||||||
store.RunStoragePath = func() string { return filepath.Join(testDir, store.StoragePathSuffix, "run") }
|
|
||||||
fs.TestSetRunStoragePath(filepath.Join(testDir, "vc", "run"))
|
fs.TestSetRunStoragePath(filepath.Join(testDir, "vc", "run"))
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
store.ConfigStoragePath = ConfigStoragePathSaved
|
fs.TestSetRunStoragePath(runPathSave)
|
||||||
store.RunStoragePath = RunStoragePathSaved
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// set now that configStoragePath has been overridden.
|
// set now that configStoragePath has been overridden.
|
||||||
sandboxDirConfig = filepath.Join(store.ConfigStoragePath(), testSandboxID)
|
sandboxDirState = filepath.Join(fs.RunStoragePath(), testSandboxID)
|
||||||
sandboxFileConfig = filepath.Join(store.ConfigStoragePath(), testSandboxID, store.ConfigurationFile)
|
|
||||||
sandboxDirState = filepath.Join(store.RunStoragePath(), testSandboxID)
|
|
||||||
sandboxDirLock = filepath.Join(store.RunStoragePath(), testSandboxID)
|
|
||||||
sandboxFileState = filepath.Join(store.RunStoragePath(), testSandboxID, store.StateFile)
|
|
||||||
sandboxFileLock = filepath.Join(store.RunStoragePath(), testSandboxID, store.LockFile)
|
|
||||||
|
|
||||||
testHyperstartCtlSocket = filepath.Join(testDir, "test_hyper.sock")
|
testHyperstartCtlSocket = filepath.Join(testDir, "test_hyper.sock")
|
||||||
testHyperstartTtySocket = filepath.Join(testDir, "test_tty.sock")
|
testHyperstartTtySocket = filepath.Join(testDir, "test_tty.sock")
|
||||||
|
@ -16,8 +16,8 @@ import (
|
|||||||
pb "github.com/kata-containers/runtime/protocols/cache"
|
pb "github.com/kata-containers/runtime/protocols/cache"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/persist"
|
"github.com/kata-containers/runtime/virtcontainers/persist"
|
||||||
persistapi "github.com/kata-containers/runtime/virtcontainers/persist/api"
|
persistapi "github.com/kata-containers/runtime/virtcontainers/persist/api"
|
||||||
|
"github.com/kata-containers/runtime/virtcontainers/persist/fs"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/pkg/uuid"
|
"github.com/kata-containers/runtime/virtcontainers/pkg/uuid"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/store"
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -285,7 +285,7 @@ func NewVMFromGrpc(ctx context.Context, v *pb.GrpcVM, config VMConfig) (*VM, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
func buildVMSharePath(id string) string {
|
func buildVMSharePath(id string) string {
|
||||||
return filepath.Join(store.RunVMStoragePath(), id, "shared")
|
return filepath.Join(fs.RunVMStoragePath(), id, "shared")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *VM) logger() logrus.FieldLogger {
|
func (v *VM) logger() logrus.FieldLogger {
|
||||||
|
Loading…
Reference in New Issue
Block a user