summaryrefslogtreecommitdiff
diff options
authorPawel Stolowski <stolowski@gmail.com>2018-07-19 17:32:02 +0200
committerPawel Stolowski <stolowski@gmail.com>2018-07-19 17:32:02 +0200
commit1145f67924f0d068b01e695a0f8e4b776868b0ba (patch)
tree3d3159a1ead6aa56623cddbe0750bb6f97fb42d9
parent44a9d8a15e963d138fcd2881f72a8127ffe94da4 (diff)
Check undesired flag when deciding on ErrAlreadyConnected.prevent-re-connect
-rw-r--r--overlord/ifacestate/ifacestate.go2
-rw-r--r--overlord/ifacestate/ifacestate_test.go13
2 files changed, 14 insertions, 1 deletions
diff --git a/overlord/ifacestate/ifacestate.go b/overlord/ifacestate/ifacestate.go
index 305af7dbfa..e76ab2b47a 100644
--- a/overlord/ifacestate/ifacestate.go
+++ b/overlord/ifacestate/ifacestate.go
@@ -175,7 +175,7 @@ func connect(st *state.State, plugSnap, plugName, slotSnap, slotName string, fla
return nil, err
}
connRef := interfaces.ConnRef{PlugRef: interfaces.PlugRef{Snap: plugSnap, Name: plugName}, SlotRef: interfaces.SlotRef{Snap: slotSnap, Name: slotName}}
- if _, ok := conns[connRef.ID()]; ok {
+ if conn, ok := conns[connRef.ID()]; ok && conn.Undesired == false {
return nil, &ErrAlreadyConnected{Connection: connRef}
}
diff --git a/overlord/ifacestate/ifacestate_test.go b/overlord/ifacestate/ifacestate_test.go
index 90c0d043d5..3f8cd07017 100644
--- a/overlord/ifacestate/ifacestate_test.go
+++ b/overlord/ifacestate/ifacestate_test.go
@@ -283,6 +283,19 @@ func (s *interfaceManagerSuite) TestConnectAlreadyConnected(c *C) {
c.Assert(ok, Equals, true)
c.Assert(alreadyConnected.Connection, DeepEquals, interfaces.ConnRef{PlugRef: interfaces.PlugRef{Snap: "consumer", Name: "plug"}, SlotRef: interfaces.SlotRef{Snap: "producer", Name: "slot"}})
c.Assert(err, ErrorMatches, `already connected: "consumer:plug producer:slot"`)
+
+ conns = map[string]interface{}{
+ "consumer:plug producer:slot": map[string]interface{}{
+ "auto": true,
+ "undesired": true,
+ },
+ }
+ s.state.Set("conns", conns)
+
+ // ErrAlreadyConnected is not reported if connection exists but is undesired
+ ts, err = ifacestate.Connect(s.state, "consumer", "plug", "producer", "slot")
+ c.Assert(err, IsNil)
+ c.Assert(ts, NotNil)
}
func (s *interfaceManagerSuite) testConnectDisconnectConflicts(c *C, f func(*state.State, string, string, string, string) (*state.TaskSet, error), snapName string, otherTaskKind string, expectedErr string) {