Blame SOURCES/BZ_1931784-SR-IOV-fail-on-verification-if-total_vfs-does-not-ma.patch

520691
From a43609607abe30b973f1cb78cb1754f1a9a91514 Mon Sep 17 00:00:00 2001
520691
From: Fernando Fernandez Mancera <ffmancera@riseup.net>
520691
Date: Mon, 22 Feb 2021 13:33:06 +0100
520691
Subject: [PATCH 4/5] SR-IOV: fail on verification if `total_vfs` does not
520691
 match vfs len
520691
520691
Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
520691
---
520691
 libnmstate/ifaces/ethernet.py | 11 +++++++++++
520691
 libnmstate/ifaces/ifaces.py   | 17 +++++++++++++++++
520691
 2 files changed, 28 insertions(+)
520691
520691
diff --git a/libnmstate/ifaces/ethernet.py b/libnmstate/ifaces/ethernet.py
520691
index 1c3ca266..4903bde7 100644
520691
--- a/libnmstate/ifaces/ethernet.py
520691
+++ b/libnmstate/ifaces/ethernet.py
520691
@@ -52,6 +52,14 @@ class EthernetIface(BaseIface):
520691
         _capitalize_sriov_vf_mac(state)
520691
         return state
520691
 
520691
+    @property
520691
+    def sriov_vfs(self):
520691
+        return (
520691
+            self.raw.get(Ethernet.CONFIG_SUBTREE, {})
520691
+            .get(Ethernet.SRIOV_SUBTREE, {})
520691
+            .get(Ethernet.SRIOV.VFS_SUBTREE, {})
520691
+        )
520691
+
520691
     @property
520691
     def sriov_total_vfs(self):
520691
         return (
520691
@@ -109,6 +117,9 @@ class EthernetIface(BaseIface):
520691
             for i in range(self.sriov_total_vfs, old_sriov_total_vfs)
520691
         ]
520691
 
520691
+    def check_total_vfs_matches_vf_list(self, total_vfs):
520691
+        return total_vfs == len(self.sriov_vfs)
520691
+
520691
 
520691
 def _capitalize_sriov_vf_mac(state):
520691
     vfs = (
520691
diff --git a/libnmstate/ifaces/ifaces.py b/libnmstate/ifaces/ifaces.py
520691
index b212ebb5..1d30d0c6 100644
520691
--- a/libnmstate/ifaces/ifaces.py
520691
+++ b/libnmstate/ifaces/ifaces.py
520691
@@ -146,6 +146,11 @@ class Ifaces:
520691
                         new_iface.mark_as_desired()
520691
                         new_iface.mark_as_new_sr_iov_vf()
520691
                         new_ifaces.append(new_iface)
520691
+                    else:
520691
+                        # When the VFs are being modified, all VFs link are
520691
+                        # being removed from kernel and created again. Nmstate
520691
+                        # must verify they have been created.
520691
+                        self._ifaces[new_iface.name].mark_as_desired()
520691
         for new_iface in new_ifaces:
520691
             self._ifaces[new_iface.name] = new_iface
520691
 
520691
@@ -403,6 +408,18 @@ class Ifaces:
520691
                                 cur_iface.state_for_verify(),
520691
                             )
520691
                         )
520691
+                    elif (
520691
+                        iface.type == InterfaceType.ETHERNET and iface.is_sriov
520691
+                    ):
520691
+                        if not cur_iface.check_total_vfs_matches_vf_list(
520691
+                            iface.sriov_total_vfs
520691
+                        ):
520691
+                            raise NmstateVerificationError(
520691
+                                "The NIC exceeded the waiting time for "
520691
+                                "verification and it is failing because "
520691
+                                "the `total_vfs` does not match the VF "
520691
+                                "list length."
520691
+                            )
520691
 
520691
     def gen_dns_metadata(self, dns_state, route_state):
520691
         iface_metadata = dns_state.gen_metadata(self, route_state)
520691
-- 
520691
2.29.2
520691