Skip to content

Commit c810db3

Browse files
committed
Altered buildVMConfiguration tests
Signed-off-by: Plamen Petrov <[email protected]>
1 parent 58dcb44 commit c810db3

File tree

5 files changed

+38
-24
lines changed

5 files changed

+38
-24
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ require (
4949
go.etcd.io/bbolt v1.3.1-etcd.8 // indirect
5050
golang.org/x/sync v0.0.0-20190423024810-112230192c58
5151
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd
52+
golang.org/x/tools v0.0.0-20200710042808-f1c4188a97a1 // indirect
5253
google.golang.org/genproto v0.0.0-20181109154231-b5d43981345b // indirect
5354
google.golang.org/grpc v1.21.0
5455
gotest.tools v2.2.0+incompatible // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ golang.org/x/lint v0.0.0-20200302205851-738671d3881b h1:Wh+f8QHJXR411sJR8/vRBTZ7
366366
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
367367
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
368368
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
369+
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
369370
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
370371
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
371372
golang.org/x/net v0.0.0-20180926154720-4dfa2610cdf3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -443,8 +444,11 @@ golang.org/x/tools v0.0.0-20200615222825-6aa8f57aacd9 h1:cwgUY+1ja2qxWb2dyaCoixa
443444
golang.org/x/tools v0.0.0-20200615222825-6aa8f57aacd9/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
444445
golang.org/x/tools v0.0.0-20200708183856-df98bc6d456c h1:Jt8nybBNSGn80qEV8fQLwCam6RQeX4dsxit8if67Sfc=
445446
golang.org/x/tools v0.0.0-20200708183856-df98bc6d456c/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
447+
golang.org/x/tools v0.0.0-20200710042808-f1c4188a97a1 h1:rD1FcWVsRaMY+l8biE9jbWP5MS/CJJ/90a9TMkMgNrM=
448+
golang.org/x/tools v0.0.0-20200710042808-f1c4188a97a1/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
446449
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
447450
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
451+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
448452
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
449453
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
450454
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 {
@@ -1518,6 +1520,8 @@ func (s *service) cleanup() error {
15181520
}
15191521

15201522
// monitorVMExit watches the VM and cleanup resources when it terminates.
1523+
// Comment out because unused
1524+
/*
15211525
func (s *service) monitorVMExit() {
15221526
// Block until the VM exits
15231527
if err := s.machine.Wait(s.shimCtx); err != nil && err != context.Canceled {
@@ -1528,6 +1532,7 @@ func (s *service) monitorVMExit() {
15281532
s.logger.WithError(err).Error("failed to clean up the VM")
15291533
}
15301534
}
1535+
*/
15311536

15321537
func (s *service) createHTTPControlClient() {
15331538
u := &httpunix.Transport{
@@ -1642,20 +1647,20 @@ func formCreateSnapReq(snapshotPath, memPath string) (*http.Request, error) {
16421647
return req, nil
16431648
}
16441649

1645-
func formPatchDriveReq(drive_id, path_on_host string) (*http.Request, error) {
1650+
func formPatchDriveReq(driveID, pathOnHost string) (*http.Request, error) {
16461651
var req *http.Request
16471652

16481653
data := map[string]string{
1649-
"drive_id": drive_id,
1650-
"path_on_host": path_on_host,
1654+
"drive_id": driveID,
1655+
"path_on_host": pathOnHost,
16511656
}
16521657
json, err := json.Marshal(data)
16531658
if err != nil {
16541659
logrus.WithError(err).Error("Failed to marshal json data")
16551660
return nil, err
16561661
}
16571662

1658-
req, err = http.NewRequest("PATCH", fmt.Sprintf("http+unix://firecracker/drives/%s", drive_id), bytes.NewBuffer(json))
1663+
req, err = http.NewRequest("PATCH", fmt.Sprintf("http+unix://firecracker/drives/%s", driveID), bytes.NewBuffer(json))
16591664
if err != nil {
16601665
logrus.WithError(err).Error("Failed to create new HTTP request in formPauseReq")
16611666
return nil, err
@@ -1674,14 +1679,13 @@ func (s *service) startFirecrackerProcess() error {
16741679
return err
16751680
}
16761681

1677-
16781682
// TODO: Remove hardcoding and make a parameter
16791683
logFilePath := fmt.Sprintf("/tmp/log_%s_after.logs", s.vmID)
16801684
if err := os.RemoveAll(logFilePath); err != nil {
16811685
s.logger.WithError(err).Errorf("Failed to delete %s", logFilePath)
16821686
return err
16831687
}
1684-
if _, err := os.OpenFile(logFilePath, os.O_RDONLY|os.O_CREATE, 0666); err != nil {
1688+
if _, err := os.OpenFile(logFilePath, os.O_RDONLY|os.O_CREATE, 0600); err != nil {
16851689
s.logger.WithError(err).Errorf("Failed to create %s", logFilePath)
16861690
return err
16871691
}
@@ -1706,4 +1710,4 @@ func (s *service) startFirecrackerProcess() error {
17061710
s.firecrackerPid = firecrackerCmd.Process.Pid
17071711

17081712
return nil
1709-
}
1713+
}

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)