Skip to content

Commit 67aece3

Browse files
plamenmpetrovustiugov
authored andcommitted
Altered buildVMConfiguration tests
Signed-off-by: Plamen Petrov <[email protected]>
1 parent 58f5b45 commit 67aece3

File tree

5 files changed

+38
-25
lines changed

5 files changed

+38
-25
lines changed

firecracker-control/local.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,4 +555,3 @@ func (s *local) Offload(ctx context.Context, req *proto.OffloadRequest) (*empty.
555555

556556
return resp, nil
557557
}
558-

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ require (
5050
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
5151
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208
5252
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd
53-
golang.org/x/tools v0.0.0-20200708183856-df98bc6d456c // indirect
53+
golang.org/x/tools v0.0.0-20200710042808-f1c4188a97a1 // indirect
5454
google.golang.org/genproto v0.0.0-20181109154231-b5d43981345b // indirect
5555
google.golang.org/grpc v1.21.0
5656
gotest.tools v2.2.0+incompatible // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ golang.org/x/lint v0.0.0-20200302205851-738671d3881b h1:Wh+f8QHJXR411sJR8/vRBTZ7
300300
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
301301
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
302302
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
303+
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
303304
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
304305
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
305306
golang.org/x/net v0.0.0-20180926154720-4dfa2610cdf3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -370,8 +371,11 @@ golang.org/x/tools v0.0.0-20200615222825-6aa8f57aacd9 h1:cwgUY+1ja2qxWb2dyaCoixa
370371
golang.org/x/tools v0.0.0-20200615222825-6aa8f57aacd9/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
371372
golang.org/x/tools v0.0.0-20200708183856-df98bc6d456c h1:Jt8nybBNSGn80qEV8fQLwCam6RQeX4dsxit8if67Sfc=
372373
golang.org/x/tools v0.0.0-20200708183856-df98bc6d456c/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
374+
golang.org/x/tools v0.0.0-20200710042808-f1c4188a97a1 h1:rD1FcWVsRaMY+l8biE9jbWP5MS/CJJ/90a9TMkMgNrM=
375+
golang.org/x/tools v0.0.0-20200710042808-f1c4188a97a1/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
373376
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
374377
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
378+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
375379
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
376380
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
377381
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=

runtime/service.go

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ import (
2222
"net"
2323
"net/http"
2424
"os"
25+
"os/exec"
2526
"runtime/debug"
2627
"strconv"
2728
"strings"
2829
"sync"
29-
"time"
30-
"os/exec"
3130
"syscall"
31+
"time"
3232

3333
// disable gosec check for math/rand. We just need a random starting
3434
// place to start looking for CIDs; no need for cryptographically
@@ -152,8 +152,8 @@ type service struct {
152152
vsockPortMu sync.Mutex
153153

154154
// httpControlClient is to send pause/resume/snapshot commands to the microVM
155-
httpControlClient *http.Client
156-
firecrackerPid int
155+
httpControlClient *http.Client
156+
firecrackerPid int
157157
taskDrivePathOnHost string
158158
}
159159

@@ -489,7 +489,7 @@ func (s *service) CreateVM(requestCtx context.Context, request *proto.CreateVMRe
489489
s.logger.WithError(err).Error("failed to publish start VM event")
490490
}
491491

492-
// Commented out because its execution cancels the shim, and
492+
// Commented out because its execution cancels the shim, and
493493
// it would get executed on Offload if we leave it, killing the shim,
494494
// and making snapshots impossible.
495495
//go s.monitorVMExit()
@@ -595,12 +595,14 @@ func (s *service) createVM(requestCtx context.Context, request *proto.CreateVMRe
595595

596596
s.createHTTPControlClient()
597597

598-
if pid, err := s.machine.PID(); err != nil {
598+
pid, err := s.machine.PID()
599+
if err != nil {
599600
s.logger.WithError(err).Error("Failed to get PID of firecracker process")
600601
return err
601-
} else {
602-
s.firecrackerPid = pid
603602
}
603+
604+
s.firecrackerPid = pid
605+
604606
s.logger.Info("successfully started the VM")
605607

606608
return nil
@@ -782,7 +784,7 @@ func (s *service) ResumeVM(ctx context.Context, req *proto.ResumeVMRequest) (*em
782784

783785
// LoadSnapshot Loads a VM from a snapshot
784786
func (s *service) LoadSnapshot(ctx context.Context, req *proto.LoadSnapshotRequest) (*empty.Empty, error) {
785-
if err := s.startFirecrackerProcess() ; err != nil {
787+
if err := s.startFirecrackerProcess(); err != nil {
786788
s.logger.WithError(err).Error("startFirecrackerProcess returned an error")
787789
return nil, err
788790
}
@@ -894,7 +896,7 @@ func (s *service) buildVMConfiguration(req *proto.CreateVMRequest) (*firecracker
894896
s.logger.WithError(err).Errorf("Failed to delete %s", logFilePath)
895897
return nil, err
896898
}
897-
if _, err := os.OpenFile(logFilePath, os.O_RDONLY|os.O_CREATE, 0666); err != nil {
899+
if _, err := os.OpenFile(logFilePath, os.O_RDONLY|os.O_CREATE, 0600); err != nil {
898900
s.logger.WithError(err).Errorf("Failed to create %s", logFilePath)
899901
return nil, err
900902
}
@@ -906,10 +908,10 @@ func (s *service) buildVMConfiguration(req *proto.CreateVMRequest) (*firecracker
906908
ID: "agent_api",
907909
}},
908910
// Put LogPath insteadof LogFifo here to comply with the new Firecracker logging
909-
LogPath: logFilePath,
910-
MachineCfg: machineConfigurationFromProto(s.config, req.MachineCfg),
911-
LogLevel: s.config.DebugHelper.GetFirecrackerLogLevel(),
912-
VMID: s.vmID,
911+
LogPath: logFilePath,
912+
MachineCfg: machineConfigurationFromProto(s.config, req.MachineCfg),
913+
LogLevel: s.config.DebugHelper.GetFirecrackerLogLevel(),
914+
VMID: s.vmID,
913915
}
914916

915917
if req.JailerConfig != nil {
@@ -1511,6 +1513,8 @@ func (s *service) cleanup() error {
15111513
}
15121514

15131515
// monitorVMExit watches the VM and cleanup resources when it terminates.
1516+
// Comment out because unused
1517+
/*
15141518
func (s *service) monitorVMExit() {
15151519
// Block until the VM exits
15161520
if err := s.machine.Wait(s.shimCtx); err != nil && err != context.Canceled {
@@ -1521,6 +1525,7 @@ func (s *service) monitorVMExit() {
15211525
s.logger.WithError(err).Error("failed to clean up the VM")
15221526
}
15231527
}
1528+
*/
15241529

15251530
func (s *service) createHTTPControlClient() {
15261531
u := &httpunix.Transport{
@@ -1635,20 +1640,20 @@ func formCreateSnapReq(snapshotPath, memPath string) (*http.Request, error) {
16351640
return req, nil
16361641
}
16371642

1638-
func formPatchDriveReq(drive_id, path_on_host string) (*http.Request, error) {
1643+
func formPatchDriveReq(driveID, pathOnHost string) (*http.Request, error) {
16391644
var req *http.Request
16401645

16411646
data := map[string]string{
1642-
"drive_id": drive_id,
1643-
"path_on_host": path_on_host,
1647+
"drive_id": driveID,
1648+
"path_on_host": pathOnHost,
16441649
}
16451650
json, err := json.Marshal(data)
16461651
if err != nil {
16471652
logrus.WithError(err).Error("Failed to marshal json data")
16481653
return nil, err
16491654
}
16501655

1651-
req, err = http.NewRequest("PATCH", fmt.Sprintf("http+unix://firecracker/drives/%s", drive_id), bytes.NewBuffer(json))
1656+
req, err = http.NewRequest("PATCH", fmt.Sprintf("http+unix://firecracker/drives/%s", driveID), bytes.NewBuffer(json))
16521657
if err != nil {
16531658
logrus.WithError(err).Error("Failed to create new HTTP request in formPauseReq")
16541659
return nil, err
@@ -1667,14 +1672,13 @@ func (s *service) startFirecrackerProcess() error {
16671672
return err
16681673
}
16691674

1670-
16711675
// TODO: Remove hardcoding and make a parameter
16721676
logFilePath := fmt.Sprintf("/tmp/log_%s_after.logs", s.vmID)
16731677
if err := os.RemoveAll(logFilePath); err != nil {
16741678
s.logger.WithError(err).Errorf("Failed to delete %s", logFilePath)
16751679
return err
16761680
}
1677-
if _, err := os.OpenFile(logFilePath, os.O_RDONLY|os.O_CREATE, 0666); err != nil {
1681+
if _, err := os.OpenFile(logFilePath, os.O_RDONLY|os.O_CREATE, 0600); err != nil {
16781682
s.logger.WithError(err).Errorf("Failed to create %s", logFilePath)
16791683
return err
16801684
}
@@ -1699,4 +1703,4 @@ func (s *service) startFirecrackerProcess() error {
16991703
s.firecrackerPid = firecrackerCmd.Process.Pid
17001704

17011705
return nil
1702-
}
1706+
}

runtime/service_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,14 @@ func TestBuildVMConfiguration(t *testing.T) {
253253
Path: relVSockPath,
254254
ID: "agent_api",
255255
}}
256-
tc.expectedCfg.LogFifo = svc.shimDir.FirecrackerLogFifoPath()
257-
tc.expectedCfg.MetricsFifo = svc.shimDir.FirecrackerMetricsFifoPath()
256+
257+
// Remove LogFifo and MetricsInfo in order to comply
258+
// with new Firecracker logging.
259+
// Include hard coded LogPath
260+
// TODO: FIX TEST WHEN LogPath is no longer hardcoded
261+
//tc.expectedCfg.LogFifo = svc.shimDir.FirecrackerLogFifoPath()
262+
//tc.expectedCfg.MetricsFifo = svc.shimDir.FirecrackerMetricsFifoPath()
263+
tc.expectedCfg.LogPath = "/tmp/log__start.logs"
258264

259265
drives := make([]models.Drive, tc.expectedStubDriveCount)
260266
for i := 0; i < tc.expectedStubDriveCount; i++ {

0 commit comments

Comments
 (0)