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