kata-env: Fix display of debug options

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⚠️ struct of size 408 could be 400 (maligned)
```

Fixes #724.

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
This commit is contained in:
James O. D. Hunt 2018-09-13 09:22:53 +01:00
parent a5f05bf3e1
commit 23a35c84c9
5 changed files with 39 additions and 14 deletions

View File

@ -532,6 +532,7 @@ func loadConfiguration(configPath string, ignoreLogging bool) (resolvedConfigPat
}
if tomlConf.Runtime.Debug {
config.Debug = true
debug = true
crashOnError = true
} else {

View File

@ -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
@ -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 {

View File

@ -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,
@ -284,6 +285,7 @@ func getHypervisorInfo(config oci.RuntimeConfig) HypervisorInfo {
}
return HypervisorInfo{
Debug: config.HypervisorConfig.Debug,
MachineType: config.HypervisorConfig.HypervisorMachineType,
Version: version,
Path: hypervisorPath,

View File

@ -149,6 +149,7 @@ func getExpectedShimDetails(config oci.RuntimeConfig) (ShimInfo, error) {
Type: string(config.ShimType),
Version: testShimVersion,
Path: shimPath,
Debug: shimConfig.Debug,
}, nil
}
@ -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,
}
}
@ -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{
@ -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 {
@ -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) {
@ -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)

View File

@ -103,8 +103,6 @@ type RuntimeConfig struct {
HypervisorType vc.HypervisorType
HypervisorConfig vc.HypervisorConfig
FactoryConfig FactoryConfig
AgentType vc.AgentType
AgentConfig interface{}
@ -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