set the primary interface for ovs bond (nmstate provider)
Set the OvsDB entry "other_config:bond-primary=<iface>" for the bond. The patch also addresses the incorrect hierarchy for OvsDB used while parsing the ovs_options. It also includes an option to support ovs_options having other-config as well as other_config. Change-Id: I5f7feb9d41d877c965f31b8d9023b196fe5a3635
This commit is contained in:
parent
803840f65f
commit
d2f1423008
|
@ -169,15 +169,25 @@ def set_linux_bonding_options(bond_options, primary_iface=None):
|
|||
|
||||
|
||||
def set_ovs_bonding_options(bond_options):
|
||||
ovs_other_config = ["other-config:lacp-fallback-ab",
|
||||
# Duplicate entries for other-config are added so as to avoid
|
||||
# the confusion around other-config vs other_config in ovs
|
||||
ovs_other_config = ["other_config:lacp-fallback-ab",
|
||||
"other_config:lacp-time",
|
||||
"other_config:bond-detect-mode",
|
||||
"other_config:bond-miimon-interval",
|
||||
"other_config:bond-rebalance-interval"]
|
||||
"other_config:bond-rebalance-interval",
|
||||
"other_config:bond-primary",
|
||||
"other-config:lacp-fallback-ab",
|
||||
"other-config:lacp-time",
|
||||
"other-config:bond-detect-mode",
|
||||
"other-config:bond-miimon-interval",
|
||||
"other-config:bond-rebalance-interval",
|
||||
"other-config:bond-primary"]
|
||||
other_config = {}
|
||||
bond_data = {OVSBridge.Port.LinkAggregation.MODE: 'active-backup',
|
||||
OVSBridge.PORT_SUBTREE:
|
||||
[{OVSBridge.Port.LinkAggregation.PORT_SUBTREE: []}]}
|
||||
other_config = {}
|
||||
[{OVSBridge.Port.LinkAggregation.PORT_SUBTREE: []}],
|
||||
OvsDB.KEY: {OvsDB.OTHER_CONFIG: other_config}}
|
||||
|
||||
if 'bond_mode' in bond_options:
|
||||
bond_data[OVSBridge.Port.LinkAggregation.MODE
|
||||
|
@ -195,7 +205,7 @@ def set_ovs_bonding_options(bond_options):
|
|||
other_config[options[len("other_config:"):]
|
||||
] = bond_options[options]
|
||||
|
||||
return bond_data, other_config
|
||||
return bond_data
|
||||
|
||||
|
||||
def _is_any_ip_addr(address):
|
||||
|
@ -525,6 +535,11 @@ class NmstateNetConfig(os_net_config.NetConfig):
|
|||
rules.extend(reqd_rule)
|
||||
return rules
|
||||
|
||||
def interface_mac(self, iface):
|
||||
iface_data = self.iface_state(iface)
|
||||
if iface_data and Interface.MAC in iface_data:
|
||||
return iface_data[Interface.MAC]
|
||||
|
||||
def get_ovs_ports(self, members):
|
||||
bps = []
|
||||
for member in members:
|
||||
|
@ -1093,13 +1108,23 @@ class NmstateNetConfig(os_net_config.NetConfig):
|
|||
'sub_tree': [OvsDB.KEY, OvsDB.OTHER_CONFIG],
|
||||
'nm_config': None,
|
||||
'nm_config_regex': r'^other_config:(.+?)=',
|
||||
'value_pattern': r'^other_config:.*=(.+?)$'}]
|
||||
'value_pattern': r'^other_config:.*=(.+?)$'},
|
||||
{'config': r'^other-config:[\w+]',
|
||||
'sub_tree': [OvsDB.KEY, OvsDB.OTHER_CONFIG],
|
||||
'nm_config': None,
|
||||
'nm_config_regex': r'^other-config:(.+?)=',
|
||||
'value_pattern': r'^other-config:.*=(.+?)$'}]
|
||||
|
||||
iface_cfg = [{'config': r'^other_config:[\w+]',
|
||||
'sub_tree': [OvsDB.KEY, OvsDB.OTHER_CONFIG],
|
||||
'nm_config': None,
|
||||
'nm_config_regex': r'^other_config:(.+?)=',
|
||||
'value_pattern': r'^other_config:.*=(.+?)$'}]
|
||||
'value_pattern': r'^other_config:.*=(.+?)$'},
|
||||
{'config': r'^other-config:[\w+]',
|
||||
'sub_tree': [OvsDB.KEY, OvsDB.OTHER_CONFIG],
|
||||
'nm_config': None,
|
||||
'nm_config_regex': r'^other-config:(.+?)=',
|
||||
'value_pattern': r'^other-config:.*=(.+?)$'}]
|
||||
|
||||
external_id_cfg = [{'sub_tree': [OvsDB.KEY, OvsDB.EXTERNAL_IDS],
|
||||
'config': r'.*',
|
||||
|
@ -1199,6 +1224,10 @@ class NmstateNetConfig(os_net_config.NetConfig):
|
|||
}
|
||||
data[OvsDB.KEY] = {OvsDB.EXTERNAL_IDS: {},
|
||||
OvsDB.OTHER_CONFIG: {}}
|
||||
if bridge.primary_interface_name:
|
||||
mac = self.interface_mac(bridge.primary_interface_name)
|
||||
bridge.ovs_extra.append("set bridge %s other_config:hwaddr=%s" %
|
||||
(bridge.name, mac))
|
||||
if bridge.ovs_extra:
|
||||
logger.info(f"Parsing ovs_extra : {bridge.ovs_extra}")
|
||||
self.parse_ovs_extra(bridge.ovs_extra, bridge.name, data)
|
||||
|
@ -1216,9 +1245,18 @@ class NmstateNetConfig(os_net_config.NetConfig):
|
|||
msg = "Ovs Bond and ovs port can't be members to "\
|
||||
"the ovs bridge"
|
||||
raise os_net_config.ConfigurationError(msg)
|
||||
if member.primary_interface_name:
|
||||
add_bond_setting = "other_config:bond-primary="\
|
||||
f"{member.primary_interface_name}"
|
||||
if member.ovs_options:
|
||||
member.ovs_options = member.ovs_options + " " +\
|
||||
add_bond_setting
|
||||
else:
|
||||
member.ovs_options = add_bond_setting
|
||||
|
||||
logger.info(f"OVS Options are {member.ovs_options}")
|
||||
bond_options = parse_bonding_options(member.ovs_options)
|
||||
bond_data, other_config = set_ovs_bonding_options(
|
||||
bond_options)
|
||||
bond_data = set_ovs_bonding_options(bond_options)
|
||||
bond_port = [{
|
||||
OVSBridge.Port.LINK_AGGREGATION_SUBTREE: bond_data,
|
||||
OVSBridge.Port.NAME: member.name},
|
||||
|
@ -1226,7 +1264,6 @@ class NmstateNetConfig(os_net_config.NetConfig):
|
|||
data[OVSBridge.CONFIG_SUBTREE
|
||||
][OVSBridge.PORT_SUBTREE] = bond_port
|
||||
|
||||
# TODO(Karthik) Is primary interface required now
|
||||
ovs_bond = True
|
||||
logger.debug("OVS Bond members %s added" % members)
|
||||
if member.members:
|
||||
|
@ -1254,10 +1291,9 @@ class NmstateNetConfig(os_net_config.NetConfig):
|
|||
data[OVSBridge.CONFIG_SUBTREE][OVSBridge.PORT_SUBTREE] = bps
|
||||
elif ovs_bond:
|
||||
bond_data[OVSBridge.Port.LinkAggregation.PORT_SUBTREE] = bps
|
||||
data[OvsDB.KEY][OvsDB.OTHER_CONFIG].update(other_config)
|
||||
|
||||
if bridge.primary_interface_name:
|
||||
mac = utils.interface_mac(bridge.primary_interface_name)
|
||||
mac = self.interface_mac(bridge.primary_interface_name)
|
||||
data[Interface.MAC] = mac
|
||||
|
||||
self.bridge_data[bridge.name] = data
|
||||
|
|
|
@ -754,6 +754,9 @@ class TestNmstateNetConfig(base.TestCase):
|
|||
port:
|
||||
- name: em2
|
||||
- name: em3
|
||||
ovs-db:
|
||||
other_config:
|
||||
bond-primary: em2
|
||||
- name: br-ctlplane2-p
|
||||
ovs-db:
|
||||
external_ids: {}
|
||||
|
@ -787,6 +790,14 @@ class TestNmstateNetConfig(base.TestCase):
|
|||
link-aggregation:
|
||||
bond-updelay: 1000
|
||||
mode: balance-slb
|
||||
ovs-db:
|
||||
other_config:
|
||||
bond-detect-mode: miimon
|
||||
bond-miimon-interval: 100
|
||||
bond-rebalance-interval: 10000
|
||||
bond-primary: em2
|
||||
lacp-fallback-ab: true
|
||||
lacp-time: fast
|
||||
port:
|
||||
- name: em2
|
||||
- name: em3
|
||||
|
@ -794,19 +805,14 @@ class TestNmstateNetConfig(base.TestCase):
|
|||
state: up
|
||||
ovs-db:
|
||||
external_ids: {}
|
||||
other_config:
|
||||
bond-detect-mode: miimon
|
||||
bond-miimon-interval: 100
|
||||
bond-rebalance-interval: 10000
|
||||
lacp-fallback-ab: true
|
||||
lacp-time: fast
|
||||
other_config: {}
|
||||
"""
|
||||
interface1 = objects.Interface('em2')
|
||||
interface2 = objects.Interface('em3')
|
||||
|
||||
ovs_options = 'bond_mode=balance-slb ' \
|
||||
'other-config:lacp-fallback-ab=true ' \
|
||||
'other_config:lacp-time=fast ' \
|
||||
'other-config:lacp-time=fast ' \
|
||||
'other_config:bond-detect-mode=miimon ' \
|
||||
'other_config:bond-miimon-interval=100 ' \
|
||||
'bond_updelay=1000 ' \
|
||||
|
@ -836,6 +842,9 @@ class TestNmstateNetConfig(base.TestCase):
|
|||
port:
|
||||
- name: em2
|
||||
- name: em3
|
||||
ovs-db:
|
||||
other_config:
|
||||
bond-primary: em2
|
||||
- name: br-ctlplane2-p
|
||||
vlan:
|
||||
tag: 70
|
||||
|
@ -1351,6 +1360,9 @@ class TestNmstateNetConfig(base.TestCase):
|
|||
- name: bond_vf
|
||||
link-aggregation:
|
||||
mode: active-backup
|
||||
ovs-db:
|
||||
other_config:
|
||||
bond-primary: eth2_2
|
||||
port:
|
||||
- name: eth2_2
|
||||
- name: eth1_2
|
||||
|
|
Loading…
Reference in New Issue