Add linkdelay option

Change-Id: Ica0a160ce7c8f781d37cd4da67e04cd03db7de94
Closes-Bug: 1842999
(cherry picked from commit 04f285ad02)
This commit is contained in:
junbo 2019-09-06 12:23:07 +08:00 committed by Bob Fournier
parent 1aab969eed
commit 2504f788bf
4 changed files with 25 additions and 2 deletions

View File

@ -376,6 +376,9 @@ class IfcfgNetConfig(os_net_config.NetConfig):
data += "TYPE=Infiniband\n" data += "TYPE=Infiniband\n"
elif re.match('\w+\.\d+$', base_opt.name): elif re.match('\w+\.\d+$', base_opt.name):
data += "VLAN=yes\n" data += "VLAN=yes\n"
elif isinstance(base_opt, objects.Interface):
if base_opt.linkdelay:
data += "LINKDELAY=%s\n" % base_opt.linkdelay
if base_opt.linux_bond_name: if base_opt.linux_bond_name:
data += "MASTER=%s\n" % base_opt.linux_bond_name data += "MASTER=%s\n" % base_opt.linux_bond_name
data += "SLAVE=yes\n" data += "SLAVE=yes\n"

View File

@ -457,7 +457,8 @@ class Interface(_BaseOpts):
routes=None, rules=None, mtu=None, primary=False, routes=None, rules=None, mtu=None, primary=False,
nic_mapping=None, persist_mapping=False, defroute=True, nic_mapping=None, persist_mapping=False, defroute=True,
dhclient_args=None, dns_servers=None, nm_controlled=False, dhclient_args=None, dns_servers=None, nm_controlled=False,
onboot=True, domain=None, ethtool_opts=None, hotplug=False): onboot=True, domain=None, ethtool_opts=None, hotplug=False,
linkdelay=None):
addresses = addresses or [] addresses = addresses or []
routes = routes or [] routes = routes or []
rules = rules or [] rules = rules or []
@ -469,6 +470,7 @@ class Interface(_BaseOpts):
nm_controlled, onboot, domain) nm_controlled, onboot, domain)
self.ethtool_opts = ethtool_opts self.ethtool_opts = ethtool_opts
self.hotplug = hotplug self.hotplug = hotplug
self.linkdelay = linkdelay
@staticmethod @staticmethod
def from_json(json): def from_json(json):
@ -476,8 +478,9 @@ class Interface(_BaseOpts):
hotplug = strutils.bool_from_string(str(json.get('hotplug', False))) hotplug = strutils.bool_from_string(str(json.get('hotplug', False)))
opts = _BaseOpts.base_opts_from_json(json) opts = _BaseOpts.base_opts_from_json(json)
ethtool_opts = json.get('ethtool_opts', None) ethtool_opts = json.get('ethtool_opts', None)
linkdelay = json.get('linkdelay', None)
return Interface(name, *opts, ethtool_opts=ethtool_opts, return Interface(name, *opts, ethtool_opts=ethtool_opts,
hotplug=hotplug) hotplug=hotplug, linkdelay=linkdelay)
class Vlan(_BaseOpts): class Vlan(_BaseOpts):

View File

@ -291,6 +291,8 @@ definitions:
$ref: "#/definitions/bool_or_param" $ref: "#/definitions/bool_or_param"
domain: domain:
$ref: "#/definitions/list_of_domain_name_string_or_domain_name_string" $ref: "#/definitions/list_of_domain_name_string_or_domain_name_string"
linkdelay:
$ref: "#/definitions/int_or_param"
required: required:
- type - type
- name - name

View File

@ -63,6 +63,16 @@ PEERDNS=no
BOOTPROTO=none BOOTPROTO=none
""" """
_LINKDELAY = """# This file is autogenerated by os-net-config
DEVICE=em1
ONBOOT=yes
HOTPLUG=no
NM_CONTROLLED=no
PEERDNS=no
LINKDELAY=10
BOOTPROTO=none
"""
_NO_IP = _BASE_IFCFG + "BOOTPROTO=none\n" _NO_IP = _BASE_IFCFG + "BOOTPROTO=none\n"
_V4_IFCFG = _BASE_IFCFG + """BOOTPROTO=static _V4_IFCFG = _BASE_IFCFG + """BOOTPROTO=static
@ -659,6 +669,11 @@ class TestIfcfgNetConfig(base.TestCase):
self.provider.add_interface(interface) self.provider.add_interface(interface)
self.assertEqual(_ONBOOT, self.get_interface_config()) self.assertEqual(_ONBOOT, self.get_interface_config())
def test_add_interface_with_linkdelay(self):
interface = objects.Interface('em1', linkdelay=10)
self.provider.add_interface(interface)
self.assertEqual(_LINKDELAY, self.get_interface_config())
def test_add_base_interface_vlan(self): def test_add_base_interface_vlan(self):
interface = objects.Interface('em1.120') interface = objects.Interface('em1.120')
self.provider.add_interface(interface) self.provider.add_interface(interface)