From 3d46d08a902297a211c7dd202b8f13d56d71052d Mon Sep 17 00:00:00 2001 From: David Gibson Date: Thu, 3 Sep 2020 14:02:44 +1000 Subject: [PATCH] Add qom-get function Add a function to access the qom-get QMP command so we can query information from qemu. Signed-off-by: David Gibson --- qemu/qmp.go | 15 +++++++++++++++ qemu/qmp_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/qemu/qmp.go b/qemu/qmp.go index 4942727c42..fc3f1e3f3a 100644 --- a/qemu/qmp.go +++ b/qemu/qmp.go @@ -1639,3 +1639,18 @@ func (q *QMP) ExecQomSet(ctx context.Context, path, property string, value uint6 return q.executeCommand(ctx, "qom-set", args, nil) } + +// ExecQomGet qom-get path property +func (q *QMP) ExecQomGet(ctx context.Context, path, property string) (interface{}, error) { + args := map[string]interface{}{ + "path": path, + "property": property, + } + + response, err := q.executeCommandWithResponse(ctx, "qom-get", args, nil, nil) + if err != nil { + return "", err + } + + return response, nil +} diff --git a/qemu/qmp_test.go b/qemu/qmp_test.go index 81cb399de4..14bfd24921 100644 --- a/qemu/qmp_test.go +++ b/qemu/qmp_test.go @@ -1770,3 +1770,27 @@ func TestExecQomSet(t *testing.T) { q.Shutdown() <-disconnectedCh } + +// Checks qom-get +func TestExecQomGet(t *testing.T) { + connectedCh := make(chan *QMPVersion) + disconnectedCh := make(chan struct{}) + buf := newQMPTestCommandBuffer(t) + buf.AddCommand("qom-get", nil, "return", "container") + cfg := QMPConfig{Logger: qmpTestLogger{}} + q := startQMPLoop(buf, cfg, connectedCh, disconnectedCh) + checkVersion(t, connectedCh) + val, err := q.ExecQomGet(context.Background(), "/", "type") + if err != nil { + t.Fatalf("Unexpected error: %v", err) + } + vals, ok := val.(string) + if !ok { + t.Fatalf("Unexpected type in qom-get") + } + if vals != "container" { + t.Fatalf("Unpexected value in qom-get") + } + q.Shutdown() + <-disconnectedCh +}