From 0b1e3f5d7efd12eca7712db22df32a8bb23e77c8 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Wed, 3 Mar 2021 14:45:21 -0500 Subject: [PATCH] commands: port tracing helper type from cephfs/admin This debugging code can be made common. Signed-off-by: John Mulligan --- internal/commands/trace.go | 51 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 internal/commands/trace.go diff --git a/internal/commands/trace.go b/internal/commands/trace.go new file mode 100644 index 0000000..687249d --- /dev/null +++ b/internal/commands/trace.go @@ -0,0 +1,51 @@ +package commands + +import ( + "fmt" +) + +// NewTraceCommander is a RadosCommander that wraps a given RadosCommander +// and when commands are executes prints debug level "traces" to the +// standard output. +func NewTraceCommander(c RadosCommander) RadosCommander { + return &tracingCommander{c} +} + +// tracingCommander serves two purposes: first, it allows one to trace the +// input and output json when running the tests. It can help with actually +// debugging the tests. Second, it demonstrates the rationale for using an +// interface in FSAdmin. You can layer any sort of debugging, error injection, +// or whatnot between the FSAdmin layer and the RADOS layer. +type tracingCommander struct { + conn RadosCommander +} + +func (t *tracingCommander) MgrCommand(buf [][]byte) ([]byte, string, error) { + fmt.Println("(MGR Command)") + for i := range buf { + fmt.Println("IN:", string(buf[i])) + } + r, s, err := t.conn.MgrCommand(buf) + fmt.Println("OUT(result):", string(r)) + if s != "" { + fmt.Println("OUT(status):", s) + } + if err != nil { + fmt.Println("OUT(error):", err.Error()) + } + return r, s, err +} + +func (t *tracingCommander) MonCommand(buf []byte) ([]byte, string, error) { + fmt.Println("(MON Command)") + fmt.Println("IN:", string(buf)) + r, s, err := t.conn.MonCommand(buf) + fmt.Println("OUT(result):", string(r)) + if s != "" { + fmt.Println("OUT(status):", s) + } + if err != nil { + fmt.Println("OUT(error):", err.Error()) + } + return r, s, err +}