The internal_port_add was fundamentaly wrong as there's no such
thing as an
internal port in OpenVSwitch. Instead a user may add a port with internal
device implementation (type internal).
This patch removes the internal_port_add method and refactors port_add method
to fit all of the following cases:
* ovs-vsctl port-add t_br0 eth0
that adds an existing device
* ovs-vsctl port-add t_br0 vnet0 -- set Interface vnet0 ofport_request=5
same with openflow rules
* ovs-vsctl port-add t_br0 int0 -- set Interface int0 type=internal
that adds a port with interface of type internal
* ovs-vsctl port-add t_br0 vxlan0 -- set Interface vxlan0 type=vxlan ...
that adds a port with interface of type vxlan
The method now takes three parameters
* device which must be a Device instance, applicable only for internal and
tunnel type interfaces
I will have to send v2 for this. It should say 'not applicable'.
I will wait for other comments.
* port_options, a dictionary of any Port column key-values, e.g.
{'tag': 9}
* interface_options, a dictionary of any Interface column key-values, e.g.
{'type': 'internal'}, that would generate command like
'set Interface iface type=internal'
The method tunnel_add was modified to use the refactored port_add method to
remove duplicated code.
All recipes that previously used any of the modified methods were updated.
Signed-off-by: Jan Tluka <jtluka(a)redhat.com>
---
lnst/Devices/OvsBridgeDevice.py | 59 ++++++-------------
lnst/Recipes/ENRT/NoVirtOvsVxlanRecipe.py | 7 ++-
lnst/Recipes/ENRT/VirtOvsVxlanRecipe.py | 5 +-
...rtualOvsBridgeVlanInGuestMirroredRecipe.py | 2 +-
...irtualOvsBridgeVlanInHostMirroredRecipe.py | 2 +-
.../ENRT/VirtualOvsBridgeVlanInHostRecipe.py | 2 +-
.../VirtualOvsBridgeVlansOverBondRecipe.py | 2 +-
7 files changed, 31 insertions(+), 48 deletions(-)
diff --git a/lnst/Devices/OvsBridgeDevice.py b/lnst/Devices/OvsBridgeDevice.py
index 4205470e..28d786bb 100644
--- a/lnst/Devices/OvsBridgeDevice.py
+++ b/lnst/Devices/OvsBridgeDevice.py
@@ -50,15 +50,23 @@ class OvsBridgeDevice(SoftDevice):
return cmd
- def port_add(self, dev, **kwargs):
- options = ""
- for opt_name, opt_value in kwargs.items():
- if opt_name == "set_iface" and opt_value:
- options = (" -- set Interface %s" + options) % dev.name
- else:
- options += " %s=%s" % (opt_name, opt_value)
+ def port_add(self, device=None, port_options={}, interface_options={}):
+ if device is None:
+ dev_name = interface_options.get('name',
+ self._if_manager.assign_name(interface_options['type']))
+ else:
+ dev_name = device.name
+
+ exec_cmd("ovs-vsctl add-port {} {}{}{}".format(self.name, dev_name,
+ self._dict_to_keyvalues(port_options),
+ self._interface_cmd(dev_name, interface_options)))
+
+ iface = None
+ if 'type' in interface_options and interface_options['type'] ==
'internal':
+ iface = self._if_manager.get_device_by_name(dev_name)
+ iface._enable()
- exec_cmd("ovs-vsctl add-port %s %s%s" % (self.name, dev.name,
options))
+ return iface
def port_del(self, dev):
if isinstance(dev, Device):
@@ -83,39 +91,10 @@ class OvsBridgeDevice(SoftDevice):
def bond_del(self, dev):
self.port_del(dev)
- def internal_port_add(self, **kwargs):
- name = self._if_manager.assign_name("int")
-
- options = ""
- for opt_name, opt_value in kwargs.items():
- if opt_name == "name":
- name = opt_value
- continue
-
- options += " %s=%s" % (opt_name, opt_value)
-
- exec_cmd("ovs-vsctl add-port %s %s -- set Interface %s "\
- "type=internal %s" % (self.name, name,
- name, options))
-
- dev = self._if_manager.get_device_by_name(name)
- dev._enable()
- return dev
-
def tunnel_add(self, tunnel_type, options):
- name = self._if_manager.assign_name(tunnel_type)
-
- opts = ""
- for opt_name, opt_value in options.items():
- if opt_name == "name":
- name = opt_value
- continue
-
- opts += " %s=%s" % (opt_name, opt_value)
-
- exec_cmd("ovs-vsctl add-port %s %s -- set Interface %s "\
- "type=%s %s" % (self.name, name, name,
- tunnel_type, opts))
+ options_copy = options.copy()
+ options_copy['type'] = tunnel_type
+ self.port_add(device=None, interface_options=options_copy)
def tunnel_del(self, name):
self.port_del(name)
diff --git a/lnst/Recipes/ENRT/NoVirtOvsVxlanRecipe.py
b/lnst/Recipes/ENRT/NoVirtOvsVxlanRecipe.py
index 44cd4b6f..0c7b7520 100644
--- a/lnst/Recipes/ENRT/NoVirtOvsVxlanRecipe.py
+++ b/lnst/Recipes/ENRT/NoVirtOvsVxlanRecipe.py
@@ -31,8 +31,11 @@ class NoVirtOvsVxlanRecipe(CommonHWSubConfigMixin, BaseEnrtRecipe):
host.eth0.down()
host.eth0.ip_add(ipaddress(net_addr + "." + str(i+1) +
"/24"))
host.br0 = OvsBridgeDevice()
- host.int0 = host.br0.internal_port_add(ofport_request='5',
- name="int0")
+ host.int0 = host.br0.port_add(
+ interface_options={
+ 'type': 'internal',
+ 'ofport_request': 5,
+ 'name': 'int0'})
host.int0.ip_add(ipaddress(vxlan_net_addr + "." + str(i+1) +
"/24"))
host.int0.ip_add(ipaddress(vxlan_net_addr6 + "::" + str(i+1) +
diff --git a/lnst/Recipes/ENRT/VirtOvsVxlanRecipe.py
b/lnst/Recipes/ENRT/VirtOvsVxlanRecipe.py
index e7fcee1d..3d47e407 100644
--- a/lnst/Recipes/ENRT/VirtOvsVxlanRecipe.py
+++ b/lnst/Recipes/ENRT/VirtOvsVxlanRecipe.py
@@ -67,8 +67,9 @@ class VirtOvsVxlanRecipe(VlanPingEvaluatorMixin,
host.eth0.ip_add(ipaddress(net_addr + "." + str(i+1) +
"/24"))
host.br0 = OvsBridgeDevice()
for dev, ofport_r in [(host.tap0, '5'), (host.tap1, '6')]:
- host.br0.port_add(dev, set_iface=True,
- ofport_request=ofport_r)
+ host.br0.port_add(
+ device=dev,
+ interface_options={'ofport_request': ofport_r})
tunnel_opts = {"option:remote_ip" : net_addr + "." +
str(2-i),
"option:key" : "flow", "ofport_request" :
'10'}
host.br0.tunnel_add("vxlan", tunnel_opts)
diff --git a/lnst/Recipes/ENRT/VirtualOvsBridgeVlanInGuestMirroredRecipe.py
b/lnst/Recipes/ENRT/VirtualOvsBridgeVlanInGuestMirroredRecipe.py
index 2bdc0aaf..05245c03 100644
--- a/lnst/Recipes/ENRT/VirtualOvsBridgeVlanInGuestMirroredRecipe.py
+++ b/lnst/Recipes/ENRT/VirtualOvsBridgeVlanInGuestMirroredRecipe.py
@@ -43,7 +43,7 @@ class VirtualOvsBridgeVlanInGuestMirroredRecipe(CommonHWSubConfigMixin,
host.tap0.down()
host.br0 = OvsBridgeDevice()
for dev in [host.eth0, host.tap0]:
- host.br0.port_add(dev)
+ host.br0.port_add(device=dev)
guest1.eth0.down()
guest2.eth0.down()
diff --git a/lnst/Recipes/ENRT/VirtualOvsBridgeVlanInHostMirroredRecipe.py
b/lnst/Recipes/ENRT/VirtualOvsBridgeVlanInHostMirroredRecipe.py
index 00720968..b85350ab 100644
--- a/lnst/Recipes/ENRT/VirtualOvsBridgeVlanInHostMirroredRecipe.py
+++ b/lnst/Recipes/ENRT/VirtualOvsBridgeVlanInHostMirroredRecipe.py
@@ -42,7 +42,7 @@ class VirtualOvsBridgeVlanInHostMirroredRecipe(CommonHWSubConfigMixin,
host.eth0.down()
host.tap0.down()
host.br0.port_add(host.eth0)
- host.br0.port_add(host.tap0, tag="10")
+ host.br0.port_add(host.tap0, port_options={'tag': 10})
guest1.eth0.down()
guest2.eth0.down()
diff --git a/lnst/Recipes/ENRT/VirtualOvsBridgeVlanInHostRecipe.py
b/lnst/Recipes/ENRT/VirtualOvsBridgeVlanInHostRecipe.py
index ee97fa74..93f2c281 100644
--- a/lnst/Recipes/ENRT/VirtualOvsBridgeVlanInHostRecipe.py
+++ b/lnst/Recipes/ENRT/VirtualOvsBridgeVlanInHostRecipe.py
@@ -38,7 +38,7 @@ class VirtualOvsBridgeVlanInHostRecipe(CommonHWSubConfigMixin,
host1.tap0.down()
host1.br0 = OvsBridgeDevice()
host1.br0.port_add(host1.eth0)
- host1.br0.port_add(host1.tap0, tag="10")
+ host1.br0.port_add(host1.tap0, port_options={'tag': 10})
host2.eth0.down()
guest1.eth0.down()
diff --git a/lnst/Recipes/ENRT/VirtualOvsBridgeVlansOverBondRecipe.py
b/lnst/Recipes/ENRT/VirtualOvsBridgeVlansOverBondRecipe.py
index 45f59d07..9d75423d 100644
--- a/lnst/Recipes/ENRT/VirtualOvsBridgeVlansOverBondRecipe.py
+++ b/lnst/Recipes/ENRT/VirtualOvsBridgeVlansOverBondRecipe.py
@@ -58,7 +58,7 @@ class VirtualOvsBridgeVlansOverBondRecipe(VlanPingEvaluatorMixin,
dev.down()
host.br0 = OvsBridgeDevice()
for dev, tag in [(host.tap0, "10"), (host.tap1, "20")]:
- host.br0.port_add(dev, tag=tag)
+ host.br0.port_add(device=dev, port_options={'tag': tag})
#miimon cannot be set due to colon in argument name -->
#other_config:bond-miimon-interval
host.br0.bond_add(port_name, (host.eth0, host.eth1),
--
2.21.1
_______________________________________________
LNST-developers mailing list -- lnst-developers(a)lists.fedorahosted.org
To unsubscribe send an email to lnst-developers-leave(a)lists.fedorahosted.org
Fedora Code of Conduct:
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines:
https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives:
https://lists.fedorahosted.org/archives/list/lnst-developers@lists.fedora...