From 8e6d52fa80370445ccc9a3dcbe39ebcc31611a6b Mon Sep 17 00:00:00 2001 From: Alessandro Boch Date: Fri, 8 Apr 2016 21:38:30 -0700 Subject: [PATCH] Use newly introduce plugins method to validate plugin response - for endpoints which are not expected to be implemented by all remote drivers. Signed-off-by: Alessandro Boch --- libnetwork/docs/remote.md | 2 ++ libnetwork/drivers/remote/driver.go | 9 ++------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/libnetwork/docs/remote.md b/libnetwork/docs/remote.md index 57cecd17eb..bcb8d6e8c7 100644 --- a/libnetwork/docs/remote.md +++ b/libnetwork/docs/remote.md @@ -31,6 +31,8 @@ The remote driver protocol is a set of RPCs, issued as HTTP POSTs with JSON payl If the remote process cannot decode, or otherwise detects a syntactic problem with the HTTP request or payload, it must respond with an HTTP error status (4xx or 5xx). +If the remote process http server receives a request for an unknown URI, it should respond with the HTTP StatusCode `404 Not Found`. This allows libnetwork to detect when a remote driver does not implement yet a newly added method, therefore not to deem the request as failed. + If the remote process can decode the request, but cannot complete the operation, it must send a response in the form { diff --git a/libnetwork/drivers/remote/driver.go b/libnetwork/drivers/remote/driver.go index 32533533dd..e3f2cd58e2 100644 --- a/libnetwork/drivers/remote/driver.go +++ b/libnetwork/drivers/remote/driver.go @@ -3,7 +3,6 @@ package remote import ( "fmt" "net" - "strings" log "github.com/Sirupsen/logrus" "github.com/docker/docker/pkg/plugins" @@ -14,10 +13,6 @@ import ( "github.com/docker/libnetwork/types" ) -const ( - missingMethod = "404 page not found" -) - type driver struct { endpoint *plugins.Client networkType string @@ -260,7 +255,7 @@ func (d *driver) ProgramExternalConnectivity(nid, eid string, options map[string Options: options, } err := d.call("ProgramExternalConnectivity", data, &api.ProgramExternalConnectivityResponse{}) - if err != nil && strings.Contains(err.Error(), missingMethod) { + if err != nil && plugins.IsNotFound(err) { // It is not mandatory yet to support this method return nil } @@ -274,7 +269,7 @@ func (d *driver) RevokeExternalConnectivity(nid, eid string) error { EndpointID: eid, } err := d.call("RevokeExternalConnectivity", data, &api.RevokeExternalConnectivityResponse{}) - if err != nil && strings.Contains(err.Error(), missingMethod) { + if err != nil && plugins.IsNotFound(err) { // It is not mandatory yet to support this method return nil }