mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-09 11:58:16 +00:00
virtcontainers: support new persist API
Fix API, container and kata implementations and unit tests to support the new persist API Signed-off-by: Julio Montes <julio.montes@intel.com>
This commit is contained in:
parent
9585bc929a
commit
11bd456a89
@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
deviceApi "github.com/kata-containers/runtime/virtcontainers/device/api"
|
deviceApi "github.com/kata-containers/runtime/virtcontainers/device/api"
|
||||||
deviceConfig "github.com/kata-containers/runtime/virtcontainers/device/config"
|
deviceConfig "github.com/kata-containers/runtime/virtcontainers/device/config"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/persist/fs"
|
"github.com/kata-containers/runtime/virtcontainers/persist"
|
||||||
"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/types"
|
"github.com/kata-containers/runtime/virtcontainers/types"
|
||||||
@ -308,9 +308,12 @@ func ListSandbox(ctx context.Context) ([]SandboxStatus, error) {
|
|||||||
span, ctx := trace(ctx, "ListSandbox")
|
span, ctx := trace(ctx, "ListSandbox")
|
||||||
defer span.Finish()
|
defer span.Finish()
|
||||||
|
|
||||||
sbsdir := fs.RunStoragePath()
|
store, err := persist.GetDriver()
|
||||||
|
if err != nil {
|
||||||
|
return []SandboxStatus{}, err
|
||||||
|
}
|
||||||
|
|
||||||
dir, err := os.Open(sbsdir)
|
dir, err := os.Open(store.RunStoragePath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
// No sandbox directory is not an error
|
// No sandbox directory is not an error
|
||||||
|
@ -17,7 +17,6 @@ import (
|
|||||||
|
|
||||||
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"
|
||||||
"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"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/pkg/rootless"
|
"github.com/kata-containers/runtime/virtcontainers/pkg/rootless"
|
||||||
@ -75,7 +74,7 @@ func newBasicTestCmd() types.Cmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func rmSandboxDir(sid string) error {
|
func rmSandboxDir(sid string) error {
|
||||||
store, err := persist.GetDriver("fs")
|
store, err := persist.GetDriver()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to get fs persist driver: %v", err)
|
return fmt.Errorf("failed to get fs persist driver: %v", err)
|
||||||
}
|
}
|
||||||
@ -154,7 +153,9 @@ func TestCreateSandboxNoopAgentSuccessful(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
s, ok := p.(*Sandbox)
|
||||||
|
assert.True(ok)
|
||||||
|
sandboxDir := filepath.Join(s.newStore.RunStoragePath(), p.ID())
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
}
|
}
|
||||||
@ -191,7 +192,9 @@ func TestCreateSandboxKataAgentSuccessful(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
s, ok := p.(*Sandbox)
|
||||||
|
assert.True(ok)
|
||||||
|
sandboxDir := filepath.Join(s.newStore.RunStoragePath(), p.ID())
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
}
|
}
|
||||||
@ -218,7 +221,9 @@ func TestDeleteSandboxNoopAgentSuccessful(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
s, ok := p.(*Sandbox)
|
||||||
|
assert.True(ok)
|
||||||
|
sandboxDir := filepath.Join(s.newStore.RunStoragePath(), p.ID())
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
@ -263,7 +268,9 @@ func TestDeleteSandboxKataAgentSuccessful(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
s, ok := p.(*Sandbox)
|
||||||
|
assert.True(ok)
|
||||||
|
sandboxDir := filepath.Join(s.newStore.RunStoragePath(), p.ID())
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
@ -279,9 +286,6 @@ func TestDeleteSandboxFailing(t *testing.T) {
|
|||||||
defer cleanUp()
|
defer cleanUp()
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
sandboxDir := filepath.Join(fs.RunStoragePath(), testSandboxID)
|
|
||||||
os.Remove(sandboxDir)
|
|
||||||
|
|
||||||
p, err := DeleteSandbox(context.Background(), testSandboxID)
|
p, err := DeleteSandbox(context.Background(), testSandboxID)
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
assert.Nil(p)
|
assert.Nil(p)
|
||||||
@ -343,9 +347,6 @@ func TestStartSandboxFailing(t *testing.T) {
|
|||||||
defer cleanUp()
|
defer cleanUp()
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
sandboxDir := filepath.Join(fs.RunStoragePath(), testSandboxID)
|
|
||||||
os.Remove(sandboxDir)
|
|
||||||
|
|
||||||
p, err := StartSandbox(context.Background(), testSandboxID)
|
p, err := StartSandbox(context.Background(), testSandboxID)
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
assert.Nil(p)
|
assert.Nil(p)
|
||||||
@ -410,9 +411,6 @@ func TestStopSandboxKataAgentSuccessful(t *testing.T) {
|
|||||||
func TestStopSandboxFailing(t *testing.T) {
|
func TestStopSandboxFailing(t *testing.T) {
|
||||||
defer cleanUp()
|
defer cleanUp()
|
||||||
|
|
||||||
sandboxDir := filepath.Join(fs.RunStoragePath(), testSandboxID)
|
|
||||||
os.Remove(sandboxDir)
|
|
||||||
|
|
||||||
p, err := StopSandbox(context.Background(), testSandboxID, false)
|
p, err := StopSandbox(context.Background(), testSandboxID, false)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
assert.Nil(t, p)
|
assert.Nil(t, p)
|
||||||
@ -428,7 +426,9 @@ func TestRunSandboxNoopAgentSuccessful(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
s, ok := p.(*Sandbox)
|
||||||
|
assert.True(ok)
|
||||||
|
sandboxDir := filepath.Join(s.newStore.RunStoragePath(), p.ID())
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
}
|
}
|
||||||
@ -466,13 +466,13 @@ func TestRunSandboxKataAgentSuccessful(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
|
||||||
_, err = os.Stat(sandboxDir)
|
|
||||||
assert.NoError(err)
|
|
||||||
|
|
||||||
pImpl, ok := p.(*Sandbox)
|
pImpl, ok := p.(*Sandbox)
|
||||||
assert.True(ok)
|
assert.True(ok)
|
||||||
|
|
||||||
|
sandboxDir := filepath.Join(pImpl.newStore.RunStoragePath(), p.ID())
|
||||||
|
_, err = os.Stat(sandboxDir)
|
||||||
|
assert.NoError(err)
|
||||||
|
|
||||||
err = bindUnmountAllRootfs(ctx, testDir, pImpl)
|
err = bindUnmountAllRootfs(ctx, testDir, pImpl)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
}
|
}
|
||||||
@ -693,7 +693,9 @@ func TestCreateContainerSuccessful(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
s, ok := p.(*Sandbox)
|
||||||
|
assert.True(ok)
|
||||||
|
sandboxDir := filepath.Join(s.newStore.RunStoragePath(), p.ID())
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
@ -724,7 +726,9 @@ func TestCreateContainerFailingNoSandbox(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
s, ok := p.(*Sandbox)
|
||||||
|
assert.True(ok)
|
||||||
|
sandboxDir := filepath.Join(s.newStore.RunStoragePath(), p.ID())
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
|
|
||||||
@ -747,7 +751,9 @@ func TestDeleteContainerSuccessful(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
s, ok := p.(*Sandbox)
|
||||||
|
assert.True(ok)
|
||||||
|
sandboxDir := filepath.Join(s.newStore.RunStoragePath(), p.ID())
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
@ -791,7 +797,9 @@ func TestDeleteContainerFailingNoContainer(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
s, ok := p.(*Sandbox)
|
||||||
|
assert.True(ok)
|
||||||
|
sandboxDir := filepath.Join(s.newStore.RunStoragePath(), p.ID())
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
@ -848,7 +856,9 @@ func TestStartContainerFailingNoContainer(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
s, ok := p.(*Sandbox)
|
||||||
|
assert.True(ok)
|
||||||
|
sandboxDir := filepath.Join(s.newStore.RunStoragePath(), p.ID())
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
@ -869,7 +879,9 @@ func TestStartContainerFailingSandboxNotStarted(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
s, ok := p.(*Sandbox)
|
||||||
|
assert.True(ok)
|
||||||
|
sandboxDir := filepath.Join(s.newStore.RunStoragePath(), p.ID())
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
@ -949,7 +961,9 @@ func TestStopContainerFailingNoContainer(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
s, ok := p.(*Sandbox)
|
||||||
|
assert.True(ok)
|
||||||
|
sandboxDir := filepath.Join(s.newStore.RunStoragePath(), p.ID())
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
@ -1053,7 +1067,9 @@ func TestEnterContainerFailingNoContainer(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
s, ok := p.(*Sandbox)
|
||||||
|
assert.True(ok)
|
||||||
|
sandboxDir := filepath.Join(s.newStore.RunStoragePath(), p.ID())
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
@ -1106,7 +1122,9 @@ func TestStatusContainerSuccessful(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
pImpl, ok := p.(*Sandbox)
|
||||||
|
assert.True(ok)
|
||||||
|
sandboxDir := filepath.Join(pImpl.newStore.RunStoragePath(), p.ID())
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
@ -1123,9 +1141,6 @@ func TestStatusContainerSuccessful(t *testing.T) {
|
|||||||
status, err := StatusContainer(ctx, p.ID(), contID)
|
status, err := StatusContainer(ctx, p.ID(), contID)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
pImpl, ok := p.(*Sandbox)
|
|
||||||
assert.True(ok)
|
|
||||||
|
|
||||||
cImpl, ok := c.(*Container)
|
cImpl, ok := c.(*Container)
|
||||||
assert.True(ok)
|
assert.True(ok)
|
||||||
|
|
||||||
@ -1149,7 +1164,9 @@ func TestStatusContainerStateReady(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
s, ok := p.(*Sandbox)
|
||||||
|
assert.True(ok)
|
||||||
|
sandboxDir := filepath.Join(s.newStore.RunStoragePath(), p.ID())
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
@ -1212,7 +1229,9 @@ func TestStatusContainerStateRunning(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
s, ok := p.(*Sandbox)
|
||||||
|
assert.True(ok)
|
||||||
|
sandboxDir := filepath.Join(s.newStore.RunStoragePath(), p.ID())
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
@ -1424,7 +1443,11 @@ func createAndStartSandbox(ctx context.Context, config SandboxConfig) (sandbox V
|
|||||||
return nil, "", err
|
return nil, "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
sandboxDir = filepath.Join(fs.RunStoragePath(), sandbox.ID())
|
s, ok := sandbox.(*Sandbox)
|
||||||
|
if !ok {
|
||||||
|
return nil, "", fmt.Errorf("Could not get Sandbox")
|
||||||
|
}
|
||||||
|
sandboxDir = filepath.Join(s.newStore.RunStoragePath(), sandbox.ID())
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
@ -1682,6 +1705,7 @@ func TestNetworkOperation(t *testing.T) {
|
|||||||
|
|
||||||
func TestCleanupContainer(t *testing.T) {
|
func TestCleanupContainer(t *testing.T) {
|
||||||
config := newTestSandboxConfigNoop()
|
config := newTestSandboxConfigNoop()
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
@ -1709,7 +1733,9 @@ func TestCleanupContainer(t *testing.T) {
|
|||||||
CleanupContainer(ctx, p.ID(), c.ID(), true)
|
CleanupContainer(ctx, p.ID(), c.ID(), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
sandboxDir := filepath.Join(fs.RunStoragePath(), p.ID())
|
s, ok := p.(*Sandbox)
|
||||||
|
assert.True(ok)
|
||||||
|
sandboxDir := filepath.Join(s.newStore.RunStoragePath(), p.ID())
|
||||||
|
|
||||||
_, err = os.Stat(sandboxDir)
|
_, err = os.Stat(sandboxDir)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -316,7 +316,7 @@ func TestContainerAddDriveDir(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
sandbox.newStore, err = persist.GetDriver("fs")
|
sandbox.newStore, err = persist.GetDriver()
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(sandbox.newStore)
|
assert.NotNil(sandbox.newStore)
|
||||||
|
|
||||||
|
@ -621,8 +621,8 @@ func TestAgentPathAPI(t *testing.T) {
|
|||||||
id := "foobar"
|
id := "foobar"
|
||||||
|
|
||||||
// getSharePath
|
// getSharePath
|
||||||
path1 = k1.getSharePath(id)
|
path1 := k1.getSharePath(id)
|
||||||
path2 = k2.getSharePath(id)
|
path2 := k2.getSharePath(id)
|
||||||
assert.Equal(path1, path2)
|
assert.Equal(path1, path2)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -710,7 +710,7 @@ func TestAgentCreateContainer(t *testing.T) {
|
|||||||
hypervisor: &mockHypervisor{},
|
hypervisor: &mockHypervisor{},
|
||||||
}
|
}
|
||||||
|
|
||||||
newStore, err := persist.GetDriver("fs")
|
newStore, err := persist.GetDriver()
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(newStore)
|
assert.NotNil(newStore)
|
||||||
sandbox.newStore = newStore
|
sandbox.newStore = newStore
|
||||||
|
@ -5,9 +5,7 @@
|
|||||||
|
|
||||||
package virtcontainers
|
package virtcontainers
|
||||||
|
|
||||||
import (
|
import "testing"
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestKataProxyStart(t *testing.T) {
|
func TestKataProxyStart(t *testing.T) {
|
||||||
agent := &kataAgent{}
|
agent := &kataAgent{}
|
||||||
|
@ -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/persist/fs"
|
"github.com/kata-containers/runtime/virtcontainers/persist"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -146,7 +146,11 @@ 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(filepath.Join(fs.RunStoragePath(), id), "proxy.sock")
|
store, err := persist.GetDriver()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
socketPath := filepath.Join(filepath.Join(store.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
|
||||||
|
@ -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(filepath.Join(fs.RunStoragePath(), sandboxID), "proxy.sock")
|
path := filepath.Join(filepath.Join(fs.MockRunStoragePath(), 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(filepath.Join(fs.RunStoragePath(), sandboxID), "proxy.sock")
|
path := filepath.Join(filepath.Join(fs.MockRunStoragePath(), 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(filepath.Join(fs.RunStoragePath(), testSandboxID), "proxy.sock")
|
expectedSocketPath := filepath.Join(filepath.Join(fs.MockRunStoragePath(), testSandboxID), "proxy.sock")
|
||||||
expectedURI := fmt.Sprintf("unix://%s", expectedSocketPath)
|
expectedURI := fmt.Sprintf("unix://%s", expectedSocketPath)
|
||||||
|
|
||||||
data := []testData{
|
data := []testData{
|
||||||
|
@ -15,6 +15,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"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/store"
|
"github.com/kata-containers/runtime/virtcontainers/store"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/utils"
|
"github.com/kata-containers/runtime/virtcontainers/utils"
|
||||||
@ -56,8 +57,8 @@ var testHyperstartTtySocket = ""
|
|||||||
// the next test to run.
|
// the next test to run.
|
||||||
func cleanUp() {
|
func cleanUp() {
|
||||||
globalSandboxList.removeSandbox(testSandboxID)
|
globalSandboxList.removeSandbox(testSandboxID)
|
||||||
os.RemoveAll(fs.RunStoragePath())
|
os.RemoveAll(fs.MockRunStoragePath())
|
||||||
os.RemoveAll(fs.RunVMStoragePath())
|
os.RemoveAll(fs.MockRunVMStoragePath())
|
||||||
os.RemoveAll(testDir)
|
os.RemoveAll(testDir)
|
||||||
os.MkdirAll(testDir, DirMode)
|
os.MkdirAll(testDir, DirMode)
|
||||||
|
|
||||||
@ -109,6 +110,8 @@ func setupClh() {
|
|||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
persist.EnableMockTesting()
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
logger := logrus.NewEntry(logrus.New())
|
logger := logrus.NewEntry(logrus.New())
|
||||||
@ -161,19 +164,8 @@ func TestMain(m *testing.M) {
|
|||||||
|
|
||||||
setupClh()
|
setupClh()
|
||||||
|
|
||||||
// allow the tests to run without affecting the host system.
|
|
||||||
runPathSave := fs.RunStoragePath()
|
|
||||||
rootPathSave := fs.StorageRootPath()
|
|
||||||
fs.TestSetRunStoragePath(filepath.Join(testDir, "vc", "run"))
|
|
||||||
fs.TestSetStorageRootPath(filepath.Join(testDir, "vc"))
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
fs.TestSetRunStoragePath(runPathSave)
|
|
||||||
fs.TestSetStorageRootPath(rootPathSave)
|
|
||||||
}()
|
|
||||||
|
|
||||||
// set now that configStoragePath has been overridden.
|
// set now that configStoragePath has been overridden.
|
||||||
sandboxDirState = filepath.Join(fs.RunStoragePath(), testSandboxID)
|
sandboxDirState = filepath.Join(fs.MockRunStoragePath(), testSandboxID)
|
||||||
|
|
||||||
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")
|
||||||
|
Loading…
Reference in New Issue
Block a user