Blame SOURCES/BZ_1740584-Ignore-not-active-failure-when-deactivate.patch

245567
From 6334eb32df01326b85ca6cd589a5ea91117189e6 Mon Sep 17 00:00:00 2001
245567
From: Gris Ge <fge@redhat.com>
245567
Date: Fri, 9 Aug 2019 13:26:02 +0800
245567
Subject: [PATCH] nm: Ignore not active failure when deactivate
245567
245567
Ignore the failure:
245567
245567
    Connection deactivation failed on nm2: error=nm-manager-error-quark: The
245567
    connection was not active.
245567
245567
Even we check activate connection status before deactivating, there is
245567
still a small chance that NM deactivated the connection after we
245567
checked.
245567
245567
This patch also fix the random failure of
245567
`test_add_bond_with_slaves_and_ipv4` test when tear down:
245567
245567
 * The tear down will delete bond99 and eth1/eth2.
245567
 * After bond99 got deleted, the connections of eth1/eth2 will be
245567
   brought down automatically by NM.
245567
 * There is a small chance(about 1 out of 10) to trigger the problem of
245567
   deactivating a non-active connection.
245567
245567
Signed-off-by: Gris Ge <fge@redhat.com>
245567
---
245567
 libnmstate/nm/active_connection.py     | 27 +++++++++++++++++++-----
245567
 tests/lib/nm/active_connection_test.py | 29 ++++++++++++++++++++++++++
245567
 2 files changed, 51 insertions(+), 5 deletions(-)
245567
 create mode 100644 tests/lib/nm/active_connection_test.py
245567
245567
diff --git a/libnmstate/nm/active_connection.py b/libnmstate/nm/active_connection.py
245567
index 81ec9b5..28a89d5 100644
245567
--- a/libnmstate/nm/active_connection.py
245567
+++ b/libnmstate/nm/active_connection.py
245567
@@ -20,6 +20,11 @@
245567
 import logging
245567
 
245567
 from . import nmclient
245567
+from .nmclient import GLib
245567
+from .nmclient import NM
245567
+
245567
+
245567
+NM_MANAGER_ERROR_DOMAIN = 'nm-manager-error-quark'
245567
 
245567
 
245567
 class AlternativeACState(object):
245567
@@ -96,12 +101,24 @@ class ActiveConnection(object):
245567
                     e,
245567
                 )
245567
             else:
245567
-                self._mainloop.quit(
245567
-                    'Connection deactivation failed on {}: error={}'.format(
245567
-                        self._nmdev.get_iface(), e
245567
+                if (
245567
+                    isinstance(e, GLib.GError)
245567
+                    # pylint: disable=no-member
245567
+                    and e.domain == NM_MANAGER_ERROR_DOMAIN
245567
+                    and e.code == NM.ManagerError.CONNECTIONNOTACTIVE
245567
+                    # pylint: enable=no-member
245567
+                ):
245567
+                    success = True
245567
+                    logging.debug(
245567
+                        'Connection is not active on {}, no need to '
245567
+                        'deactivate'.format(self.devname)
245567
                     )
245567
-                )
245567
-            return
245567
+                else:
245567
+                    self._mainloop.quit(
245567
+                        'Connection deactivation failed on {}: '
245567
+                        'error={}'.format(self._nmdev.get_iface(), e)
245567
+                    )
245567
+                    return
245567
 
245567
         if success:
245567
             logging.debug(
245567
diff --git a/tests/lib/nm/active_connection_test.py b/tests/lib/nm/active_connection_test.py
245567
new file mode 100644
245567
index 0000000..5bd6d66
245567
--- /dev/null
245567
+++ b/tests/lib/nm/active_connection_test.py
245567
@@ -0,0 +1,29 @@
245567
+#
245567
+# Copyright (c) 2019 Red Hat, Inc.
245567
+#
245567
+# This file is part of nmstate
245567
+#
245567
+# This program is free software: you can redistribute it and/or modify
245567
+# it under the terms of the GNU Lesser General Public License as published by
245567
+# the Free Software Foundation, either version 2.1 of the License, or
245567
+# (at your option) any later version.
245567
+#
245567
+# This program is distributed in the hope that it will be useful,
245567
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
245567
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
245567
+# GNU Lesser General Public License for more details.
245567
+#
245567
+# You should have received a copy of the GNU Lesser General Public License
245567
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
245567
+#
245567
+
245567
+from libnmstate.nm.nmclient import NM
245567
+from libnmstate.nm.nmclient import GLib
245567
+
245567
+from libnmstate.nm.active_connection import NM_MANAGER_ERROR_DOMAIN
245567
+
245567
+
245567
+def test_nm_manager_error_domain_str():
245567
+    assert NM_MANAGER_ERROR_DOMAIN == GLib.quark_to_string(
245567
+        NM.ManagerError.quark()
245567
+    )
245567
-- 
245567
2.22.0
245567