Browse Source

Add ETHTOOL_OPTS support for LinuxBond class

LinuxBonding accepts ETHTOOL_OPTS.
This commit adds ETHTOOL_OPTS support for LinuxBond class.

Closes-bug: 1837764
Change-Id: I85fc4a617532bf8ebd19f54dc87f49b5a2e3810f
(cherry picked from commit 35fc5d66ab)
tags/8.5.1
Keigo Noha 2 months ago
parent
commit
2aa173d975

+ 4
- 2
os_net_config/objects.py View File

@@ -965,7 +965,7 @@ class LinuxBond(_BaseOpts):
965 965
                  members=None, bonding_options=None, nic_mapping=None,
966 966
                  persist_mapping=False, defroute=True, dhclient_args=None,
967 967
                  dns_servers=None, nm_controlled=False, onboot=True,
968
-                 domain=None):
968
+                 domain=None, ethtool_opts=None):
969 969
         addresses = addresses or []
970 970
         routes = routes or []
971 971
         rules = rules or []
@@ -978,6 +978,7 @@ class LinuxBond(_BaseOpts):
978 978
                                         nm_controlled, onboot, domain)
979 979
         self.members = members
980 980
         self.bonding_options = bonding_options
981
+        self.ethtool_opts = ethtool_opts
981 982
         for member in self.members:
982 983
             if isinstance(member, SriovVF):
983 984
                 LinuxBond.update_vf_config(member)
@@ -1019,6 +1020,7 @@ class LinuxBond(_BaseOpts):
1019 1020
          onboot, domain) = _BaseOpts.base_opts_from_json(
1020 1021
              json, include_primary=False)
1021 1022
         bonding_options = json.get('bonding_options')
1023
+        ethtool_opts = json.get('ethtool_opts', None)
1022 1024
 
1023 1025
         members = _update_members(json, nic_mapping, persist_mapping)
1024 1026
 
@@ -1030,7 +1032,7 @@ class LinuxBond(_BaseOpts):
1030 1032
                          persist_mapping=persist_mapping, defroute=defroute,
1031 1033
                          dhclient_args=dhclient_args, dns_servers=dns_servers,
1032 1034
                          nm_controlled=nm_controlled, onboot=onboot,
1033
-                         domain=domain)
1035
+                         domain=domain, ethtool_opts=ethtool_opts)
1034 1036
 
1035 1037
 
1036 1038
 class OvsBond(_BaseOpts):

+ 2
- 0
os_net_config/schema.yaml View File

@@ -1162,6 +1162,8 @@ definitions:
1162 1162
                 $ref: "#/definitions/bool_or_param"
1163 1163
             domain:
1164 1164
                 $ref: "#/definitions/list_of_domain_name_string_or_domain_name_string"
1165
+            ethtool_opts:
1166
+                $ref: "#/definitions/string_or_param"
1165 1167
         required:
1166 1168
           - type
1167 1169
           - name

+ 25
- 0
os_net_config/tests/test_impl_ifcfg.py View File

@@ -1204,6 +1204,31 @@ ETHTOOL_OPTS=\"speed 1000 duplex full\"
1204 1204
                              "ETHTOOL_OPTS=\"speed 1000 duplex full\"\n"))
1205 1205
         self.assertEqual(ib_config, self.get_interface_config('ib0'))
1206 1206
 
1207
+    def test_linux_bond_with_ethtool_opts(self):
1208
+        interface1 = objects.Interface(
1209
+            'em1',
1210
+            ethtool_opts='-K ${DEVICE} tx-gre-csum-segmentation off')
1211
+        interface2 = objects.Interface(
1212
+            'em2',
1213
+            ethtool_opts='-K ${DEVICE} tx-gre-csum-segmentation off')
1214
+        bond = objects.LinuxBond(
1215
+            'bond0', use_dhcp=True,
1216
+            members=[interface1, interface2],
1217
+            ethtool_opts='-K ${DEVICE} tx-gre-csum-segmentation off')
1218
+        self.provider.add_linux_bond(bond)
1219
+        self.provider.add_interface(interface1)
1220
+        self.provider.add_interface(interface2)
1221
+        bond_config = "".join(
1222
+            (_LINUX_BOND_DHCP,
1223
+             "ETHTOOL_OPTS=\"-K ${DEVICE} tx-gre-csum-segmentation off\"\n"))
1224
+        interface_config = "".join(
1225
+            (_LINUX_BOND_INTERFACE,
1226
+             "ETHTOOL_OPTS=\"-K ${DEVICE} tx-gre-csum-segmentation off\"\n"))
1227
+        self.assertEqual(bond_config,
1228
+                         self.get_linux_bond_config('bond0'))
1229
+        self.assertEqual(interface_config,
1230
+                         self.get_interface_config('em1'))
1231
+
1207 1232
     def test_interface_single_dns_server(self):
1208 1233
         interface1 = objects.Interface('em1', dns_servers=['1.2.3.4'])
1209 1234
         self.provider.add_interface(interface1)

+ 44
- 10
os_net_config/tests/test_objects.py View File

@@ -1104,12 +1104,13 @@ class TestLinuxBond(base.TestCase):
1104 1104
 ]
1105 1105
 }
1106 1106
 """
1107
-        bridge = objects.object_from_json(json.loads(data))
1108
-        self.assertEqual("bond1", bridge.name)
1109
-        self.assertTrue(bridge.use_dhcp)
1110
-        interface1 = bridge.members[0]
1107
+        bond = objects.object_from_json(json.loads(data))
1108
+        self.assertEqual("bond1", bond.name)
1109
+        self.assertTrue(bond.use_dhcp)
1110
+        self.assertIsNone(bond.ethtool_opts)
1111
+        interface1 = bond.members[0]
1111 1112
         self.assertEqual("em1", interface1.name)
1112
-        interface2 = bridge.members[1]
1113
+        interface2 = bond.members[1]
1113 1114
         self.assertEqual("em2", interface2.name)
1114 1115
 
1115 1116
     def test_from_json_dhcp_with_nic1_nic2(self):
@@ -1134,12 +1135,12 @@ class TestLinuxBond(base.TestCase):
1134 1135
 ]
1135 1136
 }
1136 1137
 """
1137
-        bridge = objects.object_from_json(json.loads(data))
1138
-        self.assertEqual("bond1", bridge.name)
1139
-        self.assertTrue(bridge.use_dhcp)
1140
-        interface1 = bridge.members[0]
1138
+        bond = objects.object_from_json(json.loads(data))
1139
+        self.assertEqual("bond1", bond.name)
1140
+        self.assertTrue(bond.use_dhcp)
1141
+        interface1 = bond.members[0]
1141 1142
         self.assertEqual("em1", interface1.name)
1142
-        interface2 = bridge.members[1]
1143
+        interface2 = bond.members[1]
1143 1144
         self.assertEqual("em2", interface2.name)
1144 1145
 
1145 1146
     def test_linux_bond_with_vf_default(self):
@@ -1241,6 +1242,39 @@ class TestLinuxBond(base.TestCase):
1241 1242
         vf_map = yaml.safe_load(contents) if contents else []
1242 1243
         self.assertListEqual(vf_final, vf_map)
1243 1244
 
1245
+    def test_linux_bond_with_ethtool_opts(self):
1246
+        data = """{
1247
+"type": "linux_bond",
1248
+"name": "bond1",
1249
+"use_dhcp": true,
1250
+"ethtool_opts": "-K ${DEVICE} tx-gre-csum-segmentation off",
1251
+"members": [
1252
+    {
1253
+    "type": "interface",
1254
+    "name": "em1",
1255
+    "ethtool_opts": "-K ${DEVICE} tx-gre-csum-segmentation off"
1256
+    },
1257
+    {
1258
+    "type": "interface",
1259
+    "name": "em2",
1260
+    "ethtool_opts": "-K ${DEVICE} tx-gre-csum-segmentation off"
1261
+    }
1262
+]
1263
+}
1264
+"""
1265
+        bond = objects.object_from_json(json.loads(data))
1266
+        self.assertEqual("bond1", bond.name)
1267
+        self.assertEqual("-K ${DEVICE} tx-gre-csum-segmentation off",
1268
+                         bond.ethtool_opts)
1269
+        interface1 = bond.members[0]
1270
+        interface2 = bond.members[1]
1271
+        self.assertEqual("em1", interface1.name)
1272
+        self.assertEqual("em2", interface2.name)
1273
+        self.assertEqual("-K ${DEVICE} tx-gre-csum-segmentation off",
1274
+                         interface1.ethtool_opts)
1275
+        self.assertEqual("-K ${DEVICE} tx-gre-csum-segmentation off",
1276
+                         interface2.ethtool_opts)
1277
+
1244 1278
 
1245 1279
 class TestOvsTunnel(base.TestCase):
1246 1280
 

Loading…
Cancel
Save