From 95d77329b30c9a9a435a881941e27f9a1bed074e Mon Sep 17 00:00:00 2001 From: Fernando Fernandez Mancera Date: Wed, 5 May 2021 10:14:40 +0200 Subject: [PATCH 1/2] nm.profile: do not activate new interfaces twice The current code is always adding the action MODIFIED if the interface is marked as up on the desired state. When a new interface is being added, Nmstate is adding two actions MODIFIED and NEW_*, that is incorrect. This patch is improving the performance when creating new interfaces. Signed-off-by: Fernando Fernandez Mancera Signed-off-by: Gris Ge --- libnmstate/nm/profile.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libnmstate/nm/profile.py b/libnmstate/nm/profile.py index b4814d9..e117dfe 100644 --- a/libnmstate/nm/profile.py +++ b/libnmstate/nm/profile.py @@ -164,7 +164,6 @@ class NmProfile: if self._iface.is_virtual and self._nm_dev: self._add_action(NmProfile.ACTION_DELETE_DEVICE) elif self._iface.is_up and not self._needs_veth_activation(): - self._add_action(NmProfile.ACTION_MODIFIED) if not self._nm_dev: if self._iface.type == InterfaceType.OVS_PORT: self._add_action(NmProfile.ACTION_NEW_OVS_PORT) @@ -176,6 +175,8 @@ class NmProfile: self._add_action(NmProfile.ACTION_NEW_VXLAN) else: self._add_action(NmProfile.ACTION_NEW_IFACES) + else: + self._add_action(NmProfile.ACTION_MODIFIED) elif self._iface.is_down: if self._nm_ac: -- 2.31.1 From 9ea925a9a978671881e428abf82aac39c01376e8 Mon Sep 17 00:00:00 2001 From: Fernando Fernandez Mancera Date: Wed, 5 May 2021 10:52:32 +0200 Subject: [PATCH 2/2] nm.profile: activate modified ovs-port first When removing an ovs-br with an ovs-iface attached and creating a new ovs-br with the ovs-iface attached in the same transaction the order of the activations is important. The ovs-port must be activated before the ovs-iface. If not, NM will throw a dependency error. This error is correct because the ovs-iface depends on the ovs-port, so it must be updated first. This fixes: ``` Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/libnmstate/nm/checkpoint.py", line 93, in _refresh_checkpoint_timeout self._dbuspath, self._timeout, cancellable, cb, cb_data TypeError: Argument 1 does not allow None as a value ^CTraceback (most recent call last): File "/usr/lib/python3.6/site-packages/libnmstate/nmstate.py", line 53, in plugin_context yield plugins File "/usr/lib/python3.6/site-packages/libnmstate/netapplier.py", line 78, in apply _apply_ifaces_state(plugins, net_state, verify_change, save_to_disk) File "/usr/lib/python3.6/site-packages/libnmstate/netapplier.py", line 116, in _apply_ifaces_state plugin.apply_changes(net_state, save_to_disk) File "/usr/lib/python3.6/site-packages/libnmstate/nm/plugin.py", line 204, in apply_changes NmProfiles(self.context).apply_config(net_state, save_to_disk) File "/usr/lib/python3.6/site-packages/libnmstate/nm/profiles.py", line 89, in apply_config self._ctx.wait_all_finish() File "/usr/lib/python3.6/site-packages/libnmstate/nm/context.py", line 213, in wait_all_finish raise tmp_error libnmstate.error.NmstateLibnmError: Activate profile uuid:3a359cd0-d68a-4c7a-ae50-f97b47390142 iface:net type: ovs-interface failed: reason= ``` Integration test added Ref: https://bugzilla.redhat.com/1947287 Signed-off-by: Fernando Fernandez Mancera Signed-off-by: Gris Ge --- libnmstate/nm/profile.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/libnmstate/nm/profile.py b/libnmstate/nm/profile.py index e117dfe..b655885 100644 --- a/libnmstate/nm/profile.py +++ b/libnmstate/nm/profile.py @@ -69,6 +69,8 @@ class NmProfile: ACTION_OTHER_MASTER = "other_master" ACTION_DELETE_PROFILE = "delete_profile" ACTION_TOP_MASTER = "top_master" + ACTION_MODIFIED_OVS_PORT = "modified_ovs_port" + ACTION_MODIFIED_OVS_IFACE = "modified_ovs_iface" # This is order on group for activation/deactivation ACTIONS = ( @@ -81,6 +83,8 @@ class NmProfile: ACTION_NEW_OVS_IFACE, ACTION_NEW_VETH, ACTION_NEW_VETH_PEER, + ACTION_MODIFIED_OVS_PORT, + ACTION_MODIFIED_OVS_IFACE, ACTION_MODIFIED, ACTION_NEW_VLAN, ACTION_NEW_VXLAN, @@ -176,7 +180,12 @@ class NmProfile: else: self._add_action(NmProfile.ACTION_NEW_IFACES) else: - self._add_action(NmProfile.ACTION_MODIFIED) + if self._iface.type == InterfaceType.OVS_PORT: + self._add_action(NmProfile.ACTION_MODIFIED_OVS_PORT) + if self._iface.type == InterfaceType.OVS_INTERFACE: + self._add_action(NmProfile.ACTION_MODIFIED_OVS_IFACE) + else: + self._add_action(NmProfile.ACTION_MODIFIED) elif self._iface.is_down: if self._nm_ac: @@ -420,6 +429,8 @@ class NmProfile: def do_action(self, action): if action in ( NmProfile.ACTION_MODIFIED, + NmProfile.ACTION_MODIFIED_OVS_PORT, + NmProfile.ACTION_MODIFIED_OVS_IFACE, NmProfile.ACTION_ACTIVATE_FIRST, NmProfile.ACTION_TOP_MASTER, NmProfile.ACTION_NEW_IFACES, -- 2.31.1