summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAravinda VK <avishwan@redhat.com>2014-01-20 12:23:35 +0530
committerVijay Bellur <vbellur@redhat.com>2014-02-10 17:07:42 -0800
commit8014bf281294e155dfbc7041cfef5151ae4f19e5 (patch)
tree5a9ea804c133821bcc63570371de385ff842a8a2
parentc6ef2cd937c1a8b4b7ef1c2636177c3345f0cedf (diff)
geo-rep: Config file upgrade
When old config file is used with new geo-rep, config item like 'georep_session_working_dir' was missing in old config file. With this patch geo-rep sets the default value for new items. Following config options supported: - georep_session_working_dir - gluster_params - ssh_command_tar BUG: 1036539 Change-Id: If277a14d21f4caee568908b73a2988352c08dcc8 Reviewed-on: http://review.gluster.org/6934 Signed-off-by: Aravinda VK <avishwan@redhat.com> Reviewed-on: http://review.gluster.org/6935 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Vijay Bellur <vbellur@redhat.com>
-rw-r--r--geo-replication/syncdaemon/configinterface.py52
-rw-r--r--geo-replication/syncdaemon/gsyncd.py4
2 files changed, 55 insertions, 1 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"""
diff --git a/geo-replication/syncdaemon/gsyncd.py b/geo-replication/syncdaemon/gsyncd.py
index 64c26a5d29d..6eb62c6b076 100644
--- a/geo-replication/syncdaemon/gsyncd.py
+++ b/geo-replication/syncdaemon/gsyncd.py
@@ -20,7 +20,7 @@ from ipaddr import IPAddress, IPNetwork
from gconf import gconf
from syncdutils import FreeObject, norm, grabpidfile, finalize, log_raise_exception
from syncdutils import GsyncdError, select, set_term_handler, privileged, update_file
-from configinterface import GConffile
+from configinterface import GConffile, upgrade_config_file
import resource
from monitor import monitor
@@ -371,6 +371,8 @@ def main_i():
namedict['remotehost'] = x.remotehost
if not 'config_file' in rconf:
rconf['config_file'] = os.path.join(os.path.dirname(sys.argv[0]), "conf/gsyncd_template.conf")
+
+ upgrade_config_file(rconf['config_file'])
gcnf = GConffile(rconf['config_file'], canon_peers, defaults.__dict__, opts.__dict__, namedict)
checkpoint_change = False