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
This commit is contained in:
parent
4fdb0a6a2b
commit
469c0ab91a
|
@ -25,7 +25,8 @@
|
|||
"type": "interface",
|
||||
"name": "em2",
|
||||
"use_dhcp": true,
|
||||
"defroute": no
|
||||
"defroute": no,
|
||||
"ethtool_opts": "speed 1000 duplex full"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -20,3 +20,4 @@ network_config:
|
|||
name: em2
|
||||
use_dhcp: true
|
||||
defroute: no
|
||||
ethtool_opts: "speed 1000 duplex full"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -739,6 +739,21 @@ NM_CONTROLLED=no
|
|||
PEERDNS=no
|
||||
BOOTPROTO=none
|
||||
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'))
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue