Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
kata-env: Fix display of debug options
Browse files Browse the repository at this point in the history
The runtime and hypervisor `Debug` options were always showing as
`false` (although all debug options in `configuration.toml` were
correctly honoured).

Note: Also moved location of `FactoryConfig` in `RuntimeConfig` as the
`malign` linter was complaining:

```
virtcontainers/pkg/oci/utils.go:102:20:warning: struct of size 408 could be 400 (maligned)
```

Original-master-commit: https://github.com/kata-containers/runtime/commits/23a35c84c92e6ce73366edc575ae875ba4d77473

Fixes #724.

Signed-off-by: James O. D. Hunt <[email protected]>
  • Loading branch information
jodh-intel committed Sep 17, 2018
1 parent 3cdc501 commit 8c0d498
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 14 deletions.
1 change: 1 addition & 0 deletions cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ func loadConfiguration(configPath string, ignoreLogging bool) (resolvedConfigPat
}

if tomlConf.Runtime.Debug {
config.Debug = true
debug = true
crashOnError = true
} else {
Expand Down
12 changes: 11 additions & 1 deletion cli/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ import (
"github.com/stretchr/testify/assert"
)

var (
hypervisorDebug = false
proxyDebug = false
runtimeDebug = false
shimDebug = false
)

type testRuntimeConfig struct {
RuntimeConfig oci.RuntimeConfig
RuntimeConfigFile string
Expand All @@ -50,17 +57,20 @@ func makeRuntimeConfigFileData(hypervisor, hypervisorPath, kernelPath, imagePath
disable_block_device_use = ` + strconv.FormatBool(disableBlock) + `
enable_iothreads = ` + strconv.FormatBool(enableIOThreads) + `
msize_9p = ` + strconv.FormatUint(uint64(defaultMsize9p), 10) + `
enable_debug = ` + strconv.FormatBool(hypervisorDebug) + `
[proxy.kata]
enable_debug = ` + strconv.FormatBool(proxyDebug) + `
path = "` + proxyPath + `"
[shim.kata]
path = "` + shimPath + `"
enable_debug = ` + strconv.FormatBool(shimDebug) + `
[agent.kata]
[runtime]
`
enable_debug = ` + strconv.FormatBool(runtimeDebug)
}

func createConfig(configPath string, fileData string) error {
Expand Down
2 changes: 2 additions & 0 deletions cli/kata-env.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ func getRuntimeInfo(configFile string, config oci.RuntimeConfig) RuntimeInfo {
runtimePath, _ := os.Executable()

return RuntimeInfo{
Debug: config.Debug,
Version: runtimeVersion,
Config: runtimeConfig,
Path: runtimePath,
Expand Down Expand Up @@ -284,6 +285,7 @@ func getHypervisorInfo(config oci.RuntimeConfig) HypervisorInfo {
}

return HypervisorInfo{
Debug: config.HypervisorConfig.Debug,
MachineType: config.HypervisorConfig.HypervisorMachineType,
Version: version,
Path: hypervisorPath,
Expand Down
34 changes: 23 additions & 11 deletions cli/kata-env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func getExpectedShimDetails(config oci.RuntimeConfig) (ShimInfo, error) {
Type: string(config.ShimType),
Version: testShimVersion,
Path: shimPath,
Debug: shimConfig.Debug,
}, nil
}

Expand Down Expand Up @@ -240,6 +241,7 @@ func getExpectedHypervisor(config oci.RuntimeConfig) HypervisorInfo {
MachineType: config.HypervisorConfig.HypervisorMachineType,
BlockDeviceDriver: config.HypervisorConfig.BlockDeviceDriver,
Msize9p: config.HypervisorConfig.Msize9p,
Debug: config.HypervisorConfig.Debug,
}
}

Expand All @@ -256,7 +258,7 @@ func getExpectedKernel(config oci.RuntimeConfig) KernelInfo {
}
}

func getExpectedRuntimeDetails(configFile string) RuntimeInfo {
func getExpectedRuntimeDetails(config oci.RuntimeConfig, configFile string) RuntimeInfo {
runtimePath, _ := os.Executable()

return RuntimeInfo{
Expand All @@ -268,14 +270,15 @@ func getExpectedRuntimeDetails(configFile string) RuntimeInfo {
Config: RuntimeConfigInfo{
Path: configFile,
},
Path: runtimePath,
Path: runtimePath,
Debug: config.Debug,
}
}

func getExpectedSettings(config oci.RuntimeConfig, tmpdir, configFile string) (EnvInfo, error) {
meta := getExpectedMetaInfo()

runtime := getExpectedRuntimeDetails(configFile)
runtime := getExpectedRuntimeDetails(config, configFile)

proxy, err := getExpectedProxyDetails(config)
if err != nil {
Expand Down Expand Up @@ -404,16 +407,25 @@ func TestEnvGetEnvInfo(t *testing.T) {
}
defer os.RemoveAll(tmpdir)

configFile, config, err := makeRuntimeConfig(tmpdir)
assert.NoError(t, err)
// Run test twice to ensure the individual component debug options are
// tested.
for _, debug := range []bool{false, true} {
hypervisorDebug = debug
proxyDebug = debug
runtimeDebug = debug
shimDebug = debug

expectedEnv, err := getExpectedSettings(config, tmpdir, configFile)
assert.NoError(t, err)
configFile, config, err := makeRuntimeConfig(tmpdir)
assert.NoError(t, err)

env, err := getEnvInfo(configFile, config)
assert.NoError(t, err)
expectedEnv, err := getExpectedSettings(config, tmpdir, configFile)
assert.NoError(t, err)

assert.Equal(t, expectedEnv, env)
env, err := getEnvInfo(configFile, config)
assert.NoError(t, err)

assert.Equal(t, expectedEnv, env)
}
}

func TestEnvGetEnvInfoNoHypervisorVersion(t *testing.T) {
Expand Down Expand Up @@ -542,7 +554,7 @@ func TestEnvGetRuntimeInfo(t *testing.T) {
configFile, config, err := makeRuntimeConfig(tmpdir)
assert.NoError(t, err)

expectedRuntime := getExpectedRuntimeDetails(configFile)
expectedRuntime := getExpectedRuntimeDetails(config, configFile)

runtime := getRuntimeInfo(configFile, config)

Expand Down
4 changes: 2 additions & 2 deletions virtcontainers/pkg/oci/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ type RuntimeConfig struct {
HypervisorType vc.HypervisorType
HypervisorConfig vc.HypervisorConfig

FactoryConfig FactoryConfig

AgentType vc.AgentType
AgentConfig interface{}

Expand All @@ -120,6 +118,8 @@ type RuntimeConfig struct {
//Determines how the VM should be connected to the
//the container network interface
InterNetworkModel vc.NetInterworkingModel
FactoryConfig FactoryConfig
Debug bool
}

// AddKernelParam allows the addition of new kernel parameters to an existing
Expand Down

0 comments on commit 8c0d498

Please sign in to comment.