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