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

Commit

Permalink
cli: test: add unit test for kata-env and kata-check
Browse files Browse the repository at this point in the history
Add unit test for `disable_new_netns`

Signed-off-by: Ruidong Cao <[email protected]>
  • Loading branch information
caoruidong committed Oct 22, 2018
1 parent 14e5437 commit 7a5a57d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
31 changes: 27 additions & 4 deletions cli/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type testRuntimeConfig struct {
LogPath string
}

func makeRuntimeConfigFileData(hypervisor, hypervisorPath, kernelPath, imagePath, kernelParams, machineType, shimPath, proxyPath, netmonPath, 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, disableNewNetNs bool) string {
return `
# Runtime configuration file
Expand Down Expand Up @@ -77,7 +77,8 @@ func makeRuntimeConfigFileData(hypervisor, hypervisorPath, kernelPath, imagePath
enable_debug = ` + strconv.FormatBool(netmonDebug) + `
[runtime]
enable_debug = ` + strconv.FormatBool(runtimeDebug)
enable_debug = ` + strconv.FormatBool(runtimeDebug) + `
disable_new_netns= ` + strconv.FormatBool(disableNewNetNs)
}

func createConfig(configPath string, fileData string) error {
Expand Down Expand Up @@ -116,8 +117,9 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
blockDeviceDriver := "virtio-scsi"
enableIOThreads := true
hotplugVFIOOnRootBus := true
disableNewNetNs := false

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

configPath := path.Join(dir, "runtime.toml")
err = createConfig(configPath, runtimeConfigFileData)
Expand Down Expand Up @@ -192,7 +194,8 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
ShimType: defaultShim,
ShimConfig: shimConfig,

NetmonConfig: netmonConfig,
NetmonConfig: netmonConfig,
DisableNewNetNs: disableNewNetNs,
}

config = testRuntimeConfig{
Expand Down Expand Up @@ -1455,3 +1458,23 @@ func TestCheckHypervisorConfig(t *testing.T) {
kataLog.Logger.Out = savedOut
}
}

func TestCheckNetNsConfig(t *testing.T) {
assert := assert.New(t)

config := oci.RuntimeConfig{
DisableNewNetNs: true,
NetmonConfig: vc.NetmonConfig{
Enable: true,
},
}
err := checkNetNsConfig(config)
assert.Error(err)

config = oci.RuntimeConfig{
DisableNewNetNs: true,
InterNetworkModel: vc.NetXConnectDefaultModel,
}
err = checkNetNsConfig(config)
assert.Error(err)
}
7 changes: 5 additions & 2 deletions cli/kata-env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func makeRuntimeConfig(prefixDir string) (configFile string, config oci.RuntimeC
blockStorageDriver := "virtio-scsi"
enableIOThreads := true
hotplugVFIOOnRootBus := true
disableNewNetNs := false

// override
defaultProxyPath = proxyPath
Expand Down Expand Up @@ -121,6 +122,7 @@ func makeRuntimeConfig(prefixDir string) (configFile string, config oci.RuntimeC
blockStorageDriver,
enableIOThreads,
hotplugVFIOOnRootBus,
disableNewNetNs,
)

configFile = path.Join(prefixDir, "runtime.toml")
Expand Down Expand Up @@ -293,8 +295,9 @@ func getExpectedRuntimeDetails(config oci.RuntimeConfig, configFile string) Runt
Config: RuntimeConfigInfo{
Path: configFile,
},
Path: runtimePath,
Debug: config.Debug,
Path: runtimePath,
Debug: config.Debug,
DisableNewNetNs: config.DisableNewNetNs,
}
}

Expand Down
5 changes: 5 additions & 0 deletions cli/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,9 @@ func TestSetupNetworkNamespace(t *testing.T) {
n.Close()
unix.Unmount(config.NetNSPath, unix.MNT_DETACH)
os.RemoveAll(config.NetNSPath)

// Config with DisableNewNetNs
config = &vc.NetworkConfig{DisableNewNetNs: true}
err = setupNetworkNamespace(config)
assert.NoError(err)
}
1 change: 1 addition & 0 deletions virtcontainers/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ func TestNetInterworkingModelSetModel(t *testing.T) {
{"bridged Model", "bridged", false},
{"macvtap Model", "macvtap", false},
{"enlightened Model", "enlightened", false},
{"none Model", "none", false},
}

for _, tt := range tests {
Expand Down

0 comments on commit 7a5a57d

Please sign in to comment.