@@ -71,6 +71,8 @@ const (
71
71
numberOfVmsEnvName = "NUMBER_OF_VMS"
72
72
defaultNumberOfVms = 5
73
73
74
+ tapPrefixEnvName = "TAP_PREFIX"
75
+
74
76
defaultBalloonMemory = int64 (66 )
75
77
defaultStatsPollingIntervals = int64 (1 )
76
78
@@ -223,30 +225,27 @@ func vmIDtoMacAddr(vmID uint) string {
223
225
return strings .Join (addrParts , ":" )
224
226
}
225
227
226
- func deleteTapDevice (ctx context.Context , tapName string ) error {
227
- if err := exec .CommandContext (ctx , "ip" , "link" , "delete" , tapName ).Run (); err != nil {
228
- return err
228
+ func ipCommand (ctx context.Context , args ... string ) error {
229
+ out , err := exec .CommandContext (ctx , "ip" , args ... ).CombinedOutput ()
230
+ if err != nil {
231
+ s := strings .Trim (string (out ), "\n " )
232
+ return fmt .Errorf ("failed to execute ip %s: %s: %w" , strings .Join (args , " " ), s , err )
229
233
}
234
+ return nil
235
+ }
230
236
231
- if err := exec .CommandContext (ctx , "ip" , "tuntap" , "del" , tapName , "mode" , "tap" ).Run (); err != nil {
237
+ func deleteTapDevice (ctx context.Context , tapName string ) error {
238
+ if err := ipCommand (ctx , "link" , "delete" , tapName ); err != nil {
232
239
return err
233
240
}
234
-
235
- return nil
241
+ return ipCommand (ctx , "tuntap" , "del" , tapName , "mode" , "tap" )
236
242
}
237
243
238
244
func createTapDevice (ctx context.Context , tapName string ) error {
239
- err := exec .CommandContext (ctx , "ip" , "tuntap" , "add" , tapName , "mode" , "tap" ).Run ()
240
- if err != nil {
241
- return errors .Wrapf (err , "failed to create tap device %s" , tapName )
242
- }
243
-
244
- err = exec .CommandContext (ctx , "ip" , "link" , "set" , tapName , "up" ).Run ()
245
- if err != nil {
246
- return errors .Wrapf (err , "failed to up tap device %s" , tapName )
245
+ if err := ipCommand (ctx , "tuntap" , "add" , tapName , "mode" , "tap" ); err != nil {
246
+ return err
247
247
}
248
-
249
- return nil
248
+ return ipCommand (ctx , "link" , "set" , tapName , "up" )
250
249
}
251
250
252
251
func TestMultipleVMs_Isolated (t * testing.T ) {
@@ -263,6 +262,8 @@ func TestMultipleVMs_Isolated(t *testing.T) {
263
262
}
264
263
t .Logf ("TestMultipleVMs_Isolated: will run %d vm's" , numberOfVms )
265
264
265
+ tapPrefix := os .Getenv (tapPrefixEnvName )
266
+
266
267
cases := []struct {
267
268
MaxContainers int32
268
269
JailerConfig * proto.JailerConfig
@@ -319,7 +320,7 @@ func TestMultipleVMs_Isolated(t *testing.T) {
319
320
containerCount := c .MaxContainers
320
321
jailerConfig := c .JailerConfig
321
322
322
- tapName := fmt .Sprintf ("tap%d" , vmID )
323
+ tapName := fmt .Sprintf ("%stap%d" , tapPrefix , vmID )
323
324
err := createTapDevice (ctx , tapName )
324
325
if err != nil {
325
326
return err
0 commit comments