From 82f86233a6c788690b6bd0f0409fcba43f7fe19c Mon Sep 17 00:00:00 2001 From: Madhu Venugopal Date: Tue, 20 Oct 2015 19:49:08 -0700 Subject: [PATCH 1/2] Vendoring in libnetwork to fix daemon bootup instabilities Signed-off-by: Madhu Venugopal Upstream-commit: 2de2192c27bf72e5036e9914b984ab6d71f70c60 Component: engine --- components/engine/hack/vendor.sh | 2 +- .../src/github.com/docker/libnetwork/store.go | 54 ++++++++----------- 2 files changed, 23 insertions(+), 33 deletions(-) diff --git a/components/engine/hack/vendor.sh b/components/engine/hack/vendor.sh index 9e0a033d4a..1fb3e162dc 100755 --- a/components/engine/hack/vendor.sh +++ b/components/engine/hack/vendor.sh @@ -21,7 +21,7 @@ clone git github.com/vdemeester/shakers 3c10293ce22b900c27acad7b28656196fcc2f73b clone git golang.org/x/net 3cffabab72adf04f8e3b01c5baf775361837b5fe https://github.com/golang/net.git #get libnetwork packages -clone git github.com/docker/libnetwork fc6cbea49cd8197c0a8d22b9e8f24f37d9e7b1b8 +clone git github.com/docker/libnetwork 0d7a57ddb94a92a57755eec5dc54f905287c7e65 clone git github.com/armon/go-metrics eb0af217e5e9747e41dd5303755356b62d28e3ec clone git github.com/hashicorp/go-msgpack 71c2886f5a673a35f909803f38ece5810165097b clone git github.com/hashicorp/memberlist 9a1e242e454d2443df330bdd51a436d5a9058fc4 diff --git a/components/engine/vendor/src/github.com/docker/libnetwork/store.go b/components/engine/vendor/src/github.com/docker/libnetwork/store.go index 65d3b02a32..c70caf08d3 100644 --- a/components/engine/vendor/src/github.com/docker/libnetwork/store.go +++ b/components/engine/vendor/src/github.com/docker/libnetwork/store.go @@ -60,12 +60,11 @@ func (c *controller) getNetworkFromStore(nid string) (*network, error) { for _, store := range c.getStores() { n := &network{id: nid, ctrlr: c} err := store.GetObject(datastore.Key(n.Key()...), n) - if err != nil && err != datastore.ErrKeyNotFound { - return nil, fmt.Errorf("could not find network %s: %v", nid, err) - } - // Continue searching in the next store if the key is not found in this store - if err == datastore.ErrKeyNotFound { + if err != nil { + if err != datastore.ErrKeyNotFound { + log.Debugf("could not find network %s: %v", nid, err) + } continue } @@ -120,13 +119,11 @@ func (c *controller) getNetworksFromStore() ([]*network, error) { for _, store := range c.getStores() { kvol, err := store.List(datastore.Key(datastore.NetworkKeyPrefix), &network{ctrlr: c}) - if err != nil && err != datastore.ErrKeyNotFound { - return nil, fmt.Errorf("failed to get networks for scope %s: %v", - store.Scope(), err) - } - // Continue searching in the next store if no keys found in this store - if err == datastore.ErrKeyNotFound { + if err != nil { + if err != datastore.ErrKeyNotFound { + log.Debugf("failed to get networks for scope %s: %v", store.Scope(), err) + } continue } @@ -149,22 +146,17 @@ func (c *controller) getNetworksFromStore() ([]*network, error) { } func (n *network) getEndpointFromStore(eid string) (*endpoint, error) { - for _, store := range n.ctrlr.getStores() { - ep := &endpoint{id: eid, network: n} - err := store.GetObject(datastore.Key(ep.Key()...), ep) - if err != nil && err != datastore.ErrKeyNotFound { - return nil, fmt.Errorf("could not find endpoint %s: %v", eid, err) - } - - // Continue searching in the next store if the key is not found in this store - if err == datastore.ErrKeyNotFound { - continue - } - - return ep, nil + store := n.ctrlr.getStore(n.Scope()) + if store == nil { + return nil, fmt.Errorf("could not find endpoint %s: datastore not found for scope %s", eid, n.Scope()) } - return nil, fmt.Errorf("endpoint %s not found", eid) + ep := &endpoint{id: eid, network: n} + err := store.GetObject(datastore.Key(ep.Key()...), ep) + if err != nil { + return nil, fmt.Errorf("could not find endpoint %s: %v", eid, err) + } + return ep, nil } func (n *network) getEndpointsFromStore() ([]*endpoint, error) { @@ -173,14 +165,12 @@ func (n *network) getEndpointsFromStore() ([]*endpoint, error) { tmp := endpoint{network: n} for _, store := range n.getController().getStores() { kvol, err := store.List(datastore.Key(tmp.KeyPrefix()...), &endpoint{network: n}) - if err != nil && err != datastore.ErrKeyNotFound { - return nil, - fmt.Errorf("failed to get endpoints for network %s scope %s: %v", - n.Name(), store.Scope(), err) - } - // Continue searching in the next store if no keys found in this store - if err == datastore.ErrKeyNotFound { + if err != nil { + if err != datastore.ErrKeyNotFound { + log.Debugf("failed to get endpoints for network %s scope %s: %v", + n.Name(), store.Scope(), err) + } continue } From c3f438b95a6c50f2216f3f4fa99abb23d13b4a00 Mon Sep 17 00:00:00 2001 From: Madhu Venugopal Date: Tue, 20 Oct 2015 19:17:18 -0700 Subject: [PATCH 2/2] Integration test for default bridge init with invalid cluster config Signed-off-by: Madhu Venugopal Upstream-commit: 37627427a2ad9dcb06a2a6ea958670683a6c7934 Component: engine --- .../integration-cli/docker_cli_daemon_test.go | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/components/engine/integration-cli/docker_cli_daemon_test.go b/components/engine/integration-cli/docker_cli_daemon_test.go index d538a7dd6b..68c07a0e3e 100644 --- a/components/engine/integration-cli/docker_cli_daemon_test.go +++ b/components/engine/integration-cli/docker_cli_daemon_test.go @@ -16,6 +16,7 @@ import ( "strings" "time" + "github.com/docker/docker/pkg/integration/checker" "github.com/docker/libnetwork/iptables" "github.com/docker/libtrust" "github.com/go-check/check" @@ -848,6 +849,29 @@ func (s *DockerDaemonSuite) TestDaemonDefaultGatewayIPv4ExplicitOutsideContainer s.d.Restart() } +func (s *DockerDaemonSuite) TestDaemonDefaultNetworkInvalidClusterConfig(c *check.C) { + testRequires(c, SameHostDaemon) + + // Start daemon without docker0 bridge + defaultNetworkBridge := "docker0" + deleteInterface(c, defaultNetworkBridge) + + d := NewDaemon(c) + discoveryBackend := "consul://consuladdr:consulport/some/path" + err := d.Start(fmt.Sprintf("--cluster-store=%s", discoveryBackend)) + c.Assert(err, checker.IsNil) + + // Start daemon with docker0 bridge + ifconfigCmd := exec.Command("ifconfig", defaultNetworkBridge) + _, err = runCommand(ifconfigCmd) + c.Assert(err, check.IsNil) + + err = d.Restart(fmt.Sprintf("--cluster-store=%s", discoveryBackend)) + c.Assert(err, checker.IsNil) + + d.Stop() +} + func (s *DockerDaemonSuite) TestDaemonIP(c *check.C) { d := s.d