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