@@ -26,6 +26,7 @@ import (
26
26
"gotest.tools/v3/assert"
27
27
28
28
"github.com/containerd/nerdctl/mod/tigron/expect"
29
+ "github.com/containerd/nerdctl/mod/tigron/require"
29
30
"github.com/containerd/nerdctl/mod/tigron/test"
30
31
"github.com/containerd/nerdctl/mod/tigron/tig"
31
32
@@ -159,3 +160,100 @@ func TestNetworkCreate(t *testing.T) {
159
160
160
161
testCase .Run (t )
161
162
}
163
+
164
+ func TestNetworkCreateICC (t * testing.T ) {
165
+ testCase := nerdtest .Setup ()
166
+
167
+ testCase .Require = require .All (
168
+ require .Linux ,
169
+ )
170
+
171
+ testCase .SubTests = []* test.Case {
172
+ {
173
+ Description : "with enable_icc=false" ,
174
+ Require : nerdtest .CNIFirewallVersion ("1.7.1" ),
175
+ NoParallel : true ,
176
+ Setup : func (data test.Data , helpers test.Helpers ) {
177
+ // Create a network with ICC disabled
178
+ helpers .Ensure ("network" , "create" , data .Identifier (), "--driver" , "bridge" ,
179
+ "--opt" , "com.docker.network.bridge.enable_icc=false" )
180
+
181
+ // Run a container in that network
182
+ data .Labels ().Set ("container1" , helpers .Capture ("run" , "-d" , "--net" , data .Identifier (),
183
+ "--name" , data .Identifier ("c1" ), testutil .CommonImage , "sleep" , "infinity" ))
184
+
185
+ // Wait for container to be running
186
+ nerdtest .EnsureContainerStarted (helpers , data .Identifier ("c1" ))
187
+ },
188
+ Cleanup : func (data test.Data , helpers test.Helpers ) {
189
+ helpers .Anyhow ("container" , "rm" , "-f" , data .Identifier ("c1" ))
190
+ helpers .Anyhow ("network" , "rm" , data .Identifier ())
191
+ },
192
+ Command : func (data test.Data , helpers test.Helpers ) test.TestableCommand {
193
+ // DEBUG: Check br_netfilter module status
194
+ helpers .Custom ("sh" , "-ec" , "lsmod | grep br_netfilter || echo 'br_netfilter not loaded'" ).Run (& test.Expected {})
195
+ helpers .Custom ("sh" , "-ec" , "cat /proc/sys/net/bridge/bridge-nf-call-iptables 2>/dev/null || echo 'bridge-nf-call-iptables not available'" ).Run (& test.Expected {})
196
+ helpers .Custom ("sh" , "-ec" , "ls /proc/sys/net/bridge/ 2>/dev/null || echo 'bridge sysctl not available'" ).Run (& test.Expected {})
197
+ // Try to ping the other container in the same network
198
+ // This should fail when ICC is disabled
199
+ return helpers .Command ("run" , "--rm" , "--net" , data .Identifier (),
200
+ testutil .CommonImage , "ping" , "-c" , "1" , "-W" , "1" , data .Identifier ("c1" ))
201
+ },
202
+ Expected : test .Expects (expect .ExitCodeGenericFail , nil , nil ), // Expect ping to fail with exit code 1
203
+ },
204
+ {
205
+ Description : "with enable_icc=true" ,
206
+ Require : nerdtest .CNIFirewallVersion ("1.7.1" ),
207
+ NoParallel : true ,
208
+ Setup : func (data test.Data , helpers test.Helpers ) {
209
+ // Create a network with ICC enabled (default)
210
+ helpers .Ensure ("network" , "create" , data .Identifier (), "--driver" , "bridge" ,
211
+ "--opt" , "com.docker.network.bridge.enable_icc=true" )
212
+
213
+ // Run a container in that network
214
+ data .Labels ().Set ("container1" , helpers .Capture ("run" , "-d" , "--net" , data .Identifier (),
215
+ "--name" , data .Identifier ("c1" ), testutil .CommonImage , "sleep" , "infinity" ))
216
+ // Wait for container to be running
217
+ nerdtest .EnsureContainerStarted (helpers , data .Identifier ("c1" ))
218
+ },
219
+ Cleanup : func (data test.Data , helpers test.Helpers ) {
220
+ helpers .Anyhow ("container" , "rm" , "-f" , data .Identifier ("c1" ))
221
+ helpers .Anyhow ("network" , "rm" , data .Identifier ())
222
+ },
223
+ Command : func (data test.Data , helpers test.Helpers ) test.TestableCommand {
224
+ // Try to ping the other container in the same network
225
+ // This should succeed when ICC is enabled
226
+ return helpers .Command ("run" , "--rm" , "--net" , data .Identifier (),
227
+ testutil .CommonImage , "ping" , "-c" , "1" , "-W" , "1" , data .Identifier ("c1" ))
228
+ },
229
+ Expected : test .Expects (0 , nil , nil ), // Expect ping to succeed with exit code 0
230
+ },
231
+ {
232
+ Description : "with no enable_icc option set" ,
233
+ NoParallel : true ,
234
+ Setup : func (data test.Data , helpers test.Helpers ) {
235
+ // Create a network with ICC enabled (default)
236
+ helpers .Ensure ("network" , "create" , data .Identifier (), "--driver" , "bridge" )
237
+
238
+ // Run a container in that network
239
+ data .Labels ().Set ("container1" , helpers .Capture ("run" , "-d" , "--net" , data .Identifier (),
240
+ "--name" , data .Identifier ("c1" ), testutil .CommonImage , "sleep" , "infinity" ))
241
+ // Wait for container to be running
242
+ nerdtest .EnsureContainerStarted (helpers , data .Identifier ("c1" ))
243
+ },
244
+ Cleanup : func (data test.Data , helpers test.Helpers ) {
245
+ helpers .Anyhow ("container" , "rm" , "-f" , data .Identifier ("c1" ))
246
+ helpers .Anyhow ("network" , "rm" , data .Identifier ())
247
+ },
248
+ Command : func (data test.Data , helpers test.Helpers ) test.TestableCommand {
249
+ // Try to ping the other container in the same network
250
+ // This should succeed when no ICC is set
251
+ return helpers .Command ("run" , "--rm" , "--net" , data .Identifier (),
252
+ testutil .CommonImage , "ping" , "-c" , "1" , "-W" , "1" , data .Identifier ("c1" ))
253
+ },
254
+ Expected : test .Expects (0 , nil , nil ), // Expect ping to succeed with exit code 0
255
+ },
256
+ }
257
+
258
+ testCase .Run (t )
259
+ }
0 commit comments