summaryrefslogtreecommitdiffstats
path: root/geo-replication/syncdaemon/configinterface.py
diff options
context:
space:
mode:
Diffstat (limited to 'geo-replication/syncdaemon/configinterface.py')
-rw-r--r--geo-replication/syncdaemon/configinterface.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/geo-replication/syncdaemon/configinterface.py b/geo-replication/syncdaemon/configinterface.py
index 8353c1161b2..35f754c98c9 100644
--- a/geo-replication/syncdaemon/configinterface.py
+++ b/geo-replication/syncdaemon/configinterface.py
@@ -9,6 +9,8 @@ import os
import errno
import sys
from stat import ST_DEV, ST_INO, ST_MTIME
+import tempfile
+import shutil
from syncdutils import escape, unescape, norm, update_file, GsyncdError
@@ -19,6 +21,56 @@ config_version = 2.0
re_type = type(re.compile(''))
+
+# (SECTION, OPTION, OLD VALUE, NEW VALUE)
+CONFIGS = (
+ ("peersrx . .", "georep_session_working_dir", "", "/var/lib/glusterd/geo-replication/${mastervol}_${remotehost}_${slavevol}/"),
+ ("peersrx .", "gluster_params", "aux-gfid-mount xlator-option=\*-dht.assert-no-child-down=true", "aux-gfid-mount"),
+ ("peersrx . .", "ssh_command_tar", "", "ssh -oPasswordAuthentication=no -oStrictHostKeyChecking=no -i /var/lib/glusterd/geo-replication/tar_ssh.pem"),
+)
+
+def upgrade_config_file(path):
+ config_change = False
+ config = ConfigParser.RawConfigParser()
+ config.read(path)
+
+ for sec, opt, oldval, newval in CONFIGS:
+ try:
+ val = config.get(sec, opt)
+ except ConfigParser.NoOptionError:
+ # if new config opt not exists
+ config_change = True
+ config.set(sec, opt, newval)
+ continue
+ except ConfigParser.Error:
+ """
+ When gsyncd invoked at the time of create, config file
+ will not be their. Ignore any ConfigParser errors
+ """
+ continue
+
+ if val == newval:
+ # value is same as new val
+ continue
+
+ if val == oldval:
+ # config value needs update
+ config_change = True
+ config.set(sec, opt, newval)
+
+ if config_change:
+ tempConfigFile = tempfile.NamedTemporaryFile(mode="wb", delete=False)
+ with open(tempConfigFile.name, 'wb') as configFile:
+ config.write(configFile)
+
+ # If src and dst are two different file system, then os.rename
+ # fails, In this case if temp file created in /tmp and if /tmp is
+ # seperate fs then os.rename gives following error, so use shutil
+ # OSError: [Errno 18] Invalid cross-device link
+ # mail.python.org/pipermail/python-list/2005-February/342893.html
+ shutil.move(tempConfigFile.name, path)
+
+
class MultiDict(object):
"""a virtual dict-like class which functions as the union of underlying dicts"""