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

Commit

Permalink
cli: config: Make netmon configurable
Browse files Browse the repository at this point in the history
In order to choose if the network monitor should be used or not, this
patch makes it configurable from the configuration.toml file.

Signed-off-by: Sebastien Boeuf <[email protected]>
  • Loading branch information
Sebastien Boeuf committed Sep 14, 2018
1 parent 1406d99 commit 0ffe81c
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 4 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ SHIMPATH := $(PKGLIBEXECDIR)/$(SHIMCMD)
PROXYCMD := $(BIN_PREFIX)-proxy
PROXYPATH := $(PKGLIBEXECDIR)/$(PROXYCMD)

NETMONCMD := $(BIN_PREFIX)-netmon
NETMONPATH := $(PKGLIBEXECDIR)/$(NETMONCMD)

# Default number of vCPUs
DEFVCPUS := 1
# Default maximum number of vCPUs
Expand Down Expand Up @@ -189,6 +192,7 @@ USER_VARS += PROJECT_NAME
USER_VARS += PROJECT_PREFIX
USER_VARS += PROJECT_TYPE
USER_VARS += PROXYPATH
USER_VARS += NETMONPATH
USER_VARS += QEMUBINDIR
USER_VARS += QEMUCMD
USER_VARS += QEMUPATH
Expand Down Expand Up @@ -319,6 +323,7 @@ var defaultRuntimeConfiguration = "$(CONFIG_PATH)"
var defaultSysConfRuntimeConfiguration = "$(SYSCONFIG)"

var defaultProxyPath = "$(PROXYPATH)"
var defaultNetmonPath = "$(NETMONPATH)"
endef

export GENERATED_CODE
Expand Down Expand Up @@ -373,6 +378,7 @@ $(GENERATED_FILES): %: %.in Makefile VERSION
-e "s|@LOCALSTATEDIR@|$(LOCALSTATEDIR)|g" \
-e "s|@PKGLIBEXECDIR@|$(PKGLIBEXECDIR)|g" \
-e "s|@PROXYPATH@|$(PROXYPATH)|g" \
-e "s|@NETMONPATH@|$(NETMONPATH)|g" \
-e "s|@PROJECT_BUG_URL@|$(PROJECT_BUG_URL)|g" \
-e "s|@PROJECT_URL@|$(PROJECT_URL)|g" \
-e "s|@PROJECT_NAME@|$(PROJECT_NAME)|g" \
Expand Down
29 changes: 29 additions & 0 deletions cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type tomlConfig struct {
Agent map[string]agent
Runtime runtime
Factory factory
Netmon netmon
}

type factory struct {
Expand Down Expand Up @@ -116,6 +117,12 @@ type shim struct {
type agent struct {
}

type netmon struct {
Path string `toml:"path"`
Debug bool `toml:"enable_debug"`
Enable bool `toml:"enable_netmon"`
}

func (h hypervisor) path() (string, error) {
p := h.Path

Expand Down Expand Up @@ -302,6 +309,22 @@ func (s shim) debug() bool {
return s.Debug
}

func (n netmon) enable() bool {
return n.Enable
}

func (n netmon) path() string {
if n.Path == "" {
return defaultNetmonPath
}

return n.Path
}

func (n netmon) debug() bool {
return n.Debug
}

func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
hypervisor, err := h.path()
if err != nil {
Expand Down Expand Up @@ -464,6 +487,12 @@ func updateRuntimeConfig(configPath string, tomlConf tomlConfig, config *oci.Run
}
config.FactoryConfig = fConfig

config.NetmonConfig = vc.NetmonConfig{
Path: tomlConf.Netmon.path(),
Debug: tomlConf.Netmon.debug(),
Enable: tomlConf.Netmon.enable(),
}

return nil
}

Expand Down
15 changes: 15 additions & 0 deletions cli/config/configuration.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,21 @@ path = "@SHIMPATH@"
# There is no field for this section. The goal is only to be able to
# specify which type of agent the user wants to use.

[netmon]
# If enabled, the network monitoring process gets started when the
# sandbox is created. This allows for the detection of some additional
# network being added to the existing network namespace, after the
# sandbox has been created.
# (default: disabled)
#enable_netmon = true

# Specify the path to the netmon binary.
path = "@NETMONPATH@"

# If enabled, netmon messages will be sent to the system log
# (default: disabled)
#enable_debug = true

[runtime]
# If enabled, the runtime will log additional debug messages to the
# system log
Expand Down
36 changes: 33 additions & 3 deletions cli/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var (
proxyDebug = false
runtimeDebug = false
shimDebug = false
netmonDebug = false
)

type testRuntimeConfig struct {
Expand All @@ -41,7 +42,7 @@ type testRuntimeConfig struct {
LogPath string
}

func makeRuntimeConfigFileData(hypervisor, hypervisorPath, kernelPath, imagePath, kernelParams, machineType, shimPath, proxyPath, logPath string, disableBlock bool, blockDeviceDriver string, enableIOThreads bool, hotplugVFIOOnRootBus bool) string {
func makeRuntimeConfigFileData(hypervisor, hypervisorPath, kernelPath, imagePath, kernelParams, machineType, shimPath, proxyPath, netmonPath, logPath string, disableBlock bool, blockDeviceDriver string, enableIOThreads bool, hotplugVFIOOnRootBus bool) string {
return `
# Runtime configuration file
Expand Down Expand Up @@ -71,6 +72,10 @@ func makeRuntimeConfigFileData(hypervisor, hypervisorPath, kernelPath, imagePath
[agent.kata]
[netmon]
path = "` + netmonPath + `"
enable_debug = ` + strconv.FormatBool(netmonDebug) + `
[runtime]
enable_debug = ` + strconv.FormatBool(runtimeDebug)
}
Expand Down Expand Up @@ -103,6 +108,7 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
imagePath := path.Join(dir, "image")
shimPath := path.Join(dir, "shim")
proxyPath := path.Join(dir, "proxy")
netmonPath := path.Join(dir, "netmon")
logDir := path.Join(dir, "logs")
logPath := path.Join(logDir, "runtime.log")
machineType := "machineType"
Expand All @@ -111,7 +117,7 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
enableIOThreads := true
hotplugVFIOOnRootBus := true

runtimeConfigFileData := makeRuntimeConfigFileData(hypervisor, hypervisorPath, kernelPath, imagePath, kernelParams, machineType, shimPath, proxyPath, logPath, disableBlockDevice, blockDeviceDriver, enableIOThreads, hotplugVFIOOnRootBus)
runtimeConfigFileData := makeRuntimeConfigFileData(hypervisor, hypervisorPath, kernelPath, imagePath, kernelParams, machineType, shimPath, proxyPath, netmonPath, logPath, disableBlockDevice, blockDeviceDriver, enableIOThreads, hotplugVFIOOnRootBus)

configPath := path.Join(dir, "runtime.toml")
err = createConfig(configPath, runtimeConfigFileData)
Expand Down Expand Up @@ -165,6 +171,12 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
Path: shimPath,
}

netmonConfig := vc.NetmonConfig{
Path: netmonPath,
Debug: false,
Enable: false,
}

runtimeConfig := oci.RuntimeConfig{
HypervisorType: defaultHypervisor,
HypervisorConfig: hypervisorConfig,
Expand All @@ -177,6 +189,8 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf

ShimType: defaultShim,
ShimConfig: shimConfig,

NetmonConfig: netmonConfig,
}

config = testRuntimeConfig{
Expand Down Expand Up @@ -482,11 +496,11 @@ func TestMinimalRuntimeConfig(t *testing.T) {
proxyPath := path.Join(dir, "proxy")
hypervisorPath := path.Join(dir, "hypervisor")
defaultHypervisorPath = hypervisorPath
netmonPath := path.Join(dir, "netmon")

imagePath := path.Join(dir, "image.img")
initrdPath := path.Join(dir, "initrd.img")

hypervisorPath = path.Join(dir, "hypervisor")
kernelPath := path.Join(dir, "kernel")

savedDefaultImagePath := defaultImagePath
Expand Down Expand Up @@ -525,6 +539,9 @@ func TestMinimalRuntimeConfig(t *testing.T) {
path = "` + shimPath + `"
[agent.kata]
[netmon]
path = "` + netmonPath + `"
`

configPath := path.Join(dir, "runtime.toml")
Expand Down Expand Up @@ -553,6 +570,11 @@ func TestMinimalRuntimeConfig(t *testing.T) {
t.Error(err)
}

err = createEmptyFile(netmonPath)
if err != nil {
t.Error(err)
}

_, config, err = loadConfiguration(configPath, false)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -584,6 +606,12 @@ func TestMinimalRuntimeConfig(t *testing.T) {
Path: shimPath,
}

expectedNetmonConfig := vc.NetmonConfig{
Path: netmonPath,
Debug: false,
Enable: false,
}

expectedConfig := oci.RuntimeConfig{
HypervisorType: defaultHypervisor,
HypervisorConfig: expectedHypervisorConfig,
Expand All @@ -596,6 +624,8 @@ func TestMinimalRuntimeConfig(t *testing.T) {

ShimType: defaultShim,
ShimConfig: expectedShimConfig,

NetmonConfig: expectedNetmonConfig,
}

if reflect.DeepEqual(config, expectedConfig) == false {
Expand Down
30 changes: 29 additions & 1 deletion cli/kata-env.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
//
// XXX: Increment for every change to the output format
// (meaning any change to the EnvInfo type).
const formatVersion = "1.0.15"
const formatVersion = "1.0.16"

// MetaInfo stores information on the format of the output itself
type MetaInfo struct {
Expand Down Expand Up @@ -123,6 +123,14 @@ type HostInfo struct {
SupportVSocks bool
}

// NetmonInfo stores netmon details
type NetmonInfo struct {
Version string
Path string
Debug bool
Enable bool
}

// EnvInfo collects all information that will be displayed by the
// env command.
//
Expand All @@ -138,6 +146,7 @@ type EnvInfo struct {
Shim ShimInfo
Agent AgentInfo
Host HostInfo
Netmon NetmonInfo
}

func getMetaInfo() MetaInfo {
Expand Down Expand Up @@ -241,6 +250,22 @@ func getProxyInfo(config oci.RuntimeConfig) (ProxyInfo, error) {
return proxy, nil
}

func getNetmonInfo(config oci.RuntimeConfig) (NetmonInfo, error) {
version, err := getCommandVersion(defaultNetmonPath)
if err != nil {
version = unknown
}

netmon := NetmonInfo{
Version: version,
Path: config.NetmonConfig.Path,
Debug: config.NetmonConfig.Debug,
Enable: config.NetmonConfig.Enable,
}

return netmon, nil
}

func getCommandVersion(cmd string) (string, error) {
return runCommand([]string{cmd, "--version"})
}
Expand Down Expand Up @@ -309,6 +334,8 @@ func getEnvInfo(configFile string, config oci.RuntimeConfig) (env EnvInfo, err e

proxy, _ := getProxyInfo(config)

netmon, _ := getNetmonInfo(config)

shim, err := getShimInfo(config)
if err != nil {
return EnvInfo{}, err
Expand Down Expand Up @@ -342,6 +369,7 @@ func getEnvInfo(configFile string, config oci.RuntimeConfig) (env EnvInfo, err e
Shim: shim,
Agent: agent,
Host: host,
Netmon: netmon,
}

return env, nil
Expand Down
Loading

0 comments on commit 0ffe81c

Please sign in to comment.