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)
```

Fixes #724.

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
  • Loading branch information
jodh-intel committed Sep 13, 2018
1 parent a5f05bf commit 23a35c8
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
Expand Up @@ -532,6 +532,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
Expand Up @@ -25,6 +25,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 Down Expand Up @@ -52,17 +59,20 @@ func makeRuntimeConfigFileData(hypervisor, hypervisorPath, kernelPath, imagePath
enable_iothreads = ` + strconv.FormatBool(enableIOThreads) + `
hotplug_vfio_on_root_bus = ` + strconv.FormatBool(hotplugVFIOOnRootBus) + `
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
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
Expand Up @@ -149,6 +149,7 @@ func getExpectedShimDetails(config oci.RuntimeConfig) (ShimInfo, error) {
Type: string(config.ShimType),
Version: testShimVersion,
Path: shimPath,
Debug: shimConfig.Debug,
}, nil
}

Expand Down Expand Up @@ -243,6 +244,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 @@ -259,7 +261,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 @@ -271,14 +273,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 @@ -407,16 +410,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 @@ -545,7 +557,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
Expand Up @@ -103,8 +103,6 @@ type RuntimeConfig struct {
HypervisorType vc.HypervisorType
HypervisorConfig vc.HypervisorConfig

FactoryConfig FactoryConfig

AgentType vc.AgentType
AgentConfig interface{}

Expand All @@ -119,6 +117,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 23a35c8

Please sign in to comment.