netlist: Add 'Macvtap device...' manual entry

Similar to the bridge option. We will be removing the explicit
device listing support soon, so this will be required for specifying
a macvtap device

Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson 2020-01-25 19:22:30 -05:00
parent 00da972b14
commit 66e1eb7324
4 changed files with 71 additions and 43 deletions

View File

@ -272,7 +272,7 @@ class AddHardware(uiutils.UITestCase):
finish.click()
uiutils.check_in_loop(lambda: details.active)
# macvtap
# macvtap selection
self._open_addhw_window(details)
tab = self._select_hw(addhw, "Network", "network-tab")
src.click()
@ -287,7 +287,7 @@ class AddHardware(uiutils.UITestCase):
src.click()
self.pressKey("End")
tab.find_fuzzy("Bridge device...", "menu item").click()
tab.find("Bridge name:", "text").text = "zbr0"
tab.find("Device name:", "text").text = "zbr0"
finish.click()
# Check MAC validation error
@ -301,14 +301,15 @@ class AddHardware(uiutils.UITestCase):
finish.click()
uiutils.check_in_loop(lambda: details.active)
# Network with portops
# Manual macvtap
self._open_addhw_window(details)
tab = self._select_hw(addhw, "Network", "network-tab")
tab.find("MAC Address Field", "text").text = "00:11:0B:11:00:11"
src.click()
self.sleep(1)
self.pressKey("Home")
tab.find_fuzzy("plainbridge-portgroups", "menu item").click()
tab.find_fuzzy("Macvtap device...", "menu item").click()
tab.find("Device name:", "text").text = "macvtapfoo7"
finish.click()
uiutils.check_in_loop(lambda: details.active)

View File

@ -251,16 +251,18 @@ class Details(uiutils.UITestCase):
alert = self.app.root.find("vmm dialog", "alert")
alert.find_fuzzy("Error changing VM configuration", "label")
alert.find("Close", "push button").click()
tab.find("Bridge name:", "text").text = "zbr0"
tab.find("Device name:", "text").text = "zbr0"
appl.click()
uiutils.check_in_loop(lambda: not appl.sensitive)
# Network with portops
# Manual macvtap
src.click()
self.pressKey("Home")
tab.find_fuzzy("plainbridge-portgroups",
tab.find_fuzzy("Macvtap device...",
"menu item").bring_on_screen().click()
appl.click()
tab.find("Device name:", "text").text = "fakedev12"
appl.click()
uiutils.check_in_loop(lambda: not appl.sensitive)

View File

@ -13,9 +13,9 @@
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="hexpand">False</property>
<property name="label" translatable="yes">_Bridge name:</property>
<property name="label" translatable="yes">De_vice name:</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">net-bridge-name</property>
<property name="mnemonic_widget">net-manual-source</property>
</object>
<packing>
<property name="left_attach">0</property>
@ -23,7 +23,7 @@
</packing>
</child>
<child>
<object class="GtkEntry" id="net-bridge-name">
<object class="GtkEntry" id="net-manual-source">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">start</property>

View File

@ -40,8 +40,8 @@ def _build_label_row(label, active):
return _build_row(None, None, label, active)
def _build_manual_row(label):
return _build_row(None, None, label, True, manual=True)
def _build_manual_row(nettype, label):
return _build_row(nettype, None, label, True, manual=True)
def _pretty_network_desc(nettype, source=None, netobj=None):
@ -228,7 +228,14 @@ class vmmNetworkList(vmmGObjectUI):
model.clear()
def _add_manual_bridge_row():
model.append(_build_manual_row(_("Bridge device...")))
_nettype = virtinst.DeviceInterface.TYPE_BRIDGE
_label = _("Bridge device...")
model.append(_build_manual_row(_nettype, _label))
def _add_manual_macvtap_row():
_label = _("Macvtap device...")
_nettype = virtinst.DeviceInterface.TYPE_DIRECT
model.append(_build_manual_row(_nettype, _label))
if self.conn.is_qemu_session():
nettype = virtinst.DeviceInterface.TYPE_USER
@ -272,6 +279,7 @@ class vmmNetworkList(vmmGObjectUI):
model_label[2] == label][0]
_add_manual_bridge_row()
_add_manual_macvtap_row()
return default
def _check_network_is_running(self, net):
@ -305,6 +313,49 @@ class vmmNetworkList(vmmGObjectUI):
return self.err.show_err(_("Could not start virtual network "
"'%s': %s") % (devname, str(e)))
def _find_rowiter_for_dev(self, net):
nettype = net.type
source = net.source
if net.network:
# If using type=network with a forward mode=bridge network,
# on domain startup the runtime XML will be changed to
# type=bridge and both source/@bridge and source/@network will
# be filled in. For our purposes, treat this as a type=network
source = net.network
nettype = "network"
def _find_row(_nettype, _source, _manual):
for row in combo.get_model():
if _nettype and row[NET_ROW_TYPE] != _nettype:
continue
if _source and row[NET_ROW_SOURCE] != _source:
continue
if _manual and row[NET_ROW_MANUAL] != _manual:
continue
return row.iter
# Find the matching row in the net list
combo = self.widget("net-source")
rowiter = _find_row(nettype, source, None)
if rowiter:
return rowiter
# If this is a bridge or macvtap device, show the
# manual source mode
if nettype in [virtinst.DeviceInterface.TYPE_BRIDGE,
virtinst.DeviceInterface.TYPE_DIRECT]:
rowiter = _find_row(nettype, None, True)
self.widget("net-manual-source").set_text(source or "")
if rowiter:
return rowiter
# This is some network type we don't know about. Generate
# a label for it and stuff it in the list
desc = _pretty_network_desc(nettype, source)
combo.get_model().insert(0,
_build_row(nettype, source, desc, True))
return combo.get_model()[0].iter
###############
# Public APIs #
@ -323,8 +374,7 @@ class vmmNetworkList(vmmGObjectUI):
net_check_manual = row[NET_ROW_MANUAL]
if net_check_manual:
net_type = virtinst.DeviceInterface.TYPE_BRIDGE
net_src = self.widget("net-bridge-name").get_text() or None
net_src = self.widget("net-manual-source").get_text() or None
mode = None
is_direct = (net_type == virtinst.DeviceInterface.TYPE_DIRECT)
@ -363,38 +413,13 @@ class vmmNetworkList(vmmGObjectUI):
net_warn.set_visible(bool(net_err))
net_warn.set_tooltip_text(net_err or "")
self.widget("net-bridge-name").set_text("")
self.widget("net-manual-source").set_text("")
def set_dev(self, net):
self.reset_state()
rowiter = self._find_rowiter_for_dev(net)
nettype = net.type
source = net.source
if net.network:
# If using type=network with a forward mode=bridge network,
# on domain startup the runtime XML will be changed to
# type=bridge and both source/@bridge and source/@network will
# be filled in. For our purposes, treat this as a type=network
source = net.network
nettype = "network"
# Find the matching row in the net list
combo = self.widget("net-source")
rowiter = None
for row in combo.get_model():
if row[0] == nettype and row[1] == source:
rowiter = row.iter
break
if not rowiter:
if nettype == "bridge":
rowiter = combo.get_model()[-1].iter
self.widget("net-bridge-name").set_text(source)
if not rowiter:
desc = _pretty_network_desc(nettype, source)
combo.get_model().insert(0,
_build_row(nettype, source, desc, True))
rowiter = combo.get_model()[0].iter
combo.set_active_iter(rowiter)
combo.emit("changed")
@ -450,4 +475,4 @@ class vmmNetworkList(vmmGObjectUI):
show_bridge = row[NET_ROW_MANUAL]
uiutil.set_grid_row_visible(
self.widget("net-bridge-name"), show_bridge)
self.widget("net-manual-source"), show_bridge)