[node-patches] Change in ovirt-node[master]: config: Fix validation of NTP/DNS servers

fabiand at fedoraproject.org fabiand at fedoraproject.org
Mon Mar 4 08:57:26 UTC 2013


Fabian Deutsch has uploaded a new change for review.

Change subject: config: Fix validation of NTP/DNS servers
......................................................................

config: Fix validation of NTP/DNS servers

Previously the validation of NTP and DNS servers failed in some cases
because the validator was called incorrectly.
Now the validator is called correctly.

rhbz#917485

Change-Id: I233c9b9fc2dfeba1c1ed8bbab3d8ba2c656ccd80
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M scripts/tui/src/ovirt/node/app.py
M scripts/tui/src/ovirt/node/config/defaults.py
2 files changed, 26 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/16/12616/1

diff --git a/scripts/tui/src/ovirt/node/app.py b/scripts/tui/src/ovirt/node/app.py
index 9543f5f..984032c 100644
--- a/scripts/tui/src/ovirt/node/app.py
+++ b/scripts/tui/src/ovirt/node/app.py
@@ -300,7 +300,7 @@
         except Exception as e:
             utils.process.call("reset")
             self.logger.error("An error appeared in the UI: %s" % repr(e))
-            self.logger.debug("%s" % traceback.format_exc())
+            self.logger.debug("Exception:", exc_info=True)
             console.writeln("Press ENTER to logout ...")
             console.writeln("or enter 's' to drop to shell")
             if console.wait_for_keypress() == 's':
diff --git a/scripts/tui/src/ovirt/node/config/defaults.py b/scripts/tui/src/ovirt/node/config/defaults.py
index 5bca3a9..a53cd95 100644
--- a/scripts/tui/src/ovirt/node/config/defaults.py
+++ b/scripts/tui/src/ovirt/node/config/defaults.py
@@ -201,9 +201,13 @@
             A dict mapping an argname to it's cfg key (or vice versa)
         """
         func = self.update.wrapped_func
-        varnames = func.func_code.co_varnames[1:]
-        assert len(varnames) == len(self.keys)
-        mapping = zip(self.keys, varnames) if keys_to_args else zip(varnames,
+        # co_varnames contains all args within the func, the args are kept
+        # at the beginning of the list, that's why we slice the varnames list
+        # (start after self until the number of args)
+        argnames = func.func_code.co_varnames[1:func.func_code.co_argcount]
+        assert len(argnames) == len(self.keys), "argnames (%s) != keys (%s)" %\
+            (argnames, self.keys)
+        mapping = zip(self.keys, argnames) if keys_to_args else zip(argnames,
                                                                     self.keys)
         return dict(mapping)
 
@@ -442,8 +446,15 @@
     @NodeConfigFileSection.map_and_update_defaults_decorator
     def update(self, servers):
         assert type(servers) is list
-        servers = filter(lambda i: i.strip() not in ["", None], servers)
-        map(valid.IPv4Address(), servers)
+        # Preparation
+        servers = [i.strip() for i in servers]
+        servers = [i for i in servers if i not in ["", None]]
+
+        # Validation
+        validator = lambda v: valid.FQDNOrIPAddress()
+        map(validator, servers)
+
+        # Mangling for the conf file format
         return {"OVIRT_DNS": ",".join(servers) or None
                 }
 
@@ -554,8 +565,15 @@
     @NodeConfigFileSection.map_and_update_defaults_decorator
     def update(self, servers):
         assert type(servers) is list
-        servers = filter(lambda i: i.strip() not in ["", None], servers)
-        map(valid.FQDNOrIPAddress(), servers)
+        # Preparation
+        servers = [i.strip() for i in servers]
+        servers = [i for i in servers if i not in ["", None]]
+
+        # Validation
+        validator = lambda v: valid.FQDNOrIPAddress()
+        map(validator, servers)
+
+        # Mangling to match the conf file
         return {"OVIRT_NTP": ",".join(servers) or None
                 }
 


--
To view, visit http://gerrit.ovirt.org/12616
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I233c9b9fc2dfeba1c1ed8bbab3d8ba2c656ccd80
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Fabian Deutsch <fabiand at fedoraproject.org>



More information about the node-patches mailing list