[node-patches] Change in ovirt-node[node-3.0]: valid: Add NFSAddress validator

fabiand at fedoraproject.org fabiand at fedoraproject.org
Thu May 23 15:19:50 UTC 2013


Fabian Deutsch has uploaded a new change for review.

Change subject: valid: Add NFSAddress validator
......................................................................

valid: Add NFSAddress validator

rhbz#917485

Change-Id: I0a80f18981b6ffc683c17499dca418d2cbd739c1
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M src/ovirt/node/config/defaults.py
M src/ovirt/node/setup/kdump_page.py
M src/ovirt/node/valid.py
3 files changed, 49 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/34/15034/1

diff --git a/src/ovirt/node/config/defaults.py b/src/ovirt/node/config/defaults.py
index 39f7fcf..c6068ef 100644
--- a/src/ovirt/node/config/defaults.py
+++ b/src/ovirt/node/config/defaults.py
@@ -793,7 +793,7 @@
 
     @NodeConfigFileSection.map_and_update_defaults_decorator
     def update(self, nfs, ssh, local):
-        (valid.Empty(or_none=True) | valid.FQDNOrIPAddress())(nfs)
+        (valid.Empty(or_none=True) | valid.NFSAddress())(nfs)
         (valid.Empty(or_none=True) | valid.URL())(ssh)
         (valid.Empty(or_none=True) | valid.Boolean())(local)
         return {"OVIRT_KDUMP_LOCAL": "true" if local else None
diff --git a/src/ovirt/node/setup/kdump_page.py b/src/ovirt/node/setup/kdump_page.py
index e19f9f3..3017520 100644
--- a/src/ovirt/node/setup/kdump_page.py
+++ b/src/ovirt/node/setup/kdump_page.py
@@ -68,8 +68,8 @@
         """
         # FIXME improve validation for ssh and nfs
         return {"kdump.type": valid.Options(dict(self._types).keys()),
-                "kdump.ssh_location": valid.Empty() | valid.NoSpaces(),
-                "kdump.nfs_location": valid.Empty() | valid.NoSpaces(),
+                "kdump.ssh_location": valid.Empty() | valid.URL(),
+                "kdump.nfs_location": valid.Empty() | valid.NFSAddress(),
                 }
 
     def ui_content(self):
diff --git a/src/ovirt/node/valid.py b/src/ovirt/node/valid.py
index 14288b7..d9928b0 100644
--- a/src/ovirt/node/valid.py
+++ b/src/ovirt/node/valid.py
@@ -259,7 +259,7 @@
 
 
 class FQDN(RegexValidator):
-    """Matches a FQDN
+    """Matches a FQDN or a simple hostname
 
     >>> FQDN()("example.com")
     True
@@ -452,3 +452,48 @@
         except:
             is_valid = False
         return is_valid
+
+
+class NFSAddress(Validator):
+    """Validate an NFS Address
+
+    >>> NFSAddress().validate("1.2.3.4:/var/nfsserver")
+    True
+    >>> NFSAddress().validate("1::4:/var/nfsserver")
+    True
+
+    >>> NFSAddress().validate("")
+    False
+    >>> NFSAddress().validate("1234")
+    False
+    >>> NFSAddress().validate("1.2.3.4")
+    False
+    >>> NFSAddress().validate("1.2.3.4:")
+    False
+    >>> NFSAddress().validate("1.2.3.4/var/nfsserver")
+    False
+    >>> NFSAddress().validate("1.2.3.4:var/nfsserver")
+    False
+    >>> NFSAddress().validate("1::4")
+    False
+    >>> NFSAddress().validate("1:2:3:4")
+    False
+    >>> NFSAddress().validate(":/var/nfsserver")
+    False
+    >>> NFSAddress().validate("/var/nfsserver")
+    False
+    """
+    description = "a valid NFS address"
+
+    def validate(self, value):
+        is_valid = False
+        try:
+            # Addr can be IPv6 or IPv4, therefor a bit more cplx
+            parts = value.split(":")
+            addr, path = ":".join(parts[:-1]), parts[-1]
+            FQDNOrIPAddress()(addr)
+            is_valid = path.startswith("/")
+        except:
+            is_valid = False
+
+        return is_valid


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

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



More information about the node-patches mailing list