mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-04 02:56:18 +00:00
cli: test: add unit test for kata-env and kata-check
Add unit test for `disable_new_netns` Signed-off-by: Ruidong Cao <caoruidong@huawei.com>
This commit is contained in:
parent
14e5437cae
commit
7a5a57d50f
@ -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
|
||||
|
||||
@ -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 {
|
||||
@ -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)
|
||||
@ -192,7 +194,8 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
|
||||
ShimType: defaultShim,
|
||||
ShimConfig: shimConfig,
|
||||
|
||||
NetmonConfig: netmonConfig,
|
||||
NetmonConfig: netmonConfig,
|
||||
DisableNewNetNs: disableNewNetNs,
|
||||
}
|
||||
|
||||
config = testRuntimeConfig{
|
||||
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
@ -121,6 +122,7 @@ func makeRuntimeConfig(prefixDir string) (configFile string, config oci.RuntimeC
|
||||
blockStorageDriver,
|
||||
enableIOThreads,
|
||||
hotplugVFIOOnRootBus,
|
||||
disableNewNetNs,
|
||||
)
|
||||
|
||||
configFile = path.Join(prefixDir, "runtime.toml")
|
||||
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user