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.
Closes-Bug: #1705316
Change-Id: I6b594e89ba6b4c17e8df79def997f6c9ea427a3a
(cherry picked from commit 469c0ab91a
)
This commit is contained in:
parent
3471ff7ba9
commit
8246e5e8ec
|
@ -20,7 +20,8 @@
|
|||
"type": "interface",
|
||||
"name": "em2",
|
||||
"use_dhcp": true,
|
||||
"defroute": false
|
||||
"defroute": false,
|
||||
"ethtool_opts": "speed 1000 duplex full"
|
||||
},
|
||||
{
|
||||
"type": "interface",
|
||||
|
|
|
@ -16,6 +16,7 @@ network_config:
|
|||
name: em2
|
||||
use_dhcp: true
|
||||
defroute: false
|
||||
ethtool_opts: "speed 1000 duplex full"
|
||||
-
|
||||
type: interface
|
||||
name: em3
|
||||
|
|
|
@ -163,6 +163,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:
|
||||
|
@ -315,6 +317,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
|
||||
|
|
|
@ -286,7 +286,8 @@ 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, nm_controlled=False, hotplug=False):
|
||||
dns_servers=None, nm_controlled=False, ethtool_opts=None,
|
||||
hotplug=False):
|
||||
addresses = addresses or []
|
||||
routes = routes or []
|
||||
dns_servers = dns_servers or []
|
||||
|
@ -296,13 +297,16 @@ class Interface(_BaseOpts):
|
|||
dhclient_args, dns_servers,
|
||||
nm_controlled)
|
||||
self.hotplug = hotplug
|
||||
self.ethtool_opts = ethtool_opts
|
||||
|
||||
@staticmethod
|
||||
def from_json(json):
|
||||
name = _get_required_field(json, 'name', 'Interface')
|
||||
hotplug = strutils.bool_from_string(str(json.get('hotplug', False)))
|
||||
opts = _BaseOpts.base_opts_from_json(json)
|
||||
return Interface(name, *opts, hotplug=hotplug)
|
||||
ethtool_opts = json.get('ethtool_opts', None)
|
||||
return Interface(name, *opts, ethtool_opts=ethtool_opts,
|
||||
hotplug=hotplug)
|
||||
|
||||
|
||||
class Vlan(_BaseOpts):
|
||||
|
@ -975,7 +979,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, nm_controlled=False):
|
||||
dns_servers=None, nm_controlled=False, ethtool_opts=None):
|
||||
addresses = addresses or []
|
||||
routes = routes or []
|
||||
dns_servers = dns_servers or []
|
||||
|
@ -984,12 +988,14 @@ class IbInterface(_BaseOpts):
|
|||
nic_mapping, persist_mapping,
|
||||
defroute, dhclient_args, dns_servers,
|
||||
nm_controlled)
|
||||
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):
|
||||
|
|
|
@ -808,6 +808,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'))
|
||||
|
||||
|
|
|
@ -167,6 +167,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"
|
||||
}],
|
||||
|
@ -181,6 +182,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