mirror of
https://github.com/aljazceru/kata-containers.git
synced 2026-01-03 22:44:24 +01:00
Merge pull request #365 from liubin/feature/delete-shim-364
runtime: clean up shim abstraction
This commit is contained in:
@@ -362,16 +362,6 @@ var kataCheckCLICommand = cli.Command{
|
||||
fmt.Println(successMessageCreate)
|
||||
}
|
||||
|
||||
strict := context.Bool("strict")
|
||||
if strict {
|
||||
err = checkVersionConsistencyInComponents(runtimeConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(successMessageVersion)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
@@ -469,35 +459,3 @@ func genericCheckKVMExtensions(extensions map[string]kvmExtension) (map[string]i
|
||||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
// checkVersionConsistencyInComponents checks version consistency in Kata Components.
|
||||
func checkVersionConsistencyInComponents(config oci.RuntimeConfig) error {
|
||||
proxyInfo := getProxyInfo(config)
|
||||
|
||||
shimInfo, err := getShimInfo(config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
shimVersionInfo := shimInfo.Version
|
||||
|
||||
runtimeVersionInfo := constructVersionInfo(version)
|
||||
|
||||
// kata-proxy exists
|
||||
if proxyInfo.Type != string(vc.NoProxyType) {
|
||||
proxyVersionInfo := proxyInfo.Version
|
||||
if !versionEqual(proxyVersionInfo, runtimeVersionInfo) || !versionEqual(shimVersionInfo, runtimeVersionInfo) {
|
||||
return fmt.Errorf("there exists version inconsistency in kata components. kata-proxy: v%d.%d.%d, kata-shim: v%d.%d.%d, kata-runtime: v%d.%d.%d",
|
||||
proxyVersionInfo.Major, proxyVersionInfo.Minor, proxyVersionInfo.Patch,
|
||||
shimVersionInfo.Major, shimVersionInfo.Minor, shimVersionInfo.Patch,
|
||||
runtimeVersionInfo.Major, runtimeVersionInfo.Minor, runtimeVersionInfo.Patch)
|
||||
}
|
||||
} else {
|
||||
if !versionEqual(shimVersionInfo, runtimeVersionInfo) {
|
||||
return fmt.Errorf("there exists version inconsistency in kata components. kata-shim: v%d.%d.%d, kata-runtime: v%d.%d.%d",
|
||||
shimVersionInfo.Major, shimVersionInfo.Minor, shimVersionInfo.Patch,
|
||||
runtimeVersionInfo.Major, runtimeVersionInfo.Minor, runtimeVersionInfo.Patch)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ import (
|
||||
|
||||
ktu "github.com/kata-containers/kata-containers/src/runtime/pkg/katatestutils"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/pkg/katautils"
|
||||
vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/urfave/cli"
|
||||
@@ -906,94 +905,3 @@ func TestArchRequiredKernelModules(t *testing.T) {
|
||||
|
||||
assert.EqualValues(count, expectedCount)
|
||||
}
|
||||
|
||||
func TestCheckVersionConsistencyInComponents(t *testing.T) {
|
||||
type testData struct {
|
||||
proxyExist bool
|
||||
expectError bool
|
||||
shimVersion string
|
||||
proxyVersion string
|
||||
runtimeVersion string
|
||||
}
|
||||
|
||||
data := []testData{
|
||||
{
|
||||
true,
|
||||
true,
|
||||
"kata-shim version 0.2.0-rc0-xxxxxxxxxxxxx",
|
||||
"kata-proxy version 0.1.0-rc0-xxxxxxxxxxxxx",
|
||||
"0.2.0-rc0",
|
||||
},
|
||||
{
|
||||
true,
|
||||
true,
|
||||
"kata-shim version 0.1.0-rc0-xxxxxxxxxxxxx",
|
||||
"kata-proxy version 0.2.0-rc0-xxxxxxxxxxxxx",
|
||||
"0.2.0-rc0",
|
||||
},
|
||||
{
|
||||
true,
|
||||
true,
|
||||
"kata-shim version 0.1.0-rc0-xxxxxxxxxxxxx",
|
||||
"kata-proxy version 0.1.0-rc0-xxxxxxxxxxxxx",
|
||||
"0.2.0-rc0",
|
||||
},
|
||||
{
|
||||
true,
|
||||
false,
|
||||
"kata-shim version 0.2.0-rc0-xxxxxxxxxxxxx",
|
||||
"kata-proxy version 0.2.0-rc0-xxxxxxxxxxxxx",
|
||||
"0.2.0-rc0",
|
||||
},
|
||||
{
|
||||
false,
|
||||
true,
|
||||
"kata-shim version 0.1.0-rc0-xxxxxxxxxxxxx",
|
||||
"",
|
||||
"0.2.0-rc0",
|
||||
},
|
||||
{
|
||||
false,
|
||||
false,
|
||||
"kata-shim version 0.2.0-rc0-xxxxxxxxxxxxx",
|
||||
"",
|
||||
"0.2.0-rc0",
|
||||
},
|
||||
{
|
||||
false,
|
||||
false,
|
||||
"kata-shim version 0.2.0-xxxxxxxxxxxxx",
|
||||
"",
|
||||
"0.2.0",
|
||||
},
|
||||
}
|
||||
|
||||
origVersion := version
|
||||
for _, d := range data {
|
||||
tmpdir, err := ioutil.TempDir("", "")
|
||||
assert.NoError(t, err)
|
||||
defer os.RemoveAll(tmpdir)
|
||||
|
||||
testShimVersion = d.shimVersion
|
||||
if d.proxyExist {
|
||||
testProxyVersion = d.proxyVersion
|
||||
}
|
||||
_, config, err := makeRuntimeConfig(tmpdir)
|
||||
assert.NoError(t, err)
|
||||
if !d.proxyExist {
|
||||
config.ProxyType = vc.NoProxyType
|
||||
}
|
||||
version = d.runtimeVersion
|
||||
defer func() {
|
||||
version = origVersion
|
||||
}()
|
||||
|
||||
err = checkVersionConsistencyInComponents(config)
|
||||
if d.expectError {
|
||||
assert.Error(t, err, fmt.Sprintf("%+v", d))
|
||||
continue
|
||||
} else {
|
||||
assert.NoError(t, err, fmt.Sprintf("%+v", d))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,14 +112,6 @@ type ProxyInfo struct {
|
||||
Debug bool
|
||||
}
|
||||
|
||||
// ShimInfo stores shim details
|
||||
type ShimInfo struct {
|
||||
Type string
|
||||
Version VersionInfo
|
||||
Path string
|
||||
Debug bool
|
||||
}
|
||||
|
||||
// AgentInfo stores agent details
|
||||
type AgentInfo struct {
|
||||
Type string
|
||||
@@ -165,7 +157,6 @@ type EnvInfo struct {
|
||||
Kernel KernelInfo
|
||||
Initrd InitrdInfo
|
||||
Proxy ProxyInfo
|
||||
Shim ShimInfo
|
||||
Agent AgentInfo
|
||||
Host HostInfo
|
||||
Netmon NetmonInfo
|
||||
@@ -304,31 +295,6 @@ func getCommandVersion(cmd string) (string, error) {
|
||||
return katautils.RunCommand([]string{cmd, "--version"})
|
||||
}
|
||||
|
||||
func getShimInfo(config oci.RuntimeConfig) (ShimInfo, error) {
|
||||
shimConfig, ok := config.ShimConfig.(vc.ShimConfig)
|
||||
if !ok {
|
||||
return ShimInfo{}, errors.New("cannot determine shim config")
|
||||
}
|
||||
|
||||
shimPath := shimConfig.Path
|
||||
|
||||
var shimVersionInfo VersionInfo
|
||||
if version, err := getCommandVersion(shimConfig.Path); err != nil {
|
||||
shimVersionInfo = unknownVersionInfo
|
||||
} else {
|
||||
shimVersionInfo = constructVersionInfo(version)
|
||||
}
|
||||
|
||||
shim := ShimInfo{
|
||||
Type: string(config.ShimType),
|
||||
Version: shimVersionInfo,
|
||||
Path: shimPath,
|
||||
Debug: shimConfig.Debug,
|
||||
}
|
||||
|
||||
return shim, nil
|
||||
}
|
||||
|
||||
func getAgentInfo(config oci.RuntimeConfig) (AgentInfo, error) {
|
||||
agent := AgentInfo{
|
||||
Type: string(config.AgentType),
|
||||
@@ -396,11 +362,6 @@ func getEnvInfo(configFile string, config oci.RuntimeConfig) (env EnvInfo, err e
|
||||
|
||||
netmon := getNetmonInfo(config)
|
||||
|
||||
shim, err := getShimInfo(config)
|
||||
if err != nil {
|
||||
return EnvInfo{}, err
|
||||
}
|
||||
|
||||
agent, err := getAgentInfo(config)
|
||||
if err != nil {
|
||||
return EnvInfo{}, err
|
||||
@@ -429,7 +390,6 @@ func getEnvInfo(configFile string, config oci.RuntimeConfig) (env EnvInfo, err e
|
||||
Kernel: kernel,
|
||||
Initrd: initrd,
|
||||
Proxy: proxy,
|
||||
Shim: shim,
|
||||
Agent: agent,
|
||||
Host: host,
|
||||
Netmon: netmon,
|
||||
|
||||
@@ -32,7 +32,6 @@ import (
|
||||
|
||||
var (
|
||||
testProxyVersion = "proxy version 0.1"
|
||||
testShimVersion = "shim version 0.1"
|
||||
testNetmonVersion = "netmon version 0.1"
|
||||
testHypervisorVersion = "QEMU emulator version 2.7.0+git.741f430a96-6.1, Copyright (c) 2003-2016 Fabrice Bellard and the QEMU Project developers"
|
||||
)
|
||||
@@ -43,7 +42,6 @@ var (
|
||||
proxyDebug = false
|
||||
runtimeDebug = false
|
||||
runtimeTrace = false
|
||||
shimDebug = false
|
||||
netmonDebug = false
|
||||
agentDebug = false
|
||||
agentTrace = false
|
||||
@@ -86,7 +84,6 @@ func makeRuntimeConfig(prefixDir string) (configFile string, config oci.RuntimeC
|
||||
imagePath := filepath.Join(prefixDir, "image")
|
||||
kernelParams := "foo=bar xyz"
|
||||
machineType := "machineType"
|
||||
shimPath := filepath.Join(prefixDir, "shim")
|
||||
proxyPath := filepath.Join(prefixDir, "proxy")
|
||||
netmonPath := filepath.Join(prefixDir, "netmon")
|
||||
disableBlock := true
|
||||
@@ -112,11 +109,6 @@ func makeRuntimeConfig(prefixDir string) (configFile string, config oci.RuntimeC
|
||||
}
|
||||
}
|
||||
|
||||
err = makeVersionBinary(shimPath, testShimVersion)
|
||||
if err != nil {
|
||||
return "", oci.RuntimeConfig{}, err
|
||||
}
|
||||
|
||||
err = makeVersionBinary(proxyPath, testProxyVersion)
|
||||
if err != nil {
|
||||
return "", oci.RuntimeConfig{}, err
|
||||
@@ -145,7 +137,6 @@ func makeRuntimeConfig(prefixDir string) (configFile string, config oci.RuntimeC
|
||||
ImagePath: imagePath,
|
||||
KernelParams: kernelParams,
|
||||
MachineType: machineType,
|
||||
ShimPath: shimPath,
|
||||
ProxyPath: proxyPath,
|
||||
NetmonPath: netmonPath,
|
||||
LogPath: logPath,
|
||||
@@ -164,7 +155,6 @@ func makeRuntimeConfig(prefixDir string) (configFile string, config oci.RuntimeC
|
||||
RuntimeDebug: runtimeDebug,
|
||||
RuntimeTrace: runtimeTrace,
|
||||
ProxyDebug: proxyDebug,
|
||||
ShimDebug: shimDebug,
|
||||
NetmonDebug: netmonDebug,
|
||||
AgentDebug: agentDebug,
|
||||
AgentTrace: agentTrace,
|
||||
@@ -206,22 +196,6 @@ func getExpectedNetmonDetails(config oci.RuntimeConfig) (NetmonInfo, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func getExpectedShimDetails(config oci.RuntimeConfig) (ShimInfo, error) {
|
||||
shimConfig, ok := config.ShimConfig.(vc.ShimConfig)
|
||||
if !ok {
|
||||
return ShimInfo{}, fmt.Errorf("failed to get shim config")
|
||||
}
|
||||
|
||||
shimPath := shimConfig.Path
|
||||
|
||||
return ShimInfo{
|
||||
Type: string(config.ShimType),
|
||||
Version: constructVersionInfo(testShimVersion),
|
||||
Path: shimPath,
|
||||
Debug: shimConfig.Debug,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func getExpectedAgentDetails(config oci.RuntimeConfig) (AgentInfo, error) {
|
||||
|
||||
agentConfig, ok := config.AgentConfig.(vc.KataAgentConfig)
|
||||
@@ -385,11 +359,6 @@ func getExpectedSettings(config oci.RuntimeConfig, tmpdir, configFile string) (E
|
||||
return EnvInfo{}, err
|
||||
}
|
||||
|
||||
shim, err := getExpectedShimDetails(config)
|
||||
if err != nil {
|
||||
return EnvInfo{}, err
|
||||
}
|
||||
|
||||
agent, err := getExpectedAgentDetails(config)
|
||||
if err != nil {
|
||||
return EnvInfo{}, err
|
||||
@@ -416,7 +385,6 @@ func getExpectedSettings(config oci.RuntimeConfig, tmpdir, configFile string) (E
|
||||
Image: image,
|
||||
Kernel: kernel,
|
||||
Proxy: proxy,
|
||||
Shim: shim,
|
||||
Agent: agent,
|
||||
Host: host,
|
||||
Netmon: netmon,
|
||||
@@ -521,7 +489,6 @@ func TestEnvGetEnvInfo(t *testing.T) {
|
||||
proxyDebug = toggle
|
||||
runtimeDebug = toggle
|
||||
runtimeTrace = toggle
|
||||
shimDebug = toggle
|
||||
agentDebug = toggle
|
||||
agentTrace = toggle
|
||||
|
||||
@@ -562,22 +529,6 @@ func TestEnvGetEnvInfoNoHypervisorVersion(t *testing.T) {
|
||||
assert.Equal(expectedEnv, env)
|
||||
}
|
||||
|
||||
func TestEnvGetEnvInfoShimError(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
tmpdir, err := ioutil.TempDir("", "")
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(tmpdir)
|
||||
|
||||
configFile, config, err := makeRuntimeConfig(tmpdir)
|
||||
assert.NoError(err)
|
||||
|
||||
config.ShimConfig = "invalid shim config"
|
||||
|
||||
_, err = getEnvInfo(configFile, config)
|
||||
assert.Error(err)
|
||||
}
|
||||
|
||||
func TestEnvGetEnvInfoAgentError(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
@@ -759,71 +710,6 @@ func TestEnvGetNetmonInfoNoVersion(t *testing.T) {
|
||||
assert.Equal(t, expectedNetmon, netmon)
|
||||
}
|
||||
|
||||
func TestEnvGetShimInfo(t *testing.T) {
|
||||
tmpdir, err := ioutil.TempDir("", "")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer os.RemoveAll(tmpdir)
|
||||
|
||||
_, config, err := makeRuntimeConfig(tmpdir)
|
||||
assert.NoError(t, err)
|
||||
|
||||
expectedShim, err := getExpectedShimDetails(config)
|
||||
assert.NoError(t, err)
|
||||
|
||||
shim, err := getShimInfo(config)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, expectedShim, shim)
|
||||
}
|
||||
|
||||
func TestEnvGetShimInfoNoVersion(t *testing.T) {
|
||||
tmpdir, err := ioutil.TempDir("", "")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer os.RemoveAll(tmpdir)
|
||||
|
||||
_, config, err := makeRuntimeConfig(tmpdir)
|
||||
assert.NoError(t, err)
|
||||
|
||||
expectedShim, err := getExpectedShimDetails(config)
|
||||
assert.NoError(t, err)
|
||||
|
||||
shimPath := expectedShim.Path
|
||||
|
||||
// ensure querying the shim version fails
|
||||
err = createFile(shimPath, `#!/bin/sh
|
||||
exit 1`)
|
||||
assert.NoError(t, err)
|
||||
|
||||
expectedShim.Version = unknownVersionInfo
|
||||
|
||||
shim, err := getShimInfo(config)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, expectedShim, shim)
|
||||
}
|
||||
|
||||
func TestEnvGetShimInfoInvalidType(t *testing.T) {
|
||||
tmpdir, err := ioutil.TempDir("", "")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer os.RemoveAll(tmpdir)
|
||||
|
||||
_, config, err := makeRuntimeConfig(tmpdir)
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = getExpectedShimDetails(config)
|
||||
assert.NoError(t, err)
|
||||
|
||||
config.ShimConfig = "foo"
|
||||
_, err = getShimInfo(config)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestEnvGetAgentInfo(t *testing.T) {
|
||||
tmpdir, err := ioutil.TempDir("", "")
|
||||
if err != nil {
|
||||
@@ -891,12 +777,6 @@ func testEnvShowTOMLSettings(t *testing.T, tmpdir string, tmpfile *os.File) erro
|
||||
Debug: false,
|
||||
}
|
||||
|
||||
shim := ShimInfo{
|
||||
Type: "shim-type",
|
||||
Version: constructVersionInfo(testShimVersion),
|
||||
Path: "/resolved/shim/path",
|
||||
}
|
||||
|
||||
agent := AgentInfo{
|
||||
Type: "agent-type",
|
||||
}
|
||||
@@ -910,7 +790,6 @@ func testEnvShowTOMLSettings(t *testing.T, tmpdir string, tmpfile *os.File) erro
|
||||
Image: image,
|
||||
Kernel: kernel,
|
||||
Proxy: proxy,
|
||||
Shim: shim,
|
||||
Agent: agent,
|
||||
Host: expectedHostDetails,
|
||||
}
|
||||
@@ -960,12 +839,6 @@ func testEnvShowJSONSettings(t *testing.T, tmpdir string, tmpfile *os.File) erro
|
||||
Debug: false,
|
||||
}
|
||||
|
||||
shim := ShimInfo{
|
||||
Type: "shim-type",
|
||||
Version: constructVersionInfo(testShimVersion),
|
||||
Path: "/resolved/shim/path",
|
||||
}
|
||||
|
||||
agent := AgentInfo{
|
||||
Type: "agent-type",
|
||||
}
|
||||
@@ -979,7 +852,6 @@ func testEnvShowJSONSettings(t *testing.T, tmpdir string, tmpfile *os.File) erro
|
||||
Image: image,
|
||||
Kernel: kernel,
|
||||
Proxy: proxy,
|
||||
Shim: shim,
|
||||
Agent: agent,
|
||||
Host: expectedHostDetails,
|
||||
}
|
||||
@@ -1083,34 +955,6 @@ func TestEnvHandleSettings(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestEnvHandleSettingsInvalidShimConfig(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
tmpdir, err := ioutil.TempDir("", "")
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(tmpdir)
|
||||
|
||||
configFile, config, err := makeRuntimeConfig(tmpdir)
|
||||
assert.NoError(err)
|
||||
|
||||
_, err = getExpectedSettings(config, tmpdir, configFile)
|
||||
assert.NoError(err)
|
||||
|
||||
config.ShimConfig = "invalid shim config"
|
||||
|
||||
ctx := createCLIContext(nil)
|
||||
ctx.App.Name = "foo"
|
||||
ctx.App.Metadata["configFile"] = configFile
|
||||
ctx.App.Metadata["runtimeConfig"] = config
|
||||
|
||||
tmpfile, err := ioutil.TempFile("", "")
|
||||
assert.NoError(err)
|
||||
defer os.Remove(tmpfile.Name())
|
||||
|
||||
err = handleSettings(tmpfile, ctx)
|
||||
assert.Error(err)
|
||||
}
|
||||
|
||||
func TestEnvHandleSettingsInvalidParams(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
|
||||
@@ -244,7 +244,6 @@ func newTestRuntimeConfig(dir, consolePath string, create bool) (oci.RuntimeConf
|
||||
HypervisorConfig: hypervisorConfig,
|
||||
AgentType: vc.KataContainersAgent,
|
||||
ProxyType: vc.KataProxyType,
|
||||
ShimType: vc.KataShimType,
|
||||
Console: consolePath,
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user