chiark / gitweb /
process putatives: Add many log_debug_config calls
[hippotat.git] / hippotatlib / __init__.py
index 7781c1f54c30b241a5afbec67f063ce2a68dd73c..bd5d2c3cf58262989707c279c00691e5a969a29b 100644 (file)
@@ -126,7 +126,7 @@ class LogNotBoringTwisted:
 #---------- default config ----------
 
 defcfg = '''
-[DEFAULT]
+[COMMON]
 max_batch_down = 65536
 max_queue_time = 10
 target_requests_outstanding = 3
@@ -386,11 +386,20 @@ def _cfg_process_putatives():
   server_pat = r'[-.0-9A-Za-z]+'
   client_pat = r'[.:0-9a-f]+'
   server_re = regexp.compile(server_pat)
-  serverclient_re = regexp.compile(server_pat + r' ' + client_pat)
+  serverclient_re = regexp.compile(
+        server_pat + r' ' + '(?:' + client_pat + '|LIMIT)')
 
   for cs in cfg.sections():
-    if cs == 'LIMIT':
-      # plan A "[LIMIT]"
+    log_debug_config('putatives: section [%s]...' % (cs))
+
+    def log_ignore(why):
+      log_debug_config('putatives: section [%s] X ignore: %s' % (cs, why))
+      print('warning: ignoring config section [%s] (%s)' % (cs, why),
+            file=sys.stderr)
+
+    if cs == 'LIMIT' or cs == 'COMMON':
+      # plan A "[LIMIT]" or "[COMMON]"
+      log_debug_config('putatives: section [%s] A ignore' % (cs))
       continue
 
     try:
@@ -400,6 +409,7 @@ def _cfg_process_putatives():
 
       if server_re.fullmatch(cs):
         # plan C "[<servername>]"
+        log_debug_config('putatives: section [%s] C <server>' % (cs))
         putative(servers, cs, cs)
         continue
 
@@ -409,6 +419,7 @@ def _cfg_process_putatives():
 
         if pcs == 'LIMIT':
           # plan E "[<servername> LIMIT]"
+          log_debug_config('putatives: section [%s] E <server> LIMIT' % (cs))
           continue
 
         try:
@@ -416,25 +427,27 @@ def _cfg_process_putatives():
           ci = ipaddr(pc)
         except AddressValueError:
           # plan F "[<some thing we do not understand>]"
-          # well, we ignore this
-          print('warning: ignoring config section %s' % cs, file=sys.stderr)
+          log_ignore('bad-addr')
           continue
 
         else: # no AddressValueError
-          # plan D "[<servername> <client]" part 3
+          # plan D "[<servername> <client>]" part 3
+          log_debug_config('putatives: section [%s] D <server> <client>'
+                           % (cs))
           putative(clients, ci, pcs)
           putative(servers, pss, pss)
           continue
 
     else: # no AddressValueError
       # plan B "[<client>" part 2
+      log_debug_config('putatives: section [%s] B <client>' % (cs))
       putative(clients, ci, cs)
       continue
 
   return (servers, clients)
 
 def cfg_process_general(c, ss):
-  c.mtu = cfg.getint(ss, 'mtu')
+  c.mtu = cfg1getint(ss, 'mtu')
 
 def cfg_process_saddrs(c, ss):
   class ServerAddr():
@@ -460,20 +473,20 @@ def cfg_process_saddrs(c, ss):
     def __repr__(self):
       return 'ServerAddr'+repr((self.port,self.addr))
 
-  c.port = cfg.getint(ss,'port')
+  c.port = cfg1getint(ss,'port')
   c.saddrs = [ ]
-  for addrspec in cfg.get(ss, 'addrs').split():
+  for addrspec in cfg1get(ss, 'addrs').split():
     sa = ServerAddr(c.port, addrspec)
     c.saddrs.append(sa)
 
 def cfg_process_vnetwork(c, ss):
-  c.vnetwork = ipnetwork(cfg.get(ss,'vnetwork'))
+  c.vnetwork = ipnetwork(cfg1get(ss,'vnetwork'))
   if c.vnetwork.num_addresses < 3 + 2:
     raise ValueError('vnetwork needs at least 2^3 addresses')
 
 def cfg_process_vaddr(c, ss):
   try:
-    c.vaddr = cfg.get(ss,'vaddr')
+    c.vaddr = cfg1get(ss,'vaddr')
   except NoOptionError:
     cfg_process_vnetwork(c, ss)
     c.vaddr = next(c.vnetwork.hosts())
@@ -492,9 +505,16 @@ def cfg_search(getter,key,sections):
   section = cfg_search_section(key,sections)
   return getter(section, key)
 
+def cfg1get(section,key, getter=cfg.get,**kwargs):
+  section = cfg_search_section(key,[section,'COMMON'])
+  return getter(section,key,**kwargs)
+
+def cfg1getint(section,key, **kwargs):
+  return cfg1get(section,key, getter=cfg.getint,**kwargs);
+
 def cfg_process_client_limited(cc,ss,sections,key):
-  val = cfg_search(cfg.getint, key, sections)
-  lim = cfg_search(cfg.getint, key, ['%s LIMIT' % ss, 'LIMIT'])
+  val = cfg_search(cfg1getint, key, sections)
+  lim = cfg_search(cfg1getint, key, ['%s LIMIT' % ss, 'LIMIT'])
   cc.__dict__[key] = min(val,lim)
 
 def cfg_process_client_common(cc,ss,cs,ci):
@@ -504,12 +524,12 @@ def cfg_process_client_common(cc,ss,cs,ci):
   sections = ['%s %s' % (ss,cs),
               cs,
               ss,
-              'DEFAULT']
+              'COMMON']
 
   try: pwsection = cfg_search_section('password', sections)
   except NoOptionError: return None
     
-  pw = cfg.get(pwsection, 'password')
+  pw = cfg1get(pwsection, 'password')
   cc.password = pw.encode('utf-8')
 
   cfg_process_client_limited(cc,ss,sections,'target_requests_outstanding')
@@ -526,7 +546,7 @@ def cfg_process_ipif(c, sections, varmap):
   #print('CFGIPIF',repr((varmap, sections, c.__dict__)),file=sys.stderr)
 
   section = cfg_search_section('ipif', sections)
-  c.ipif_command = cfg.get(section,'ipif', vars=c.__dict__)
+  c.ipif_command = cfg1get(section,'ipif', vars=c.__dict__)
 
 #---------- startup ----------