Task 5544441: Make plugin names configurable for testing
This commit is contained in:
Родитель
f369a8bd5e
Коммит
e2b61617bd
40
ipam/null.go
40
ipam/null.go
|
@ -19,7 +19,9 @@ const endpointName = "IpamDriver"
|
|||
|
||||
// IpamPlugin object and interface
|
||||
type ipamPlugin struct {
|
||||
name string
|
||||
version string
|
||||
scope string
|
||||
listener *core.Listener
|
||||
sync.Mutex
|
||||
}
|
||||
|
@ -32,7 +34,9 @@ type IpamPlugin interface {
|
|||
// Creates a new IpamPlugin object.
|
||||
func NewPlugin(version string) (IpamPlugin, error) {
|
||||
return &ipamPlugin{
|
||||
name: pluginName,
|
||||
version: version,
|
||||
scope: "local",
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -40,7 +44,7 @@ func NewPlugin(version string) (IpamPlugin, error) {
|
|||
func (plugin *ipamPlugin) Start(errChan chan error) error {
|
||||
|
||||
// Create the listener.
|
||||
listener, err := core.NewListener(pluginName)
|
||||
listener, err := core.NewListener(plugin.name)
|
||||
if err != nil {
|
||||
log.Printf("Failed to create listener %v", err)
|
||||
return err
|
||||
|
@ -63,7 +67,7 @@ func (plugin *ipamPlugin) Start(errChan chan error) error {
|
|||
return err
|
||||
}
|
||||
|
||||
log.Printf("%s: Plugin started.", pluginName)
|
||||
log.Printf("%s: Plugin started.", plugin.name)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -71,7 +75,7 @@ func (plugin *ipamPlugin) Start(errChan chan error) error {
|
|||
// Stops the plugin.
|
||||
func (plugin *ipamPlugin) Stop() {
|
||||
plugin.listener.Stop()
|
||||
log.Printf("%s: Plugin stopped.\n", pluginName)
|
||||
log.Printf("%s: Plugin stopped.\n", plugin.name)
|
||||
}
|
||||
|
||||
type activateResponse struct {
|
||||
|
@ -79,21 +83,21 @@ type activateResponse struct {
|
|||
}
|
||||
|
||||
func (plugin *ipamPlugin) activatePlugin(w http.ResponseWriter, r *http.Request) {
|
||||
log.Request(pluginName, "Activate", nil, nil)
|
||||
log.Request(plugin.name, "Activate", nil, nil)
|
||||
|
||||
resp := &activateResponse{[]string{endpointName}}
|
||||
err := plugin.listener.Encode(w, resp)
|
||||
|
||||
log.Response(pluginName, "Activate", resp, err)
|
||||
log.Response(plugin.name, "Activate", resp, err)
|
||||
}
|
||||
|
||||
func (plugin *ipamPlugin) getCapabilities(w http.ResponseWriter, r *http.Request) {
|
||||
log.Request(pluginName, "GetCapabilities", nil, nil)
|
||||
log.Request(plugin.name, "GetCapabilities", nil, nil)
|
||||
|
||||
resp := map[string]string{"Scope": "local"}
|
||||
resp := map[string]string{"Scope": plugin.scope}
|
||||
err := plugin.listener.Encode(w, resp)
|
||||
|
||||
log.Response(pluginName, "GetCapabilities", resp, err)
|
||||
log.Response(plugin.name, "GetCapabilities", resp, err)
|
||||
}
|
||||
|
||||
type defaultAddressSpacesResponseFormat struct {
|
||||
|
@ -102,7 +106,7 @@ type defaultAddressSpacesResponseFormat struct {
|
|||
}
|
||||
|
||||
func (plugin *ipamPlugin) getDefaultAddressSpaces(w http.ResponseWriter, r *http.Request) {
|
||||
log.Request(pluginName, "GetDefaultAddressSpaces", nil, nil)
|
||||
log.Request(plugin.name, "GetDefaultAddressSpaces", nil, nil)
|
||||
|
||||
resp := &defaultAddressSpacesResponseFormat{
|
||||
LocalDefaultAddressSpace: "",
|
||||
|
@ -111,7 +115,7 @@ func (plugin *ipamPlugin) getDefaultAddressSpaces(w http.ResponseWriter, r *http
|
|||
|
||||
err := plugin.listener.Encode(w, resp)
|
||||
|
||||
log.Response(pluginName, "GetDefaultAddressSpaces", resp, err)
|
||||
log.Response(plugin.name, "GetDefaultAddressSpaces", resp, err)
|
||||
}
|
||||
|
||||
type requestPoolRequestFormat struct {
|
||||
|
@ -133,7 +137,7 @@ func (plugin *ipamPlugin) requestPool(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
err := plugin.listener.Decode(w, r, &req)
|
||||
|
||||
log.Request(pluginName, "RequestPool", req, err)
|
||||
log.Request(plugin.name, "RequestPool", req, err)
|
||||
|
||||
if err == nil {
|
||||
data := make(map[string]string)
|
||||
|
@ -141,7 +145,7 @@ func (plugin *ipamPlugin) requestPool(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
err = plugin.listener.Encode(w, resp)
|
||||
|
||||
log.Response(pluginName, "RequestPool", resp, err)
|
||||
log.Response(plugin.name, "RequestPool", resp, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,14 +161,14 @@ func (plugin *ipamPlugin) releasePool(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
err := plugin.listener.Decode(w, r, &req)
|
||||
|
||||
log.Request(pluginName, "ReleasePool", req, err)
|
||||
log.Request(plugin.name, "ReleasePool", req, err)
|
||||
|
||||
if err == nil {
|
||||
resp := &releasePoolRequestFormat{}
|
||||
|
||||
err = plugin.listener.Encode(w, resp)
|
||||
|
||||
log.Response(pluginName, "ReleasePool", resp, err)
|
||||
log.Response(plugin.name, "ReleasePool", resp, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -185,14 +189,14 @@ func (plugin *ipamPlugin) requestAddress(w http.ResponseWriter, r *http.Request)
|
|||
|
||||
err := plugin.listener.Decode(w, r, &req)
|
||||
|
||||
log.Request(pluginName, "RequestAddress", req, err)
|
||||
log.Request(plugin.name, "RequestAddress", req, err)
|
||||
|
||||
if err == nil {
|
||||
resp := &requestAddressResponseFormat{"", "", make(map[string]string)}
|
||||
|
||||
err = plugin.listener.Encode(w, resp)
|
||||
|
||||
log.Response(pluginName, "RequestAddress", resp, err)
|
||||
log.Response(plugin.name, "RequestAddress", resp, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -206,13 +210,13 @@ func (plugin *ipamPlugin) releaseAddress(w http.ResponseWriter, r *http.Request)
|
|||
|
||||
err := plugin.listener.Decode(w, r, &req)
|
||||
|
||||
log.Request(pluginName, "ReleaseAddress", req, err)
|
||||
log.Request(plugin.name, "ReleaseAddress", req, err)
|
||||
|
||||
if err == nil {
|
||||
resp := map[string]string{}
|
||||
|
||||
err = plugin.listener.Encode(w, resp)
|
||||
|
||||
log.Response(pluginName, "ReleaseAddress", resp, err)
|
||||
log.Response(plugin.name, "ReleaseAddress", resp, err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ const endpointName = "NetworkDriver"
|
|||
|
||||
// NetPlugin object and its interface
|
||||
type netPlugin struct {
|
||||
name string
|
||||
version string
|
||||
scope string
|
||||
listener *core.Listener
|
||||
|
@ -35,6 +36,7 @@ type NetPlugin interface {
|
|||
// Creates a new NetPlugin object.
|
||||
func NewPlugin(version string) (NetPlugin, error) {
|
||||
return &netPlugin{
|
||||
name: pluginName,
|
||||
version: version,
|
||||
scope: "local",
|
||||
}, nil
|
||||
|
@ -44,7 +46,7 @@ func NewPlugin(version string) (NetPlugin, error) {
|
|||
func (plugin *netPlugin) Start(errChan chan error) error {
|
||||
|
||||
// Create the listener.
|
||||
listener, err := core.NewListener(pluginName)
|
||||
listener, err := core.NewListener(plugin.name)
|
||||
if err != nil {
|
||||
log.Printf("Failed to create listener %v", err)
|
||||
return err
|
||||
|
@ -69,7 +71,7 @@ func (plugin *netPlugin) Start(errChan chan error) error {
|
|||
return err
|
||||
}
|
||||
|
||||
log.Printf("%s: Plugin started.", pluginName)
|
||||
log.Printf("%s: Plugin started.", plugin.name)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -77,7 +79,7 @@ func (plugin *netPlugin) Start(errChan chan error) error {
|
|||
// Stops the plugin.
|
||||
func (plugin *netPlugin) Stop() {
|
||||
plugin.listener.Stop()
|
||||
log.Printf("%s: Plugin stopped.\n", pluginName)
|
||||
log.Printf("%s: Plugin stopped.\n", plugin.name)
|
||||
}
|
||||
|
||||
func (plugin *netPlugin) networkExists(networkID string) bool {
|
||||
|
@ -105,21 +107,21 @@ type activateResponse struct {
|
|||
}
|
||||
|
||||
func (plugin *netPlugin) activatePlugin(w http.ResponseWriter, r *http.Request) {
|
||||
log.Request(pluginName, "Activate", nil, nil)
|
||||
log.Request(plugin.name, "Activate", nil, nil)
|
||||
|
||||
resp := &activateResponse{[]string{endpointName}}
|
||||
err := plugin.listener.Encode(w, resp)
|
||||
|
||||
log.Response(pluginName, "Activate", resp, err)
|
||||
log.Response(plugin.name, "Activate", resp, err)
|
||||
}
|
||||
|
||||
func (plugin *netPlugin) getCapabilities(w http.ResponseWriter, r *http.Request) {
|
||||
log.Request(pluginName, "GetCapabilities", nil, nil)
|
||||
log.Request(plugin.name, "GetCapabilities", nil, nil)
|
||||
|
||||
resp := map[string]string{"Scope": plugin.scope}
|
||||
err := plugin.listener.Encode(w, resp)
|
||||
|
||||
log.Response(pluginName, "GetCapabilities", resp, err)
|
||||
log.Response(plugin.name, "GetCapabilities", resp, err)
|
||||
}
|
||||
|
||||
// All request and response formats are well known and are published by libnetwork
|
||||
|
@ -133,7 +135,7 @@ func (plugin *netPlugin) createNetwork(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
err := plugin.listener.Decode(w, r, &req)
|
||||
|
||||
log.Request(pluginName, "CreateNetwork", req, err)
|
||||
log.Request(plugin.name, "CreateNetwork", req, err)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -163,7 +165,7 @@ func (plugin *netPlugin) createNetwork(w http.ResponseWriter, r *http.Request) {
|
|||
resp := map[string]string{}
|
||||
err = plugin.listener.Encode(w, resp)
|
||||
|
||||
log.Response(pluginName, "CreateNetwork", resp, err)
|
||||
log.Response(plugin.name, "CreateNetwork", resp, err)
|
||||
}
|
||||
|
||||
type networkDeleteRequestFormat struct {
|
||||
|
@ -175,7 +177,7 @@ func (plugin *netPlugin) deleteNetwork(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
err := plugin.listener.Decode(w, r, &req)
|
||||
|
||||
log.Request(pluginName, "DeleteNetwork", req, err)
|
||||
log.Request(plugin.name, "DeleteNetwork", req, err)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -193,7 +195,7 @@ func (plugin *netPlugin) deleteNetwork(w http.ResponseWriter, r *http.Request) {
|
|||
resp := map[string]string{}
|
||||
err = plugin.listener.Encode(w, resp)
|
||||
|
||||
log.Response(pluginName, "DeleteNetwork", resp, err)
|
||||
log.Response(plugin.name, "DeleteNetwork", resp, err)
|
||||
}
|
||||
|
||||
type azInterface struct {
|
||||
|
@ -222,7 +224,7 @@ func (plugin *netPlugin) createEndpoint(w http.ResponseWriter, r *http.Request)
|
|||
|
||||
err := plugin.listener.Decode(w, r, &req)
|
||||
|
||||
log.Request(pluginName, "CreateEndpoint", req, err)
|
||||
log.Request(plugin.name, "CreateEndpoint", req, err)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -338,7 +340,7 @@ func (plugin *netPlugin) createEndpoint(w http.ResponseWriter, r *http.Request)
|
|||
|
||||
err = plugin.listener.Encode(w, resp)
|
||||
|
||||
log.Response(pluginName, "CreateEndpoint", resp, err)
|
||||
log.Response(plugin.name, "CreateEndpoint", resp, err)
|
||||
}
|
||||
|
||||
type joinRequestFormat struct {
|
||||
|
@ -371,7 +373,7 @@ func (plugin *netPlugin) join(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
err := plugin.listener.Decode(w, r, &req)
|
||||
|
||||
log.Request(pluginName, "Join", req, err)
|
||||
log.Request(plugin.name, "Join", req, err)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -405,7 +407,7 @@ func (plugin *netPlugin) join(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
err = plugin.listener.Encode(w, resp)
|
||||
|
||||
log.Response(pluginName, "Join", resp, err)
|
||||
log.Response(plugin.name, "Join", resp, err)
|
||||
|
||||
fmt.Printf("srcname: %s dstPRefix:%s \n", ifname.SrcName, ifname.DstPrefix)
|
||||
|
||||
|
@ -423,7 +425,7 @@ func (plugin *netPlugin) deleteEndpoint(w http.ResponseWriter, r *http.Request)
|
|||
|
||||
err := plugin.listener.Decode(w, r, &req)
|
||||
|
||||
log.Request(pluginName, "DeleteEndpoint", req, err)
|
||||
log.Request(plugin.name, "DeleteEndpoint", req, err)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -446,7 +448,7 @@ func (plugin *netPlugin) deleteEndpoint(w http.ResponseWriter, r *http.Request)
|
|||
resp := &map[string]string{}
|
||||
err = plugin.listener.Encode(w, resp)
|
||||
|
||||
log.Response(pluginName, "DeleteEndpoint", resp, err)
|
||||
log.Response(plugin.name, "DeleteEndpoint", resp, err)
|
||||
}
|
||||
|
||||
type leaveRequestFormat struct {
|
||||
|
@ -462,7 +464,7 @@ func (plugin *netPlugin) leave(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
err := plugin.listener.Decode(w, r, &req)
|
||||
|
||||
log.Request(pluginName, "Leave", req, err)
|
||||
log.Request(plugin.name, "Leave", req, err)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -472,7 +474,7 @@ func (plugin *netPlugin) leave(w http.ResponseWriter, r *http.Request) {
|
|||
resp := &leaveResponse{}
|
||||
err = plugin.listener.Encode(w, resp)
|
||||
|
||||
log.Response(pluginName, "Leave", resp, err)
|
||||
log.Response(plugin.name, "Leave", resp, err)
|
||||
}
|
||||
|
||||
type endpointOperInfoRequestFormat struct {
|
||||
|
@ -489,7 +491,7 @@ func (plugin *netPlugin) endpointOperInfo(w http.ResponseWriter, r *http.Request
|
|||
|
||||
err := plugin.listener.Decode(w, r, &req)
|
||||
|
||||
log.Request(pluginName, "EndpointOperInfo", req, err)
|
||||
log.Request(plugin.name, "EndpointOperInfo", req, err)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -502,5 +504,5 @@ func (plugin *netPlugin) endpointOperInfo(w http.ResponseWriter, r *http.Request
|
|||
resp := &endpointOperInfoResponseFormat{Value: value}
|
||||
err = plugin.listener.Encode(w, resp)
|
||||
|
||||
log.Response(pluginName, "EndpointOperInfo", resp, err)
|
||||
log.Response(plugin.name, "EndpointOperInfo", resp, err)
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче