~mdw
/
hippotat
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
config: Abolish use of ConfigParser's DEFAULT feature
[hippotat]
/
hippotatlib
/
__init__.py
diff --git
a/hippotatlib/__init__.py
b/hippotatlib/__init__.py
index
701a5f2
..
8e00c15
100644
(file)
--- a/
hippotatlib/__init__.py
+++ b/
hippotatlib/__init__.py
@@
-100,27
+100,33
@@
def log_debug(dflag, msg, idof=None, d=None):
msg += ' ' + d + trunc
log.info('{dflag} {msgcore}', dflag=dflag, msgcore=msg)
msg += ' ' + d + trunc
log.info('{dflag} {msgcore}', dflag=dflag, msgcore=msg)
+def logevent_is_boringtwisted(event):
+ try:
+ if event.get('log_level') != LogLevel.info:
+ return False
+ dflag = event.get('dflag')
+ if dflag is False : return False
+ if dflag in debug_set: return False
+ if dflag is None and DBG.TWISTED in debug_set: return False
+ return True
+ except Exception:
+ print('EXCEPTION (IN BORINGTWISTED CHECK)',
+ traceback.format_exc(), file=org_stderr)
+ return False
+
@implementer(twisted.logger.ILogFilterPredicate)
class LogNotBoringTwisted:
def __call__(self, event):
@implementer(twisted.logger.ILogFilterPredicate)
class LogNotBoringTwisted:
def __call__(self, event):
- yes = twisted.logger.PredicateResult.yes
- no = twisted.logger.PredicateResult.no
- try:
- if event.get('log_level') != LogLevel.info:
- return yes
- dflag = event.get('dflag')
- if dflag is False : return yes
- if dflag in debug_set: return yes
- if dflag is None and DBG.TWISTED in debug_set: return yes
- return no
- except Exception:
- print(traceback.format_exc(), file=org_stderr)
- return yes
+ return (
+ twisted.logger.PredicateResult.no
+ if logevent_is_boringtwisted(event) else
+ twisted.logger.PredicateResult.yes
+ )
#---------- default config ----------
defcfg = '''
#---------- default config ----------
defcfg = '''
-[
DEFAULT
]
+[
COMMON
]
max_batch_down = 65536
max_queue_time = 10
target_requests_outstanding = 3
max_batch_down = 65536
max_queue_time = 10
target_requests_outstanding = 3
@@
-131,22
+137,22
@@
max_batch_up = 4000
http_retry = 5
port = 80
vroutes = ''
http_retry = 5
port = 80
vroutes = ''
+ifname_client = hippo%%d
+ifname_server = shippo%%d
#[server] or [<client>] overrides
#[server] or [<client>] overrides
-ipif = userv root ipif %(local)s,%(peer)s,%(mtu)s,slip %(rnets)s
+ipif = userv root ipif %(local)s,%(peer)s,%(mtu)s,slip
,%(ifname)s
%(rnets)s
# relating to virtual network
mtu = 1500
# relating to virtual network
mtu = 1500
-[SERVER]
-server = SERVER
# addrs = 127.0.0.1 ::1
# url
# relating to virtual network
vvnetwork = 172.24.230.192
# vnetwork = <prefix>/<len>
# addrs = 127.0.0.1 ::1
# url
# relating to virtual network
vvnetwork = 172.24.230.192
# vnetwork = <prefix>/<len>
-# vadd
r
= <ipaddr>
+# vadd
r
= <ipaddr>
# vrelay = <ipaddr>
# vrelay = <ipaddr>
@@
-383,8
+389,8
@@
def _cfg_process_putatives():
serverclient_re = regexp.compile(server_pat + r' ' + client_pat)
for cs in cfg.sections():
serverclient_re = regexp.compile(server_pat + r' ' + client_pat)
for cs in cfg.sections():
- if cs == 'LIMIT':
- # plan A "[LIMIT]"
+ if cs == 'LIMIT'
or cs == 'COMMON'
:
+ # plan A "[LIMIT]"
or "[COMMON]"
continue
try:
continue
try:
@@
-427,8
+433,8
@@
def _cfg_process_putatives():
return (servers, clients)
return (servers, clients)
-def cfg_process_
common
(c, ss):
- c.mtu = cfg
.
getint(ss, 'mtu')
+def cfg_process_
general
(c, ss):
+ c.mtu = cfg
1
getint(ss, 'mtu')
def cfg_process_saddrs(c, ss):
class ServerAddr():
def cfg_process_saddrs(c, ss):
class ServerAddr():
@@
-444,27
+450,30
@@
def cfg_process_saddrs(c, ss):
self._endpointfactory = twisted.internet.endpoints.TCP6ServerEndpoint
self._inurl = b'[%s]'
def make_endpoint(self):
self._endpointfactory = twisted.internet.endpoints.TCP6ServerEndpoint
self._inurl = b'[%s]'
def make_endpoint(self):
- return self._endpointfactory(reactor, self.port, self.addr)
+ return self._endpointfactory(reactor, self.port,
+ interface= '%s' % self.addr)
def url(self):
url = b'http://' + (self._inurl % str(self.addr).encode('ascii'))
if self.port != 80: url += b':%d' % self.port
url += b'/'
return url
def url(self):
url = b'http://' + (self._inurl % str(self.addr).encode('ascii'))
if self.port != 80: url += b':%d' % self.port
url += b'/'
return url
+ def __repr__(self):
+ return 'ServerAddr'+repr((self.port,self.addr))
- c.port = cfg
.
getint(ss,'port')
+ c.port = cfg
1
getint(ss,'port')
c.saddrs = [ ]
c.saddrs = [ ]
- for addrspec in cfg
.
get(ss, 'addrs').split():
+ for addrspec in cfg
1
get(ss, 'addrs').split():
sa = ServerAddr(c.port, addrspec)
c.saddrs.append(sa)
def cfg_process_vnetwork(c, ss):
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(cfg
1
get(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:
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 = cfg
1
get(ss,'vaddr')
except NoOptionError:
cfg_process_vnetwork(c, ss)
c.vaddr = next(c.vnetwork.hosts())
except NoOptionError:
cfg_process_vnetwork(c, ss)
c.vaddr = next(c.vnetwork.hosts())
@@
-475,13
+484,24
@@
def cfg_search_section(key,sections):
return section
raise NoOptionError(key, repr(sections))
return section
raise NoOptionError(key, repr(sections))
+def cfg_get_raw(*args, **kwargs):
+ # for passing to cfg_search
+ return cfg.get(*args, raw=True, **kwargs)
+
def cfg_search(getter,key,sections):
section = cfg_search_section(key,sections)
return getter(section, key)
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):
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(cfg
1
getint, key, sections)
+ lim = cfg_search(cfg
1
getint, key, ['%s LIMIT' % ss, 'LIMIT'])
cc.__dict__[key] = min(val,lim)
def cfg_process_client_common(cc,ss,cs,ci):
cc.__dict__[key] = min(val,lim)
def cfg_process_client_common(cc,ss,cs,ci):
@@
-491,12
+511,12
@@
def cfg_process_client_common(cc,ss,cs,ci):
sections = ['%s %s' % (ss,cs),
cs,
ss,
sections = ['%s %s' % (ss,cs),
cs,
ss,
- '
DEFAULT
']
+ '
COMMON
']
try: pwsection = cfg_search_section('password', sections)
except NoOptionError: return None
try: pwsection = cfg_search_section('password', sections)
except NoOptionError: return None
- pw = cfg
.
get(pwsection, 'password')
+ pw = cfg
1
get(pwsection, 'password')
cc.password = pw.encode('utf-8')
cfg_process_client_limited(cc,ss,sections,'target_requests_outstanding')
cc.password = pw.encode('utf-8')
cfg_process_client_limited(cc,ss,sections,'target_requests_outstanding')
@@
-513,10
+533,14
@@
def cfg_process_ipif(c, sections, varmap):
#print('CFGIPIF',repr((varmap, sections, c.__dict__)),file=sys.stderr)
section = cfg_search_section('ipif', sections)
#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 = cfg
1
get(section,'ipif', vars=c.__dict__)
#---------- startup ----------
#---------- startup ----------
+def log_debug_config(m):
+ if not DBG.CONFIG in debug_set: return
+ print('DBG.CONFIG:', m)
+
def common_startup(process_cfg):
# calls process_cfg(putative_clients, putative_servers)
def common_startup(process_cfg):
# calls process_cfg(putative_clients, putative_servers)
@@
-528,7
+552,7
@@
def common_startup(process_cfg):
def readconfig(pathname, mandatory=True):
def log(m, p=pathname):
if not DBG.CONFIG in debug_set: return
def readconfig(pathname, mandatory=True):
def log(m, p=pathname):
if not DBG.CONFIG in debug_set: return
-
print('DBG.CONFIG: %s: %s' % (m, pathname
))
+
log_debug_config('%s: %s' % (m, p
))
try:
files = os.listdir(pathname)
try:
files = os.listdir(pathname)
@@
-546,7
+570,7
@@
def common_startup(process_cfg):
# is a directory
log('directory')
re = regexp.compile('[^-A-Za-z0-9_]')
# is a directory
log('directory')
re = regexp.compile('[^-A-Za-z0-9_]')
- for f in os.listdir(
cdir
):
+ for f in os.listdir(
pathname
):
if re.search(f): continue
subpath = pathname + '/' + f
try:
if re.search(f): continue
subpath = pathname + '/' + f
try:
@@
-562,6
+586,19
@@
def common_startup(process_cfg):
need_defcfg = False
readconfig(value)
need_defcfg = False
readconfig(value)
+ def oc_extra_config(od,os, value, op):
+ readconfig(value)
+
+ def read_defconfig():
+ readconfig('/etc/hippotat/config.d', False)
+ readconfig('/etc/hippotat/passwords.d', False)
+ readconfig('/etc/hippotat/master.cfg', False)
+
+ def oc_defconfig(od,os, value, op):
+ nonlocal need_defcfg
+ need_defcfg = False
+ read_defconfig(value)
+
def dfs_less_detailed(dl):
return [df for df in DBG.iterconstants() if df <= dl]
def dfs_less_detailed(dl):
return [df for df in DBG.iterconstants() if df <= dl]
@@
-625,12
+662,23
@@
just `+': all DFLAGs.
action='callback',
callback= oc_config)
action='callback',
callback= oc_config)
+ optparser.add_option('--extra-config',
+ nargs=1,
+ type='string',
+ metavar='CONFIGFILE',
+ dest='configfile',
+ action='callback',
+ callback= oc_extra_config)
+
+ optparser.add_option('--default-config',
+ action='callback',
+ callback= oc_defconfig)
+
(opts, args) = optparser.parse_args()
if len(args): optparser.error('no non-option arguments please')
if need_defcfg:
(opts, args) = optparser.parse_args()
if len(args): optparser.error('no non-option arguments please')
if need_defcfg:
- readconfig('/etc/hippotat/config', False)
- readconfig('/etc/hippotat/config.d', False)
+ read_defconfig()
try:
(pss, pcs) = _cfg_process_putatives()
try:
(pss, pcs) = _cfg_process_putatives()
@@
-650,15
+698,17
@@
just `+': all DFLAGs.
stdsomething_obs = twisted.logger.FilteringLogObserver(
stderr_obs, [pred], stdout_obs
)
stdsomething_obs = twisted.logger.FilteringLogObserver(
stderr_obs, [pred], stdout_obs
)
- log_observer = twisted.logger.FilteringLogObserver(
+ global file_log_observer
+ file_log_observer = twisted.logger.FilteringLogObserver(
stdsomething_obs, [LogNotBoringTwisted()]
)
#log_observer = stdsomething_obs
twisted.logger.globalLogBeginner.beginLoggingTo(
stdsomething_obs, [LogNotBoringTwisted()]
)
#log_observer = stdsomething_obs
twisted.logger.globalLogBeginner.beginLoggingTo(
- [ log_observer, crash_on_critical ]
+ [
file_
log_observer, crash_on_critical ]
)
def common_run():
log_debug(DBG.INIT, 'entering reactor')
if not _crashing: reactor.run()
)
def common_run():
log_debug(DBG.INIT, 'entering reactor')
if not _crashing: reactor.run()
- print('CRASHED (end)', file=sys.stderr)
+ print('ENDED', file=sys.stderr)
+ sys.exit(16)