many: abbreviated forms of disconnect #2066

Merged
merged 33 commits into from Oct 4, 2016

Conversation

Projects
None yet
3 participants
Contributor

zyga commented Oct 3, 2016

This picks up #2046

WIP

zyga and others added some commits Apr 18, 2016

interfaces: add {Plug,Slot}.Ref
This patch adds two helpers so that it is easy to create a PlugRef from
Plug and a SlotRef from Slot.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
interfaces: add ConnRef
This patch adds a structure representing a single connection.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
interfaces: return list of affected connections and snaps from Discon…
…nect

Disconnect supports abbreviated forms where one can disconnect,
for example, all the connections affecting a given snap.

Since interface manager needs to setup security of all the affected
snaps and to forget the persistent state of all the affected connections
this information is now provided directly by the Disconnect
operation.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
overlord/ifacestate: add support for abbreviated disconnect operations
This patch adds support for abbreviated disconnect operations that match
the suggestions printed by "$ snap disconnect --help". This also fixes a
bug where snapd would crash if any of those abbreviated forms were to be
used.

Fixes: https://bugs.launchpad.net/snappy/+bug/1571497
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
interfaces: add ResolveDisconnectAll and DisconnectAll
This patch adds a new pair of methods, ResolveDisconnectAll and
DisconnectAll that respectively look up a list of connections to sever
and disconect a list of connections.

DisconnectAll returns a list of names of snaps that were affected by the
operation.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>

zyga added some commits Oct 3, 2016

interfaces: tweak error message in ResolveDisconnectAll
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
interfaces: fix typo
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
interfaces/repo.go
-func (r *Repository) disconnectEverythingFromSnap(slotSnapName string) error {
- if _, ok := r.slots[slotSnapName]; !ok {
- return fmt.Errorf("cannot disconnect plug from snap %q, no such snap", slotSnapName)
+// ResolveDisconnectAll finds all of the connections that would be disconnected by DisconnectAll()
@niemeyer

niemeyer Oct 3, 2016

Contributor

That sounds strange. It's this function that defines what DisconnectAll should disconnect, not the other way around. Suggestion for rename and documentation:

// Connected returns references for all connections that are currently
// established with the provided plug or slot.

// DisconnectAll disconnects all provided connection references.
@niemeyer

niemeyer Oct 3, 2016

Contributor

Updated comment. Connected might be good enough, actually. This is much less magical than ResolveConnect, as there isn't much "resolving" going on.

@zyga

zyga Oct 4, 2016

Contributor

Done

interfaces/repo.go
- for plug := range r.slotPlugs[slot] {
+ var conns []ConnRef
+ if plugOrSlotName == "" {
+ // "wildcard" mode, affect all the plugs or slots in this snap
@niemeyer

niemeyer Oct 3, 2016

Contributor

Do we have any real use cases for this today? We don't want this in the CLI, so if there are no other use cases we should probably just error for now.

@zyga

zyga Oct 4, 2016

Contributor

It doesn't seem that we do. I've simplified the code and removed this case.

@zyga

zyga Oct 4, 2016

Contributor

Removed and simplified

interfaces/repo.go
+ return conns, nil
+}
+
+// DisconnectAll disconnects all of the given connections, returning the list of affected snap names.
@niemeyer

niemeyer Oct 3, 2016

Contributor

Why are we returning a list of snap names? We asked the repository itself to resolve the list of affected connections for us, so we already have it at hand are actually handing it in. Feels strange to get this list out from this function.

@zyga

zyga Oct 3, 2016

Contributor

You are right, we don't have to get this back from the function. I was just transcribing things mechanically. I'll get rid of it and move the relevant logic to ifacestate where we actually need it.

@zyga

zyga Oct 4, 2016

Contributor

Also simplified

zyga added some commits Oct 4, 2016

interfaces: drop unlocked version of ResolveDisconnectAll
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
interfaces: don't return anything from DisconnctAll
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
interfaces: tweak documentation
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
interfaces: fix typo
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
interfaces: drop wildcard mode on repo.Connected
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
interfaces: tweak error test
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
interfaces: simplify and tweak disconnect methods and tests
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
overlord/interfaces: use new Disconnect/DisconnectAll
This patch changes the interface manager to use the new APIs offered by
interfaces.Repository for disconnecting. In particular we no longer
obtain snap.Info of the affected snaps from the repository (which can
contain stale data). Instead we use the snapstate to fetch the current
info).

In addition of the fully-spelled-out "disconnect snap:plug snap:slot" we
now correctly support "disconnect snap:plug" or "disconnect snap:slot".
In those two new forms the snap name can be empty (it then defaults to
the core snap). This is thanks to the use of the new DisconnectAll
method.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
overlord/ifacestate: add more disconnect tests
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
daemon: adjust tests after message changes
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>

Looks good overall. One minor comment below about the strictness of snap/plug/snap/slot argument checking.

overlord/ifacestate/handlers.go
+ return err
+ }
+ affectedConns = []interfaces.ConnRef{{*plugRef, *slotRef}}
+ } else if plugRef.Name != "" {
@stolowski

stolowski Oct 4, 2016

Contributor

Should we try to explicitly list all the valid cases in the if/else clauses here? In this case for example user could provide plug name and slot snap name, hoping that this is going to narrow the effect of disconnect down, but in fact I think it would be silently ignored?

@zyga

zyga Oct 4, 2016

Contributor

This would result in an error from repo but I can easily make the test more obvious. I think you are also right since we are multiplexing to one of two functions depending on argument layout.

Done, have a look please.

zyga added some commits Oct 4, 2016

interfaces: be extra paranoid about disconnect dispatch
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
overlord/ifacestate: return {Plug,Slot}Ref by value
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Contributor

stolowski commented Oct 4, 2016

LGTM. +1

Merging, but would be good to sort a few trivials later:

-
-Disconnects all plugs from the provided snap.
+Disconnects everything from the provided plug or slot.
+The snap name may be omitted for the OS snap.
@niemeyer

niemeyer Oct 4, 2016

Contributor

s/OS snap/core snap/

-
-Disconnects all plugs from the provided snap.
+Disconnects everything from the provided plug or slot.
+The snap name may be omitted for the OS snap.
@niemeyer

niemeyer Oct 4, 2016

Contributor

s/OS snap/core snap/

+ case r.slots["ubuntu-core"] != nil:
+ snapName = "ubuntu-core"
+ default:
+ return nil, fmt.Errorf("cannot resolve disconnect, snap name is empty")
@niemeyer

niemeyer Oct 4, 2016

Contributor

s/cannot resolve disconnect, // (not a disconnection in this context)

+ }
+ var conns []ConnRef
+ if plugOrSlotName == "" {
+ return nil, fmt.Errorf("cannot resolve disconnect, plug or slot name is empty")
@niemeyer

niemeyer Oct 4, 2016

Contributor

s/cannot resolve disconnect, //

@niemeyer niemeyer merged commit b64b2ae into snapcore:master Oct 4, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@zyga zyga deleted the zyga:disconnect-short-form branch Oct 4, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment