Bug 1454883

Summary: [RFE] extend D-Bus API to better export active connection state
Product: Red Hat Enterprise Linux 7 Reporter: Thomas Haller <thaller>
Component: NetworkManagerAssignee: Thomas Haller <thaller>
Status: CLOSED ERRATA QA Contact: Desktop QE <desktop-qa-list>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.5CC: aloughla, atragler, bgalvani, fgiudici, lrintel, rkhan, sukulkar, thaller, vbenes
Target Milestone: rcKeywords: FutureFeature
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-04-10 13:24:24 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1470965    

Description Thomas Haller 2017-05-23 16:54:34 UTC
When a connection in NM activates, this is tracked via the active-connection [1]

[1] https://developer.gnome.org/NetworkManager/unstable/gdbus-org.freedesktop.NetworkManager.Connection.Active.html


`nmcli connection up "$CONN"` has a --wait option (that defaults to 90 seconds). That means, nmcli will wait until the connection is fully activated.


The concept of what it means to be fully activated has many aspects. E.g. is IPv4 ready? IPv6? Is the layer2 up? Is the master activated but waiting for slaves?


For that reason, nmcli not only monitors the active-connection state, but also considers the device-state [2]

[2] https://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/clients/cli/connections.c?id=9c3df9caa3296a55fe54e6aa02fe8a11b27deaba#n2199



For a client, it should be sufficient to monitor only the active-connection option to decide whether a device is activted. For that, we should add a "StateFlags" argument, with flags like:

   NM_ACTIVATION_STATE_FLAG_LAYER2_READY,
   NM_ACTIVATION_STATE_FLAG_IP4_READY,
   NM_ACTIVATION_STATE_FLAG_DHCP4_READY,
   NM_ACTIVATION_STATE_FLAG_IP6_READY,
   NM_ACTIVATION_STATE_FLAG_DHCP6_READY,
   NM_ACTIVATION_STATE_FLAG_AUTO6_READY,
   NM_ACTIVATION_STATE_FLAG_MASTER_READY,
   NM_ACTIVATION_STATE_FLAG_MASTER_HAS_SLAVES,



with these flags, nmcli would wait until
  - state reaches NM_ACTIVE_CONNECTION_STATE_ACTIVATED
  - or, state-flags have NM_ACTIVATION_STATE_FLAG_MASTER_READY
    -- but possibly: if NM_ACTIVATION_STATE_FLAG_MASTER_HAS_SLAVES is set too, 
       we would wait for the device to reach     
       state=NM_ACTIVE_CONNECTION_STATE_ACTIVATED.

Comment 2 Thomas Haller 2017-10-02 12:27:38 UTC
pleas review th/activation-state-flags-rh1454883

Comment 3 Beniamino Galvani 2017-10-03 12:27:44 UTC
(In reply to Thomas Haller from comment #2)
> pleas review th/activation-state-flags-rh1454883

Looks good to me.

Comment 4 Francesco Giudici 2017-10-04 17:04:10 UTC
@@ -1219,17 +1241,25 @@ constructed (GObject *object)

        G_OBJECT_CLASS (nm_active_connection_parent_class)->constructed (object);

-       if (!priv->applied_connection && priv->settings_connection)
+       if (   !priv->applied_connection
+           && priv->settings_connection)
                priv->applied_connection = nm_simple_connection_new_clone (NM_CONNECTION (priv->settings_connection));

-       if (priv->applied_connection)
-               nm_connection_clear_secrets (priv->applied_connection);
-
        _LOGD ("constructed (%s, version-id %llu, type %s)",
               G_OBJECT_TYPE_NAME (self),
               (unsigned long long) priv->version_id,
               nm_activation_type_to_string (priv->activation_type));

+       if (priv->applied_connection) {
+               /* priv->applied_connection was set during the construction of the object.
+                * It's not yet fully initialized, so do that now.
+                *
+                * We delayed that, because we may log in _set_applied_connection_take(), and the
+                * first logging line should be "constructed" above). */
+               _set_applied_connection_take (self,
+                                             g_steal_pointer (&priv->applied_connection));

If we call the constructed method and priv->applied_connection is already set, we will end failing _set_applied_connection_take as it does:
nm_assert (!priv->applied_connection);

rest looks good

Comment 5 Francesco Giudici 2017-10-05 09:49:01 UTC
(In reply to Francesco Giudici from comment #4)
> @@ -1219,17 +1241,25 @@ constructed (GObject *object)
> 
> [...]
> +                                    g_steal_pointer (&priv->applied_connection));

I was wrong: there is a g_steal_pointer there, so the assert in _set_applied_connection_take will be true.
Sorry.

Branch lgtm

Comment 8 Vladimir Benes 2018-01-22 15:46:44 UTC
Automated checks added for bond master/slave and ethernet devices. Will be executed on a daily bases.

Comment 9 Vladimir Benes 2018-01-25 09:15:56 UTC
Automated for CI, working well in 7.5 for both bond master/slave and ethernet devices.

Comment 12 errata-xmlrpc 2018-04-10 13:24:24 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2018:0778