New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
interfaces: disconnect hooks #4767
Changes from all commits
c3363c0
3b12672
88eabba
079d777
23a215e
c3031eb
3fced34
57aaa8b
c725d92
9e95a6c
00e236c
161e86d
93f7544
a984f42
e11df74
d0b395b
30e65c9
601abe2
69aacd6
8ff8c20
d25bdad
795b04f
5f2d13a
51a4add
4741a9e
c5f417e
cb382f6
466adae
e377997
b2a76d9
07565db
ce8bcf8
acc69b1
9655e07
d6821ab
853706d
3bc7844
ca0a98a
66ec721
d33f27d
00e9cbe
2125a2f
8a1b248
a4ebc07
0c6f2ef
1f772a9
48aee81
ea8704d
fa5c2d5
180e9fa
828587c
d9c68c7
48d147f
047194f
1403080
b2230e7
ced4431
fa70f44
5c307ab
e3b9c03
da465d2
6b53d6c
ab4bfcd
c4354e6
6a5a4b8
3bc1f1f
9fc2382
29ba44a
804c1b3
b85f76d
638b160
a65787d
4740f86
a7fb7cc
a25ed44
57039c1
9786be9
87e2569
3c20901
a89b89b
c601eba
73d818c
102ba89
7f82429
9bc7c37
0875b6b
0c9d669
73e8383
4f51d68
1bdcfd3
338000c
ef0c531
2c405c3
0a3b4fc
e2653f5
367f60d
82447f0
e94622b
94357e3
0767a02
9cbe816
5c94036
fdad323
55604a0
2cf253b
477cdd8
53a79d1
c134c5c
4d5bee5
df8a225
298891b
57414c0
fc6912a
e804b32
4ba6552
e083088
c48f62d
d4af3e1
29813f6
4f2aa8e
04e43ea
eab06db
de78236
cb3a1bf
b6ceddc
577d2b8
6098a07
bd27318
7fd3a31
3435ac2
5c94e53
82713ee
a978ac9
724565e
a75122e
f6e7a92
a29a576
5fd2f5e
01b64b8
f54ba35
19755b7
bc7e54e
a515183
57154ba
6ee6633
5b63122
680dade
9fd9637
f65ddd7
4365841
23c5acf
c078566
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4255,6 +4255,15 @@ func (s *apiSuite) testDisconnect(c *check.C, plugSnap, plugName, slotSnap, slot | |
_, err := repo.Connect(connRef, nil, nil, nil) | ||
c.Assert(err, check.IsNil) | ||
|
||
st := d.overlord.State() | ||
st.Lock() | ||
st.Set("conns", map[string]interface{}{ | ||
"consumer:plug producer:slot": map[string]interface{}{ | ||
"interface": "test", | ||
}, | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's because |
||
st.Unlock() | ||
|
||
d.overlord.Loop() | ||
defer d.overlord.Stop() | ||
|
||
|
@@ -4276,7 +4285,6 @@ func (s *apiSuite) testDisconnect(c *check.C, plugSnap, plugName, slotSnap, slot | |
c.Check(err, check.IsNil) | ||
id := body["change"].(string) | ||
|
||
st := d.overlord.State() | ||
st.Lock() | ||
chg := st.Change(id) | ||
st.Unlock() | ||
|
@@ -4460,6 +4468,15 @@ func (s *apiSuite) TestDisconnectCoreSystemAlias(c *check.C) { | |
_, err := repo.Connect(connRef, nil, nil, nil) | ||
c.Assert(err, check.IsNil) | ||
|
||
st := d.overlord.State() | ||
st.Lock() | ||
st.Set("conns", map[string]interface{}{ | ||
"consumer:plug core:slot": map[string]interface{}{ | ||
"interface": "test", | ||
}, | ||
}) | ||
st.Unlock() | ||
|
||
d.overlord.Loop() | ||
defer d.overlord.Stop() | ||
|
||
|
@@ -4481,7 +4498,6 @@ func (s *apiSuite) TestDisconnectCoreSystemAlias(c *check.C) { | |
c.Check(err, check.IsNil) | ||
id := body["change"].(string) | ||
|
||
st := d.overlord.State() | ||
st.Lock() | ||
chg := st.Change(id) | ||
st.Unlock() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -277,6 +277,29 @@ func (r *Repository) Plug(snapName, plugName string) *snap.PlugInfo { | |
return r.plugs[snapName][plugName] | ||
} | ||
|
||
// Connection returns the specified Connection object or an error. | ||
func (r *Repository) Connection(connRef *ConnRef) (*Connection, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks fine |
||
// Ensure that such plug exists | ||
plug := r.plugs[connRef.PlugRef.Snap][connRef.PlugRef.Name] | ||
if plug == nil { | ||
return nil, fmt.Errorf("snap %q has no plug named %q", connRef.PlugRef.Snap, connRef.PlugRef.Name) | ||
} | ||
// Ensure that such slot exists | ||
slot := r.slots[connRef.SlotRef.Snap][connRef.SlotRef.Name] | ||
if slot == nil { | ||
return nil, fmt.Errorf("snap %q has no slot named %q", connRef.SlotRef.Snap, connRef.SlotRef.Name) | ||
} | ||
// Ensure that slot and plug are connected | ||
conn, ok := r.slotPlugs[slot][plug] | ||
if !ok { | ||
return nil, fmt.Errorf("no connection from %s:%s to %s:%s", | ||
connRef.PlugRef.Snap, connRef.PlugRef.Name, | ||
connRef.SlotRef.Snap, connRef.SlotRef.Name) | ||
} | ||
|
||
return conn, nil | ||
} | ||
|
||
// AddPlug adds a plug to the repository. | ||
// Plug names must be valid snap names, as defined by ValidateName. | ||
// Plug name must be unique within a particular snap. | ||
|
@@ -760,6 +783,10 @@ func (r *Repository) Connections(snapName string) ([]*ConnRef, error) { | |
} | ||
for _, slotInfo := range r.slots[snapName] { | ||
for plugInfo := range r.slotPlugs[slotInfo] { | ||
// self-connection, ignore here as we got it already in the plugs loop above | ||
if plugInfo.Snap == slotInfo.Snap { | ||
continue | ||
} | ||
connRef := NewConnRef(plugInfo, slotInfo) | ||
conns = append(conns, connRef) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fine