Commit 1736d934 authored by Alex Dadgar's avatar Alex Dadgar
Browse files

Review comments

parent cfc6992e
Showing with 95 additions and 82 deletions
+95 -82
package shared
package base
import (
"github.com/hashicorp/nomad/plugins/shared/hclspec"
......
package shared
package base
import (
"context"
"fmt"
"github.com/hashicorp/nomad/plugins/base/proto"
"github.com/hashicorp/nomad/plugins/shared/hclspec"
"golang.org/x/net/context"
)
// basePluginClient implements the client side of a remote base plugin, using
......@@ -22,8 +22,6 @@ func (b *basePluginClient) PluginInfo() (*PluginInfoResponse, error) {
var ptype string
switch presp.GetType() {
case proto.PluginType_BASE:
ptype = PluginTypeBase
case proto.PluginType_DRIVER:
ptype = PluginTypeDriver
case proto.PluginType_DEVICE:
......
package shared
package base
import (
"github.com/hashicorp/nomad/plugins/shared/hclspec"
......
package shared
package base
import (
"golang.org/x/net/context"
"context"
plugin "github.com/hashicorp/go-plugin"
"github.com/hashicorp/nomad/plugins/base/proto"
......@@ -9,9 +9,6 @@ import (
)
const (
// PluginTypeBase implements the base plugin driver interface
PluginTypeBase = "base"
// PluginTypeDriver implements the driver plugin interface
PluginTypeDriver = "driver"
......@@ -28,6 +25,8 @@ var (
}
)
// PluginBase is wraps a BasePlugin and implements go-plugins GRPCPlugin
// interface to expose the interface over gRPC.
type PluginBase struct {
plugin.NetRPCUnsupportedPlugin
impl BasePlugin
......
package shared
package base
import (
"testing"
......@@ -6,12 +6,10 @@ import (
pb "github.com/golang/protobuf/proto"
plugin "github.com/hashicorp/go-plugin"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/plugins/base/proto"
"github.com/hashicorp/nomad/plugins/shared/hclspec"
"github.com/stretchr/testify/require"
"github.com/zclconf/go-cty/cty"
"github.com/zclconf/go-cty/cty/msgpack"
"google.golang.org/grpc"
)
var (
......@@ -68,7 +66,7 @@ func TestBasePlugin_PluginInfo_GRPC(t *testing.T) {
knownType := func() (*PluginInfoResponse, error) {
info := &PluginInfoResponse{
Type: PluginTypeBase,
Type: PluginTypeDriver,
PluginApiVersion: apiVersion,
PluginVersion: pluginVersion,
Name: pluginName,
......@@ -89,24 +87,32 @@ func TestBasePlugin_PluginInfo_GRPC(t *testing.T) {
PluginInfoF: knownType,
}
conn, server := plugin.TestGRPCConn(t, func(s *grpc.Server) {
proto.RegisterBasePluginServer(s, &basePluginServer{impl: mock})
client, server := plugin.TestPluginGRPCConn(t, map[string]plugin.Plugin{
"base": &PluginBase{impl: mock},
})
defer conn.Close()
defer server.Stop()
grpcClient := proto.NewBasePluginClient(conn)
client := basePluginClient{client: grpcClient}
defer client.Close()
resp, err := client.PluginInfo()
raw, err := client.Dispense("base")
if err != nil {
t.Fatalf("err: %s", err)
}
impl, ok := raw.(BasePlugin)
if !ok {
t.Fatalf("bad: %#v", raw)
}
resp, err := impl.PluginInfo()
require.NoError(err)
require.Equal(apiVersion, resp.PluginApiVersion)
require.Equal(pluginVersion, resp.PluginVersion)
require.Equal(pluginName, resp.Name)
require.Equal(PluginTypeBase, resp.Type)
require.Equal(PluginTypeDriver, resp.Type)
// Swap the implementation to return an unknown type
mock.PluginInfoF = unknownType
_, err = client.PluginInfo()
_, err = impl.PluginInfo()
require.Error(err)
require.Contains(err.Error(), "unknown type")
}
......@@ -121,15 +127,23 @@ func TestBasePlugin_ConfigSchema(t *testing.T) {
},
}
conn, server := plugin.TestGRPCConn(t, func(s *grpc.Server) {
proto.RegisterBasePluginServer(s, &basePluginServer{impl: mock})
client, server := plugin.TestPluginGRPCConn(t, map[string]plugin.Plugin{
"base": &PluginBase{impl: mock},
})
defer conn.Close()
defer server.Stop()
grpcClient := proto.NewBasePluginClient(conn)
client := basePluginClient{client: grpcClient}
defer client.Close()
raw, err := client.Dispense("base")
if err != nil {
t.Fatalf("err: %s", err)
}
specOut, err := client.ConfigSchema()
impl, ok := raw.(BasePlugin)
if !ok {
t.Fatalf("bad: %#v", raw)
}
specOut, err := impl.ConfigSchema()
require.NoError(err)
require.True(pb.Equal(testSpec, specOut))
}
......@@ -149,13 +163,21 @@ func TestBasePlugin_SetConfig(t *testing.T) {
},
}
conn, server := plugin.TestGRPCConn(t, func(s *grpc.Server) {
proto.RegisterBasePluginServer(s, &basePluginServer{impl: mock})
client, server := plugin.TestPluginGRPCConn(t, map[string]plugin.Plugin{
"base": &PluginBase{impl: mock},
})
defer conn.Close()
defer server.Stop()
grpcClient := proto.NewBasePluginClient(conn)
client := basePluginClient{client: grpcClient}
defer client.Close()
raw, err := client.Dispense("base")
if err != nil {
t.Fatalf("err: %s", err)
}
impl, ok := raw.(BasePlugin)
if !ok {
t.Fatalf("bad: %#v", raw)
}
config := cty.ObjectVal(map[string]cty.Value{
"foo": cty.StringVal("v1"),
......@@ -164,7 +186,7 @@ func TestBasePlugin_SetConfig(t *testing.T) {
})
cdata, err := msgpack.Marshal(config, config.Type())
require.NoError(err)
require.NoError(client.SetConfig(cdata))
require.NoError(impl.SetConfig(cdata))
require.Equal(cdata, receivedData)
// Decode the value back
......
......@@ -29,20 +29,17 @@ type PluginType int32
const (
PluginType_UNKNOWN PluginType = 0
PluginType_BASE PluginType = 1
PluginType_DRIVER PluginType = 2
PluginType_DEVICE PluginType = 3
)
var PluginType_name = map[int32]string{
0: "UNKNOWN",
1: "BASE",
2: "DRIVER",
3: "DEVICE",
}
var PluginType_value = map[string]int32{
"UNKNOWN": 0,
"BASE": 1,
"DRIVER": 2,
"DEVICE": 3,
}
......@@ -51,7 +48,7 @@ func (x PluginType) String() string {
return proto.EnumName(PluginType_name, int32(x))
}
func (PluginType) EnumDescriptor() ([]byte, []int) {
return fileDescriptor_base_d24a6a23488adb59, []int{0}
return fileDescriptor_base_9cc78dc32b158b08, []int{0}
}
// PluginInfoRequest is used to request the plugins basic information.
......@@ -65,7 +62,7 @@ func (m *PluginInfoRequest) Reset() { *m = PluginInfoRequest{} }
func (m *PluginInfoRequest) String() string { return proto.CompactTextString(m) }
func (*PluginInfoRequest) ProtoMessage() {}
func (*PluginInfoRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_base_d24a6a23488adb59, []int{0}
return fileDescriptor_base_9cc78dc32b158b08, []int{0}
}
func (m *PluginInfoRequest) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_PluginInfoRequest.Unmarshal(m, b)
......@@ -107,7 +104,7 @@ func (m *PluginInfoResponse) Reset() { *m = PluginInfoResponse{} }
func (m *PluginInfoResponse) String() string { return proto.CompactTextString(m) }
func (*PluginInfoResponse) ProtoMessage() {}
func (*PluginInfoResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_base_d24a6a23488adb59, []int{1}
return fileDescriptor_base_9cc78dc32b158b08, []int{1}
}
func (m *PluginInfoResponse) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_PluginInfoResponse.Unmarshal(m, b)
......@@ -166,7 +163,7 @@ func (m *ConfigSchemaRequest) Reset() { *m = ConfigSchemaRequest{} }
func (m *ConfigSchemaRequest) String() string { return proto.CompactTextString(m) }
func (*ConfigSchemaRequest) ProtoMessage() {}
func (*ConfigSchemaRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_base_d24a6a23488adb59, []int{2}
return fileDescriptor_base_9cc78dc32b158b08, []int{2}
}
func (m *ConfigSchemaRequest) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_ConfigSchemaRequest.Unmarshal(m, b)
......@@ -199,7 +196,7 @@ func (m *ConfigSchemaResponse) Reset() { *m = ConfigSchemaResponse{} }
func (m *ConfigSchemaResponse) String() string { return proto.CompactTextString(m) }
func (*ConfigSchemaResponse) ProtoMessage() {}
func (*ConfigSchemaResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_base_d24a6a23488adb59, []int{3}
return fileDescriptor_base_9cc78dc32b158b08, []int{3}
}
func (m *ConfigSchemaResponse) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_ConfigSchemaResponse.Unmarshal(m, b)
......@@ -239,7 +236,7 @@ func (m *SetConfigRequest) Reset() { *m = SetConfigRequest{} }
func (m *SetConfigRequest) String() string { return proto.CompactTextString(m) }
func (*SetConfigRequest) ProtoMessage() {}
func (*SetConfigRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_base_d24a6a23488adb59, []int{4}
return fileDescriptor_base_9cc78dc32b158b08, []int{4}
}
func (m *SetConfigRequest) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_SetConfigRequest.Unmarshal(m, b)
......@@ -277,7 +274,7 @@ func (m *SetConfigResponse) Reset() { *m = SetConfigResponse{} }
func (m *SetConfigResponse) String() string { return proto.CompactTextString(m) }
func (*SetConfigResponse) ProtoMessage() {}
func (*SetConfigResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_base_d24a6a23488adb59, []int{5}
return fileDescriptor_base_9cc78dc32b158b08, []int{5}
}
func (m *SetConfigResponse) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_SetConfigResponse.Unmarshal(m, b)
......@@ -452,37 +449,37 @@ var _BasePlugin_serviceDesc = grpc.ServiceDesc{
}
func init() {
proto.RegisterFile("github.com/hashicorp/nomad/plugins/base/proto/base.proto", fileDescriptor_base_d24a6a23488adb59)
}
var fileDescriptor_base_d24a6a23488adb59 = []byte{
// 446 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x92, 0xdf, 0x8b, 0xd3, 0x40,
0x10, 0xc7, 0x2f, 0xd7, 0x78, 0xe7, 0xcd, 0xfd, 0x20, 0xee, 0x29, 0x94, 0x3c, 0x1d, 0x01, 0xe1,
0x90, 0x63, 0x03, 0xd5, 0xd3, 0x13, 0x5f, 0xae, 0xa9, 0x79, 0x28, 0x42, 0x95, 0x44, 0xab, 0xf8,
0x12, 0xb6, 0xdb, 0x6d, 0x12, 0x6c, 0xb2, 0x6b, 0x36, 0x15, 0x2a, 0xf8, 0xe4, 0xb3, 0x7f, 0x94,
0xff, 0x99, 0x64, 0x37, 0x69, 0xa3, 0x28, 0xa6, 0x4f, 0x19, 0x66, 0x3e, 0xf3, 0xdd, 0x99, 0xef,
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omad/plugins/base/proto/base.proto", fileDescriptor_base_9cc78dc32b158b08)
}
var fileDescriptor_base_9cc78dc32b158b08 = []byte{
// 436 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x92, 0xcf, 0x8b, 0xd3, 0x40,
0x14, 0xc7, 0x37, 0xdb, 0xb8, 0xcb, 0xbe, 0xdd, 0x2d, 0x71, 0xaa, 0x50, 0x72, 0x2a, 0x01, 0xa1,
0x48, 0x99, 0x60, 0xb5, 0x5a, 0x6f, 0xb5, 0xb5, 0x87, 0x22, 0x54, 0x49, 0xb5, 0x8a, 0x97, 0x30,
0x9d, 0x4e, 0x93, 0x60, 0x93, 0x19, 0x33, 0xa9, 0x50, 0xc1, 0x93, 0x67, 0xff, 0x28, 0xff, 0x33,
0xc9, 0x4c, 0xd2, 0x46, 0x51, 0x4c, 0x4f, 0x79, 0xbc, 0xf7, 0xf9, 0x7e, 0xe7, 0xfd, 0x08, 0x0c,
0x83, 0x28, 0x0b, 0x77, 0x2b, 0x4c, 0x79, 0xec, 0x86, 0x44, 0x86, 0x11, 0xe5, 0xa9, 0x70, 0x13,
0x1e, 0x93, 0xb5, 0x2b, 0xb6, 0xbb, 0x20, 0x4a, 0xa4, 0xbb, 0x22, 0x92, 0xb9, 0x22, 0xe5, 0x19,
0x57, 0x21, 0x56, 0x21, 0x72, 0x0e, 0x38, 0x56, 0x38, 0x2e, 0x70, 0x7c, 0x64, 0xec, 0x51, 0x0d,
0x77, 0x19, 0x92, 0x94, 0xad, 0xdd, 0x90, 0x6e, 0xa5, 0x60, 0x34, 0xff, 0xfa, 0x79, 0xa0, 0x1d,
0x9c, 0x16, 0xdc, 0x7d, 0xa3, 0xc0, 0x59, 0xb2, 0xe1, 0x1e, 0xfb, 0xbc, 0x63, 0x32, 0x73, 0x7e,
0x1a, 0x80, 0xaa, 0x59, 0x29, 0x78, 0x22, 0x19, 0x1a, 0x83, 0x99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6, 0x75, 0xe8, 0x5b, 0xe9, 0x90, 0x5f, 0x11, 0x0d, 0xea, 0xdf, 0xab, 0xf2, 0x2f,
0xd8, 0x4f, 0x4f, 0x95, 0xe9, 0xf6, 0x9d, 0x33, 0xf4, 0xdd, 0x80, 0x9b, 0xea, 0xae, 0xd1, 0xb3,
0x3a, 0x56, 0x7f, 0x39, 0x9a, 0x3d, 0x3c, 0x5d, 0x78, 0xe8, 0xe2, 0x2b, 0x5c, 0x1d, 0x76, 0x8b,
0x9e, 0xd4, 0x31, 0xfa, 0xf3, 0x8a, 0xf6, 0xe0, 0x44, 0x55, 0xf9, 0xf6, 0xf8, 0xf2, 0xe3, 0x1d,
0x55, 0x5c, 0x5d, 0xa8, 0xcf, 0xe3, 0x5f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x0b, 0x29, 0x9a, 0xb0,
0x0e, 0x04, 0x00, 0x00,
}
......@@ -20,7 +20,6 @@ service BasePlugin {
// PluginType enumerates the type of plugins Nomad supports
enum PluginType {
UNKNOWN = 0;
BASE = 1;
DRIVER = 2;
DEVICE = 3;
}
......
package shared
package base
import (
"fmt"
......@@ -23,8 +23,6 @@ func (b *basePluginServer) PluginInfo(context.Context, *proto.PluginInfoRequest)
var ptype proto.PluginType
switch resp.Type {
case PluginTypeBase:
ptype = proto.PluginType_BASE
case PluginTypeDriver:
ptype = proto.PluginType_DRIVER
case PluginTypeDevice:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment