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