mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-04 11:06:21 +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
|
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 `
|
return `
|
||||||
# Runtime configuration file
|
# Runtime configuration file
|
||||||
|
|
||||||
@ -77,7 +77,8 @@ func makeRuntimeConfigFileData(hypervisor, hypervisorPath, kernelPath, imagePath
|
|||||||
enable_debug = ` + strconv.FormatBool(netmonDebug) + `
|
enable_debug = ` + strconv.FormatBool(netmonDebug) + `
|
||||||
|
|
||||||
[runtime]
|
[runtime]
|
||||||
enable_debug = ` + strconv.FormatBool(runtimeDebug)
|
enable_debug = ` + strconv.FormatBool(runtimeDebug) + `
|
||||||
|
disable_new_netns= ` + strconv.FormatBool(disableNewNetNs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func createConfig(configPath string, fileData string) error {
|
func createConfig(configPath string, fileData string) error {
|
||||||
@ -116,8 +117,9 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
|
|||||||
blockDeviceDriver := "virtio-scsi"
|
blockDeviceDriver := "virtio-scsi"
|
||||||
enableIOThreads := true
|
enableIOThreads := true
|
||||||
hotplugVFIOOnRootBus := 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")
|
configPath := path.Join(dir, "runtime.toml")
|
||||||
err = createConfig(configPath, runtimeConfigFileData)
|
err = createConfig(configPath, runtimeConfigFileData)
|
||||||
@ -192,7 +194,8 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
|
|||||||
ShimType: defaultShim,
|
ShimType: defaultShim,
|
||||||
ShimConfig: shimConfig,
|
ShimConfig: shimConfig,
|
||||||
|
|
||||||
NetmonConfig: netmonConfig,
|
NetmonConfig: netmonConfig,
|
||||||
|
DisableNewNetNs: disableNewNetNs,
|
||||||
}
|
}
|
||||||
|
|
||||||
config = testRuntimeConfig{
|
config = testRuntimeConfig{
|
||||||
@ -1455,3 +1458,23 @@ func TestCheckHypervisorConfig(t *testing.T) {
|
|||||||
kataLog.Logger.Out = savedOut
|
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"
|
blockStorageDriver := "virtio-scsi"
|
||||||
enableIOThreads := true
|
enableIOThreads := true
|
||||||
hotplugVFIOOnRootBus := true
|
hotplugVFIOOnRootBus := true
|
||||||
|
disableNewNetNs := false
|
||||||
|
|
||||||
// override
|
// override
|
||||||
defaultProxyPath = proxyPath
|
defaultProxyPath = proxyPath
|
||||||
@ -121,6 +122,7 @@ func makeRuntimeConfig(prefixDir string) (configFile string, config oci.RuntimeC
|
|||||||
blockStorageDriver,
|
blockStorageDriver,
|
||||||
enableIOThreads,
|
enableIOThreads,
|
||||||
hotplugVFIOOnRootBus,
|
hotplugVFIOOnRootBus,
|
||||||
|
disableNewNetNs,
|
||||||
)
|
)
|
||||||
|
|
||||||
configFile = path.Join(prefixDir, "runtime.toml")
|
configFile = path.Join(prefixDir, "runtime.toml")
|
||||||
@ -293,8 +295,9 @@ func getExpectedRuntimeDetails(config oci.RuntimeConfig, configFile string) Runt
|
|||||||
Config: RuntimeConfigInfo{
|
Config: RuntimeConfigInfo{
|
||||||
Path: configFile,
|
Path: configFile,
|
||||||
},
|
},
|
||||||
Path: runtimePath,
|
Path: runtimePath,
|
||||||
Debug: config.Debug,
|
Debug: config.Debug,
|
||||||
|
DisableNewNetNs: config.DisableNewNetNs,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,4 +217,9 @@ func TestSetupNetworkNamespace(t *testing.T) {
|
|||||||
n.Close()
|
n.Close()
|
||||||
unix.Unmount(config.NetNSPath, unix.MNT_DETACH)
|
unix.Unmount(config.NetNSPath, unix.MNT_DETACH)
|
||||||
os.RemoveAll(config.NetNSPath)
|
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},
|
{"bridged Model", "bridged", false},
|
||||||
{"macvtap Model", "macvtap", false},
|
{"macvtap Model", "macvtap", false},
|
||||||
{"enlightened Model", "enlightened", false},
|
{"enlightened Model", "enlightened", false},
|
||||||
|
{"none Model", "none", false},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
Loading…
Reference in New Issue
Block a user