Skip to content

Commit 3de37ab

Browse files
authored
Merge pull request #583 from kzys/fix-tap-al2
Fix tap-related test failures
2 parents b0a91e8 + 6cc5c69 commit 3de37ab

File tree

4 files changed

+52
-22
lines changed

4 files changed

+52
-22
lines changed

.buildkite/al2_test.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ sudo -E PATH=$PATH \
1818
containerd_pid=$!
1919

2020
sudo $bin_path/firecracker-ctr --address $dir/containerd.sock content fetch docker.io/library/alpine:3.10.1
21-
sudo -E PATH=$bin_path:$PATH /usr/local/bin/go test -count=1 -run TestMultipleVMs_Isolated ./... -v
21+
22+
TAP_PREFIX=build$BUILDKITE_BUILD_NUMBER \
23+
sudo -E PATH=$bin_path:$PATH /usr/local/bin/go test -count=1 -run TestMultipleVMs_Isolated ./... -v
2224

2325
sudo kill $containerd_pid

internal/vm/vsock.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,9 @@ func (e vsockAckError) Temporary() bool {
314314
// error, according to the interface defined here:
315315
// https://golang.org/pkg/net/#Error
316316
func isTemporaryNetErr(err error) bool {
317-
terr, ok := err.(interface {
317+
type tempError interface {
318318
Temporary() bool
319-
})
320-
321-
return err != nil && ok && terr.Temporary()
319+
}
320+
var terr tempError
321+
return err != nil && errors.As(err, &terr) && terr.Temporary()
322322
}

internal/vm/vsock_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
// not use this file except in compliance with the License. A copy of the
5+
// License is located at
6+
//
7+
// http://aws.amazon.com/apache2.0/
8+
//
9+
// or in the "license" file accompanying this file. This file is distributed
10+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
// express or implied. See the License for the specific language governing
12+
// permissions and limitations under the License.
13+
14+
package vm
15+
16+
import (
17+
"errors"
18+
"testing"
19+
20+
"github.com/stretchr/testify/assert"
21+
)
22+
23+
func TestTemporaryNetErr(t *testing.T) {
24+
assert.False(t, isTemporaryNetErr(nil))
25+
assert.False(t, isTemporaryNetErr(errors.New("hello")))
26+
assert.True(t, isTemporaryNetErr(&vsockAckError{cause: errors.New("hello")}))
27+
}

runtime/service_integ_test.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ const (
7171
numberOfVmsEnvName = "NUMBER_OF_VMS"
7272
defaultNumberOfVms = 5
7373

74+
tapPrefixEnvName = "TAP_PREFIX"
75+
7476
defaultBalloonMemory = int64(66)
7577
defaultStatsPollingIntervals = int64(1)
7678

@@ -223,30 +225,27 @@ func vmIDtoMacAddr(vmID uint) string {
223225
return strings.Join(addrParts, ":")
224226
}
225227

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)
229233
}
234+
return nil
235+
}
230236

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 {
232239
return err
233240
}
234-
235-
return nil
241+
return ipCommand(ctx, "tuntap", "del", tapName, "mode", "tap")
236242
}
237243

238244
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
247247
}
248-
249-
return nil
248+
return ipCommand(ctx, "link", "set", tapName, "up")
250249
}
251250

252251
func TestMultipleVMs_Isolated(t *testing.T) {
@@ -263,6 +262,8 @@ func TestMultipleVMs_Isolated(t *testing.T) {
263262
}
264263
t.Logf("TestMultipleVMs_Isolated: will run %d vm's", numberOfVms)
265264

265+
tapPrefix := os.Getenv(tapPrefixEnvName)
266+
266267
cases := []struct {
267268
MaxContainers int32
268269
JailerConfig *proto.JailerConfig
@@ -319,7 +320,7 @@ func TestMultipleVMs_Isolated(t *testing.T) {
319320
containerCount := c.MaxContainers
320321
jailerConfig := c.JailerConfig
321322

322-
tapName := fmt.Sprintf("tap%d", vmID)
323+
tapName := fmt.Sprintf("%stap%d", tapPrefix, vmID)
323324
err := createTapDevice(ctx, tapName)
324325
if err != nil {
325326
return err

0 commit comments

Comments
 (0)