From 79ed0886c62fa96014a25af92733259b49ea6019 Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Tue, 5 Feb 2019 11:54:57 +0100 Subject: [PATCH] virtcontainers: Reduce hyperstart mock test noise We don't need that many logs, especially for the positive path. Fixes: #1211 Signed-off-by: Samuel Ortiz --- .../pkg/hyperstart/mock/hyperstart.go | 48 +------------------ 1 file changed, 2 insertions(+), 46 deletions(-) diff --git a/virtcontainers/pkg/hyperstart/mock/hyperstart.go b/virtcontainers/pkg/hyperstart/mock/hyperstart.go index 8714849a1c..086d394ecc 100644 --- a/virtcontainers/pkg/hyperstart/mock/hyperstart.go +++ b/virtcontainers/pkg/hyperstart/mock/hyperstart.go @@ -42,27 +42,6 @@ const ( SetupRoute = "setuproute" ) -var codeList = map[int]string{ - hyper.VersionCode: Version, - hyper.StartSandboxCode: StartSandbox, - hyper.DestroySandboxCode: DestroySandbox, - hyper.ExecCmdCode: ExecCmd, - hyper.ReadyCode: Ready, - hyper.AckCode: Ack, - hyper.ErrorCode: Error, - hyper.WinsizeCode: WinSize, - hyper.PingCode: Ping, - hyper.NextCode: Next, - hyper.WriteFileCode: WriteFile, - hyper.ReadFileCode: ReadFile, - hyper.NewContainerCode: NewContainer, - hyper.KillContainerCode: KillContainer, - hyper.OnlineCPUMemCode: OnlineCPUMem, - hyper.SetupInterfaceCode: SetupInterface, - hyper.SetupRouteCode: SetupRoute, - hyper.RemoveContainerCode: RemoveContainer, -} - // Hyperstart is an object mocking the hyperstart agent. type Hyperstart struct { t *testing.T @@ -119,10 +98,6 @@ func (h *Hyperstart) GetLastMessages() []hyper.DecodedMessage { return msgs } -func (h *Hyperstart) log(s string) { - h.logf("%s\n", s) -} - func (h *Hyperstart) logf(format string, args ...interface{}) { h.t.Logf("[hyperstart] "+format, args...) } @@ -214,24 +189,13 @@ func (h *Hyperstart) readMessage() (int, []byte, error) { return cmd, data, nil } -func cmdToString(cmd int) (string, error) { - _, ok := codeList[cmd] - if ok == false { - return "", fmt.Errorf("unknown command '%d'", cmd) - } - - return codeList[cmd], nil -} - func (h *Hyperstart) handleCtl() { for { cmd, data, err := h.readMessage() if err != nil { break } - cmdName, err := cmdToString(cmd) - assert.Nil(h.t, err) - h.logf("ctl: --> command %s, payload_len=%d\n", cmdName, len(data)) + if len(data) != 0 { h.logData(data) } @@ -244,8 +208,6 @@ func (h *Hyperstart) handleCtl() { // answer back with the message exit status // XXX: may be interesting to be able to configure the mock // hyperstart to fail and test the reaction of proxy/clients - h.logf("ctl: <-- command %s executed successfully\n", cmdName) - h.SendMessage(hyper.AckCode, nil) } @@ -274,8 +236,6 @@ func (h *Hyperstart) SendIo(seq uint64, data []byte) { length := ioHeaderSize + len(data) header := make([]byte, ioHeaderSize) - h.logf("io: <-- writing %d bytes for seq %d\n", len(data), seq) - binary.BigEndian.PutUint64(header[:], seq) binary.BigEndian.PutUint32(header[8:], uint32(length)) h.writeIo(header) @@ -329,15 +289,14 @@ func (h *Hyperstart) startListening(path string, cb acceptCb) *net.UnixListener assert.Nil(h.t, err) go func() { - h.logf("%s: waiting for connection\n", path) c, err := l.Accept() if err != nil { + h.logf("%s: Connection failed %s\n", path, err) cb(nil) return } cb(c) - h.logf("%s: accepted connection\n", path) }() return l @@ -346,7 +305,6 @@ func (h *Hyperstart) startListening(path string, cb acceptCb) *net.UnixListener // Start will // Once finished with the Hyperstart object, Close must be called. func (h *Hyperstart) Start() { - h.log("start") h.wgConnected.Add(1) h.wgConnected.Add(1) h.ctlListener = h.startListening(h.ctlSocketPath, func(s net.Conn) { @@ -394,6 +352,4 @@ func (h *Hyperstart) Stop() { os.Remove(h.ctlSocketPath) os.Remove(h.ioSocketPath) - - h.log("stopped") }