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