Skip to content

Commit 6af679b

Browse files
committed
Adding requirements to support ARM instance
- If arch is ARM, SendCtrlAltDel is not supported and Skip testPing Signed-off-by: Vaishnavi Vejella <[email protected]>
1 parent 7af7903 commit 6af679b

File tree

6 files changed

+67
-50
lines changed

6 files changed

+67
-50
lines changed

.hack/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ go 1.11
1212
require (
1313
github.com/awslabs/tc-redirect-tap v0.0.0-20220715050423-f2af44521093 // indirect
1414
github.com/containernetworking/plugins v1.1.1 // indirect
15+
github.com/kunalkushwaha/ltag v0.2.3 // indirect
1516
)

.hack/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,8 @@ github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfn
393393
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
394394
github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA=
395395
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
396+
github.com/kunalkushwaha/ltag v0.2.3 h1:5rwJiC1oQ/OiamZ8JNCHQGUe7OkHTFrRtyNon3VYPok=
397+
github.com/kunalkushwaha/ltag v0.2.3/go.mod h1:w1hVMWOh870f+WAv/UIoZAy0bHCbPP4+W6JxNcPUiQA=
396398
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
397399
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
398400
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ DISABLE_ROOT_TESTS?=1
1717
DOCKER_IMAGE_TAG?=latest
1818
EXTRAGOARGS:=
1919
FIRECRACKER_DIR=build/firecracker
20-
FIRECRACKER_TARGET?=x86_64-unknown-linux-musl
20+
arch=$(shell uname -m)
21+
FIRECRACKER_TARGET?=$(arch)-unknown-linux-musl
2122

2223
FC_TEST_DATA_PATH?=testdata
2324
FC_TEST_BIN_PATH:=$(FC_TEST_DATA_PATH)/bin
@@ -28,7 +29,6 @@ UID = $(shell id -u)
2829
GID = $(shell id -g)
2930

3031
firecracker_version=v1.0.0
31-
arch=$(shell uname -m)
3232

3333
# The below files are needed and can be downloaded from the internet
3434
release_url=https://github.com/firecracker-microvm/firecracker/releases/download/$(firecracker_version)/firecracker-$(firecracker_version)-$(arch).tgz

machine.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"os/exec"
2525
"os/signal"
2626
"path/filepath"
27+
"runtime"
2728
"strconv"
2829
"strings"
2930
"sync"
@@ -65,6 +66,9 @@ type SeccompConfig struct {
6566
// be started again.
6667
var ErrAlreadyStarted = errors.New("firecracker: machine already started")
6768

69+
// ErrGraceShutdown signifies that the Machine will shutdown gracefully and SendCtrlAltDelete is unable to send
70+
var ErrGraceShutdown = errors.New("Shutdown gracefully: SendCtrlAltDelete is not supported if the arch is ARM64")
71+
6872
type MMDSVersion string
6973

7074
const (
@@ -456,7 +460,10 @@ func (m *Machine) Start(ctx context.Context) error {
456460
// Shutdown requests a clean shutdown of the VM by sending CtrlAltDelete on the virtual keyboard
457461
func (m *Machine) Shutdown(ctx context.Context) error {
458462
m.logger.Debug("Called machine.Shutdown()")
459-
return m.sendCtrlAltDel(ctx)
463+
if runtime.GOARCH != "arm64" {
464+
return m.sendCtrlAltDel(ctx)
465+
}
466+
return ErrGraceShutdown
460467
}
461468

462469
// Wait will wait until the firecracker process has finished. Wait is safe to

machine_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"os/signal"
2828
"path/filepath"
2929
"regexp"
30+
"runtime"
3031
"strconv"
3132
"strings"
3233
"sync"
@@ -865,8 +866,10 @@ func TestStopVMMCleanup(t *testing.T) {
865866

866867
func testShutdown(ctx context.Context, t *testing.T, m *Machine) {
867868
err := m.Shutdown(ctx)
868-
if err != nil {
869-
t.Errorf("machine.Shutdown() failed: %s", err)
869+
if runtime.GOARCH == "arm64" {
870+
assert.ErrorIs(t, err, ErrGraceShutdown)
871+
} else {
872+
assert.NoError(t, err, "machine.Shutdown() failed")
870873
}
871874
}
872875

network_test.go

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"net"
2121
"os"
2222
"path/filepath"
23+
"runtime"
2324
"sync"
2425
"testing"
2526
"time"
@@ -253,7 +254,7 @@ func testNetworkMachineCNI(t *testing.T, useConfFile bool) {
253254
}
254255
fctesting.RequiresRoot(t)
255256

256-
cniBinPath := []string{"/opt/cni/bin", testDataBin}
257+
cniBinPath := []string{testDataBin, "/opt/cni/bin"}
257258

258259
dir, err := ioutil.TempDir("", fsSafeTestName.Replace(t.Name()))
259260
require.NoError(t, err)
@@ -312,63 +313,67 @@ func testNetworkMachineCNI(t *testing.T, useConfFile bool) {
312313
require.NoError(t, err, "cni conf should parse")
313314
}
314315

315-
numVMs := 10
316-
vmIPs := make(chan string, numVMs)
316+
if runtime.GOARCH == "arm64" {
317+
t.Skip()
318+
} else {
319+
numVMs := 10
320+
vmIPs := make(chan string, numVMs)
317321

318-
// used as part of the VMIDs to make sure different test suites don't use the same CNI ContainerID (which can reak havok)
319-
timestamp := time.Now().UnixNano()
322+
// used as part of the VMIDs to make sure different test suites don't use the same CNI ContainerID (which can reak havok)
323+
timestamp := time.Now().UnixNano()
320324

321-
var vmWg sync.WaitGroup
322-
for i := 0; i < numVMs; i++ {
323-
vmWg.Add(1)
325+
var vmWg sync.WaitGroup
326+
for i := 0; i < numVMs; i++ {
327+
vmWg.Add(1)
324328

325-
vmID := fmt.Sprintf("%d-%s-%d", timestamp, networkName, i)
329+
vmID := fmt.Sprintf("%d-%s-%d", timestamp, networkName, i)
326330

327-
firecrackerSockPath := filepath.Join(testCNIDir, fmt.Sprintf("%s.sock", vmID))
328-
rootfsPath := filepath.Join(testCNIDir, fmt.Sprintf("%s.img", vmID))
331+
firecrackerSockPath := filepath.Join(testCNIDir, fmt.Sprintf("%s.sock", vmID))
332+
rootfsPath := filepath.Join(testCNIDir, fmt.Sprintf("%s.img", vmID))
329333

330-
ctx, cancel := context.WithCancel(context.Background())
331-
// NewMachine cannot be in the goroutine below, since go-openapi/runtime has a globally-shared mutable logger...
332-
// https://github.com/go-openapi/runtime/blob/553c9d1fb273d9550562d9f76949a413af265138/client/runtime.go#L463
333-
m := newCNIMachine(t, ctx, firecrackerSockPath, rootfsPath, cniConfDir, cniCacheDir, networkName, ifName, vmID, cniBinPath, networkConf)
334+
ctx, cancel := context.WithCancel(context.Background())
335+
// NewMachine cannot be in the goroutine below, since go-openapi/runtime has a globally-shared mutable logger...
336+
// https://github.com/go-openapi/runtime/blob/553c9d1fb273d9550562d9f76949a413af265138/client/runtime.go#L463
337+
m := newCNIMachine(t, ctx, firecrackerSockPath, rootfsPath, cniConfDir, cniCacheDir, networkName, ifName, vmID, cniBinPath, networkConf)
334338

335-
go func(ctx context.Context, cancel func(), m *Machine, vmID string) {
336-
defer vmWg.Done()
337-
defer cancel()
339+
go func(ctx context.Context, cancel func(), m *Machine, vmID string) {
340+
defer vmWg.Done()
341+
defer cancel()
338342

339-
expectedCacheDirPath := filepath.Join(cniCacheDir, "results",
340-
fmt.Sprintf("%s-%s-%s", networkName, vmID, ifName))
343+
expectedCacheDirPath := filepath.Join(cniCacheDir, "results",
344+
fmt.Sprintf("%s-%s-%s", networkName, vmID, ifName))
341345

342-
vmIP := startCNIMachine(t, ctx, m)
343-
vmIPs <- vmIP
346+
vmIP := startCNIMachine(t, ctx, m)
347+
vmIPs <- vmIP
344348

345-
assert.FileExists(t, expectedCacheDirPath, "CNI cache dir doesn't exist after vm startup")
349+
assert.FileExists(t, expectedCacheDirPath, "CNI cache dir doesn't exist after vm startup")
346350

347-
testPing(t, vmIP, 3, 5*time.Second)
351+
testPing(t, vmIP, 3, 5*time.Second)
348352

349-
require.NoError(t, m.StopVMM(), "failed to stop machine")
350-
waitCtx, waitCancel := context.WithTimeout(ctx, 3*time.Second)
353+
require.NoError(t, m.StopVMM(), "failed to stop machine")
354+
waitCtx, waitCancel := context.WithTimeout(ctx, 3*time.Second)
351355

352-
// Having an error is fine, since StopVM() kills a Firecracker process.
353-
// Shutdown() uses SendCtrAltDel action, which doesn't work with the kernel we are using here.
354-
// https://github.com/firecracker-microvm/firecracker/issues/1095
355-
assert.NotEqual(t, m.Wait(waitCtx), context.DeadlineExceeded, "failed waiting for machine stop")
356-
waitCancel()
356+
// Having an error is fine, since StopVM() kills a Firecracker process.
357+
// Shutdown() uses SendCtrAltDel action, which doesn't work with the kernel we are using here.
358+
// https://github.com/firecracker-microvm/firecracker/issues/1095
359+
assert.NotEqual(t, m.Wait(waitCtx), context.DeadlineExceeded, "failed waiting for machine stop")
360+
waitCancel()
357361

358-
_, err := os.Stat(expectedCacheDirPath)
359-
assert.True(t, os.IsNotExist(err), "expected CNI cache dir to not exist after vm exit")
362+
_, err := os.Stat(expectedCacheDirPath)
363+
assert.True(t, os.IsNotExist(err), "expected CNI cache dir to not exist after vm exit")
360364

361-
}(ctx, cancel, m, vmID)
362-
}
363-
vmWg.Wait()
364-
close(vmIPs)
365-
366-
vmIPSet := make(map[string]bool)
367-
for vmIP := range vmIPs {
368-
if _, ok := vmIPSet[vmIP]; ok {
369-
assert.Failf(t, "unexpected duplicate vm IP %s", vmIP)
370-
} else {
371-
vmIPSet[vmIP] = true
365+
}(ctx, cancel, m, vmID)
366+
}
367+
vmWg.Wait()
368+
close(vmIPs)
369+
370+
vmIPSet := make(map[string]bool)
371+
for vmIP := range vmIPs {
372+
if _, ok := vmIPSet[vmIP]; ok {
373+
assert.Failf(t, "unexpected duplicate vm IP %s", vmIP)
374+
} else {
375+
vmIPSet[vmIP] = true
376+
}
372377
}
373378
}
374379
}
@@ -405,7 +410,6 @@ func newCNIMachine(t *testing.T,
405410
MachineCfg: models.MachineConfiguration{
406411
VcpuCount: Int64(2),
407412
MemSizeMib: Int64(256),
408-
Smt: Bool(true),
409413
},
410414
Drives: []models.Drive{
411415
{

0 commit comments

Comments
 (0)