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