@@ -25,6 +25,7 @@ import (
25
25
"gotest.tools/v3/assert"
26
26
27
27
"github.com/containerd/nerdctl/mod/tigron/expect"
28
+ "github.com/containerd/nerdctl/mod/tigron/require"
28
29
"github.com/containerd/nerdctl/mod/tigron/test"
29
30
30
31
"github.com/containerd/nerdctl/v2/pkg/testutil"
@@ -110,3 +111,97 @@ func TestNetworkCreate(t *testing.T) {
110
111
111
112
testCase .Run (t )
112
113
}
114
+
115
+ func TestNetworkCreateICC (t * testing.T ) {
116
+ testCase := nerdtest .Setup ()
117
+
118
+ testCase .Require = require .All (
119
+ require .Linux ,
120
+ nerdtest .Rootful ,
121
+ )
122
+
123
+ testCase .SubTests = []* test.Case {
124
+ {
125
+ Description : "with enable_icc=false" ,
126
+ Require : nerdtest .CNIFirewallVersionGE ("1.7.1" ),
127
+ NoParallel : true ,
128
+ Setup : func (data test.Data , helpers test.Helpers ) {
129
+ // Create a network with ICC disabled
130
+ helpers .Ensure ("network" , "create" , data .Identifier (), "--driver" , "bridge" ,
131
+ "--opt" , "com.docker.network.bridge.enable_icc=false" )
132
+
133
+ // Run a container in that network
134
+ data .Labels ().Set ("container1" , helpers .Capture ("run" , "-d" , "--net" , data .Identifier (),
135
+ "--name" , data .Identifier ("c1" ), testutil .CommonImage , "sleep" , "infinity" ))
136
+
137
+ // Wait for container to be running
138
+ nerdtest .EnsureContainerStarted (helpers , data .Identifier ("c1" ))
139
+ },
140
+ Cleanup : func (data test.Data , helpers test.Helpers ) {
141
+ helpers .Anyhow ("container" , "rm" , "-f" , data .Identifier ("c1" ))
142
+ helpers .Anyhow ("network" , "rm" , data .Identifier ())
143
+ },
144
+ Command : func (data test.Data , helpers test.Helpers ) test.TestableCommand {
145
+ // Try to ping the other container in the same network
146
+ // This should fail when ICC is disabled
147
+ return helpers .Command ("run" , "--rm" , "--net" , data .Identifier (),
148
+ testutil .CommonImage , "ping" , "-c" , "1" , "-W" , "1" , data .Identifier ("c1" ))
149
+ },
150
+ Expected : test .Expects (expect .ExitCodeGenericFail , nil , nil ), // Expect ping to fail with exit code 1
151
+ },
152
+ {
153
+ Description : "with enable_icc=true" ,
154
+ Require : nerdtest .CNIFirewallVersionGE ("1.7.1" ),
155
+ NoParallel : true ,
156
+ Setup : func (data test.Data , helpers test.Helpers ) {
157
+ // Create a network with ICC enabled (default)
158
+ helpers .Ensure ("network" , "create" , data .Identifier (), "--driver" , "bridge" ,
159
+ "--opt" , "com.docker.network.bridge.enable_icc=true" )
160
+
161
+ // Run a container in that network
162
+ data .Labels ().Set ("container1" , helpers .Capture ("run" , "-d" , "--net" , data .Identifier (),
163
+ "--name" , data .Identifier ("c1" ), testutil .CommonImage , "sleep" , "infinity" ))
164
+ // Wait for container to be running
165
+ nerdtest .EnsureContainerStarted (helpers , data .Identifier ("c1" ))
166
+ },
167
+ Cleanup : func (data test.Data , helpers test.Helpers ) {
168
+ helpers .Anyhow ("container" , "rm" , "-f" , data .Identifier ("c1" ))
169
+ helpers .Anyhow ("network" , "rm" , data .Identifier ())
170
+ },
171
+ Command : func (data test.Data , helpers test.Helpers ) test.TestableCommand {
172
+ // Try to ping the other container in the same network
173
+ // This should succeed when ICC is enabled
174
+ return helpers .Command ("run" , "--rm" , "--net" , data .Identifier (),
175
+ testutil .CommonImage , "ping" , "-c" , "1" , "-W" , "1" , data .Identifier ("c1" ))
176
+ },
177
+ Expected : test .Expects (0 , nil , nil ), // Expect ping to succeed with exit code 0
178
+ },
179
+ {
180
+ Description : "with no enable_icc option set" ,
181
+ NoParallel : true ,
182
+ Setup : func (data test.Data , helpers test.Helpers ) {
183
+ // Create a network with ICC enabled (default)
184
+ helpers .Ensure ("network" , "create" , data .Identifier (), "--driver" , "bridge" )
185
+
186
+ // Run a container in that network
187
+ data .Labels ().Set ("container1" , helpers .Capture ("run" , "-d" , "--net" , data .Identifier (),
188
+ "--name" , data .Identifier ("c1" ), testutil .CommonImage , "sleep" , "infinity" ))
189
+ // Wait for container to be running
190
+ nerdtest .EnsureContainerStarted (helpers , data .Identifier ("c1" ))
191
+ },
192
+ Cleanup : func (data test.Data , helpers test.Helpers ) {
193
+ helpers .Anyhow ("container" , "rm" , "-f" , data .Identifier ("c1" ))
194
+ helpers .Anyhow ("network" , "rm" , data .Identifier ())
195
+ },
196
+ Command : func (data test.Data , helpers test.Helpers ) test.TestableCommand {
197
+ // Try to ping the other container in the same network
198
+ // This should succeed when no ICC is set
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 (0 , nil , nil ), // Expect ping to succeed with exit code 0
203
+ },
204
+ }
205
+
206
+ testCase .Run (t )
207
+ }
0 commit comments