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