50dc83
From 76921775b0a6760276060409882c0556f19d8d01 Mon Sep 17 00:00:00 2001
50dc83
From: Shwetha K Acharya <sacharya@redhat.com>
50dc83
Date: Wed, 29 May 2019 16:49:01 +0530
50dc83
Subject: [PATCH 214/221] geo-rep: Upgrading config file to new version
50dc83
50dc83
- configuration handling is enhanced with patch
50dc83
https://review.gluster.org/#/c/glusterfs/+/18257/
50dc83
- hence, the old configurations are not applied when
50dc83
Geo-rep session is created in the old version and upgraded.
50dc83
50dc83
This patch solves the issue. It,
50dc83
- checks if the config file is old.
50dc83
- parses required values from old config file and stores in new
50dc83
  config file, which ensures that configurations are applied on
50dc83
  upgrade.
50dc83
- stores old config file as backup.
50dc83
- handles changes in options introduced in
50dc83
  https://review.gluster.org/#/c/glusterfs/+/18257/
50dc83
50dc83
>fixes: bz#1707731
50dc83
>Change-Id: Iad8da6c1e1ae8ecf7c84dfdf8ea3ac6966d8a2a0
50dc83
>Signed-off-by: Shwetha K Acharya <sacharya@redhat.com>
50dc83
50dc83
backport of https://review.gluster.org/#/c/glusterfs/+/22894/
50dc83
50dc83
Bug: 1708064
50dc83
Change-Id: Iad8da6c1e1ae8ecf7c84dfdf8ea3ac6966d8a2a0
50dc83
Signed-off-by: Shwetha K Acharya <sacharya@redhat.com>
50dc83
Reviewed-on: https://code.engineering.redhat.com/gerrit/174743
50dc83
Tested-by: RHGS Build Bot <nigelb@redhat.com>
50dc83
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
50dc83
---
50dc83
 geo-replication/syncdaemon/gsyncd.py       |  5 ++++
50dc83
 geo-replication/syncdaemon/gsyncdconfig.py | 41 ++++++++++++++++++++++++++++++
50dc83
 2 files changed, 46 insertions(+)
50dc83
50dc83
diff --git a/geo-replication/syncdaemon/gsyncd.py b/geo-replication/syncdaemon/gsyncd.py
50dc83
index effe0ce..a4c6f32 100644
50dc83
--- a/geo-replication/syncdaemon/gsyncd.py
50dc83
+++ b/geo-replication/syncdaemon/gsyncd.py
50dc83
@@ -253,6 +253,11 @@ def main():
50dc83
     if args.subcmd == "slave":
50dc83
         override_from_args = True
50dc83
 
50dc83
+    if args.subcmd == "monitor":
50dc83
+        ret = gconf.is_config_file_old(config_file, args.master, extra_tmpl_args["slavevol"])
50dc83
+        if ret is not None:
50dc83
+           gconf.config_upgrade(config_file, ret)
50dc83
+
50dc83
     # Load Config file
50dc83
     gconf.load(GLUSTERFS_CONFDIR + "/gsyncd.conf",
50dc83
                config_file,
50dc83
diff --git a/geo-replication/syncdaemon/gsyncdconfig.py b/geo-replication/syncdaemon/gsyncdconfig.py
50dc83
index 23a1c57..7edc582 100644
50dc83
--- a/geo-replication/syncdaemon/gsyncdconfig.py
50dc83
+++ b/geo-replication/syncdaemon/gsyncdconfig.py
50dc83
@@ -14,6 +14,7 @@ try:
50dc83
 except ImportError:
50dc83
     from configparser import ConfigParser, NoSectionError
50dc83
 import os
50dc83
+import shutil
50dc83
 from string import Template
50dc83
 from datetime import datetime
50dc83
 
50dc83
@@ -325,6 +326,46 @@ class Gconf(object):
50dc83
 
50dc83
         return False
50dc83
 
50dc83
+def is_config_file_old(config_file, mastervol, slavevol):
50dc83
+    cnf = ConfigParser()
50dc83
+    cnf.read(config_file)
50dc83
+    session_section = "peers %s %s" % (mastervol, slavevol)
50dc83
+    try:
50dc83
+        return dict(cnf.items(session_section))
50dc83
+    except NoSectionError:
50dc83
+        return None
50dc83
+
50dc83
+def config_upgrade(config_file, ret):
50dc83
+    config_file_backup = os.path.join(os.path.dirname(config_file), "gsyncd.conf.bkp")
50dc83
+
50dc83
+    #copy old config file in a backup file
50dc83
+    shutil.copyfile(config_file, config_file_backup)
50dc83
+
50dc83
+    #write a new config file
50dc83
+    config = ConfigParser()
50dc83
+    config.add_section('vars')
50dc83
+
50dc83
+    for key, value in ret.items():
50dc83
+        #handle option name changes
50dc83
+        if key == "use_tarssh":
50dc83
+            new_key = "sync-method"
50dc83
+            if value == "true":
50dc83
+                new_value = "tarssh"
50dc83
+            else:
50dc83
+                new_value = "rsync"
50dc83
+                config.set('vars', new_key, new_value)
50dc83
+
50dc83
+        if key == "timeout":
50dc83
+            new_key = "slave-timeout"
50dc83
+            config.set('vars', new_key, value)
50dc83
+
50dc83
+        #for changes like: ignore_deletes to ignore-deletes
50dc83
+        new_key = key.replace("_", "-")
50dc83
+        config.set('vars', new_key, value)
50dc83
+
50dc83
+    with open(config_file, 'w') as configfile:
50dc83
+        config.write(configfile)
50dc83
+
50dc83
 
50dc83
 def validate_unixtime(value):
50dc83
     try:
50dc83
-- 
50dc83
1.8.3.1
50dc83