overlord/ifacestate: automatically rename connections on core snap #3160

Merged
merged 6 commits into from Apr 13, 2017
@@ -48,6 +48,9 @@ func (m *InterfaceManager) initialize(extraInterfaces []interfaces.Interface, ex
if err := m.addSnaps(); err != nil {
return err
}
+ if err := m.renameCorePlugConnection(); err != nil {
+ return err
+ }
if err := m.reloadConnections(""); err != nil {
return err
}
@@ -154,6 +157,35 @@ func (m *InterfaceManager) regenerateAllSecurityProfiles() error {
return nil
}
+// renameCorePlugConnection renames one connection from "core-support" plug to
+// slot so that the plug name is "core-support-plug" while the slot is
+// unchanged. This matches a change introduced in 2.24, where the core snap no
+// longer has the "core-support" plug as that was clashing with the slot with
+// the same name.
+func (m *InterfaceManager) renameCorePlugConnection() error {
+ conns, err := getConns(m.state)
+ if err != nil {
+ return err
+ }
+ const oldPlugName = "core-support"
+ const newPlugName = "core-support-plug"
+ // old connection, note that slotRef is the same in both
+ slotRef := interfaces.SlotRef{Snap: "core", Name: oldPlugName}
+ oldPlugRef := interfaces.PlugRef{Snap: "core", Name: oldPlugName}
+ oldConnRef := interfaces.ConnRef{PlugRef: oldPlugRef, SlotRef: slotRef}
+ oldID := oldConnRef.ID()
+ // if the old connection is saved, replace it with the new connection
+ if cState, ok := conns[oldID]; ok {
+ newPlugRef := interfaces.PlugRef{Snap: "core", Name: newPlugName}
+ newConnRef := interfaces.ConnRef{PlugRef: newPlugRef, SlotRef: slotRef}
+ newID := newConnRef.ID()
+ delete(conns, oldID)
+ conns[newID] = cState
+ setConns(m.state, conns)
+ }
+ return nil
+}
+
// reloadConnections reloads connections stored in the state in the repository.
// Using non-empty snapName the operation can be scoped to connections
// affecting a given snap.
@@ -1838,6 +1838,40 @@ func (s *interfaceManagerSuite) TestManagerTransitionConnectionsCoreUndo(c *C) {
})
}
+// Test "core-support" connections that loop back to core is
+// renamed to match the rename of the plug.
+func (s *interfaceManagerSuite) TestCoreConnectionsRenamed(c *C) {
+ // Put state with old connection data.
+ s.state.Lock()
+ s.state.Set("conns", map[string]interface{}{
+ "core:core-support core:core-support": map[string]interface{}{
+ "interface": "core-support", "auto": true,
+ },
+ "snap:unrelated core:unrelated": map[string]interface{}{
+ "interface": "unrelated", "auto": true,
+ },
+ })
+ s.state.Unlock()
+
+ // Start the manager, this is where renames happen.
+ s.manager(c)
+
+ // Check that "core-support" connection got renamed.
+ s.state.Lock()
+ var conns map[string]interface{}
+ err := s.state.Get("conns", &conns)
+ s.state.Unlock()
+ c.Assert(err, IsNil)
+ c.Assert(conns, DeepEquals, map[string]interface{}{
+ "core:core-support-plug core:core-support": map[string]interface{}{
+ "interface": "core-support", "auto": true,
+ },
+ "snap:unrelated core:unrelated": map[string]interface{}{
+ "interface": "unrelated", "auto": true,
+ },
+ })
+}
+
// Test that "network-bind" and "core-support" plugs are renamed to
// "network-bind-plug" and "core-support-plug" in order not to clash with slots
// with the same names.