Petr Horáček has uploaded a new change for review.
Change subject: virt: keep libvirt's <driver> element
......................................................................
virt: keep libvirt's <driver> element
Most commonly, vdsm does not supply the <driver> element to libvirt, so
that libvirt is able to apply its logic for setting the correct one
(qemu/vhost).
Once libvirt has chosen the driver, it must not change. When link state
is modified, the chosen driver must be stated explicitly.
Change-Id: I043b1c4b932cf0bc83b1f911415245e858ae350d
Signed-off-by: Petr Horáček <phoracek(a)redhat.com>
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1200418
---
M vdsm/virt/vm.py
1 file changed, 6 insertions(+), 0 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/20/39220/1
diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index 904c8e1..ed4975c 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -5510,6 +5510,10 @@
devType = x.getAttribute('type')
mac = x.getElementsByTagName('mac')[0].getAttribute('address')
alias = x.getElementsByTagName('alias')[0].getAttribute('name')
+ xdrivers = x.getElementsByTagName('driver')
+ driver = ({'name': xdrivers[0].getAttribute('name'),
+ 'queues': xdrivers[0].getAttribute('queues')}
+ if xdrivers else {})
if devType == 'hostdev':
name = alias
model = 'passthrough'
@@ -5541,6 +5545,8 @@
nic.alias = alias
nic.address = address
nic.linkActive = linkActive
+ if driver:
+ nic.driver = driver
# Update vm's conf with address for known nic devices
knownDev = False
for dev in self.conf['devices']:
--
To view, visit https://gerrit.ovirt.org/39220
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I043b1c4b932cf0bc83b1f911415245e858ae350d
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.5
Gerrit-Owner: Petr Horáček <phoracek(a)redhat.com>
Ondřej Svoboda has uploaded a new change for review.
Change subject: sourceroute: move static methods out of classes and simplify test code
......................................................................
sourceroute: move static methods out of classes and simplify test code
Change-Id: I7906cb20fb34fb09f0de18407cea8f270d710471
Signed-off-by: Ondřej Svoboda <osvoboda(a)redhat.com>
---
M tests/functional/networkTests.py
M vdsm/network/sourceroute.py
M vdsm/network/sourceroutethread.py
3 files changed, 139 insertions(+), 151 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/35/37835/1
diff --git a/tests/functional/networkTests.py b/tests/functional/networkTests.py
index 4c75dad..8b5d8c6 100644
--- a/tests/functional/networkTests.py
+++ b/tests/functional/networkTests.py
@@ -36,9 +36,8 @@
from vdsm.utils import CommandPath, RollbackContext, execCmd, pgrep, running
import caps
-from network import api, errors, tc
+from network import api, errors, sourceroute, tc
from network.configurators.ifcfg import Ifcfg
-from network.sourceroute import StaticSourceRoute
from hookValidation import ValidatesHook
from testlib import (VdsmTestCase as TestCaseBase, namedTemporaryDir,
@@ -202,6 +201,11 @@
and caps.osversion()['version'].startswith('6'))
+def _get_source_route(device_name, ipv4_address):
+ return sourceroute.StaticSourceRoute(
+ device, None, ipv4_address, IP_MASK, IP_GATEWAY)
+
+
@expandPermutations
class NetworkTest(TestCaseBase):
@@ -334,25 +338,14 @@
if ruleExists(rule):
raise self.failureException("routing rule {0} found".format(rule))
- def getSourceRoutingRules(self, deviceName, ip_addr):
- return (StaticSourceRoute(deviceName, None, ip_addr,
- IP_MASK, IP_GATEWAY))._buildRules()
-
- def getSourceRoutingRoutes(self, deviceName, ip_addr):
- return (StaticSourceRoute(deviceName, None, ip_addr,
- IP_MASK, IP_GATEWAY))._buildRoutes()
-
- def getSourceRoutingTable(self, deviceName, ip_addr):
- return (StaticSourceRoute(deviceName, None, ip_addr,
- IP_MASK, IP_GATEWAY))._table
-
- def assertSourceRoutingConfiguration(self, deviceName, ip_addr):
+ def assertSourceRoutingConfiguration(self, device_name, ipv4_address):
"""assert that the IP rules and the routing tables pointed by them
are configured correctly in order to implement source routing"""
- table = self.getSourceRoutingTable(deviceName, ip_addr)
- for route in self.getSourceRoutingRoutes(deviceName, ip_addr):
+ source_route = _get_source_route(device_name, ipv4_address)
+ table = sourceroute._generateTableId(ipv4_address)
+ for route in source_route._buildRoutes():
self.assertRouteExists(route, table)
- for rule in self.getSourceRoutingRules(deviceName, ip_addr):
+ for rule in source_route._buildRules():
self.assertRuleExists(rule)
def assertMtu(self, mtu, *elems):
@@ -1517,9 +1510,10 @@
self.assertEqual(status, SUCCESS, msg)
# Assert that routes and rules don't exist
- for route in self.getSourceRoutingRoutes(deviceName, ip_addr):
+ source_route = _get_source_route(deviceName, ip_addr)
+ for route in source_route._buildRoutes():
self.assertRouteDoesNotExist(route)
- for rule in self.getSourceRoutingRules(deviceName, ip_addr):
+ for rule in source_route._buildRules():
self.assertRuleDoesNotExist(rule)
@cleanupNet
@@ -1807,13 +1801,10 @@
# Assert that routes and rules don't exist
if dhcpv4:
- routes = self.getSourceRoutingRoutes(device_name,
- ip_addr)
- for route in routes:
+ source_route = _get_source_route(device_name, ip_addr)
+ for route in source_route._buildRoutes():
self.assertRouteDoesNotExist(route)
- rules = self.getSourceRoutingRules(device_name,
- ip_addr)
- for rule in rules:
+ for rule in source_route._buildRules():
self.assertRuleDoesNotExist(rule)
finally:
dhcp.delete_dhclient_leases(
diff --git a/vdsm/network/sourceroute.py b/vdsm/network/sourceroute.py
index bf11162..d871591 100644
--- a/vdsm/network/sourceroute.py
+++ b/vdsm/network/sourceroute.py
@@ -43,18 +43,8 @@
self._ipaddr = ipaddr
self._mask = mask
self._gateway = gateway
- self._table = str(self._generateTableId(ipaddr)) if ipaddr else None
- self._network = self._parse_network(ipaddr, mask)
-
- def _parse_network(self, ipaddr, mask):
- if not ipaddr or not mask:
- return None
- network = netaddr.IPNetwork('%s/%s' % (ipaddr, mask))
- return "%s/%s" % (network.network, network.prefixlen)
-
- def _generateTableId(self, ipaddr):
- # TODO: Future proof for IPv6
- return netaddr.IPAddress(ipaddr).value
+ self._table = str(_generateTableId(ipaddr)) if ipaddr else None
+ self._network = _parse_network(ipaddr, mask)
def _buildRoutes(self):
return [Route(network='0.0.0.0/0', via=self._gateway,
@@ -86,127 +76,133 @@
self._configurator.removeSourceRoute(None, None, self.device)
+def _generateTableId(ipaddr):
+ # TODO: Future proof for IPv6
+ return netaddr.IPAddress(ipaddr).value
+
+
+def _parse_network(ipaddr, mask):
+ if not ipaddr or not mask:
+ return None
+ network = netaddr.IPNetwork('%s/%s' % (ipaddr, mask))
+ return "%s/%s" % (network.network, network.prefixlen)
+
+
class DynamicSourceRoute(StaticSourceRoute):
- @staticmethod
- def getTrackingFilePath(device):
- return os.path.join(TRACKED_INTERFACES_FOLDER, device)
-
- @staticmethod
- def addInterfaceTracking(device):
- if device.ipConfig.bootproto == 'dhcp':
- open(DynamicSourceRoute.getTrackingFilePath(device.name), 'a').\
- close()
-
- @staticmethod
- def removeInterfaceTracking(device):
- rmFile(DynamicSourceRoute.getTrackingFilePath(device))
-
- @staticmethod
- def _getRoutes(table):
- routes = []
- for entry in routeShowTable('all'):
- try:
- route = Route.fromText(entry)
- except ValueError:
- logging.debug("Could not parse route %s", entry)
- else:
- if route.table == table:
- routes.append(route)
- return routes
-
- @staticmethod
- def _getTable(rules):
- if rules:
- return rules[0].table
- else:
- logging.error("Table not found")
- return None
-
- @staticmethod
- def _getRules(device):
- """
- 32764: from all to 10.35.0.0/23 iif ovirtmgmt lookup 170066094
- 32765: from 10.35.0.0/23 lookup 170066094
-
- The first rule we'll find directly via the interface name
- We'll then use that rule's destination network, and use it
- to find the second rule via its source network
- """
- allRules = []
- for entry in ruleList():
- try:
- rule = Rule.fromText(entry)
- except ValueError:
- logging.debug("Could not parse rule %s", entry)
- else:
- allRules.append(rule)
-
- # Find the rule we put in place with 'device' as its 'srcDevice'
- rules = [r for r in allRules if r.srcDevice == device]
-
- if not rules:
- logging.error("Routing rules not found for device %s", device)
- return
-
- # Extract its destination network
- network = rules[0].destination
-
- # Find the other rule we put in place - It'll have 'network' as
- # its source
- rules += [r for r in allRules if r.source == network]
-
- return rules
-
def remove(self):
logging.info("Removing gateway - device: %s", self.device)
- rules = self._getRules(self.device)
+ rules = _getRules(self.device)
if rules:
- table = self._getTable(rules)
+ table = _getTable(rules)
if table:
try:
self._configurator.removeSourceRoute(
- self._getRoutes(table), rules,
- self.device)
+ _getRoutes(table), rules, self.device)
except IPRoute2Error as e:
logging.error('ip binary failed during source route '
- 'removal: %s' % e.message)
+ 'removal: %s', e.message)
- @staticmethod
- def _isLibvirtInterfaceFallback(device):
- """
- Checks whether the device belongs to libvirt when libvirt is not yet
- running (network.service runs before libvirtd is started). To do so,
- it must check if there is an autostart network that uses the device.
- """
- bridged_name = "bridge name='%s'" % device
- bridgeless_name = "interface dev='%s'" % device
- for filename in iglob('/etc/libvirt/qemu/networks/autostart/'
- 'vdsm-*'):
- with open(filename, 'r') as xml_file:
- xml_content = xml_file.read()
- if bridged_name in xml_content or \
- bridgeless_name in xml_content:
- return True
- return False
- @staticmethod
- def _isLibvirtInterface(device):
+def addInterfaceTracking(device):
+ if device.ipConfig.bootproto == 'dhcp':
+ open(_getTrackingFilePath(device.name), 'a').close()
+
+
+def removeInterfaceTracking(device):
+ rmFile(_getTrackingFilePath(device))
+
+
+def isVDSMInterface(device):
+ if os.path.exists(_getTrackingFilePath(device)):
+ return True
+ else:
+ return _isLibvirtInterface(device)
+
+
+def _getTrackingFilePath(device):
+ return os.path.join(TRACKED_INTERFACES_FOLDER, device)
+
+
+def _getRoutes(table):
+ routes = []
+ for entry in routeShowTable('all'):
try:
- networks = netinfo.networks()
- except libvirtError: # libvirt might not be started or it just fails
- logging.error('Libvirt failed to answer. It might be the case that'
- ' this script is being run before libvirt startup. '
- ' Thus, check if vdsm owns %s an alternative way' %
- device)
- return DynamicSourceRoute._isLibvirtInterfaceFallback(device)
- trackedInterfaces = [network.get('bridge') or network.get('iface')
- for network in networks.itervalues()]
- return device in trackedInterfaces
-
- @staticmethod
- def isVDSMInterface(device):
- if os.path.exists(DynamicSourceRoute.getTrackingFilePath(device)):
- return True
+ route = Route.fromText(entry)
+ except ValueError:
+ logging.debug("Could not parse route %s", entry)
else:
- return DynamicSourceRoute._isLibvirtInterface(device)
+ if route.table == table:
+ routes.append(route)
+ return routes
+
+
+def _getTable(rules):
+ if rules:
+ return rules[0].table
+ else:
+ logging.error("Table not found")
+ return None
+
+
+def _getRules(device):
+ """
+ 32764: from all to 10.35.0.0/23 iif ovirtmgmt lookup 170066094
+ 32765: from 10.35.0.0/23 lookup 170066094
+
+ The first rule we'll find directly via the interface name
+ We'll then use that rule's destination network, and use it
+ to find the second rule via its source network
+ """
+ allRules = []
+ for entry in ruleList():
+ try:
+ rule = Rule.fromText(entry)
+ except ValueError:
+ logging.debug("Could not parse rule %s", entry)
+ else:
+ allRules.append(rule)
+
+ # Find the rule we put in place with 'device' as its 'srcDevice'
+ rules = [r for r in allRules if r.srcDevice == device]
+
+ if not rules:
+ logging.error("Routing rules not found for device %s", device)
+ return
+
+ # Extract its destination network
+ network = rules[0].destination
+
+ # Find the other rule we put in place - It'll have 'network' as its source
+ rules += [r for r in allRules if r.source == network]
+
+ return rules
+
+
+def _isLibvirtInterface(device):
+ try:
+ networks = netinfo.networks()
+ except libvirtError: # libvirt might not be started or it just fails
+ logging.error('libvirt failed to answer. It might be the case that '
+ 'this script is being run before libvirt startup. Thus, '
+ 'check if VDSM owns %s an alternative way', device)
+ return _isLibvirtInterfaceFallback(device)
+ trackedInterfaces = [network.get('bridge') or network.get('iface')
+ for network in networks.itervalues()]
+ return device in trackedInterfaces
+
+
+def _isLibvirtInterfaceFallback(device):
+ """
+ Checks whether the device belongs to libvirt when libvirt is not yet
+ running (network.service runs before libvirtd is started). To do so,
+ it must check if there is an autostart network that uses the device.
+ """
+ bridged_name = "bridge name='%s'" % device
+ bridgeless_name = "interface dev='%s'" % device
+ for filename in iglob('/etc/libvirt/qemu/networks/autostart/vdsm-*'):
+ with open(filename, 'r') as xml_file:
+ xml_content = xml_file.read()
+ if bridged_name in xml_content or bridgeless_name in xml_content:
+ return True
+ return False
diff --git a/vdsm/network/sourceroutethread.py b/vdsm/network/sourceroutethread.py
index 928384e..752bcb0 100644
--- a/vdsm/network/sourceroutethread.py
+++ b/vdsm/network/sourceroutethread.py
@@ -26,7 +26,8 @@
from vdsm import utils
from .configurators.iproute2 import Iproute2
-from .sourceroute import DynamicSourceRoute
+from .sourceroute import (DynamicSourceRoute, isVDSMInterface,
+ removeInterfaceTracking)
SOURCE_ROUTES_FOLDER = P_VDSM_RUN + 'sourceRoutes'
@@ -41,7 +42,7 @@
action = sourceRouteContents[0]
device = sourceRouteContents[-1]
- if DynamicSourceRoute.isVDSMInterface(device):
+ if isVDSMInterface(device):
if action == 'configure':
ip = sourceRouteContents[1]
mask = sourceRouteContents[2]
@@ -58,7 +59,7 @@
else:
logging.info("interface %s is not a libvirt interface", device)
- DynamicSourceRoute.removeInterfaceTracking(device)
+ removeInterfaceTracking(device)
os.remove(sourceRouteFilePath)
--
To view, visit http://gerrit.ovirt.org/37835
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7906cb20fb34fb09f0de18407cea8f270d710471
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Ondřej Svoboda <osvoboda(a)redhat.com>