e3c68b
From 8b5b3b247a00515d3188453c27b0ba749e93d325 Mon Sep 17 00:00:00 2001
e3c68b
From: Aravinda VK <avishwan@redhat.com>
e3c68b
Date: Tue, 26 Mar 2019 13:20:13 +0530
e3c68b
Subject: [PATCH 339/344] geo-rep: fix integer config validation
e3c68b
e3c68b
ssh-port validation is mentioned as `validation=int` in template
e3c68b
`gsyncd.conf`, but not handled this during geo-rep config set.
e3c68b
e3c68b
upstream patch:
e3c68b
    https://review.gluster.org/#/c/glusterfs/+/22418/
e3c68b
Backport of:
e3c68b
e3c68b
    >Fixes: bz#1692666
e3c68b
    >Change-Id: I3f19d9b471b0a3327e4d094dfbefcc58ed2c34f6
e3c68b
    >Signed-off-by: Aravinda VK <avishwan@redhat.com>
e3c68b
    >Signed-off-by: Sunny Kumar <sunkumar@redhat.com>
e3c68b
e3c68b
BUG: 1782162
e3c68b
Change-Id: I3f19d9b471b0a3327e4d094dfbefcc58ed2c34f6
e3c68b
Signed-off-by: Sunny Kumar <sunkumar@redhat.com>
e3c68b
Reviewed-on: https://code.engineering.redhat.com/gerrit/187533
e3c68b
Tested-by: RHGS Build Bot <nigelb@redhat.com>
e3c68b
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
e3c68b
---
e3c68b
 geo-replication/syncdaemon/gsyncdconfig.py | 23 ++++++++++++++++++-----
e3c68b
 tests/00-geo-rep/georep-basic-dr-rsync.t   |  3 +++
e3c68b
 2 files changed, 21 insertions(+), 5 deletions(-)
e3c68b
e3c68b
diff --git a/geo-replication/syncdaemon/gsyncdconfig.py b/geo-replication/syncdaemon/gsyncdconfig.py
e3c68b
index f823311..8848071 100644
e3c68b
--- a/geo-replication/syncdaemon/gsyncdconfig.py
e3c68b
+++ b/geo-replication/syncdaemon/gsyncdconfig.py
e3c68b
@@ -329,6 +329,9 @@ class Gconf(object):
e3c68b
         if item["validation"] == "unixtime":
e3c68b
             return validate_unixtime(value)
e3c68b
 
e3c68b
+        if item["validation"] == "int":
e3c68b
+            return validate_int(value)
e3c68b
+
e3c68b
         return False
e3c68b
 
e3c68b
     def _is_config_changed(self):
e3c68b
@@ -381,6 +384,14 @@ def config_upgrade(config_file, ret):
e3c68b
         config.write(configfile)
e3c68b
 
e3c68b
 
e3c68b
+def validate_int(value):
e3c68b
+    try:
e3c68b
+        _ = int(value)
e3c68b
+        return True
e3c68b
+    except ValueError:
e3c68b
+        return False
e3c68b
+
e3c68b
+
e3c68b
 def validate_unixtime(value):
e3c68b
     try:
e3c68b
         y = datetime.fromtimestamp(int(value)).strftime("%Y")
e3c68b
@@ -393,11 +404,13 @@ def validate_unixtime(value):
e3c68b
 
e3c68b
 
e3c68b
 def validate_minmax(value, minval, maxval):
e3c68b
-    value = int(value)
e3c68b
-    minval = int(minval)
e3c68b
-    maxval = int(maxval)
e3c68b
-
e3c68b
-    return value >= minval and value <= maxval
e3c68b
+    try:
e3c68b
+        value = int(value)
e3c68b
+        minval = int(minval)
e3c68b
+        maxval = int(maxval)
e3c68b
+        return value >= minval and value <= maxval
e3c68b
+    except ValueError:
e3c68b
+        return False
e3c68b
 
e3c68b
 
e3c68b
 def validate_choice(value, allowed_values):
e3c68b
diff --git a/tests/00-geo-rep/georep-basic-dr-rsync.t b/tests/00-geo-rep/georep-basic-dr-rsync.t
e3c68b
index b432635..b6fbf18 100644
e3c68b
--- a/tests/00-geo-rep/georep-basic-dr-rsync.t
e3c68b
+++ b/tests/00-geo-rep/georep-basic-dr-rsync.t
e3c68b
@@ -71,6 +71,9 @@ EXPECT_WITHIN $GEO_REP_TIMEOUT 4 check_status_num_rows "Created"
e3c68b
 #Config gluster-command-dir
e3c68b
 TEST $GEOREP_CLI $master $slave config gluster-command-dir ${GLUSTER_CMD_DIR}
e3c68b
 
e3c68b
+#Config Set ssh-port to validate int validation
e3c68b
+TEST $GEOREP_CLI $master $slave config ssh-port 22
e3c68b
+
e3c68b
 #Config gluster-command-dir
e3c68b
 TEST $GEOREP_CLI $master $slave config slave-gluster-command-dir ${GLUSTER_CMD_DIR}
e3c68b
 
e3c68b
-- 
e3c68b
1.8.3.1
e3c68b