summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCsaba Henk <csaba@gluster.com>2011-04-13 01:46:07 +0000
committerAnand Avati <avati@gluster.com>2011-04-13 04:43:14 -0700
commitac27e6980869d52ea90b869de01538dec28620ae (patch)
tree6e5afe0f84f5083105f65459892a5b7be8051047
parentb1cad2780c34f9dd664f67565ceac3b5a5cf3bcb (diff)
syncdaemon: ensure -/_ invariance in tunables, in all components
Signed-off-by: Csaba Henk <csaba@gluster.com> Signed-off-by: Anand Avati <avati@gluster.com> BUG: 2659 (gsync config-del option is not working properly) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2659
-rw-r--r--xlators/features/marker/utils/syncdaemon/configinterface.py40
-rw-r--r--xlators/features/marker/utils/syncdaemon/gsyncd.py6
-rw-r--r--xlators/features/marker/utils/syncdaemon/syncdutils.py4
3 files changed, 32 insertions, 18 deletions
diff --git a/xlators/features/marker/utils/syncdaemon/configinterface.py b/xlators/features/marker/utils/syncdaemon/configinterface.py
index 23526861fac..8bcfbcb39b6 100644
--- a/xlators/features/marker/utils/syncdaemon/configinterface.py
+++ b/xlators/features/marker/utils/syncdaemon/configinterface.py
@@ -5,7 +5,7 @@ except ImportError:
import configparser as ConfigParser
import re
-import syncdutils
+from syncdutils import escape, unescape, norm, update_file
SECT_ORD = '__section_order__'
SECT_META = '__meta__'
@@ -15,11 +15,23 @@ re_type = type(re.compile(''))
class GConffile(object):
+ def _normconfig(self):
+ for n, s in self.config._sections.items():
+ if n.find('__') == 0:
+ continue
+ s2 = type(s)()
+ for k, v in s.items():
+ if k.find('__') != 0:
+ k = norm(k)
+ s2[k] = v
+ self.config._sections[n] = s2
+
def __init__(self, path, peers):
self.peers = peers
self.path = path
self.config = ConfigParser.RawConfigParser()
self.config.read(path)
+ self._normconfig()
def section(self, rx=False):
peers = self.peers
@@ -30,13 +42,13 @@ class GConffile(object):
st = 'peersrx'
else:
st = 'peers'
- return ' '.join([st] + [syncdutils.escape(u) for u in peers])
+ return ' '.join([st] + [escape(u) for u in peers])
@staticmethod
def parse_section(section):
sl = section.split()
st = sl.pop(0)
- sl = [syncdutils.unescape(u) for u in sl]
+ sl = [unescape(u) for u in sl]
if st == 'peersrx':
sl = [re.compile(u) for u in sl]
return sl
@@ -81,11 +93,7 @@ class GConffile(object):
if not self.peers:
raise RuntimeError('no peers given, cannot select matching options')
def update_from_sect(sect):
- for k, v in self.config._sections[sect].items():
- if k == '__name__':
- continue
- k = k.replace('-', '_')
- dct[k] = v
+ dct.update(self.config._sections[sect])
for sect in self.ord_sections():
sp = self.parse_section(sect)
if isinstance(sp[0], re_type) and len(sp) == len(self.peers):
@@ -103,23 +111,25 @@ class GConffile(object):
d = {}
self.update_to(d)
if opt:
+ opt = norm(opt)
d = {opt: d.get(opt, "")}
for k, v in d.iteritems():
if k == '__name__':
continue
print("%s: %s" % (k, v))
- def write(self, trfn, *a, **kw):
+ def write(self, trfn, opt, *a, **kw):
def mergeconf(f):
self.config = ConfigParser.RawConfigParser()
self.config.readfp(f)
+ self._normconfig()
if not self.config.has_section(SECT_META):
self.config.add_section(SECT_META)
self.config.set(SECT_META, 'version', config_version)
- return trfn(*a, **kw)
+ return trfn(norm(opt), *a, **kw)
def updateconf(f):
self.config.write(f)
- syncdutils.update_file(self.path, updateconf, mergeconf)
+ update_file(self.path, updateconf, mergeconf)
def _set(self, opt, val, rx=False):
sect = self.section(rx)
@@ -132,13 +142,13 @@ class GConffile(object):
self.config.set(sect, opt, val)
return True
- def set(self, *a, **kw):
- self.write(self._set, *a, **kw)
+ def set(self, opt, *a, **kw):
+ self.write(self._set, opt, *a, **kw)
def _delete(self, opt, rx=False):
sect = self.section(rx)
if self.config.has_section(sect):
return self.config.remove_option(sect, opt)
- def delete(self, *a, **kw):
- self.write(self._delete, *a, **kw)
+ def delete(self, opt, *a, **kw):
+ self.write(self._delete, opt, *a, **kw)
diff --git a/xlators/features/marker/utils/syncdaemon/gsyncd.py b/xlators/features/marker/utils/syncdaemon/gsyncd.py
index 329500b1e93..0ed120e0397 100644
--- a/xlators/features/marker/utils/syncdaemon/gsyncd.py
+++ b/xlators/features/marker/utils/syncdaemon/gsyncd.py
@@ -15,7 +15,7 @@ from logging import Logger
from errno import EEXIST, ENOENT, EACCES, EAGAIN
from gconf import gconf
-from syncdutils import FreeObject
+from syncdutils import FreeObject, norm
from configinterface import GConffile
import resource
from monitor import monitor
@@ -239,7 +239,7 @@ def main_i():
op.add_option('--canonicalize-url', dest='do_canon', action='callback', callback=store_local_curry('raw'))
op.add_option('--canonicalize-escape-url', dest='do_canon', action='callback', callback=store_local_curry('escaped'))
- tunables = [ o.get_opt_string()[2:] for o in op.option_list if o.callback in (store_abs, None) and o.get_opt_string() not in ('--version', '--help') ]
+ tunables = [ norm(o.get_opt_string()[2:]) for o in op.option_list if o.callback in (store_abs, None) and o.get_opt_string() not in ('--version', '--help') ]
# precedence for sources of values: 1) commandline, 2) cfg file, 3) defaults
# -- for this to work out we need to tell apart defaults from explicitly set
@@ -285,7 +285,7 @@ def main_i():
gcnf = GConffile(rconf['config_file'], canon_peers)
if confdata:
- opt_ok = confdata.opt in tunables + [None]
+ opt_ok = norm(confdata.opt) in tunables + [None]
if confdata.op == 'check':
if opt_ok:
sys.exit(0)
diff --git a/xlators/features/marker/utils/syncdaemon/syncdutils.py b/xlators/features/marker/utils/syncdaemon/syncdutils.py
index 56bc515d49f..48694d238fd 100644
--- a/xlators/features/marker/utils/syncdaemon/syncdutils.py
+++ b/xlators/features/marker/utils/syncdaemon/syncdutils.py
@@ -15,6 +15,10 @@ def escape(s):
def unescape(s):
return urllib.unquote_plus(s)
+def norm(s):
+ if s:
+ return s.replace('-', '_')
+
def update_file(path, updater, merger = lambda f: True):
"""update a file in a transaction-like manner"""