diff --git a/cli/config_test.go b/cli/config_test.go index d3e7c9fbc4..2eb1c161c4 100644 --- a/cli/config_test.go +++ b/cli/config_test.go @@ -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) +} diff --git a/cli/kata-env_test.go b/cli/kata-env_test.go index c465cc96c8..45a2a08f94 100644 --- a/cli/kata-env_test.go +++ b/cli/kata-env_test.go @@ -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, } } diff --git a/cli/network_test.go b/cli/network_test.go index 3bf90f0f6a..b8c8337e2a 100644 --- a/cli/network_test.go +++ b/cli/network_test.go @@ -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) } diff --git a/virtcontainers/network_test.go b/virtcontainers/network_test.go index 209bfbc30d..6f640b7861 100644 --- a/virtcontainers/network_test.go +++ b/virtcontainers/network_test.go @@ -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 {