Skip to content

Commit

Permalink
grpc: Add GetAgentDetails gRPC function
Browse files Browse the repository at this point in the history
Add a new `GetAgentDetails()` gRPC API that will return details about
the agent to the caller. This is similar to the information the agent
logs in its "announce" log message at startup.

Partially fixes kata-containers#381.

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

func (a *agentGRPC) GetAgentDetails(ctx context.Context, req *pb.AgentDetailsRequest) (*pb.AgentDetailsResponse, error) {
details := &pb.AgentDetailsResponse{
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, nil
}
44 changes: 42 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 @@ -645,3 +647,41 @@ func TestGetGuestDetails(t *testing.T) {

assert.Equal(resp.MemBlockSizeBytes, size)
}

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

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

req := &pb.AgentDetailsRequest{}

resp, err := a.GetAgentDetails(context.TODO(), req)
assert.NoError(err)

assert.Equal(resp.Version, version)
assert.Equal(resp.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(resp.DeviceHandlers))
sort.Sort(sort.StringSlice(resp.StorageHandlers))

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

assert.Equal(resp.DeviceHandlers, devices)
assert.Equal(resp.StorageHandlers, storages)
}
Loading

0 comments on commit 14a642f

Please sign in to comment.