Skip to content

Commit fede70f

Browse files
committed
NodeUtils: change cache_delay to cache_time
conf: improve slurm group config example (again): add cache_time and use %R format instead of %P to filter '*' from partition name also in reverse upcall Change-Id: I7c5546361efafcaca2865ec45f119aa533d8b510
1 parent 6c72be0 commit fede70f

File tree

6 files changed

+42
-43
lines changed

6 files changed

+42
-43
lines changed

conf/groups.conf.d/slurm.conf.example

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
map: sinfo -h -o "%N" -p $GROUP
1010
all: sinfo -h -o "%N"
1111
list: sinfo -h -o "%R"
12-
reverse: sinfo -h -N -o "%P" -n $NODE
12+
reverse: sinfo -h -N -o "%R" -n $NODE
1313

1414
# SLURM state bindings
1515
#
@@ -18,5 +18,4 @@ map: if [ "$GROUP" == "broken" ]; then sinfo -h -o "%N" -t down,drained; else si
1818
all: sinfo -h -o "%N"
1919
list: sinfo -h -o "%T"
2020
reverse: sinfo -h -N -o "%T" -n $NODE
21-
22-
# TODO: add slurm jobs bindings here
21+
cache_time: 300

doc/extras/vim/syntax/groupsconf.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ syn match groupsGroupsDirKey "^\(groupsdir\|confdir\|autodir\)\(:\|=\)"
2121
" Sources
2222
syn match groupsVars "\(\$GROUP\|\$NODE\|$SOURCE\)" contained
2323
syn match groupsKeys "^\w\+\(:\|=\)"me=e-1 contained
24-
syn match groupsKeyValue "^\(map\|all\|list\|reverse\|cache_delay\)\+\(:\|=\).*$" contains=groupsKeys,groupsVars
24+
syn match groupsKeyValue "^\(map\|all\|list\|reverse\|cache_time\)\+\(:\|=\).*$" contains=groupsKeys,groupsVars
2525

2626
syn match groupsComment "#.*$"
2727
syn match groupsComment ";.*$"

doc/man/man5/groups.conf.5

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.\" Man page generated from reStructuredText.
22
.
3-
.TH GROUPS.CONF 5 "2015-10-12" "1.7" "ClusterShell User Manual"
3+
.TH GROUPS.CONF 5 "2015-11-06" "1.7" "ClusterShell User Manual"
44
.SH NAME
55
groups.conf \- Configuration file for ClusterShell node groups
66
.
@@ -131,7 +131,7 @@ the \fIlist\fP and \fImap\fP external calls. Also, if the number of nodes to
131131
reverse is greater than the number of available groups, the \fIreverse\fP
132132
external command is avoided automatically.
133133
.TP
134-
.B cache_delay
134+
.B cache_time
135135
Number of seconds each upcall result is kept in cache, in memory only.
136136
Default is 3600 seconds. This is useful only for daemons using nodegroups.
137137
.UNINDENT
@@ -157,7 +157,7 @@ group. The desired behaviour is up to the system administrator.
157157
.SH RESOURCE USAGE
158158
.sp
159159
All external command results are cached in memory to avoid multiple calls. Each
160-
result is kept for a limited amount of time. See cache_delay option to tune
160+
result is kept for a limited amount of time. See cache_time option to tune
161161
this behaviour.
162162
.SH EXAMPLES
163163
.sp

doc/txt/groups.conf.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Configuration file for ClusterShell node groups
77
-----------------------------------------------
88

99
:Author: Stephane Thiell, <[email protected]>
10-
:Date: 2015-10-12
10+
:Date: 2015-11-06
1111
:Copyright: CeCILL-C V1
1212
:Version: 1.7
1313
:Manual section: 5
@@ -102,7 +102,7 @@ reverse
102102
the *list* and *map* external calls. Also, if the number of nodes to
103103
reverse is greater than the number of available groups, the *reverse*
104104
external command is avoided automatically.
105-
cache_delay
105+
cache_time
106106
Number of seconds each upcall result is kept in cache, in memory only.
107107
Default is 3600 seconds. This is useful only for daemons using nodegroups.
108108

@@ -127,7 +127,7 @@ RESOURCE USAGE
127127
==============
128128

129129
All external command results are cached in memory to avoid multiple calls. Each
130-
result is kept for a limited amount of time. See cache_delay option to tune
130+
result is kept for a limited amount of time. See cache_time option to tune
131131
this behaviour.
132132

133133

lib/ClusterShell/NodeUtils.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Copyright CEA/DAM/DIF (2010, 2012, 2013, 2014)
1+
# Copyright CEA/DAM/DIF (2010-2015)
22
# Contributors:
3-
# Stephane THIELL <[email protected]>
3+
# Stephane THIELL <[email protected]>
44
# Aurelien DEGREMONT <[email protected]>
55
#
66
# This file is part of the ClusterShell library.
@@ -77,7 +77,7 @@ class GroupResolverConfigError(GroupResolverError):
7777
"""Raised when a configuration error is encountered"""
7878

7979

80-
_DEFAULT_CACHE_DELAY = 3600
80+
_DEFAULT_CACHE_TIME = 3600
8181

8282

8383
class GroupSource(object):
@@ -153,12 +153,12 @@ class UpcallGroupSource(GroupSource):
153153
GroupSource class managing external calls for nodegroup support.
154154
155155
Upcall results are cached for a customizable amount of time. This is
156-
controlled by `cache_delay` attribute. Default is 3600 seconds.
156+
controlled by `cache_time` attribute. Default is 3600 seconds.
157157
"""
158158

159159
def __init__(self, name, map_upcall, all_upcall=None,
160160
list_upcall=None, reverse_upcall=None, cfgdir=None,
161-
cache_delay=None):
161+
cache_time=None):
162162
GroupSource.__init__(self, name)
163163
self.verbosity = 0
164164
self.cfgdir = cfgdir
@@ -175,10 +175,10 @@ def __init__(self, name, map_upcall, all_upcall=None,
175175
self.has_reverse = True
176176

177177
# Cache upcall data
178-
if cache_delay is None:
179-
self.cache_delay = _DEFAULT_CACHE_DELAY
178+
if cache_time is None:
179+
self.cache_time = _DEFAULT_CACHE_TIME
180180
else:
181-
self.cache_delay = cache_delay
181+
self.cache_time = cache_time
182182
self._cache = {}
183183
self.clear_cache()
184184

@@ -219,7 +219,7 @@ def _upcall_cache(self, upcall, cache, key, **args):
219219
corresponding `upcall'.
220220
221221
If `key' is missing, it is added to provided `cache'. Each entry in a
222-
cache is kept only for a limited time equal to self.cache_delay .
222+
cache is kept only for a limited time equal to self.cache_time .
223223
"""
224224
if not self.upcalls.get(upcall):
225225
raise GroupSourceNoUpcall(upcall, self)
@@ -231,7 +231,7 @@ def _upcall_cache(self, upcall, cache, key, **args):
231231

232232
# Fetch the data if unknown of just purged
233233
if key not in cache:
234-
cache_expiry = time.time() + self.cache_delay
234+
cache_expiry = time.time() + self.cache_time
235235
# $CFGDIR and $SOURCE always replaced
236236
args['CFGDIR'] = self.cfgdir
237237
args['SOURCE'] = self.name
@@ -277,20 +277,20 @@ class YAMLGroupLoader(object):
277277
278278
- create GroupSource objects
279279
- gather groups dict content on load
280-
- reload the file once cache_delay has expired
280+
- reload the file once cache_time has expired
281281
"""
282282

283-
def __init__(self, filename, cache_delay=None):
283+
def __init__(self, filename, cache_time=None):
284284
"""
285285
Initialize YAMLGroupLoader and load file.
286286
287287
:param filename: YAML file path
288-
:param cache_delay: cache delay
288+
:param cache_time: cache time (seconds)
289289
"""
290-
if cache_delay is None:
291-
self.cache_delay = _DEFAULT_CACHE_DELAY
290+
if cache_time is None:
291+
self.cache_time = _DEFAULT_CACHE_TIME
292292
else:
293-
self.cache_delay = cache_delay
293+
self.cache_time = cache_time
294294
self.cache_expiry = 0
295295
self.filename = filename
296296
self.sources = {}
@@ -335,7 +335,7 @@ def _load(self):
335335
# else: cannot add new source on reload - just ignore it
336336

337337
# groups are loaded, set cache expiry
338-
self.cache_expiry = time.time() + self.cache_delay
338+
self.cache_expiry = time.time() + self.cache_time
339339

340340
def __iter__(self):
341341
"""Iterate over GroupSource objects."""
@@ -347,10 +347,10 @@ def groups(self, sourcename):
347347
Groups dict accessor for sourcename.
348348
349349
This method is called by associated FileGroupSource objects and simply
350-
returns dict content, after reloading file if cache_delay has expired.
350+
returns dict content, after reloading file if cache_time has expired.
351351
"""
352352
if self.cache_expiry < time.time():
353-
# reload whole file if cache delay expired
353+
# reload whole file if cache time expired
354354
self._load()
355355

356356
return self._groups[sourcename]
@@ -607,21 +607,21 @@ def _sources_from_cfg(self, cfg, cfgdir):
607607
if srcname != self.SECTION_MAIN:
608608
# only map is a mandatory upcall
609609
map_upcall = cfg.get(section, 'map', True)
610-
all_upcall = list_upcall = reverse_upcall = delay = None
610+
all_upcall = list_upcall = reverse_upcall = ctime = None
611611
if cfg.has_option(section, 'all'):
612612
all_upcall = cfg.get(section, 'all', True)
613613
if cfg.has_option(section, 'list'):
614614
list_upcall = cfg.get(section, 'list', True)
615615
if cfg.has_option(section, 'reverse'):
616616
reverse_upcall = cfg.get(section, 'reverse', True)
617-
if cfg.has_option(section, 'cache_delay'):
618-
delay = float(cfg.get(section, 'cache_delay', True))
617+
if cfg.has_option(section, 'cache_time'):
618+
ctime = float(cfg.get(section, 'cache_time', True))
619619
# add new group source
620620
self.add_source(UpcallGroupSource(srcname, map_upcall,
621621
all_upcall,
622622
list_upcall,
623623
reverse_upcall,
624-
cfgdir, delay))
624+
cfgdir, ctime))
625625
except (NoSectionError, NoOptionError, ValueError), exc:
626626
raise GroupResolverConfigError(str(exc))
627627

tests/NodeSetGroupTest.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,29 +1201,29 @@ def test_expired_cache(self):
12011201
"""test UpcallGroupSource cache entries expired according to config"""
12021202
# create custom resolver with default source
12031203
source = StaticGroupSource('cache', {'map': {'a': 'foo1', 'b': 'foo2'} })
1204-
source.cache_delay = 0.2
1204+
source.cache_time = 0.2
12051205
res = GroupResolver(source)
12061206

12071207
# Populate map cache
12081208
self.assertEqual("foo1", str(NodeSet("@a", resolver=res)))
12091209
self.assertEqual("foo2", str(NodeSet("@b", resolver=res)))
12101210
self.assertEqual(len(source._cache['map']), 2)
12111211

1212-
# Be sure 0.2 cache delay is expired (especially for old Python version)
1212+
# Be sure 0.2 cache time is expired (especially for old Python version)
12131213
time.sleep(0.25)
12141214

12151215
source._data['map']['a'] = 'something_else'
12161216
self.assertEqual('something_else', str(NodeSet("@a", resolver=res)))
12171217

1218-
def test_config_cache_delay(self):
1219-
"""test group config cache_delay options"""
1218+
def test_config_cache_time(self):
1219+
"""test group config cache_time options"""
12201220
f = make_temp_file("""
12211221
[local]
1222-
cache_delay: 0.2
1222+
cache_time: 0.2
12231223
map: echo foo1
12241224
""")
12251225
res = GroupResolverConfig(f.name)
1226-
self.assertEqual(res._sources['local'].cache_delay, 0.2)
1226+
self.assertEqual(res._sources['local'].cache_time, 0.2)
12271227
self.assertEqual("foo1", str(NodeSet("@local:foo", resolver=res)))
12281228

12291229

@@ -1303,21 +1303,21 @@ def test_multi_sources(self):
13031303
{ 'cherry': 'client-4-2' })
13041304

13051305
def test_reload(self):
1306-
"""test YAMLGroupLoader cache_delay"""
1306+
"""test YAMLGroupLoader cache_time"""
13071307
f = make_temp_file("""
13081308
vendors:
13091309
apricot: "node[1-10]"
13101310
avocado: 'node[11-20]'
13111311
banana: node[21-30]
13121312
customers:
13131313
cherry: client-4-2""")
1314-
loader = YAMLGroupLoader(f.name, cache_delay=1)
1314+
loader = YAMLGroupLoader(f.name, cache_time=1)
13151315
self.assertEqual(loader.groups("vendors"),
13161316
{ 'apricot': 'node[1-10]',
13171317
'avocado': 'node[11-20]',
13181318
'banana': 'node[21-30]' })
13191319

1320-
# modify YAML file and check that it is reloaded after cache_delay
1320+
# modify YAML file and check that it is reloaded after cache_time
13211321
f.write("\n nut: node42\n")
13221322
# oh and BTW for ultimate code coverage, test if we add a new source
13231323
# on-the-fly, this is not supported but should be ignored
@@ -1350,7 +1350,7 @@ def test_iter(self):
13501350
src3:
13511351
src3grp1: node31
13521352
src3grp2: node32""")
1353-
loader = YAMLGroupLoader(f.name, cache_delay = 0.1)
1353+
loader = YAMLGroupLoader(f.name, cache_time = 0.1)
13541354
# iterate sources with cache expired
13551355
for source in loader:
13561356
time.sleep(0.5) # force reload

0 commit comments

Comments
 (0)