diff options
| author | Aravinda VK <avishwan@redhat.com> | 2016-06-23 11:53:36 +0530 | 
|---|---|---|
| committer | Jeff Darcy <jdarcy@redhat.com> | 2016-07-12 05:09:40 -0700 | 
| commit | d94bf608b16b82f2c8f8588a96459cb746773b32 (patch) | |
| tree | 45f052e7502122518d7c70ac79b0bccc94f74a9c | |
| parent | 9733c68e878869daec196bf7bca16780eef73f74 (diff) | |
geo-rep: Handle Config parser errors
Python ConfigParser lib has two methods, readfp and read, it should
be used as follows.
    readfp(open("defaults.conf"))
    read("custom.conf")
ConfigParser.read(path) ignores any file errors, which is intentional
since errors are handled while loading default config.
Geo-rep uses only one config file(Session config in Master side and
Template config on Slave side) so we should use readfp to avoid
skipping OS errors.
config.read is retained in case of `--config-set-rx` where glusterd
creates new template config file.
BUG: 1349273
Change-Id: I15a14d3743facd7b8c7af0edc70fdefaa43efd04
Signed-off-by: Aravinda VK <avishwan@redhat.com>
Reviewed-on: http://review.gluster.org/14777
Smoke: Gluster Build System <jenkins@build.gluster.org>
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
Reviewed-by: Jeff Darcy <jdarcy@redhat.com>
| -rw-r--r-- | geo-replication/syncdaemon/configinterface.py.in | 24 | ||||
| -rw-r--r-- | geo-replication/syncdaemon/gsyncd.py | 9 | 
2 files changed, 23 insertions, 10 deletions
diff --git a/geo-replication/syncdaemon/configinterface.py.in b/geo-replication/syncdaemon/configinterface.py.in index 5d67b8a471a..e1cf007a2b8 100644 --- a/geo-replication/syncdaemon/configinterface.py.in +++ b/geo-replication/syncdaemon/configinterface.py.in @@ -30,6 +30,7 @@ config_version = 2.0  re_type = type(re.compile('')) +TMPL_CONFIG_FILE = "@GLUSTERD_WORKDIR@/geo-replication/gsyncd_template.conf"  # (SECTION, OPTION, OLD VALUE, NEW VALUE)  CONFIGS = ( @@ -79,10 +80,17 @@ CONFIGS = (  ) -def upgrade_config_file(path): +def upgrade_config_file(path, confdata):      config_change = False      config = ConfigParser.RawConfigParser() -    config.read(path) +    # If confdata.rx present then glusterd is adding config values, +    # it will create config file if not exists. config.read is fine in +    # this case since any other error will be raised during write. +    if getattr(confdata, "rx", False): +        config.read(path) +    else: +        with open(path) as fp: +            config.readfp(fp)      for sec, opt, oldval, newval in CONFIGS:          try: @@ -190,7 +198,7 @@ class GConffile(object):                  s2[k] = v              self.config._sections[n] = s2 -    def __init__(self, path, peers, *dd): +    def __init__(self, path, peers, confdata, *dd):          """          - .path: location of config file          - .config: underlying ConfigParser instance @@ -202,7 +210,12 @@ class GConffile(object):          self.path = path          self.auxdicts = dd          self.config = ConfigParser.RawConfigParser() -        self.config.read(path) +        if getattr(confdata, "rx", False): +            self.config.read(path) +        else: +            with open(path) as fp: +                self.config.readfp(fp) +          self.dev, self.ino, self.mtime = -1, -1, -1          self._normconfig() @@ -217,7 +230,8 @@ class GConffile(object):                  sres = None          self.config = ConfigParser.RawConfigParser() -        self.config.read(self.path) +        with open(self.path) as fp: +            self.config.readfp(fp)          self._normconfig()      def get_realtime(self, opt): diff --git a/geo-replication/syncdaemon/gsyncd.py b/geo-replication/syncdaemon/gsyncd.py index f41756a0b93..c2699a183ae 100644 --- a/geo-replication/syncdaemon/gsyncd.py +++ b/geo-replication/syncdaemon/gsyncd.py @@ -29,7 +29,7 @@ from gconf import gconf  from syncdutils import FreeObject, norm, grabpidfile, finalize  from syncdutils import log_raise_exception, privileged, boolify  from syncdutils import GsyncdError, select, set_term_handler -from configinterface import GConffile, upgrade_config_file +from configinterface import GConffile, upgrade_config_file, TMPL_CONFIG_FILE  import resource  from monitor import monitor  import xml.etree.ElementTree as XET @@ -536,12 +536,11 @@ def main_i():                  if name == 'remote':                      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") +        rconf['config_file'] = TMPL_CONFIG_FILE -    upgrade_config_file(rconf['config_file']) +    upgrade_config_file(rconf['config_file'], confdata)      gcnf = GConffile( -        rconf['config_file'], canon_peers, +        rconf['config_file'], canon_peers, confdata,          defaults.__dict__, opts.__dict__, namedict)      checkpoint_change = False  | 
