mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-30 09:13:29 +00:00
vc: Deprecate CC proxy and shim
Clear Containers proxy and shim are no longer supported. This was mentioned in issue #1113. Their functionalities are thus removed from the runtime. Fixes #1419 Signed-off-by: Gabi Beyer <gabrielle.n.beyer@intel.com>
This commit is contained in:
parent
c658770891
commit
c42507903d
@ -243,8 +243,8 @@ func newTestRuntimeConfig(dir, consolePath string, create bool) (oci.RuntimeConf
|
|||||||
HypervisorType: vc.QemuHypervisor,
|
HypervisorType: vc.QemuHypervisor,
|
||||||
HypervisorConfig: hypervisorConfig,
|
HypervisorConfig: hypervisorConfig,
|
||||||
AgentType: vc.KataContainersAgent,
|
AgentType: vc.KataContainersAgent,
|
||||||
ProxyType: vc.CCProxyType,
|
ProxyType: vc.KataProxyType,
|
||||||
ShimType: vc.CCShimType,
|
ShimType: vc.KataShimType,
|
||||||
Console: consolePath,
|
Console: consolePath,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -52,11 +52,9 @@ const (
|
|||||||
qemuHypervisorTableType = "qemu"
|
qemuHypervisorTableType = "qemu"
|
||||||
|
|
||||||
// supported proxy component types
|
// supported proxy component types
|
||||||
ccProxyTableType = "cc"
|
|
||||||
kataProxyTableType = "kata"
|
kataProxyTableType = "kata"
|
||||||
|
|
||||||
// supported shim component types
|
// supported shim component types
|
||||||
ccShimTableType = "cc"
|
|
||||||
kataShimTableType = "kata"
|
kataShimTableType = "kata"
|
||||||
|
|
||||||
// supported agent component types
|
// supported agent component types
|
||||||
@ -605,10 +603,10 @@ func updateRuntimeConfigProxy(configPath string, tomlConf tomlConfig, config *oc
|
|||||||
|
|
||||||
for k, proxy := range tomlConf.Proxy {
|
for k, proxy := range tomlConf.Proxy {
|
||||||
switch k {
|
switch k {
|
||||||
case ccProxyTableType:
|
|
||||||
config.ProxyType = vc.CCProxyType
|
|
||||||
case kataProxyTableType:
|
case kataProxyTableType:
|
||||||
config.ProxyType = vc.KataProxyType
|
config.ProxyType = vc.KataProxyType
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("%s proxy type not supported", k)
|
||||||
}
|
}
|
||||||
|
|
||||||
path, err := proxy.path()
|
path, err := proxy.path()
|
||||||
@ -660,10 +658,10 @@ func updateRuntimeConfigShim(configPath string, tomlConf tomlConfig, config *oci
|
|||||||
|
|
||||||
for k, shim := range tomlConf.Shim {
|
for k, shim := range tomlConf.Shim {
|
||||||
switch k {
|
switch k {
|
||||||
case ccShimTableType:
|
|
||||||
config.ShimType = vc.CCShimType
|
|
||||||
case kataShimTableType:
|
case kataShimTableType:
|
||||||
config.ShimType = vc.KataShimType
|
config.ShimType = vc.KataShimType
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("%s shim is not supported", k)
|
||||||
}
|
}
|
||||||
|
|
||||||
shConfig, err := newShimConfig(shim)
|
shConfig, err := newShimConfig(shim)
|
||||||
|
@ -121,8 +121,8 @@ func newTestRuntimeConfig(dir, consolePath string, create bool) (oci.RuntimeConf
|
|||||||
HypervisorType: vc.QemuHypervisor,
|
HypervisorType: vc.QemuHypervisor,
|
||||||
HypervisorConfig: hypervisorConfig,
|
HypervisorConfig: hypervisorConfig,
|
||||||
AgentType: vc.KataContainersAgent,
|
AgentType: vc.KataContainersAgent,
|
||||||
ProxyType: vc.CCProxyType,
|
ProxyType: vc.KataProxyType,
|
||||||
ShimType: vc.CCShimType,
|
ShimType: vc.KataShimType,
|
||||||
Console: consolePath,
|
Console: consolePath,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,6 @@ VC_BIN_DIR := $(BIN_DIR)/virtcontainers/bin
|
|||||||
TEST_BIN_DIR := $(VC_BIN_DIR)/test
|
TEST_BIN_DIR := $(VC_BIN_DIR)/test
|
||||||
HOOK_DIR := hook/mock
|
HOOK_DIR := hook/mock
|
||||||
HOOK_BIN := hook
|
HOOK_BIN := hook
|
||||||
CC_SHIM_DIR := shim/mock/cc-shim
|
|
||||||
CC_SHIM_BIN := cc-shim
|
|
||||||
KATA_SHIM_DIR := shim/mock/kata-shim
|
KATA_SHIM_DIR := shim/mock/kata-shim
|
||||||
KATA_SHIM_BIN := kata-shim
|
KATA_SHIM_BIN := kata-shim
|
||||||
MK_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
|
MK_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
|
||||||
@ -36,13 +34,10 @@ build:
|
|||||||
hook:
|
hook:
|
||||||
$(QUIET_GOBUILD)go build -o $(HOOK_DIR)/$@ $(HOOK_DIR)/*.go
|
$(QUIET_GOBUILD)go build -o $(HOOK_DIR)/$@ $(HOOK_DIR)/*.go
|
||||||
|
|
||||||
cc-shim:
|
|
||||||
$(QUIET_GOBUILD)go build -o $(CC_SHIM_DIR)/$@ $(CC_SHIM_DIR)/*.go
|
|
||||||
|
|
||||||
kata-shim:
|
kata-shim:
|
||||||
$(QUIET_GOBUILD)go build -o $(KATA_SHIM_DIR)/$@ $(KATA_SHIM_DIR)/*.go
|
$(QUIET_GOBUILD)go build -o $(KATA_SHIM_DIR)/$@ $(KATA_SHIM_DIR)/*.go
|
||||||
|
|
||||||
binaries: hook cc-shim kata-shim
|
binaries: hook kata-shim
|
||||||
|
|
||||||
#
|
#
|
||||||
# Tests
|
# Tests
|
||||||
@ -55,7 +50,6 @@ check-go-static:
|
|||||||
|
|
||||||
check-go-test:
|
check-go-test:
|
||||||
bash $(MK_DIR)/../.ci/go-test.sh \
|
bash $(MK_DIR)/../.ci/go-test.sh \
|
||||||
$(TEST_BIN_DIR)/$(CC_SHIM_BIN) \
|
|
||||||
$(TEST_BIN_DIR)/$(KATA_SHIM_BIN) \
|
$(TEST_BIN_DIR)/$(KATA_SHIM_BIN) \
|
||||||
$(TEST_BIN_DIR)/$(HOOK_BIN)
|
$(TEST_BIN_DIR)/$(HOOK_BIN)
|
||||||
|
|
||||||
@ -75,7 +69,6 @@ install:
|
|||||||
@mkdir -p $(VC_BIN_DIR)
|
@mkdir -p $(VC_BIN_DIR)
|
||||||
@mkdir -p $(TEST_BIN_DIR)
|
@mkdir -p $(TEST_BIN_DIR)
|
||||||
$(call INSTALL_TEST_EXEC,$(HOOK_DIR)/$(HOOK_BIN))
|
$(call INSTALL_TEST_EXEC,$(HOOK_DIR)/$(HOOK_BIN))
|
||||||
$(call INSTALL_TEST_EXEC,$(CC_SHIM_DIR)/$(CC_SHIM_BIN))
|
|
||||||
$(call INSTALL_TEST_EXEC,$(KATA_SHIM_DIR)/$(KATA_SHIM_BIN))
|
$(call INSTALL_TEST_EXEC,$(KATA_SHIM_DIR)/$(KATA_SHIM_BIN))
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -92,7 +85,6 @@ endef
|
|||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
$(call UNINSTALL_TEST_EXEC,$(HOOK_BIN))
|
$(call UNINSTALL_TEST_EXEC,$(HOOK_BIN))
|
||||||
$(call UNINSTALL_TEST_EXEC,$(CC_SHIM_BIN))
|
|
||||||
$(call UNINSTALL_TEST_EXEC,$(KATA_SHIM_BIN))
|
$(call UNINSTALL_TEST_EXEC,$(KATA_SHIM_BIN))
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -106,7 +98,6 @@ $(shell test -e "$(1)" && test "$(1)" != "/" && echo "$(1)")
|
|||||||
endef
|
endef
|
||||||
|
|
||||||
CLEAN_FILES += $(HOOK_DIR)/$(HOOK_BIN)
|
CLEAN_FILES += $(HOOK_DIR)/$(HOOK_BIN)
|
||||||
CLEAN_FILES += $(SHIM_DIR)/$(CC_SHIM_BIN)
|
|
||||||
CLEAN_FILES += $(SHIM_DIR)/$(KATA_SHIM_BIN)
|
CLEAN_FILES += $(SHIM_DIR)/$(KATA_SHIM_BIN)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
@ -8,11 +8,9 @@ package virtcontainers
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
@ -133,18 +131,6 @@ func TestCreateSandboxNoopAgentSuccessful(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var testCCProxySockPathTempl = "%s/cc-proxy-test.sock"
|
|
||||||
var testCCProxyURLUnixScheme = "unix://"
|
|
||||||
|
|
||||||
func testGenerateCCProxySockDir() (string, error) {
|
|
||||||
dir, err := ioutil.TempDir("", "cc-proxy-test")
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
return dir, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCreateSandboxKataAgentSuccessful(t *testing.T) {
|
func TestCreateSandboxKataAgentSuccessful(t *testing.T) {
|
||||||
if os.Geteuid() != 0 {
|
if os.Geteuid() != 0 {
|
||||||
t.Skip(testDisabledAsNonRoot)
|
t.Skip(testDisabledAsNonRoot)
|
||||||
@ -1601,42 +1587,6 @@ func createNewSandboxConfig(hType HypervisorType, aType AgentType, aConfig inter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func createNewContainerConfigs(numOfContainers int) []ContainerConfig {
|
|
||||||
var contConfigs []ContainerConfig
|
|
||||||
|
|
||||||
envs := []types.EnvVar{
|
|
||||||
{
|
|
||||||
Var: "PATH",
|
|
||||||
Value: "/bin:/usr/bin:/sbin:/usr/sbin",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd := types.Cmd{
|
|
||||||
Args: strings.Split("/bin/ps -A", " "),
|
|
||||||
Envs: envs,
|
|
||||||
WorkDir: "/",
|
|
||||||
}
|
|
||||||
|
|
||||||
_, thisFile, _, ok := runtime.Caller(0)
|
|
||||||
if ok == false {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
rootFs := RootFs{Target: filepath.Dir(thisFile) + "/utils/supportfiles/bundles/busybox/", Mounted: true}
|
|
||||||
|
|
||||||
for i := 0; i < numOfContainers; i++ {
|
|
||||||
contConfig := ContainerConfig{
|
|
||||||
ID: fmt.Sprintf("%d", i),
|
|
||||||
RootFs: rootFs,
|
|
||||||
Cmd: cmd,
|
|
||||||
}
|
|
||||||
|
|
||||||
contConfigs = append(contConfigs, contConfig)
|
|
||||||
}
|
|
||||||
|
|
||||||
return contConfigs
|
|
||||||
}
|
|
||||||
|
|
||||||
// createAndStartSandbox handles the common test operation of creating and
|
// createAndStartSandbox handles the common test operation of creating and
|
||||||
// starting a sandbox.
|
// starting a sandbox.
|
||||||
func createAndStartSandbox(ctx context.Context, config SandboxConfig) (sandbox VCSandbox, sandboxDir string,
|
func createAndStartSandbox(ctx context.Context, config SandboxConfig) (sandbox VCSandbox, sandboxDir string,
|
||||||
@ -1684,66 +1634,6 @@ func createStartStopDeleteSandbox(b *testing.B, sandboxConfig SandboxConfig) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func createStartStopDeleteContainers(b *testing.B, sandboxConfig SandboxConfig, contConfigs []ContainerConfig) {
|
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
// Create sandbox
|
|
||||||
p, err := CreateSandbox(ctx, sandboxConfig, nil)
|
|
||||||
if err != nil {
|
|
||||||
b.Fatalf("Could not create sandbox: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start sandbox
|
|
||||||
_, err = StartSandbox(ctx, p.ID())
|
|
||||||
if err != nil {
|
|
||||||
b.Fatalf("Could not start sandbox: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create containers
|
|
||||||
for _, contConfig := range contConfigs {
|
|
||||||
_, _, err := CreateContainer(ctx, p.ID(), contConfig)
|
|
||||||
if err != nil {
|
|
||||||
b.Fatalf("Could not create container %s: %s", contConfig.ID, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start containers
|
|
||||||
for _, contConfig := range contConfigs {
|
|
||||||
_, err := StartContainer(ctx, p.ID(), contConfig.ID)
|
|
||||||
if err != nil {
|
|
||||||
b.Fatalf("Could not start container %s: %s", contConfig.ID, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stop containers
|
|
||||||
for _, contConfig := range contConfigs {
|
|
||||||
_, err := StopContainer(ctx, p.ID(), contConfig.ID)
|
|
||||||
if err != nil {
|
|
||||||
b.Fatalf("Could not stop container %s: %s", contConfig.ID, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete containers
|
|
||||||
for _, contConfig := range contConfigs {
|
|
||||||
_, err := DeleteContainer(ctx, p.ID(), contConfig.ID)
|
|
||||||
if err != nil {
|
|
||||||
b.Fatalf("Could not delete container %s: %s", contConfig.ID, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stop sandbox
|
|
||||||
_, err = StopSandbox(ctx, p.ID())
|
|
||||||
if err != nil {
|
|
||||||
b.Fatalf("Could not stop sandbox: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete sandbox
|
|
||||||
_, err = DeleteSandbox(ctx, p.ID())
|
|
||||||
if err != nil {
|
|
||||||
b.Fatalf("Could not delete sandbox: %s", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func BenchmarkCreateStartStopDeleteSandboxQemuHypervisorNoopAgentNetworkNoop(b *testing.B) {
|
func BenchmarkCreateStartStopDeleteSandboxQemuHypervisorNoopAgentNetworkNoop(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
sandboxConfig := createNewSandboxConfig(QemuHypervisor, NoopAgentType, nil)
|
sandboxConfig := createNewSandboxConfig(QemuHypervisor, NoopAgentType, nil)
|
||||||
|
@ -1,47 +0,0 @@
|
|||||||
// Copyright (c) 2017 Intel Corporation
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
//
|
|
||||||
|
|
||||||
package virtcontainers
|
|
||||||
|
|
||||||
import "os/exec"
|
|
||||||
|
|
||||||
type ccProxy struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
// start is the proxy start implementation for ccProxy.
|
|
||||||
func (p *ccProxy) start(params proxyParams) (int, string, error) {
|
|
||||||
if err := validateProxyParams(params); err != nil {
|
|
||||||
return -1, "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
params.logger.Debug("Starting cc proxy")
|
|
||||||
|
|
||||||
// construct the socket path the proxy instance will use
|
|
||||||
proxyURL, err := defaultProxyURL(params.id, SocketTypeUNIX)
|
|
||||||
if err != nil {
|
|
||||||
return -1, "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
args := []string{params.path, "-uri", proxyURL}
|
|
||||||
if params.debug {
|
|
||||||
args = append(args, "-log", "debug")
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd := exec.Command(args[0], args[1:]...)
|
|
||||||
if err := cmd.Start(); err != nil {
|
|
||||||
return -1, "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
return cmd.Process.Pid, proxyURL, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *ccProxy) stop(pid int) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// The ccproxy doesn't need to watch the vm console, thus return false always.
|
|
||||||
func (p *ccProxy) consoleWatched() bool {
|
|
||||||
return false
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
// Copyright (c) 2017 Intel Corporation
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
//
|
|
||||||
|
|
||||||
package virtcontainers
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestCCProxyStart(t *testing.T) {
|
|
||||||
proxy := &ccProxy{}
|
|
||||||
|
|
||||||
testProxyStart(t, nil, proxy)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCCProxy(t *testing.T) {
|
|
||||||
proxy := &ccProxy{}
|
|
||||||
assert := assert.New(t)
|
|
||||||
|
|
||||||
err := proxy.stop(0)
|
|
||||||
assert.Nil(err)
|
|
||||||
|
|
||||||
assert.False(proxy.consoleWatched())
|
|
||||||
}
|
|
@ -1,49 +0,0 @@
|
|||||||
// Copyright (c) 2017 Intel Corporation
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
//
|
|
||||||
|
|
||||||
package virtcontainers
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ccShim struct{}
|
|
||||||
|
|
||||||
// start is the ccShim start implementation.
|
|
||||||
// It starts the cc-shim binary with URL and token flags provided by
|
|
||||||
// the proxy.
|
|
||||||
func (s *ccShim) start(sandbox *Sandbox, params ShimParams) (int, error) {
|
|
||||||
if sandbox.config == nil {
|
|
||||||
return -1, fmt.Errorf("Sandbox config cannot be nil")
|
|
||||||
}
|
|
||||||
|
|
||||||
config, ok := newShimConfig(*(sandbox.config)).(ShimConfig)
|
|
||||||
if !ok {
|
|
||||||
return -1, fmt.Errorf("Wrong shim config type, should be CCShimConfig type")
|
|
||||||
}
|
|
||||||
|
|
||||||
if config.Path == "" {
|
|
||||||
return -1, fmt.Errorf("Shim path cannot be empty")
|
|
||||||
}
|
|
||||||
|
|
||||||
if params.Token == "" {
|
|
||||||
return -1, fmt.Errorf("Token cannot be empty")
|
|
||||||
}
|
|
||||||
|
|
||||||
if params.URL == "" {
|
|
||||||
return -1, fmt.Errorf("URL cannot be empty")
|
|
||||||
}
|
|
||||||
|
|
||||||
if params.Container == "" {
|
|
||||||
return -1, fmt.Errorf("Container cannot be empty")
|
|
||||||
}
|
|
||||||
|
|
||||||
args := []string{config.Path, "-c", params.Container, "-t", params.Token, "-u", params.URL}
|
|
||||||
if config.Debug {
|
|
||||||
args = append(args, "-d")
|
|
||||||
}
|
|
||||||
|
|
||||||
return startShim(args, params)
|
|
||||||
}
|
|
@ -1,357 +0,0 @@
|
|||||||
// Copyright (c) 2017 Intel Corporation
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
//
|
|
||||||
|
|
||||||
package virtcontainers
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
"syscall"
|
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
. "github.com/kata-containers/runtime/virtcontainers/pkg/mock"
|
|
||||||
)
|
|
||||||
|
|
||||||
// These tests don't care about the format of the container ID
|
|
||||||
const testContainer = "testContainer"
|
|
||||||
|
|
||||||
var testCCShimPath = "/usr/bin/virtcontainers/bin/test/cc-shim"
|
|
||||||
var testProxyURL = "foo:///foo/clear-containers/proxy.sock"
|
|
||||||
var testWrongConsolePath = "/foo/wrong-console"
|
|
||||||
|
|
||||||
func getMockCCShimBinPath() string {
|
|
||||||
if DefaultMockCCShimBinPath == "" {
|
|
||||||
return testCCShimPath
|
|
||||||
}
|
|
||||||
|
|
||||||
return DefaultMockCCShimBinPath
|
|
||||||
}
|
|
||||||
|
|
||||||
func testCCShimStart(t *testing.T, sandbox *Sandbox, params ShimParams, expectFail bool) {
|
|
||||||
s := &ccShim{}
|
|
||||||
|
|
||||||
pid, err := s.start(sandbox, params)
|
|
||||||
if expectFail {
|
|
||||||
if err == nil || pid != -1 {
|
|
||||||
t.Fatalf("This test should fail (sandbox %+v, params %+v, expectFail %t)",
|
|
||||||
sandbox, params, expectFail)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("This test should pass (sandbox %+v, params %+v, expectFail %t): %s",
|
|
||||||
sandbox, params, expectFail, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if pid == -1 {
|
|
||||||
t.Fatalf("This test should pass (sandbox %+v, params %+v, expectFail %t)",
|
|
||||||
sandbox, params, expectFail)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCCShimStartNilSandboxConfigFailure(t *testing.T) {
|
|
||||||
testCCShimStart(t, &Sandbox{}, ShimParams{}, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCCShimStartNilShimConfigFailure(t *testing.T) {
|
|
||||||
sandbox := &Sandbox{
|
|
||||||
config: &SandboxConfig{},
|
|
||||||
}
|
|
||||||
|
|
||||||
testCCShimStart(t, sandbox, ShimParams{}, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCCShimStartShimPathEmptyFailure(t *testing.T) {
|
|
||||||
sandbox := &Sandbox{
|
|
||||||
config: &SandboxConfig{
|
|
||||||
ShimType: CCShimType,
|
|
||||||
ShimConfig: ShimConfig{},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
testCCShimStart(t, sandbox, ShimParams{}, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCCShimStartShimTypeInvalid(t *testing.T) {
|
|
||||||
sandbox := &Sandbox{
|
|
||||||
config: &SandboxConfig{
|
|
||||||
ShimType: "foo",
|
|
||||||
ShimConfig: ShimConfig{},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
testCCShimStart(t, sandbox, ShimParams{}, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCCShimStartParamsTokenEmptyFailure(t *testing.T) {
|
|
||||||
sandbox := &Sandbox{
|
|
||||||
config: &SandboxConfig{
|
|
||||||
ShimType: CCShimType,
|
|
||||||
ShimConfig: ShimConfig{
|
|
||||||
Path: getMockCCShimBinPath(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
testCCShimStart(t, sandbox, ShimParams{}, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCCShimStartParamsURLEmptyFailure(t *testing.T) {
|
|
||||||
sandbox := &Sandbox{
|
|
||||||
config: &SandboxConfig{
|
|
||||||
ShimType: CCShimType,
|
|
||||||
ShimConfig: ShimConfig{
|
|
||||||
Path: getMockCCShimBinPath(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
params := ShimParams{
|
|
||||||
Token: "testToken",
|
|
||||||
}
|
|
||||||
|
|
||||||
testCCShimStart(t, sandbox, params, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCCShimStartParamsContainerEmptyFailure(t *testing.T) {
|
|
||||||
sandbox := &Sandbox{
|
|
||||||
config: &SandboxConfig{
|
|
||||||
ShimType: CCShimType,
|
|
||||||
ShimConfig: ShimConfig{
|
|
||||||
Path: getMockCCShimBinPath(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
params := ShimParams{
|
|
||||||
Token: "testToken",
|
|
||||||
URL: "unix://is/awesome",
|
|
||||||
}
|
|
||||||
|
|
||||||
testCCShimStart(t, sandbox, params, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCCShimStartParamsInvalidCommand(t *testing.T) {
|
|
||||||
dir, err := ioutil.TempDir("", "")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
cmd := filepath.Join(dir, "does-not-exist")
|
|
||||||
|
|
||||||
sandbox := &Sandbox{
|
|
||||||
config: &SandboxConfig{
|
|
||||||
ShimType: CCShimType,
|
|
||||||
ShimConfig: ShimConfig{
|
|
||||||
Path: cmd,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
params := ShimParams{
|
|
||||||
Token: "testToken",
|
|
||||||
URL: "http://foo",
|
|
||||||
}
|
|
||||||
|
|
||||||
testCCShimStart(t, sandbox, params, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func startCCShimStartWithoutConsoleSuccessful(t *testing.T, detach bool) (*os.File, *os.File, *os.File, *Sandbox, ShimParams, error) {
|
|
||||||
saveStdout := os.Stdout
|
|
||||||
rStdout, wStdout, err := os.Pipe()
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, nil, &Sandbox{}, ShimParams{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
os.Stdout = wStdout
|
|
||||||
|
|
||||||
sandbox := &Sandbox{
|
|
||||||
config: &SandboxConfig{
|
|
||||||
ShimType: CCShimType,
|
|
||||||
ShimConfig: ShimConfig{
|
|
||||||
Path: getMockCCShimBinPath(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
params := ShimParams{
|
|
||||||
Container: testContainer,
|
|
||||||
Token: "testToken",
|
|
||||||
URL: testProxyURL,
|
|
||||||
Detach: detach,
|
|
||||||
}
|
|
||||||
|
|
||||||
return rStdout, wStdout, saveStdout, sandbox, params, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCCShimStartSuccessful(t *testing.T) {
|
|
||||||
rStdout, wStdout, saveStdout, sandbox, params, err := startCCShimStartWithoutConsoleSuccessful(t, false)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
os.Stdout = saveStdout
|
|
||||||
rStdout.Close()
|
|
||||||
wStdout.Close()
|
|
||||||
}()
|
|
||||||
|
|
||||||
testCCShimStart(t, sandbox, params, false)
|
|
||||||
|
|
||||||
bufStdout := make([]byte, 1024)
|
|
||||||
if _, err := rStdout.Read(bufStdout); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.Contains(string(bufStdout), ShimStdoutOutput) {
|
|
||||||
t.Fatalf("Substring %q not found in %q", ShimStdoutOutput, string(bufStdout))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCCShimStartDetachSuccessful(t *testing.T) {
|
|
||||||
rStdout, wStdout, saveStdout, sandbox, params, err := startCCShimStartWithoutConsoleSuccessful(t, true)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
os.Stdout = saveStdout
|
|
||||||
wStdout.Close()
|
|
||||||
rStdout.Close()
|
|
||||||
}()
|
|
||||||
|
|
||||||
testCCShimStart(t, sandbox, params, false)
|
|
||||||
|
|
||||||
readCh := make(chan error, 1)
|
|
||||||
go func() {
|
|
||||||
defer close(readCh)
|
|
||||||
bufStdout := make([]byte, 1024)
|
|
||||||
n, err := rStdout.Read(bufStdout)
|
|
||||||
if err != nil && err != io.EOF {
|
|
||||||
readCh <- err
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if n > 0 {
|
|
||||||
readCh <- fmt.Errorf("Not expecting to read anything, Got %q", string(bufStdout))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
readCh <- nil
|
|
||||||
}()
|
|
||||||
|
|
||||||
select {
|
|
||||||
case err := <-readCh:
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
case <-time.After(time.Duration(20) * time.Millisecond):
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCCShimStartWithConsoleNonExistingFailure(t *testing.T) {
|
|
||||||
sandbox := &Sandbox{
|
|
||||||
config: &SandboxConfig{
|
|
||||||
ShimType: CCShimType,
|
|
||||||
ShimConfig: ShimConfig{
|
|
||||||
Path: getMockCCShimBinPath(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
params := ShimParams{
|
|
||||||
Token: "testToken",
|
|
||||||
URL: testProxyURL,
|
|
||||||
Console: testWrongConsolePath,
|
|
||||||
}
|
|
||||||
|
|
||||||
testCCShimStart(t, sandbox, params, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func ioctl(fd uintptr, flag, data uintptr) error {
|
|
||||||
if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, flag, data); err != 0 {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// unlockpt unlocks the slave pseudoterminal device corresponding to the master pseudoterminal referred to by f.
|
|
||||||
func unlockpt(f *os.File) error {
|
|
||||||
var u int32
|
|
||||||
|
|
||||||
return ioctl(f.Fd(), syscall.TIOCSPTLCK, uintptr(unsafe.Pointer(&u)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// ptsname retrieves the name of the first available pts for the given master.
|
|
||||||
func ptsname(f *os.File) (string, error) {
|
|
||||||
var n int32
|
|
||||||
|
|
||||||
if err := ioctl(f.Fd(), syscall.TIOCGPTN, uintptr(unsafe.Pointer(&n))); err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Sprintf("/dev/pts/%d", n), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func newConsole() (*os.File, string, error) {
|
|
||||||
master, err := os.OpenFile("/dev/ptmx", syscall.O_RDWR|syscall.O_NOCTTY|syscall.O_CLOEXEC, 0)
|
|
||||||
if err != nil {
|
|
||||||
return nil, "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
console, err := ptsname(master)
|
|
||||||
if err != nil {
|
|
||||||
return nil, "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := unlockpt(master); err != nil {
|
|
||||||
return nil, "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := os.Chmod(console, 0600); err != nil {
|
|
||||||
return nil, "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
return master, console, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCCShimStartWithConsoleSuccessful(t *testing.T) {
|
|
||||||
defer cleanUp()
|
|
||||||
|
|
||||||
master, console, err := newConsole()
|
|
||||||
t.Logf("Console created for tests:%s\n", console)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
sandbox := &Sandbox{
|
|
||||||
config: &SandboxConfig{
|
|
||||||
ShimType: CCShimType,
|
|
||||||
ShimConfig: ShimConfig{
|
|
||||||
Path: getMockCCShimBinPath(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
params := ShimParams{
|
|
||||||
Container: testContainer,
|
|
||||||
Token: "testToken",
|
|
||||||
URL: testProxyURL,
|
|
||||||
Console: console,
|
|
||||||
}
|
|
||||||
|
|
||||||
testCCShimStart(t, sandbox, params, false)
|
|
||||||
master.Close()
|
|
||||||
}
|
|
@ -217,9 +217,6 @@ const (
|
|||||||
// NoProxyType is the noProxy.
|
// NoProxyType is the noProxy.
|
||||||
NoProxyType ProxyType = "noProxy"
|
NoProxyType ProxyType = "noProxy"
|
||||||
|
|
||||||
// CCProxyType is the ccProxy.
|
|
||||||
CCProxyType ProxyType = "ccProxy"
|
|
||||||
|
|
||||||
// KataProxyType is the kataProxy.
|
// KataProxyType is the kataProxy.
|
||||||
KataProxyType ProxyType = "kataProxy"
|
KataProxyType ProxyType = "kataProxy"
|
||||||
)
|
)
|
||||||
@ -241,9 +238,6 @@ type ProxyConfig struct {
|
|||||||
type ShimType string
|
type ShimType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// CCShimType is the ccShim.
|
|
||||||
CCShimType ShimType = "ccShim"
|
|
||||||
|
|
||||||
// NoopShimType is the noopShim.
|
// NoopShimType is the noopShim.
|
||||||
NoopShimType ShimType = "noopShim"
|
NoopShimType ShimType = "noopShim"
|
||||||
|
|
||||||
|
@ -12,14 +12,23 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
. "github.com/kata-containers/runtime/virtcontainers/pkg/mock"
|
. "github.com/kata-containers/runtime/virtcontainers/pkg/mock"
|
||||||
)
|
)
|
||||||
|
|
||||||
var testKataShimPath = "/usr/bin/virtcontainers/bin/test/kata-shim"
|
const (
|
||||||
var testKataShimProxyURL = "foo:///foo/kata-containers/proxy.sock"
|
testContainer = "testContainer"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
testKataShimPath = "/usr/bin/virtcontainers/bin/test/kata-shim"
|
||||||
|
testKataShimProxyURL = "foo:///foo/kata-containers/proxy.sock"
|
||||||
|
testWrongConsolePath = "/foo/wrong-console"
|
||||||
|
)
|
||||||
|
|
||||||
func getMockKataShimBinPath() string {
|
func getMockKataShimBinPath() string {
|
||||||
if DefaultMockKataShimBinPath == "" {
|
if DefaultMockKataShimBinPath == "" {
|
||||||
@ -272,6 +281,54 @@ func TestKataShimStartWithConsoleNonExistingFailure(t *testing.T) {
|
|||||||
testKataShimStart(t, sandbox, params, true)
|
testKataShimStart(t, sandbox, params, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ioctl(fd uintptr, flag, data uintptr) error {
|
||||||
|
if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, flag, data); err != 0 {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// unlockpt unlocks the slave pseudoterminal device corresponding to the master pseudoterminal referred to by f.
|
||||||
|
func unlockpt(f *os.File) error {
|
||||||
|
var u int32
|
||||||
|
|
||||||
|
return ioctl(f.Fd(), syscall.TIOCSPTLCK, uintptr(unsafe.Pointer(&u)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ptsname retrieves the name of the first available pts for the given master.
|
||||||
|
func ptsname(f *os.File) (string, error) {
|
||||||
|
var n int32
|
||||||
|
|
||||||
|
if err := ioctl(f.Fd(), syscall.TIOCGPTN, uintptr(unsafe.Pointer(&n))); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("/dev/pts/%d", n), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func newConsole() (*os.File, string, error) {
|
||||||
|
master, err := os.OpenFile("/dev/ptmx", syscall.O_RDWR|syscall.O_NOCTTY|syscall.O_CLOEXEC, 0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
console, err := ptsname(master)
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := unlockpt(master); err != nil {
|
||||||
|
return nil, "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := os.Chmod(console, 0600); err != nil {
|
||||||
|
return nil, "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return master, console, nil
|
||||||
|
}
|
||||||
|
|
||||||
func TestKataShimStartWithConsoleSuccessful(t *testing.T) {
|
func TestKataShimStartWithConsoleSuccessful(t *testing.T) {
|
||||||
defer cleanUp()
|
defer cleanUp()
|
||||||
|
|
||||||
|
@ -116,10 +116,8 @@ var DefaultNetInterworkingModel = NetXConnectMacVtapModel
|
|||||||
|
|
||||||
// Introduces constants related to networking
|
// Introduces constants related to networking
|
||||||
const (
|
const (
|
||||||
defaultRouteDest = "0.0.0.0/0"
|
defaultFilePerms = 0600
|
||||||
defaultRouteLabel = "default"
|
defaultQlen = 1500
|
||||||
defaultFilePerms = 0600
|
|
||||||
defaultQlen = 1500
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// DNSInfo describes the DNS setup related to a network interface.
|
// DNSInfo describes the DNS setup related to a network interface.
|
||||||
|
@ -1,460 +0,0 @@
|
|||||||
// Copyright (c) 2018 Intel Corporation
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
//
|
|
||||||
|
|
||||||
package mock
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"net"
|
|
||||||
"os"
|
|
||||||
"sync"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/clearcontainers/proxy/api"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
const testToken = "pF56IaDpuax6hihJ5PneB8JypqmOvjkqY-wKGVYqgIM="
|
|
||||||
|
|
||||||
// CCProxyMock is an object mocking clearcontainers Proxy
|
|
||||||
type CCProxyMock struct {
|
|
||||||
sync.Mutex
|
|
||||||
|
|
||||||
t *testing.T
|
|
||||||
connectionPath string
|
|
||||||
|
|
||||||
// proxy socket
|
|
||||||
listener net.Listener
|
|
||||||
|
|
||||||
// single client to serve
|
|
||||||
cl net.Conn
|
|
||||||
|
|
||||||
//token to be used for the connection
|
|
||||||
token string
|
|
||||||
|
|
||||||
lastStdinStream []byte
|
|
||||||
|
|
||||||
ShimConnected chan bool
|
|
||||||
Signal chan ShimSignal
|
|
||||||
ShimDisconnected chan bool
|
|
||||||
StdinReceived chan bool
|
|
||||||
|
|
||||||
wg sync.WaitGroup
|
|
||||||
|
|
||||||
stopped bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewCCProxyMock creates a hyperstart instance
|
|
||||||
func NewCCProxyMock(t *testing.T, path string) *CCProxyMock {
|
|
||||||
return &CCProxyMock{
|
|
||||||
t: t,
|
|
||||||
connectionPath: path,
|
|
||||||
lastStdinStream: nil,
|
|
||||||
Signal: make(chan ShimSignal, 5),
|
|
||||||
ShimConnected: make(chan bool),
|
|
||||||
ShimDisconnected: make(chan bool),
|
|
||||||
StdinReceived: make(chan bool),
|
|
||||||
token: testToken,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetProxyToken returns the token that mock proxy uses
|
|
||||||
// to verify its client connection
|
|
||||||
func (proxy *CCProxyMock) GetProxyToken() string {
|
|
||||||
return proxy.token
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetLastStdinStream returns the last received stdin stream
|
|
||||||
func (proxy *CCProxyMock) GetLastStdinStream() []byte {
|
|
||||||
return proxy.lastStdinStream
|
|
||||||
}
|
|
||||||
|
|
||||||
func (proxy *CCProxyMock) log(s string) {
|
|
||||||
proxy.logF("%s\n", s)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (proxy *CCProxyMock) logF(format string, args ...interface{}) {
|
|
||||||
proxy.t.Logf("[CCProxyMock] "+format, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
type client struct {
|
|
||||||
proxy *CCProxyMock
|
|
||||||
conn net.Conn
|
|
||||||
}
|
|
||||||
|
|
||||||
// ConnectShim payload defined here, as it has not been defined
|
|
||||||
// in proxy api package yet
|
|
||||||
type ConnectShim struct {
|
|
||||||
Token string `json:"token"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// ShimSignal is the struct used to represent the signal received from the shim
|
|
||||||
type ShimSignal struct {
|
|
||||||
Signal int `json:"signalNumber"`
|
|
||||||
Row int `json:"rows,omitempty"`
|
|
||||||
Column int `json:"columns,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func connectShimHandler(data []byte, userData interface{}, response *handlerResponse) {
|
|
||||||
client := userData.(*client)
|
|
||||||
proxy := client.proxy
|
|
||||||
|
|
||||||
payload := ConnectShim{}
|
|
||||||
err := json.Unmarshal(data, &payload)
|
|
||||||
assert.Nil(proxy.t, err)
|
|
||||||
|
|
||||||
if payload.Token != proxy.token {
|
|
||||||
response.SetErrorMsg("Invalid Token")
|
|
||||||
proxy.logF("Invalid Token (token=%s)", payload.Token)
|
|
||||||
}
|
|
||||||
|
|
||||||
response.AddResult("version", api.Version)
|
|
||||||
proxy.ShimConnected <- true
|
|
||||||
}
|
|
||||||
|
|
||||||
func signalShimHandler(data []byte, userData interface{}, response *handlerResponse) {
|
|
||||||
client := userData.(*client)
|
|
||||||
proxy := client.proxy
|
|
||||||
|
|
||||||
signalPayload := ShimSignal{}
|
|
||||||
err := json.Unmarshal(data, &signalPayload)
|
|
||||||
assert.Nil(proxy.t, err)
|
|
||||||
|
|
||||||
proxy.Signal <- signalPayload
|
|
||||||
}
|
|
||||||
|
|
||||||
func disconnectShimHandler(data []byte, userData interface{}, response *handlerResponse) {
|
|
||||||
client := userData.(*client)
|
|
||||||
proxy := client.proxy
|
|
||||||
|
|
||||||
proxy.ShimDisconnected <- true
|
|
||||||
}
|
|
||||||
|
|
||||||
func stdinShimHandler(data []byte, userData interface{}, response *handlerResponse) {
|
|
||||||
client := userData.(*client)
|
|
||||||
proxy := client.proxy
|
|
||||||
|
|
||||||
proxy.lastStdinStream = data
|
|
||||||
proxy.StdinReceived <- true
|
|
||||||
}
|
|
||||||
|
|
||||||
func registerVMHandler(data []byte, userData interface{}, response *handlerResponse) {
|
|
||||||
client := userData.(*client)
|
|
||||||
proxy := client.proxy
|
|
||||||
|
|
||||||
payload := api.RegisterVM{}
|
|
||||||
if err := json.Unmarshal(data, &payload); err != nil {
|
|
||||||
proxy.logF("Register VM failed (%s)", err)
|
|
||||||
response.SetError(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate fake tokens
|
|
||||||
var tokens []string
|
|
||||||
for i := 0; i < payload.NumIOStreams; i++ {
|
|
||||||
tokens = append(tokens, fmt.Sprintf("%d", i))
|
|
||||||
}
|
|
||||||
|
|
||||||
io := &api.IOResponse{
|
|
||||||
Tokens: tokens,
|
|
||||||
}
|
|
||||||
|
|
||||||
response.AddResult("io", io)
|
|
||||||
}
|
|
||||||
|
|
||||||
func unregisterVMHandler(data []byte, userData interface{}, response *handlerResponse) {
|
|
||||||
}
|
|
||||||
|
|
||||||
func attachVMHandler(data []byte, userData interface{}, response *handlerResponse) {
|
|
||||||
client := userData.(*client)
|
|
||||||
proxy := client.proxy
|
|
||||||
|
|
||||||
payload := api.AttachVM{}
|
|
||||||
if err := json.Unmarshal(data, &payload); err != nil {
|
|
||||||
proxy.logF("Attach VM failed (%s)", err)
|
|
||||||
response.SetError(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate fake tokens
|
|
||||||
var tokens []string
|
|
||||||
for i := 0; i < payload.NumIOStreams; i++ {
|
|
||||||
tokens = append(tokens, fmt.Sprintf("%d", i))
|
|
||||||
}
|
|
||||||
|
|
||||||
io := &api.IOResponse{
|
|
||||||
Tokens: tokens,
|
|
||||||
}
|
|
||||||
|
|
||||||
response.AddResult("io", io)
|
|
||||||
}
|
|
||||||
|
|
||||||
func hyperCmdHandler(data []byte, userData interface{}, response *handlerResponse) {
|
|
||||||
response.SetData([]byte{})
|
|
||||||
}
|
|
||||||
|
|
||||||
// SendStdoutStream sends a Stdout Stream Frame to connected client
|
|
||||||
func (proxy *CCProxyMock) SendStdoutStream(payload []byte) {
|
|
||||||
err := api.WriteStream(proxy.cl, api.StreamStdout, payload)
|
|
||||||
assert.Nil(proxy.t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SendStderrStream sends a Stderr Stream Frame to connected client
|
|
||||||
func (proxy *CCProxyMock) SendStderrStream(payload []byte) {
|
|
||||||
err := api.WriteStream(proxy.cl, api.StreamStderr, payload)
|
|
||||||
assert.Nil(proxy.t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SendExitNotification sends an Exit Notification Frame to connected client
|
|
||||||
func (proxy *CCProxyMock) SendExitNotification(payload []byte) {
|
|
||||||
err := api.WriteNotification(proxy.cl, api.NotificationProcessExited, payload)
|
|
||||||
assert.Nil(proxy.t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (proxy *CCProxyMock) startListening() {
|
|
||||||
|
|
||||||
l, err := net.ListenUnix("unix", &net.UnixAddr{Name: proxy.connectionPath, Net: "unix"})
|
|
||||||
assert.Nil(proxy.t, err)
|
|
||||||
|
|
||||||
proxy.listener = l
|
|
||||||
}
|
|
||||||
|
|
||||||
func (proxy *CCProxyMock) serveClient(proto *ccProxyProtocol, newConn net.Conn) {
|
|
||||||
newClient := &client{
|
|
||||||
proxy: proxy,
|
|
||||||
conn: newConn,
|
|
||||||
}
|
|
||||||
if err := proto.Serve(newConn, newClient); err != nil && err != io.EOF {
|
|
||||||
proxy.logF("Error serving client : %v\n", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
newConn.Close()
|
|
||||||
|
|
||||||
proxy.wg.Done()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (proxy *CCProxyMock) serve() {
|
|
||||||
proto := newCCProxyProtocol()
|
|
||||||
|
|
||||||
// shim handlers
|
|
||||||
proto.Handle(FrameKey{api.TypeCommand, int(api.CmdConnectShim)}, connectShimHandler)
|
|
||||||
proto.Handle(FrameKey{api.TypeCommand, int(api.CmdDisconnectShim)}, disconnectShimHandler)
|
|
||||||
proto.Handle(FrameKey{api.TypeStream, int(api.StreamStdin)}, stdinShimHandler)
|
|
||||||
|
|
||||||
// runtime handlers
|
|
||||||
proto.Handle(FrameKey{api.TypeCommand, int(api.CmdRegisterVM)}, registerVMHandler)
|
|
||||||
proto.Handle(FrameKey{api.TypeCommand, int(api.CmdUnregisterVM)}, unregisterVMHandler)
|
|
||||||
proto.Handle(FrameKey{api.TypeCommand, int(api.CmdAttachVM)}, attachVMHandler)
|
|
||||||
proto.Handle(FrameKey{api.TypeCommand, int(api.CmdHyper)}, hyperCmdHandler)
|
|
||||||
|
|
||||||
// Shared handler between shim and runtime
|
|
||||||
proto.Handle(FrameKey{api.TypeCommand, int(api.CmdSignal)}, signalShimHandler)
|
|
||||||
|
|
||||||
//Wait for a single client connection
|
|
||||||
conn, err := proxy.listener.Accept()
|
|
||||||
if err != nil {
|
|
||||||
// Ending up into this case when the listener is closed, which
|
|
||||||
// is still a valid case. We don't want to throw an error in
|
|
||||||
// this case.
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
assert.NotNil(proxy.t, conn)
|
|
||||||
|
|
||||||
proxy.wg.Add(1)
|
|
||||||
|
|
||||||
proxy.cl = conn
|
|
||||||
|
|
||||||
proxy.serveClient(proto, conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start invokes mock proxy instance to start listening.
|
|
||||||
func (proxy *CCProxyMock) Start() {
|
|
||||||
proxy.stopped = false
|
|
||||||
proxy.startListening()
|
|
||||||
go func() {
|
|
||||||
for {
|
|
||||||
proxy.serve()
|
|
||||||
|
|
||||||
proxy.Lock()
|
|
||||||
stopped := proxy.stopped
|
|
||||||
proxy.Unlock()
|
|
||||||
|
|
||||||
if stopped {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stop causes mock proxy instance to stop listening,
|
|
||||||
// close connection to client and close all channels
|
|
||||||
func (proxy *CCProxyMock) Stop() {
|
|
||||||
proxy.Lock()
|
|
||||||
proxy.stopped = true
|
|
||||||
proxy.Unlock()
|
|
||||||
|
|
||||||
proxy.listener.Close()
|
|
||||||
|
|
||||||
if proxy.cl != nil {
|
|
||||||
proxy.cl.Close()
|
|
||||||
proxy.cl = nil
|
|
||||||
} else {
|
|
||||||
proxy.log("Client connection already closed")
|
|
||||||
}
|
|
||||||
|
|
||||||
proxy.wg.Wait()
|
|
||||||
close(proxy.ShimConnected)
|
|
||||||
close(proxy.Signal)
|
|
||||||
close(proxy.ShimDisconnected)
|
|
||||||
close(proxy.StdinReceived)
|
|
||||||
os.Remove(proxy.connectionPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
// XXX: could do with its own package to remove that ugly namespacing
|
|
||||||
type ccProxyProtocolHandler func([]byte, interface{}, *handlerResponse)
|
|
||||||
|
|
||||||
// Encapsulates the different parts of what a handler can return.
|
|
||||||
type handlerResponse struct {
|
|
||||||
err error
|
|
||||||
results map[string]interface{}
|
|
||||||
data []byte
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetError indicates sets error for the response.
|
|
||||||
func (r *handlerResponse) SetError(err error) {
|
|
||||||
r.err = err
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetErrorMsg sets an error with the passed string for the response.
|
|
||||||
func (r *handlerResponse) SetErrorMsg(msg string) {
|
|
||||||
r.err = errors.New(msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetErrorf sets an error with the formatted string for the response.
|
|
||||||
func (r *handlerResponse) SetErrorf(format string, a ...interface{}) {
|
|
||||||
r.SetError(fmt.Errorf(format, a...))
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddResult adds the given key/val to the response.
|
|
||||||
func (r *handlerResponse) AddResult(key string, value interface{}) {
|
|
||||||
if r.results == nil {
|
|
||||||
r.results = make(map[string]interface{})
|
|
||||||
}
|
|
||||||
r.results[key] = value
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *handlerResponse) SetData(data []byte) {
|
|
||||||
r.data = data
|
|
||||||
}
|
|
||||||
|
|
||||||
// FrameKey is a struct composed of the the frame type and opcode,
|
|
||||||
// used as a key for retrieving the handler for handling the frame.
|
|
||||||
type FrameKey struct {
|
|
||||||
ftype api.FrameType
|
|
||||||
opcode int
|
|
||||||
}
|
|
||||||
|
|
||||||
type ccProxyProtocol struct {
|
|
||||||
cmdHandlers map[FrameKey]ccProxyProtocolHandler
|
|
||||||
}
|
|
||||||
|
|
||||||
func newCCProxyProtocol() *ccProxyProtocol {
|
|
||||||
return &ccProxyProtocol{
|
|
||||||
cmdHandlers: make(map[FrameKey]ccProxyProtocolHandler),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle retreives the handler for handling the frame
|
|
||||||
func (proto *ccProxyProtocol) Handle(key FrameKey, handler ccProxyProtocolHandler) bool {
|
|
||||||
if _, ok := proto.cmdHandlers[key]; ok {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
proto.cmdHandlers[key] = handler
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
type clientCtx struct {
|
|
||||||
conn net.Conn
|
|
||||||
userData interface{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func newErrorResponse(opcode int, errMsg string) *api.Frame {
|
|
||||||
frame, err := api.NewFrameJSON(api.TypeResponse, opcode, &api.ErrorResponse{
|
|
||||||
Message: errMsg,
|
|
||||||
})
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
frame, err = api.NewFrameJSON(api.TypeResponse, opcode, &api.ErrorResponse{
|
|
||||||
Message: fmt.Sprintf("couldn't marshal response: %v", err),
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
frame = api.NewFrame(api.TypeResponse, opcode, nil)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
frame.Header.InError = true
|
|
||||||
return frame
|
|
||||||
}
|
|
||||||
|
|
||||||
func (proto *ccProxyProtocol) handleCommand(ctx *clientCtx, cmd *api.Frame) *api.Frame {
|
|
||||||
hr := handlerResponse{}
|
|
||||||
|
|
||||||
// cmd.Header.Opcode is guaranteed to be within the right bounds by
|
|
||||||
// ReadFrame().
|
|
||||||
handler := proto.cmdHandlers[FrameKey{cmd.Header.Type, cmd.Header.Opcode}]
|
|
||||||
|
|
||||||
handler(cmd.Payload, ctx.userData, &hr)
|
|
||||||
if hr.err != nil {
|
|
||||||
return newErrorResponse(cmd.Header.Opcode, hr.err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
var payload interface{}
|
|
||||||
if len(hr.results) > 0 {
|
|
||||||
payload = hr.results
|
|
||||||
}
|
|
||||||
|
|
||||||
frame, err := api.NewFrameJSON(api.TypeResponse, cmd.Header.Opcode, payload)
|
|
||||||
if err != nil {
|
|
||||||
return newErrorResponse(cmd.Header.Opcode, err.Error())
|
|
||||||
}
|
|
||||||
return frame
|
|
||||||
}
|
|
||||||
|
|
||||||
// Serve serves the client connection in a continuous loop.
|
|
||||||
func (proto *ccProxyProtocol) Serve(conn net.Conn, userData interface{}) error {
|
|
||||||
ctx := &clientCtx{
|
|
||||||
conn: conn,
|
|
||||||
userData: userData,
|
|
||||||
}
|
|
||||||
|
|
||||||
for {
|
|
||||||
frame, err := api.ReadFrame(conn)
|
|
||||||
if err != nil {
|
|
||||||
// EOF or the client isn't even sending proper JSON,
|
|
||||||
// just kill the connection
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if frame.Header.Type != api.TypeCommand && frame.Header.Type != api.TypeStream {
|
|
||||||
// EOF or the client isn't even sending proper JSON,
|
|
||||||
// just kill the connection
|
|
||||||
return fmt.Errorf("serve: expected a command got a %v", frame.Header.Type)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Execute the corresponding handler
|
|
||||||
resp := proto.handleCommand(ctx, frame)
|
|
||||||
|
|
||||||
// Send the response back to the client.
|
|
||||||
if err = api.WriteFrame(conn, resp); err != nil {
|
|
||||||
// Something made us unable to write the response back
|
|
||||||
// to the client (could be a disconnection, ...).
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -17,9 +17,6 @@ import (
|
|||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultMockCCShimBinPath is populated at link time.
|
|
||||||
var DefaultMockCCShimBinPath string
|
|
||||||
|
|
||||||
// DefaultMockKataShimBinPath is populated at link time.
|
// DefaultMockKataShimBinPath is populated at link time.
|
||||||
var DefaultMockKataShimBinPath string
|
var DefaultMockKataShimBinPath string
|
||||||
|
|
||||||
|
@ -107,9 +107,9 @@ func TestMinimalSandboxConfig(t *testing.T) {
|
|||||||
|
|
||||||
runtimeConfig := RuntimeConfig{
|
runtimeConfig := RuntimeConfig{
|
||||||
HypervisorType: vc.QemuHypervisor,
|
HypervisorType: vc.QemuHypervisor,
|
||||||
AgentType: vc.HyperstartAgent,
|
AgentType: vc.KataContainersAgent,
|
||||||
ProxyType: vc.CCProxyType,
|
ProxyType: vc.KataProxyType,
|
||||||
ShimType: vc.CCShimType,
|
ShimType: vc.KataShimType,
|
||||||
Console: consolePath,
|
Console: consolePath,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,9 +222,9 @@ func TestMinimalSandboxConfig(t *testing.T) {
|
|||||||
Hostname: "testHostname",
|
Hostname: "testHostname",
|
||||||
|
|
||||||
HypervisorType: vc.QemuHypervisor,
|
HypervisorType: vc.QemuHypervisor,
|
||||||
AgentType: vc.HyperstartAgent,
|
AgentType: vc.KataContainersAgent,
|
||||||
ProxyType: vc.CCProxyType,
|
ProxyType: vc.KataProxyType,
|
||||||
ShimType: vc.CCShimType,
|
ShimType: vc.KataShimType,
|
||||||
|
|
||||||
NetworkConfig: expectedNetworkConfig,
|
NetworkConfig: expectedNetworkConfig,
|
||||||
|
|
||||||
|
@ -41,9 +41,6 @@ const (
|
|||||||
// NoProxyType is the noProxy.
|
// NoProxyType is the noProxy.
|
||||||
NoProxyType ProxyType = "noProxy"
|
NoProxyType ProxyType = "noProxy"
|
||||||
|
|
||||||
// CCProxyType is the ccProxy.
|
|
||||||
CCProxyType ProxyType = "ccProxy"
|
|
||||||
|
|
||||||
// KataProxyType is the kataProxy.
|
// KataProxyType is the kataProxy.
|
||||||
KataProxyType ProxyType = "kataProxy"
|
KataProxyType ProxyType = "kataProxy"
|
||||||
|
|
||||||
@ -51,12 +48,6 @@ const (
|
|||||||
KataBuiltInProxyType ProxyType = "kataBuiltInProxy"
|
KataBuiltInProxyType ProxyType = "kataBuiltInProxy"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
// Number of seconds to wait for the proxy to respond to a connection
|
|
||||||
// request.
|
|
||||||
waitForProxyTimeoutSecs = 5.0
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// unix socket type of console
|
// unix socket type of console
|
||||||
consoleProtoUnix = "unix"
|
consoleProtoUnix = "unix"
|
||||||
@ -74,9 +65,6 @@ func (pType *ProxyType) Set(value string) error {
|
|||||||
case "noProxy":
|
case "noProxy":
|
||||||
*pType = NoProxyType
|
*pType = NoProxyType
|
||||||
return nil
|
return nil
|
||||||
case "ccProxy":
|
|
||||||
*pType = CCProxyType
|
|
||||||
return nil
|
|
||||||
case "kataProxy":
|
case "kataProxy":
|
||||||
*pType = KataProxyType
|
*pType = KataProxyType
|
||||||
return nil
|
return nil
|
||||||
@ -95,8 +83,6 @@ func (pType *ProxyType) String() string {
|
|||||||
return string(NoopProxyType)
|
return string(NoopProxyType)
|
||||||
case NoProxyType:
|
case NoProxyType:
|
||||||
return string(NoProxyType)
|
return string(NoProxyType)
|
||||||
case CCProxyType:
|
|
||||||
return string(CCProxyType)
|
|
||||||
case KataProxyType:
|
case KataProxyType:
|
||||||
return string(KataProxyType)
|
return string(KataProxyType)
|
||||||
case KataBuiltInProxyType:
|
case KataBuiltInProxyType:
|
||||||
@ -115,8 +101,6 @@ func newProxy(pType ProxyType) (proxy, error) {
|
|||||||
return &noopProxy{}, nil
|
return &noopProxy{}, nil
|
||||||
case NoProxyType:
|
case NoProxyType:
|
||||||
return &noProxy{}, nil
|
return &noProxy{}, nil
|
||||||
case CCProxyType:
|
|
||||||
return &ccProxy{}, nil
|
|
||||||
case KataProxyType:
|
case KataProxyType:
|
||||||
return &kataProxy{}, nil
|
return &kataProxy{}, nil
|
||||||
case KataBuiltInProxyType:
|
case KataBuiltInProxyType:
|
||||||
|
@ -33,10 +33,6 @@ func testSetProxyType(t *testing.T, value string, expected ProxyType) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetCCProxyType(t *testing.T) {
|
|
||||||
testSetProxyType(t, "ccProxy", CCProxyType)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSetKataProxyType(t *testing.T) {
|
func TestSetKataProxyType(t *testing.T) {
|
||||||
testSetProxyType(t, "kataProxy", KataProxyType)
|
testSetProxyType(t, "kataProxy", KataProxyType)
|
||||||
}
|
}
|
||||||
@ -63,8 +59,7 @@ func TestSetUnknownProxyType(t *testing.T) {
|
|||||||
t.Fatalf("Should fail because %s type used", unknownType)
|
t.Fatalf("Should fail because %s type used", unknownType)
|
||||||
}
|
}
|
||||||
|
|
||||||
if proxyType == CCProxyType ||
|
if proxyType == NoopProxyType ||
|
||||||
proxyType == NoopProxyType ||
|
|
||||||
proxyType == NoProxyType ||
|
proxyType == NoProxyType ||
|
||||||
proxyType == KataProxyType {
|
proxyType == KataProxyType {
|
||||||
t.Fatalf("%s proxy type was not expected", proxyType)
|
t.Fatalf("%s proxy type was not expected", proxyType)
|
||||||
@ -78,11 +73,6 @@ func testStringFromProxyType(t *testing.T, proxyType ProxyType, expected string)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStringFromCCProxyType(t *testing.T) {
|
|
||||||
proxyType := CCProxyType
|
|
||||||
testStringFromProxyType(t, proxyType, "ccProxy")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestStringFromKataProxyType(t *testing.T) {
|
func TestStringFromKataProxyType(t *testing.T) {
|
||||||
proxyType := KataProxyType
|
proxyType := KataProxyType
|
||||||
testStringFromProxyType(t, proxyType, "kataProxy")
|
testStringFromProxyType(t, proxyType, "kataProxy")
|
||||||
@ -119,12 +109,6 @@ func testNewProxyFromProxyType(t *testing.T, proxyType ProxyType, expected proxy
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewProxyFromCCProxyType(t *testing.T) {
|
|
||||||
proxyType := CCProxyType
|
|
||||||
expectedProxy := &ccProxy{}
|
|
||||||
testNewProxyFromProxyType(t, proxyType, expectedProxy)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestNewProxyFromKataProxyType(t *testing.T) {
|
func TestNewProxyFromKataProxyType(t *testing.T) {
|
||||||
proxyType := KataProxyType
|
proxyType := KataProxyType
|
||||||
expectedProxy := &kataProxy{}
|
expectedProxy := &kataProxy{}
|
||||||
@ -171,19 +155,6 @@ func testNewProxyFromSandboxConfig(t *testing.T, sandboxConfig SandboxConfig) {
|
|||||||
|
|
||||||
var testProxyPath = "proxy-path"
|
var testProxyPath = "proxy-path"
|
||||||
|
|
||||||
func TestNewProxyConfigFromCCProxySandboxConfig(t *testing.T) {
|
|
||||||
proxyConfig := ProxyConfig{
|
|
||||||
Path: testProxyPath,
|
|
||||||
}
|
|
||||||
|
|
||||||
sandboxConfig := SandboxConfig{
|
|
||||||
ProxyType: CCProxyType,
|
|
||||||
ProxyConfig: proxyConfig,
|
|
||||||
}
|
|
||||||
|
|
||||||
testNewProxyFromSandboxConfig(t, sandboxConfig)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestNewProxyConfigFromKataProxySandboxConfig(t *testing.T) {
|
func TestNewProxyConfigFromKataProxySandboxConfig(t *testing.T) {
|
||||||
proxyConfig := ProxyConfig{
|
proxyConfig := ProxyConfig{
|
||||||
Path: testProxyPath,
|
Path: testProxyPath,
|
||||||
|
@ -22,9 +22,6 @@ import (
|
|||||||
type ShimType string
|
type ShimType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// CCShimType is the ccShim.
|
|
||||||
CCShimType ShimType = "ccShim"
|
|
||||||
|
|
||||||
// NoopShimType is the noopShim.
|
// NoopShimType is the noopShim.
|
||||||
NoopShimType ShimType = "noopShim"
|
NoopShimType ShimType = "noopShim"
|
||||||
|
|
||||||
@ -65,8 +62,6 @@ func (pType *ShimType) Set(value string) error {
|
|||||||
switch value {
|
switch value {
|
||||||
case "noopShim":
|
case "noopShim":
|
||||||
*pType = NoopShimType
|
*pType = NoopShimType
|
||||||
case "ccShim":
|
|
||||||
*pType = CCShimType
|
|
||||||
case "kataShim":
|
case "kataShim":
|
||||||
*pType = KataShimType
|
*pType = KataShimType
|
||||||
case "kataBuiltInShim":
|
case "kataBuiltInShim":
|
||||||
@ -82,8 +77,6 @@ func (pType *ShimType) String() string {
|
|||||||
switch *pType {
|
switch *pType {
|
||||||
case NoopShimType:
|
case NoopShimType:
|
||||||
return string(NoopShimType)
|
return string(NoopShimType)
|
||||||
case CCShimType:
|
|
||||||
return string(CCShimType)
|
|
||||||
case KataShimType:
|
case KataShimType:
|
||||||
return string(KataShimType)
|
return string(KataShimType)
|
||||||
case KataBuiltInShimType:
|
case KataBuiltInShimType:
|
||||||
@ -98,8 +91,6 @@ func newShim(pType ShimType) (shim, error) {
|
|||||||
switch pType {
|
switch pType {
|
||||||
case NoopShimType:
|
case NoopShimType:
|
||||||
return &noopShim{}, nil
|
return &noopShim{}, nil
|
||||||
case CCShimType:
|
|
||||||
return &ccShim{}, nil
|
|
||||||
case KataShimType:
|
case KataShimType:
|
||||||
return &kataShim{}, nil
|
return &kataShim{}, nil
|
||||||
case KataBuiltInShimType:
|
case KataBuiltInShimType:
|
||||||
@ -114,7 +105,7 @@ func newShimConfig(config SandboxConfig) interface{} {
|
|||||||
switch config.ShimType {
|
switch config.ShimType {
|
||||||
case NoopShimType, KataBuiltInShimType:
|
case NoopShimType, KataBuiltInShimType:
|
||||||
return nil
|
return nil
|
||||||
case CCShimType, KataShimType:
|
case KataShimType:
|
||||||
var shimConfig ShimConfig
|
var shimConfig ShimConfig
|
||||||
err := mapstructure.Decode(config.ShimConfig, &shimConfig)
|
err := mapstructure.Decode(config.ShimConfig, &shimConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
// Copyright (c) 2017 Intel Corporation
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
//
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/kata-containers/runtime/virtcontainers/pkg/mock"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
config := mock.ShimMockConfig{
|
|
||||||
Name: "cc-shim",
|
|
||||||
URLParamName: "u",
|
|
||||||
ContainerParamName: "c",
|
|
||||||
TokenParamName: "t",
|
|
||||||
}
|
|
||||||
|
|
||||||
mock.StartShim(config)
|
|
||||||
}
|
|
@ -29,10 +29,6 @@ func testSetShimType(t *testing.T, value string, expected ShimType) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetCCShimType(t *testing.T) {
|
|
||||||
testSetShimType(t, "ccShim", CCShimType)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSetKataShimType(t *testing.T) {
|
func TestSetKataShimType(t *testing.T) {
|
||||||
testSetShimType(t, "kataShim", KataShimType)
|
testSetShimType(t, "kataShim", KataShimType)
|
||||||
}
|
}
|
||||||
@ -51,7 +47,7 @@ func TestSetUnknownShimType(t *testing.T) {
|
|||||||
t.Fatalf("Should fail because %s type used", unknownType)
|
t.Fatalf("Should fail because %s type used", unknownType)
|
||||||
}
|
}
|
||||||
|
|
||||||
if shimType == CCShimType || shimType == NoopShimType {
|
if shimType == NoopShimType {
|
||||||
t.Fatalf("%s shim type was not expected", shimType)
|
t.Fatalf("%s shim type was not expected", shimType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -63,11 +59,6 @@ func testStringFromShimType(t *testing.T, shimType ShimType, expected string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStringFromCCShimType(t *testing.T) {
|
|
||||||
shimType := CCShimType
|
|
||||||
testStringFromShimType(t, shimType, "ccShim")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestStringFromKataShimType(t *testing.T) {
|
func TestStringFromKataShimType(t *testing.T) {
|
||||||
shimType := KataShimType
|
shimType := KataShimType
|
||||||
testStringFromShimType(t, shimType, "kataShim")
|
testStringFromShimType(t, shimType, "kataShim")
|
||||||
@ -99,12 +90,6 @@ func testNewShimFromShimType(t *testing.T, shimType ShimType, expected shim) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewShimFromCCShimType(t *testing.T) {
|
|
||||||
shimType := CCShimType
|
|
||||||
expectedShim := &ccShim{}
|
|
||||||
testNewShimFromShimType(t, shimType, expectedShim)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestNewShimFromKataShimType(t *testing.T) {
|
func TestNewShimFromKataShimType(t *testing.T) {
|
||||||
shimType := KataShimType
|
shimType := KataShimType
|
||||||
expectedShim := &kataShim{}
|
expectedShim := &kataShim{}
|
||||||
@ -140,17 +125,6 @@ func testNewShimConfigFromSandboxConfig(t *testing.T, sandboxConfig SandboxConfi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewShimConfigFromCCShimSandboxConfig(t *testing.T) {
|
|
||||||
shimConfig := ShimConfig{}
|
|
||||||
|
|
||||||
sandboxConfig := SandboxConfig{
|
|
||||||
ShimType: CCShimType,
|
|
||||||
ShimConfig: shimConfig,
|
|
||||||
}
|
|
||||||
|
|
||||||
testNewShimConfigFromSandboxConfig(t, sandboxConfig, shimConfig)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestNewShimConfigFromKataShimSandboxConfig(t *testing.T) {
|
func TestNewShimConfigFromKataShimSandboxConfig(t *testing.T) {
|
||||||
shimConfig := ShimConfig{}
|
shimConfig := ShimConfig{}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user