Change in vdsm[master]: sourceroute: move most of validation to configure_source_route
osvoboda at redhat.com
osvoboda at redhat.com
Fri May 29 17:17:51 UTC 2015
Ondřej Svoboda has uploaded a new change for review.
Change subject: sourceroute: move most of validation to configure_source_route
......................................................................
sourceroute: move most of validation to configure_source_route
Change-Id: I4d7f314b9d6b6ca127fa2911b9b5703fc03ef48f
Signed-off-by: Ondřej Svoboda <osvoboda at redhat.com>
---
M vdsm/network/configurators/__init__.py
M vdsm/network/sourceroutethread.py
2 files changed, 29 insertions(+), 26 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/15/41615/1
diff --git a/vdsm/network/configurators/__init__.py b/vdsm/network/configurators/__init__.py
index 20ac6f2..665a9d2 100644
--- a/vdsm/network/configurators/__init__.py
+++ b/vdsm/network/configurators/__init__.py
@@ -100,9 +100,14 @@
raise NotImplementedError
def configure_source_route(self, device_name, ipv4):
- source_route = SourceRoute(device_name, ipv4)
- source_route.prepare_configuration()
- self._configure_source_route(source_route)
+ try:
+ ipv4.validate_source_route()
+ except:
+ logging.exception('Invalid input for source routing')
+ else:
+ source_route = SourceRoute(device_name, ipv4)
+ source_route.prepare_configuration()
+ self._configure_source_route(source_route)
def remove_dynamic_source_route(self, device_name):
raise NotImplementedError
@@ -127,12 +132,7 @@
def _add_static_source_route(self, device):
# bootproto is None for both static and no bootproto
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:
- self.configure_source_route(device.name, device.ipv4)
+ self.configure_source_route(device.name, device.ipv4)
def _setNewMtu(self, iface, ifaceVlans):
"""
diff --git a/vdsm/network/sourceroutethread.py b/vdsm/network/sourceroutethread.py
index ad423ed..ee355fb 100644
--- a/vdsm/network/sourceroutethread.py
+++ b/vdsm/network/sourceroutethread.py
@@ -35,23 +35,20 @@
class DHClientEventHandler(pyinotify.ProcessEvent):
- def process_IN_CLOSE_WRITE_filePath(self, sourceRouteFilePath):
- logging.debug("Responding to DHCP response in %s", sourceRouteFilePath)
- with open(sourceRouteFilePath, 'r') as sourceRouteFile:
- sourceRouteContents = sourceRouteFile.read().split()
- action = sourceRouteContents[0]
- device = sourceRouteContents[-1]
+ def process_IN_CLOSE_WRITE(self, event):
+ self.process_tracking_file(event.pathname)
+
+ def process_tracking_file(self, tracking_file_path):
+ with open(tracking_file_path, 'r') as tracking_file:
+ file_contents = tracking_file.read().split()
+ logging.debug('Responding to DHCP response: %s', file_contents)
+ action = file_contents[0]
+ device = file_contents[-1]
if DynamicSourceRoute.isVDSMInterface(device):
if action == 'configure':
- try:
- ipv4 = IPv4(address=sourceRouteContents[1],
- netmask=sourceRouteContents[2],
- gateway=sourceRouteContents[3])
- ipv4.validate_source_route()
- except:
- logging.exception('Invalid DHCP response')
- else:
+ ipv4 = _prepare_configuration(file_contents)
+ if ipv4:
configurator.configure_source_route(device, ipv4)
else:
configurator.remove_dynamic_source_route(device)
@@ -61,9 +58,6 @@
DynamicSourceRoute.removeInterfaceTracking(device)
os.remove(sourceRouteFilePath)
-
- def process_IN_CLOSE_WRITE(self, event):
- self.process_IN_CLOSE_WRITE_filePath(event.pathname)
def start():
@@ -91,3 +85,12 @@
SOURCE_ROUTES_FOLDER + '/' + filePath)
notifier.loop()
+
+
+def _prepare_configuration(tracking_file_contents):
+ try:
+ address, netmask, gateway = tracking_file_contents[1:4]
+ return IPv4(address, netmask, gateway)
+ except:
+ logging.exception('Invalid DHCP response')
+ return None
--
To view, visit https://gerrit.ovirt.org/41615
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4d7f314b9d6b6ca127fa2911b9b5703fc03ef48f
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