Change in vdsm[master]: sourceroute: move validation into IPv4.validate_source_route
osvoboda at redhat.com
osvoboda at redhat.com
Fri May 29 14:22:29 UTC 2015
Ondřej Svoboda has uploaded a new change for review.
Change subject: sourceroute: move validation into IPv4.validate_source_route
......................................................................
sourceroute: move validation into IPv4.validate_source_route
Change-Id: I4a72aa9956cbc774805e9e31588e34b8c42a44d2
Signed-off-by: Ondřej Svoboda <osvoboda at redhat.com>
---
M vdsm/network/configurators/__init__.py
M vdsm/network/models.py
M vdsm/network/sourceroutethread.py
3 files changed, 14 insertions(+), 21 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/08/41608/1
diff --git a/vdsm/network/configurators/__init__.py b/vdsm/network/configurators/__init__.py
index 05a98ea..01476e7 100644
--- a/vdsm/network/configurators/__init__.py
+++ b/vdsm/network/configurators/__init__.py
@@ -123,19 +123,12 @@
qos.remove_outbound(top_device)
def _addSourceRoute(self, device):
- ipv4 = device.ipv4
# bootproto is None for both static and no bootproto
- if ipv4.bootproto != 'dhcp' and device.master is None:
- logging.debug("Adding source route: name=%s, addr=%s, netmask=%s, "
- "gateway=%s" % (device.name, ipv4.address,
- ipv4.netmask, ipv4.gateway))
- if (ipv4.gateway in (None, '0.0.0.0')
- or not ipv4.address or not ipv4.netmask):
- logging.warning(
- 'invalid input for source routing: name=%s, '
- 'addr=%s, netmask=%s, gateway=%s',
- device.name, ipv4.address, ipv4.netmask,
- ipv4.gateway)
+ if device.ipv4.bootproto != 'dhcp' and device.master is None:
+ try:
+ device.ipv4.validate_source_route()
+ except:
+ logging.exception('Invalid input for source routing')
else:
source_route = StaticSourceRoute(device.name, device.ipv4)
source_route.prepare_configuration()
diff --git a/vdsm/network/models.py b/vdsm/network/models.py
index 5281d28..01e4baf 100644
--- a/vdsm/network/models.py
+++ b/vdsm/network/models.py
@@ -422,6 +422,11 @@
cne.message = '%r is not a valid IPv4 gateway' % gateway
raise
+ def validate_source_route(self):
+ if not self.address or self.gateway in (None, '0.0.0.0'):
+ raise ConfigNetworkError(
+ ne.ERR_BAD_ADDR, 'Missing address or gateway: %r' % self)
+
class IPv6(object):
def __init__(self, address=None, gateway=None, defaultRoute=None,
diff --git a/vdsm/network/sourceroutethread.py b/vdsm/network/sourceroutethread.py
index f4b2ebd..08538a5 100644
--- a/vdsm/network/sourceroutethread.py
+++ b/vdsm/network/sourceroutethread.py
@@ -48,18 +48,13 @@
ipv4 = IPv4(address=sourceRouteContents[1],
netmask=sourceRouteContents[2],
gateway=sourceRouteContents[3])
+ ipv4.validate_source_route()
except:
- # IPv4() only validates addresses and guards against
- # having an address while missing a netmask
logging.exception('Invalid DHCP response')
else:
- if not ipv4.address or ipv4.gateway in (None,
- '0.0.0.0'):
- logging.error('Invalid DHCP response: %r', ipv4)
- else:
- source_route = DynamicSourceRoute(device, ipv4)
- source_route.prepare_configuration()
- configurator.configureSourceRoute(source_route)
+ source_route = DynamicSourceRoute(device, ipv4)
+ source_route.prepare_configuration()
+ configurator.configureSourceRoute(source_route)
else:
source_route = DynamicSourceRoute(device)
if source_route.prepare_removal():
--
To view, visit https://gerrit.ovirt.org/41608
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4a72aa9956cbc774805e9e31588e34b8c42a44d2
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Ondřej Svoboda <osvoboda at redhat.com>
More information about the vdsm-patches
mailing list