Blob Blame History Raw
From 83a9a81c38463c66ad512aacccfe627aa2b5a17e Mon Sep 17 00:00:00 2001
From: Fernando Fernandez Mancera <ffmancera@riseup.net>
Date: Tue, 23 Jun 2020 10:18:51 +0200
Subject: [PATCH 1/3] base_iface: rename iface_type property to type

In order to follow the property naming, it makes sense to rename
"iface_type" property to "type".

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
Signed-off-by: Gris Ge <fge@redhat.com>
---
 libnmstate/ifaces/base_iface.py            | 4 ++--
 libnmstate/ifaces/ifaces.py                | 9 ++++-----
 libnmstate/ifaces/ovs.py                   | 4 ++--
 libnmstate/plugins/nmstate_plugin_ovsdb.py | 4 ++--
 4 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/libnmstate/ifaces/base_iface.py b/libnmstate/ifaces/base_iface.py
index 56a1115..6c55f6a 100644
--- a/libnmstate/ifaces/base_iface.py
+++ b/libnmstate/ifaces/base_iface.py
@@ -152,7 +152,7 @@ class BaseIface:
         return self._name
 
     @property
-    def iface_type(self):
+    def type(self):
         return self._info.get(Interface.TYPE, InterfaceType.UNKNOWN)
 
     @property
@@ -285,7 +285,7 @@ class BaseIface:
         if self.is_master and not self.is_absent:
             for slave_name in self.slaves:
                 slave_iface = ifaces[slave_name]
-                slave_iface.set_master(self.name, self.iface_type)
+                slave_iface.set_master(self.name, self.type)
 
     def update(self, info):
         self._info.update(info)
diff --git a/libnmstate/ifaces/ifaces.py b/libnmstate/ifaces/ifaces.py
index 9c254ac..e85123c 100644
--- a/libnmstate/ifaces/ifaces.py
+++ b/libnmstate/ifaces/ifaces.py
@@ -74,7 +74,7 @@ class Ifaces:
 
                 if iface_info.get(Interface.TYPE) is None:
                     if cur_iface:
-                        iface_info[Interface.TYPE] = cur_iface.iface_type
+                        iface_info[Interface.TYPE] = cur_iface.type
                     elif iface.is_up:
                         raise NmstateValueError(
                             f"Interface {iface.name} has no type defined "
@@ -82,7 +82,7 @@ class Ifaces:
                         )
                 iface = _to_specific_iface_obj(iface_info, save_to_disk)
                 if (
-                    iface.iface_type == InterfaceType.UNKNOWN
+                    iface.type == InterfaceType.UNKNOWN
                     # Allowing deletion of down profiles
                     and not iface.is_absent
                 ):
@@ -147,7 +147,7 @@ class Ifaces:
         When OVS patch peer does not exist or is down, raise an error.
         """
         for iface in self._ifaces.values():
-            if iface.iface_type == InterfaceType.OVS_INTERFACE and iface.is_up:
+            if iface.type == InterfaceType.OVS_INTERFACE and iface.is_up:
                 if iface.peer:
                     peer_iface = self._ifaces.get(iface.peer)
                     if not peer_iface or not peer_iface.is_up:
@@ -156,8 +156,7 @@ class Ifaces:
                             "be up"
                         )
                     elif (
-                        not peer_iface.iface_type
-                        == InterfaceType.OVS_INTERFACE
+                        not peer_iface.type == InterfaceType.OVS_INTERFACE
                         or not peer_iface.is_patch_port
                     ):
                         raise NmstateValueError(
diff --git a/libnmstate/ifaces/ovs.py b/libnmstate/ifaces/ovs.py
index 0a5abe9..cd04cef 100644
--- a/libnmstate/ifaces/ovs.py
+++ b/libnmstate/ifaces/ovs.py
@@ -84,7 +84,7 @@ class OvsBridgeIface(BridgeIface):
             slave_iface.update(
                 {BridgeIface.BRPORT_OPTIONS_METADATA: port_config}
             )
-            if slave_iface.iface_type == InterfaceType.OVS_INTERFACE:
+            if slave_iface.type == InterfaceType.OVS_INTERFACE:
                 slave_iface.parent = self.name
         super().gen_metadata(ifaces)
 
@@ -101,7 +101,7 @@ class OvsBridgeIface(BridgeIface):
             }
         )
         slave_iface.mark_as_changed()
-        slave_iface.set_master(self.name, self.iface_type)
+        slave_iface.set_master(self.name, self.type)
         slave_iface.parent = self.name
         return slave_iface
 
diff --git a/libnmstate/plugins/nmstate_plugin_ovsdb.py b/libnmstate/plugins/nmstate_plugin_ovsdb.py
index a0cfbc0..83965e1 100644
--- a/libnmstate/plugins/nmstate_plugin_ovsdb.py
+++ b/libnmstate/plugins/nmstate_plugin_ovsdb.py
@@ -168,9 +168,9 @@ class NmstateOvsdbPlugin(NmstatePlugin):
                 continue
             if not iface.is_up:
                 continue
-            if iface.iface_type == OVSBridge.TYPE:
+            if iface.type == OVSBridge.TYPE:
                 table_name = "Bridge"
-            elif iface.iface_type == OVSInterface.TYPE:
+            elif iface.type == OVSInterface.TYPE:
                 table_name = "Interface"
             else:
                 continue
-- 
2.27.0


From 80a0a200fc198d9f2f31cfa67fbd3d2c776256df Mon Sep 17 00:00:00 2001
From: Adwait Thattey <coderdude1999@gmail.com>
Date: Thu, 18 Jun 2020 23:11:33 +0530
Subject: [PATCH 2/3] iface: add setter method for mtu of interface

Signed-off-by: Adwait Thattey <coderdude1999@gmail.com>
Signed-off-by: Gris Ge <fge@redhat.com>
---
 libnmstate/ifaces/base_iface.py | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libnmstate/ifaces/base_iface.py b/libnmstate/ifaces/base_iface.py
index 6c55f6a..edccb1f 100644
--- a/libnmstate/ifaces/base_iface.py
+++ b/libnmstate/ifaces/base_iface.py
@@ -298,6 +298,10 @@ class BaseIface:
     def mtu(self):
         return self._info.get(Interface.MTU)
 
+    @mtu.setter
+    def mtu(self, value):
+        self._info[Interface.MTU] = value
+
     def _capitalize_mac(self):
         if self.mac:
             self._info[Interface.MAC] = self.mac.upper()
-- 
2.27.0


From 60ef20b6b4a4cd76b47b5fa8f989eee2ca2608fd Mon Sep 17 00:00:00 2001
From: Adwait Thattey <coderdude1999@gmail.com>
Date: Thu, 18 Jun 2020 23:58:11 +0530
Subject: [PATCH 3/3] vlan: validate mtu not greater than base iface

A new validator is added that verifies that the
MTU of VLAN/VXLAN is not more than MTU of base iface

If base iface MTU doesn't exist, set as vlan MTU

Multiple tests are added to check if appropriate errors are thrown

Signed-off-by: Adwait Thattey <coderdude1999@gmail.com>
Signed-off-by: Gris Ge <fge@redhat.com>
---
 libnmstate/ifaces/ifaces.py | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/libnmstate/ifaces/ifaces.py b/libnmstate/ifaces/ifaces.py
index e85123c..c216dd8 100644
--- a/libnmstate/ifaces/ifaces.py
+++ b/libnmstate/ifaces/ifaces.py
@@ -123,6 +123,7 @@ class Ifaces:
 
     def _pre_edit_validation_and_cleanup(self):
         self._validate_over_booked_slaves()
+        self._validate_vlan_mtu()
         self._handle_master_slave_list_change()
         self._match_child_iface_state_with_parent()
         self._mark_orphen_as_absent()
@@ -164,6 +165,31 @@ class Ifaces:
                             " patch port"
                         )
 
+    def _validate_vlan_mtu(self):
+        """
+        Validate that mtu of vlan or vxlan is less than
+        or equal to it's base interface's MTU
+
+        If base MTU is not present, set same as vlan MTU
+        """
+        for iface in self._ifaces.values():
+
+            if (
+                iface.type in [InterfaceType.VLAN, InterfaceType.VXLAN]
+                and iface.is_up
+                and iface.mtu
+            ):
+                base_iface = self._ifaces.get(iface.parent)
+                if not base_iface.mtu:
+                    base_iface.mtu = iface.mtu
+                if iface.mtu > base_iface.mtu:
+                    raise NmstateValueError(
+                        f"Interface {iface.name} has bigger "
+                        f"MTU({iface.mtu}) "
+                        f"than its base interface: {iface.parent} "
+                        f"MTU({base_iface.mtu})"
+                    )
+
     def _handle_master_slave_list_change(self):
         """
          * Mark slave interface as changed if master removed.
-- 
2.27.0