@@ -248,14 +248,48 @@ def test_net_devices():
248
248
249
249
for specify_broadcast in [True , False ]:
250
250
for specify_name in [True , False ]:
251
- subprocess .run (["ip" , "link" , "add" , "testdevice" , "type" , "dummy" ])
251
+ sys .stderr .write ("# test_net_devices: creating testdevice with specify_broadcast=%s, specify_name=%s\n " % (specify_broadcast , specify_name ))
252
+ result = subprocess .run (["ip" , "link" , "add" , "testdevice" , "type" , "dummy" ], capture_output = True , text = True )
253
+ if result .returncode != 0 :
254
+ sys .stderr .write ("# ip link add failed: %s\n " % result .stderr )
255
+ return - 1
252
256
if specify_broadcast :
253
- subprocess .run (["ip" , "addr" , "add" , "10.1.2.3/24" , "brd" , "10.1.2.254" , "dev" , "testdevice" ])
257
+ result = subprocess .run (["ip" , "addr" , "add" , "10.1.2.3/24" , "brd" , "10.1.2.254" , "dev" , "testdevice" ], capture_output = True , text = True )
258
+ if result .returncode != 0 :
259
+ sys .stderr .write ("# ip addr add with broadcast failed: %s\n " % result .stderr )
260
+ return - 1
254
261
else :
255
- subprocess .run (["ip" , "addr" , "add" , "10.1.2.3/24" , "dev" , "testdevice" ])
262
+ result = subprocess .run (["ip" , "addr" , "add" , "10.1.2.3/24" , "dev" , "testdevice" ], capture_output = True , text = True )
263
+ if result .returncode != 0 :
264
+ sys .stderr .write ("# ip addr add without broadcast failed: %s\n " % result .stderr )
265
+ return - 1
256
266
257
267
conf = base_config ()
258
268
add_all_namespaces (conf )
269
+
270
+ # Add network capabilities needed for network device operations
271
+ conf ['process' ]['capabilities' ] = {
272
+ "bounding" : [
273
+ "CAP_NET_ADMIN" ,
274
+ "CAP_NET_RAW" ,
275
+ "CAP_SYS_ADMIN"
276
+ ],
277
+ "effective" : [
278
+ "CAP_NET_ADMIN" ,
279
+ "CAP_NET_RAW" ,
280
+ "CAP_SYS_ADMIN"
281
+ ],
282
+ "inheritable" : [
283
+ "CAP_NET_ADMIN" ,
284
+ "CAP_NET_RAW" ,
285
+ "CAP_SYS_ADMIN"
286
+ ],
287
+ "permitted" : [
288
+ "CAP_NET_ADMIN" ,
289
+ "CAP_NET_RAW" ,
290
+ "CAP_SYS_ADMIN"
291
+ ]
292
+ }
259
293
if specify_name :
260
294
conf ['process' ]['args' ] = ['/init' , 'ip' , 'newtestdevice' ]
261
295
conf ['linux' ]['netDevices' ] = {
@@ -272,19 +306,28 @@ def test_net_devices():
272
306
273
307
try :
274
308
out = run_and_get_output (conf )
309
+ sys .stderr .write ("# test_net_devices: specify_broadcast=%s, specify_name=%s\n " % (specify_broadcast , specify_name ))
310
+ sys .stderr .write ("# test_net_devices: output: %s\n " % repr (out [0 ]))
275
311
if "address: 10.1.2.3" not in out [0 ]:
276
312
sys .stderr .write ("# address not found in output\n " )
313
+ sys .stderr .write ("# full output: %s\n " % repr (out [0 ]))
277
314
return 1
278
315
if specify_broadcast :
279
316
if "broadcast: 10.1.2.254" not in out [0 ]:
280
317
sys .stderr .write ("# broadcast address not found in output\n " )
318
+ sys .stderr .write ("# full output: %s\n " % repr (out [0 ]))
281
319
return 1
282
320
else :
283
321
if "broadcast" in out [0 ]:
284
- sys .stderr .write ("# broadcast address found in output\n " )
322
+ sys .stderr .write ("# broadcast address found in output when it shouldn't be\n " )
323
+ sys .stderr .write ("# full output: %s\n " % repr (out [0 ]))
285
324
return 1
286
325
except Exception as e :
326
+ sys .stderr .write ("# test_net_devices exception: %s\n " % str (e ))
287
327
return - 1
328
+ finally :
329
+ # Clean up the test device
330
+ subprocess .run (["ip" , "link" , "del" , "testdevice" ], capture_output = True )
288
331
finally :
289
332
os .setns (current_netns , os .CLONE_NEWNET )
290
333
os .close (current_netns )
0 commit comments