mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-25 15:02:45 +00:00
virtcontainers/factory: support new persist API
Fix factory implementation and unit tests to support the new persist API Signed-off-by: Julio Montes <julio.montes@intel.com>
This commit is contained in:
parent
71f48a3364
commit
4b9ab557c8
21
virtcontainers/factory/cache/cache_test.go
vendored
21
virtcontainers/factory/cache/cache_test.go
vendored
@ -7,9 +7,6 @@ package cache
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@ -19,18 +16,11 @@ import (
|
|||||||
"github.com/kata-containers/runtime/virtcontainers/persist/fs"
|
"github.com/kata-containers/runtime/virtcontainers/persist/fs"
|
||||||
)
|
)
|
||||||
|
|
||||||
var rootPathSave = fs.StorageRootPath()
|
|
||||||
|
|
||||||
func TestTemplateFactory(t *testing.T) {
|
func TestTemplateFactory(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
testDir, _ := ioutil.TempDir("", "vmfactory-tmp-")
|
testDir := fs.MockStorageRootPath()
|
||||||
fs.TestSetStorageRootPath(filepath.Join(testDir, "vc"))
|
defer fs.MockStorageDestroy()
|
||||||
|
|
||||||
defer func() {
|
|
||||||
os.RemoveAll(testDir)
|
|
||||||
fs.TestSetStorageRootPath(rootPathSave)
|
|
||||||
}()
|
|
||||||
|
|
||||||
hyperConfig := vc.HypervisorConfig{
|
hyperConfig := vc.HypervisorConfig{
|
||||||
KernelPath: testDir,
|
KernelPath: testDir,
|
||||||
@ -45,13 +35,6 @@ func TestTemplateFactory(t *testing.T) {
|
|||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
runPathSave := fs.RunStoragePath()
|
|
||||||
fs.TestSetRunStoragePath(filepath.Join(testDir, "vc", "run"))
|
|
||||||
// allow the tests to run without affecting the host system.
|
|
||||||
defer func() {
|
|
||||||
fs.TestSetRunStoragePath(runPathSave)
|
|
||||||
}()
|
|
||||||
|
|
||||||
// New
|
// New
|
||||||
f := New(ctx, 2, direct.New(ctx, vmConfig))
|
f := New(ctx, 2, direct.New(ctx, vmConfig))
|
||||||
|
|
||||||
|
@ -7,9 +7,6 @@ package direct
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@ -18,28 +15,11 @@ import (
|
|||||||
"github.com/kata-containers/runtime/virtcontainers/persist/fs"
|
"github.com/kata-containers/runtime/virtcontainers/persist/fs"
|
||||||
)
|
)
|
||||||
|
|
||||||
var rootPathSave = fs.StorageRootPath()
|
|
||||||
|
|
||||||
func TestTemplateFactory(t *testing.T) {
|
func TestTemplateFactory(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
testDir, err := ioutil.TempDir("", "vmfactory-tmp-")
|
testDir := fs.MockStorageRootPath()
|
||||||
fs.TestSetStorageRootPath(filepath.Join(testDir, "vc"))
|
defer fs.MockStorageDestroy()
|
||||||
|
|
||||||
defer func() {
|
|
||||||
os.RemoveAll(testDir)
|
|
||||||
fs.TestSetStorageRootPath(rootPathSave)
|
|
||||||
}()
|
|
||||||
|
|
||||||
assert.Nil(err)
|
|
||||||
|
|
||||||
runPathSave := fs.RunStoragePath()
|
|
||||||
fs.TestSetRunStoragePath(filepath.Join(testDir, "vc", "run"))
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
os.RemoveAll(testDir)
|
|
||||||
fs.TestSetRunStoragePath(runPathSave)
|
|
||||||
}()
|
|
||||||
|
|
||||||
hyperConfig := vc.HypervisorConfig{
|
hyperConfig := vc.HypervisorConfig{
|
||||||
KernelPath: testDir,
|
KernelPath: testDir,
|
||||||
|
@ -7,9 +7,7 @@ package factory
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
vc "github.com/kata-containers/runtime/virtcontainers"
|
vc "github.com/kata-containers/runtime/virtcontainers"
|
||||||
@ -22,8 +20,6 @@ import (
|
|||||||
|
|
||||||
const testDisabledAsNonRoot = "Test disabled as requires root privileges"
|
const testDisabledAsNonRoot = "Test disabled as requires root privileges"
|
||||||
|
|
||||||
var rootPathSave = fs.StorageRootPath()
|
|
||||||
|
|
||||||
func TestNewFactory(t *testing.T) {
|
func TestNewFactory(t *testing.T) {
|
||||||
var config Config
|
var config Config
|
||||||
|
|
||||||
@ -44,17 +40,10 @@ func TestNewFactory(t *testing.T) {
|
|||||||
_, err = NewFactory(ctx, config, false)
|
_, err = NewFactory(ctx, config, false)
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
|
|
||||||
testDir, _ := ioutil.TempDir("", "vmfactory-tmp-")
|
defer fs.MockStorageDestroy()
|
||||||
fs.TestSetStorageRootPath(filepath.Join(testDir, "vc"))
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
os.RemoveAll(testDir)
|
|
||||||
fs.TestSetStorageRootPath(rootPathSave)
|
|
||||||
}()
|
|
||||||
|
|
||||||
config.VMConfig.HypervisorConfig = vc.HypervisorConfig{
|
config.VMConfig.HypervisorConfig = vc.HypervisorConfig{
|
||||||
KernelPath: testDir,
|
KernelPath: fs.MockStorageRootPath(),
|
||||||
ImagePath: testDir,
|
ImagePath: fs.MockStorageRootPath(),
|
||||||
}
|
}
|
||||||
|
|
||||||
// direct
|
// direct
|
||||||
@ -71,7 +60,7 @@ func TestNewFactory(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
config.Template = true
|
config.Template = true
|
||||||
config.TemplatePath = testDir
|
config.TemplatePath = fs.MockStorageRootPath()
|
||||||
f, err = NewFactory(ctx, config, false)
|
f, err = NewFactory(ctx, config, false)
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
f.CloseFactory(ctx)
|
f.CloseFactory(ctx)
|
||||||
@ -119,19 +108,12 @@ func TestFactorySetLogger(t *testing.T) {
|
|||||||
func TestVMConfigValid(t *testing.T) {
|
func TestVMConfigValid(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
testDir, _ := ioutil.TempDir("", "vmfactory-tmp-")
|
defer fs.MockStorageDestroy()
|
||||||
fs.TestSetStorageRootPath(filepath.Join(testDir, "vc"))
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
os.RemoveAll(testDir)
|
|
||||||
fs.TestSetStorageRootPath(rootPathSave)
|
|
||||||
}()
|
|
||||||
|
|
||||||
config := vc.VMConfig{
|
config := vc.VMConfig{
|
||||||
HypervisorType: vc.MockHypervisor,
|
HypervisorType: vc.MockHypervisor,
|
||||||
HypervisorConfig: vc.HypervisorConfig{
|
HypervisorConfig: vc.HypervisorConfig{
|
||||||
KernelPath: testDir,
|
KernelPath: fs.MockStorageRootPath(),
|
||||||
ImagePath: testDir,
|
ImagePath: fs.MockStorageRootPath(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,13 +156,8 @@ func TestCheckVMConfig(t *testing.T) {
|
|||||||
err = checkVMConfig(config1, config2)
|
err = checkVMConfig(config1, config2)
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
|
|
||||||
testDir, _ := ioutil.TempDir("", "vmfactory-tmp-")
|
testDir := fs.MockStorageRootPath()
|
||||||
fs.TestSetStorageRootPath(filepath.Join(testDir, "vc"))
|
defer fs.MockStorageDestroy()
|
||||||
|
|
||||||
defer func() {
|
|
||||||
os.RemoveAll(testDir)
|
|
||||||
fs.TestSetStorageRootPath(rootPathSave)
|
|
||||||
}()
|
|
||||||
|
|
||||||
config1.HypervisorConfig = vc.HypervisorConfig{
|
config1.HypervisorConfig = vc.HypervisorConfig{
|
||||||
KernelPath: testDir,
|
KernelPath: testDir,
|
||||||
@ -200,13 +177,8 @@ func TestCheckVMConfig(t *testing.T) {
|
|||||||
func TestFactoryGetVM(t *testing.T) {
|
func TestFactoryGetVM(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
testDir, _ := ioutil.TempDir("", "vmfactory-tmp-")
|
testDir := fs.MockStorageRootPath()
|
||||||
fs.TestSetStorageRootPath(filepath.Join(testDir, "vc"))
|
defer fs.MockStorageDestroy()
|
||||||
|
|
||||||
defer func() {
|
|
||||||
os.RemoveAll(testDir)
|
|
||||||
fs.TestSetStorageRootPath(rootPathSave)
|
|
||||||
}()
|
|
||||||
|
|
||||||
hyperConfig := vc.HypervisorConfig{
|
hyperConfig := vc.HypervisorConfig{
|
||||||
KernelPath: testDir,
|
KernelPath: testDir,
|
||||||
@ -366,13 +338,8 @@ func TestDeepCompare(t *testing.T) {
|
|||||||
AgentType: vc.NoopAgentType,
|
AgentType: vc.NoopAgentType,
|
||||||
ProxyType: vc.NoopProxyType,
|
ProxyType: vc.NoopProxyType,
|
||||||
}
|
}
|
||||||
testDir, _ := ioutil.TempDir("", "vmfactory-tmp-")
|
testDir := fs.MockStorageRootPath()
|
||||||
fs.TestSetStorageRootPath(filepath.Join(testDir, "vc"))
|
defer fs.MockStorageDestroy()
|
||||||
|
|
||||||
defer func() {
|
|
||||||
os.RemoveAll(testDir)
|
|
||||||
fs.TestSetStorageRootPath(rootPathSave)
|
|
||||||
}()
|
|
||||||
|
|
||||||
config.VMConfig.HypervisorConfig = vc.HypervisorConfig{
|
config.VMConfig.HypervisorConfig = vc.HypervisorConfig{
|
||||||
KernelPath: testDir,
|
KernelPath: testDir,
|
||||||
|
@ -7,9 +7,7 @@ package template
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -21,8 +19,6 @@ import (
|
|||||||
|
|
||||||
const testDisabledAsNonRoot = "Test disabled as requires root privileges"
|
const testDisabledAsNonRoot = "Test disabled as requires root privileges"
|
||||||
|
|
||||||
var rootPathSave = fs.StorageRootPath()
|
|
||||||
|
|
||||||
func TestTemplateFactory(t *testing.T) {
|
func TestTemplateFactory(t *testing.T) {
|
||||||
if os.Geteuid() != 0 {
|
if os.Geteuid() != 0 {
|
||||||
t.Skip(testDisabledAsNonRoot)
|
t.Skip(testDisabledAsNonRoot)
|
||||||
@ -32,13 +28,8 @@ func TestTemplateFactory(t *testing.T) {
|
|||||||
|
|
||||||
templateWaitForAgent = 1 * time.Microsecond
|
templateWaitForAgent = 1 * time.Microsecond
|
||||||
|
|
||||||
testDir, _ := ioutil.TempDir("", "vmfactory-tmp-")
|
testDir := fs.MockStorageRootPath()
|
||||||
fs.TestSetStorageRootPath(filepath.Join(testDir, "vc"))
|
defer fs.MockStorageDestroy()
|
||||||
|
|
||||||
defer func() {
|
|
||||||
os.RemoveAll(testDir)
|
|
||||||
fs.TestSetStorageRootPath(rootPathSave)
|
|
||||||
}()
|
|
||||||
|
|
||||||
hyperConfig := vc.HypervisorConfig{
|
hyperConfig := vc.HypervisorConfig{
|
||||||
KernelPath: testDir,
|
KernelPath: testDir,
|
||||||
|
Loading…
Reference in New Issue
Block a user