aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre Blanc <pblanc@redhat.com>2016-11-02 08:55:54 -0400
committerPierre Blanc <pblanc@redhat.com>2016-11-11 13:06:36 -0500
commit469c0ab91ae550945eb4d0a18ebd284994fde384 (patch)
tree690eb1b487eb5e02324fc687b7935b6e0d00b82f
parent4fdb0a6a2b355750ae8071e53a74b9257b18eeee (diff)
Add support for ethtool_opts option
This patch add an optional option to specify the ETHTOOL_OPTS for each interface. ETHTOOL_OPTS option will be written to the ifcfg file. Change-Id: I6b594e89ba6b4c17e8df79def997f6c9ea427a3a
-rw-r--r--etc/os-net-config/samples/interface.json3
-rw-r--r--etc/os-net-config/samples/interface.yaml1
-rw-r--r--os_net_config/impl_ifcfg.py5
-rw-r--r--os_net_config/objects.py12
-rw-r--r--os_net_config/tests/test_impl_ifcfg.py15
-rw-r--r--os_net_config/tests/test_objects.py2
6 files changed, 33 insertions, 5 deletions
diff --git a/etc/os-net-config/samples/interface.json b/etc/os-net-config/samples/interface.json
index 9ae0b76..6eb8f62 100644
--- a/etc/os-net-config/samples/interface.json
+++ b/etc/os-net-config/samples/interface.json
@@ -25,7 +25,8 @@
"type": "interface",
"name": "em2",
"use_dhcp": true,
- "defroute": no
+ "defroute": no,
+ "ethtool_opts": "speed 1000 duplex full"
}
]
}
diff --git a/etc/os-net-config/samples/interface.yaml b/etc/os-net-config/samples/interface.yaml
index 6b366e2..725091b 100644
--- a/etc/os-net-config/samples/interface.yaml
+++ b/etc/os-net-config/samples/interface.yaml
@@ -20,3 +20,4 @@ network_config:
name: em2
use_dhcp: true
defroute: no
+ ethtool_opts: "speed 1000 duplex full"
diff --git a/os_net_config/impl_ifcfg.py b/os_net_config/impl_ifcfg.py
index 4a4caaa..e8dbd46 100644
--- a/os_net_config/impl_ifcfg.py
+++ b/os_net_config/impl_ifcfg.py
@@ -113,6 +113,8 @@ class IfcfgNetConfig(os_net_config.NetConfig):
data += "TYPE=NFVSWITCHIntPort\n"
elif isinstance(base_opt, objects.IbInterface):
data += "TYPE=Infiniband\n"
+ if base_opt.ethtool_opts:
+ data += "ETHTOOL_OPTS=\"%s\"\n" % base_opt.ethtool_opts
elif re.match('\w+\.\d+$', base_opt.name):
data += "VLAN=yes\n"
if base_opt.linux_bond_name:
@@ -262,6 +264,9 @@ class IfcfgNetConfig(os_net_config.NetConfig):
data += "BOOTPROTO=dhcp\n"
elif not base_opt.addresses:
data += "BOOTPROTO=none\n"
+ if isinstance(base_opt, objects.Interface):
+ if base_opt.ethtool_opts:
+ data += "ETHTOOL_OPTS=\"%s\"\n" % base_opt.ethtool_opts
if base_opt.mtu:
data += "MTU=%i\n" % base_opt.mtu
diff --git a/os_net_config/objects.py b/os_net_config/objects.py
index 0e5ce08..8d7ee4c 100644
--- a/os_net_config/objects.py
+++ b/os_net_config/objects.py
@@ -279,7 +279,7 @@ class Interface(_BaseOpts):
def __init__(self, name, use_dhcp=False, use_dhcpv6=False, addresses=None,
routes=None, mtu=None, primary=False, nic_mapping=None,
persist_mapping=False, defroute=True, dhclient_args=None,
- dns_servers=None):
+ dns_servers=None, ethtool_opts=None):
addresses = addresses or []
routes = routes or []
dns_servers = dns_servers or []
@@ -287,12 +287,14 @@ class Interface(_BaseOpts):
routes, mtu, primary, nic_mapping,
persist_mapping, defroute,
dhclient_args, dns_servers)
+ self.ethtool_opts = ethtool_opts
@staticmethod
def from_json(json):
name = _get_required_field(json, 'name', 'Interface')
opts = _BaseOpts.base_opts_from_json(json)
- return Interface(name, *opts)
+ ethtool_opts = json.get('ethtool_opts', None)
+ return Interface(name, *opts, ethtool_opts=ethtool_opts)
class Vlan(_BaseOpts):
@@ -931,7 +933,7 @@ class IbInterface(_BaseOpts):
def __init__(self, name, use_dhcp=False, use_dhcpv6=False, addresses=None,
routes=None, mtu=None, primary=False, nic_mapping=None,
persist_mapping=False, defroute=True, dhclient_args=None,
- dns_servers=None):
+ dns_servers=None, ethtool_opts=None):
addresses = addresses or []
routes = routes or []
dns_servers = dns_servers or []
@@ -939,12 +941,14 @@ class IbInterface(_BaseOpts):
addresses, routes, mtu, primary,
nic_mapping, persist_mapping,
defroute, dhclient_args, dns_servers)
+ self.ethtool_opts = ethtool_opts
@staticmethod
def from_json(json):
name = _get_required_field(json, 'name', 'IbInterface')
+ ethtool_opts = json.get('ethtool_opts', None)
opts = _BaseOpts.base_opts_from_json(json)
- return IbInterface(name, *opts)
+ return IbInterface(name, *opts, ethtool_opts=ethtool_opts)
class OvsDpdkPort(_BaseOpts):
diff --git a/os_net_config/tests/test_impl_ifcfg.py b/os_net_config/tests/test_impl_ifcfg.py
index 0c14418..2e79aa1 100644
--- a/os_net_config/tests/test_impl_ifcfg.py
+++ b/os_net_config/tests/test_impl_ifcfg.py
@@ -742,6 +742,21 @@ DHCLIENTARGS=--foobar
"""
self.assertEqual(em1_config, self.get_interface_config('em1'))
+ def test_interface_ethtool_opts(self):
+ interface1 = objects.Interface('em1',
+ ethtool_opts='speed 1000 duplex full')
+ self.provider.add_interface(interface1)
+ em1_config = """# This file is autogenerated by os-net-config
+DEVICE=em1
+ONBOOT=yes
+HOTPLUG=no
+NM_CONTROLLED=no
+PEERDNS=no
+BOOTPROTO=none
+ETHTOOL_OPTS=\"speed 1000 duplex full\"
+"""
+ self.assertEqual(em1_config, self.get_interface_config('em1'))
+
def test_interface_single_dns_server(self):
interface1 = objects.Interface('em1', dns_servers=['1.2.3.4'])
self.provider.add_interface(interface1)
diff --git a/os_net_config/tests/test_objects.py b/os_net_config/tests/test_objects.py
index 4c71265..3911ef3 100644
--- a/os_net_config/tests/test_objects.py
+++ b/os_net_config/tests/test_objects.py
@@ -150,6 +150,7 @@ class TestInterface(base.TestCase):
"name": "em1",
"use_dhcp": false,
"mtu": 1501,
+"ethtool_opts": "speed 1000 duplex full",
"addresses": [{
"ip_netmask": "192.0.2.1/24"
}],
@@ -165,6 +166,7 @@ class TestInterface(base.TestCase):
self.assertFalse(interface.use_dhcp)
self.assertFalse(interface.use_dhcpv6)
self.assertEqual(1501, interface.mtu)
+ self.assertEqual("speed 1000 duplex full", interface.ethtool_opts)
address1 = interface.v4_addresses()[0]
self.assertEqual("192.0.2.1", address1.ip)
self.assertEqual("255.255.255.0", address1.netmask)