runtime: remove mock shim

Remove mock codes for shim

Fixes #444

Signed-off-by: bin liu <bin@hyper.sh>
This commit is contained in:
bin liu 2020-07-25 09:08:44 +08:00
parent d7f75dce83
commit db93a1631e
3 changed files with 1 additions and 114 deletions

View File

@ -10,8 +10,6 @@ VC_BIN_DIR := $(BIN_DIR)/virtcontainers/bin
TEST_BIN_DIR := $(VC_BIN_DIR)/test
HOOK_DIR := hook/mock
HOOK_BIN := hook
KATA_SHIM_DIR := shim/mock/kata-shim
KATA_SHIM_BIN := kata-shim
MK_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
GOBUILD_FLAGS := -mod=vendor
@ -35,10 +33,7 @@ build:
hook:
$(QUIET_GOBUILD)go build $(GOBUILD_FLAGS) -o $(HOOK_DIR)/$@ $(HOOK_DIR)/*.go
kata-shim:
$(QUIET_GOBUILD)go build $(GOBUILD_FLAGS) -o $(KATA_SHIM_DIR)/$@ $(KATA_SHIM_DIR)/*.go
binaries: hook kata-shim
binaries: hook
#
# Tests
@ -51,7 +46,6 @@ check-go-static:
check-go-test:
bash $(MK_DIR)/../.ci/go-test.sh \
$(TEST_BIN_DIR)/$(KATA_SHIM_BIN) \
$(TEST_BIN_DIR)/$(HOOK_BIN)
#
@ -70,7 +64,6 @@ install:
@mkdir -p $(VC_BIN_DIR)
@mkdir -p $(TEST_BIN_DIR)
$(call INSTALL_TEST_EXEC,$(HOOK_DIR)/$(HOOK_BIN))
$(call INSTALL_TEST_EXEC,$(KATA_SHIM_DIR)/$(KATA_SHIM_BIN))
#
# Uninstall
@ -86,7 +79,6 @@ endef
uninstall:
$(call UNINSTALL_TEST_EXEC,$(HOOK_BIN))
$(call UNINSTALL_TEST_EXEC,$(KATA_SHIM_BIN))
#
# Clean
@ -99,7 +91,6 @@ $(shell test -e "$(1)" && test "$(1)" != "/" && echo "$(1)")
endef
CLEAN_FILES += $(HOOK_DIR)/$(HOOK_BIN)
CLEAN_FILES += $(SHIM_DIR)/$(KATA_SHIM_BIN)
clean:
rm -f $(foreach f,$(CLEAN_FILES),$(call FILE_SAFE_TO_REMOVE,$(f)))
@ -108,7 +99,6 @@ clean:
all \
build \
hook \
shim \
binaries \
check \
check-go-static \

View File

@ -7,13 +7,10 @@ package mock
import (
"context"
"flag"
"fmt"
"io/ioutil"
"net"
"net/url"
"os"
"path/filepath"
"github.com/containerd/ttrpc"
gpb "github.com/gogo/protobuf/types"
@ -21,88 +18,9 @@ import (
pb "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols/grpc"
)
// DefaultMockKataShimBinPath is populated at link time.
var DefaultMockKataShimBinPath string
// DefaultMockHookBinPath is populated at link time.
var DefaultMockHookBinPath string
// ShimStdoutOutput is the expected output sent by the mock shim on stdout.
const ShimStdoutOutput = "Some output on stdout"
// ShimStderrOutput is the expected output sent by the mock shim on stderr.
const ShimStderrOutput = "Some output on stderr"
// ShimMockConfig is the configuration structure for all virtcontainers shim mock implementations.
type ShimMockConfig struct {
Name string
URLParamName string
ContainerParamName string
TokenParamName string
}
// StartShim is a common routine for starting a shim mock.
func StartShim(config ShimMockConfig) error {
logDirPath, err := ioutil.TempDir("", config.Name+"-")
if err != nil {
return err
}
logFilePath := filepath.Join(logDirPath, "mock_"+config.Name+".log")
f, err := os.Create(logFilePath)
if err != nil {
return err
}
defer f.Close()
tokenFlag := flag.String(config.TokenParamName, "", "Container token")
urlFlag := flag.String(config.URLParamName, "", "Agent URL")
containerFlag := flag.String(config.ContainerParamName, "", "Container ID")
flag.Parse()
fmt.Fprintf(f, "INFO: Token = %s\n", *tokenFlag)
fmt.Fprintf(f, "INFO: URL = %s\n", *urlFlag)
fmt.Fprintf(f, "INFO: Container = %s\n", *containerFlag)
if *tokenFlag == "" {
err := fmt.Errorf("token should not be empty")
fmt.Fprintf(f, "%s\n", err)
return err
}
if *urlFlag == "" {
err := fmt.Errorf("url should not be empty")
fmt.Fprintf(f, "%s\n", err)
return err
}
if _, err := url.Parse(*urlFlag); err != nil {
err2 := fmt.Errorf("could not parse the URL %q: %s", *urlFlag, err)
fmt.Fprintf(f, "%s\n", err2)
return err2
}
if *containerFlag == "" {
err := fmt.Errorf("container should not be empty")
fmt.Fprintf(f, "%s\n", err)
return err
}
// Print some traces to stdout
fmt.Fprint(os.Stdout, ShimStdoutOutput)
os.Stdout.Close()
// Print some traces to stderr
fmt.Fprint(os.Stderr, ShimStderrOutput)
os.Stderr.Close()
fmt.Fprint(f, "INFO: Shim exited properly\n")
return nil
}
var testKataMockHybridVSockURLTempl = "mock://%s/kata-mock-hybrid-vsock.sock"
func GenerateKataMockHybridVSock() (string, error) {

View File

@ -1,21 +0,0 @@
// Copyright (c) 2018 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//
package main
import (
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/mock"
)
func main() {
config := mock.ShimMockConfig{
Name: "kata-shim",
URLParamName: "agent",
ContainerParamName: "container",
TokenParamName: "exec-id",
}
mock.StartShim(config)
}