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