Skip to content

Commit

Permalink
grpc: Add agent details to guest details call
Browse files Browse the repository at this point in the history
Create a new `AgentDetails` message and return it inside the message
returned by `GetGuestDetails()`. The agent details provided are similar
to those logged by the agent at startup in it's "announce" message.

Partially fixes kata-containers#381.

Signed-off-by: James O. D. Hunt <[email protected]>
  • Loading branch information
jodh-intel committed Sep 26, 2018
1 parent 78396bd commit 7b71c10
Show file tree
Hide file tree
Showing 4 changed files with 597 additions and 163 deletions.
20 changes: 20 additions & 0 deletions grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1328,5 +1328,25 @@ func (a *agentGRPC) GetGuestDetails(ctx context.Context, req *pb.GuestDetailsReq
return nil, err
}
}

details.AgentDetails = a.getAgentDetails(ctx)

return &details, nil
}

func (a *agentGRPC) getAgentDetails(ctx context.Context) *pb.AgentDetails {
details := pb.AgentDetails{
Version: version,
InitDaemon: os.Getpid() == 1,
}

for handler := range deviceHandlerList {
details.DeviceHandlers = append(details.DeviceHandlers, handler)
}

for handler := range storageHandlerList {
details.StorageHandlers = append(details.StorageHandlers, handler)
}

return &details
}
48 changes: 46 additions & 2 deletions grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ import (
"os"
"path/filepath"
"reflect"
"sort"
"testing"
"time"

"strconv"
"sync"

pb "github.com/kata-containers/agent/protocols/grpc"
"github.com/opencontainers/runc/libcontainer"
"github.com/opencontainers/runc/libcontainer/configs"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/stretchr/testify/assert"
"strconv"
"sync"
)

var testSharedPidNs = "testSharedPidNs"
Expand Down Expand Up @@ -622,6 +624,33 @@ func TestMultiWaitProcess(t *testing.T) {
wg.Wait()
}

func testAgentDetails(assert *assert.Assertions, details *pb.AgentDetails) {
assert.NotNil(details)

assert.Equal(details.Version, version)
assert.Equal(details.InitDaemon, os.Getpid() == 1)

var devices []string
var storages []string

for handler := range deviceHandlerList {
devices = append(devices, handler)
}

for handler := range storageHandlerList {
storages = append(storages, handler)
}

sort.Sort(sort.StringSlice(details.DeviceHandlers))
sort.Sort(sort.StringSlice(details.StorageHandlers))

sort.Sort(sort.StringSlice(devices))
sort.Sort(sort.StringSlice(storages))

assert.Equal(details.DeviceHandlers, devices)
assert.Equal(details.StorageHandlers, storages)
}

func TestGetGuestDetails(t *testing.T) {
assert := assert.New(t)
a := &agentGRPC{
Expand All @@ -644,4 +673,19 @@ func TestGetGuestDetails(t *testing.T) {
assert.NoError(err)

assert.Equal(resp.MemBlockSizeBytes, size)
testAgentDetails(assert, resp.AgentDetails)
}

func TestGetAgentDetails(t *testing.T) {
assert := assert.New(t)

a := &agentGRPC{
sandbox: &sandbox{
containers: make(map[string]*container),
},
}

details := a.getAgentDetails(context.TODO())

testAgentDetails(assert, details)
}
Loading

0 comments on commit 7b71c10

Please sign in to comment.