Skip to content

Commit 0ddae8d

Browse files
committed
NodeUtils: allow null values in cluster.yaml (#533)
An empty group can already be defined by specifying an empty string as value in the yaml file. For convenience, now also interpret any YAML null value as an empty set. Fixes #533.
1 parent 2125ae7 commit 0ddae8d

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

doc/sphinx/config.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,10 @@ Here is an example of **/etc/clustershell/groups.d/cluster.yaml**::
344344
oss: 'oss[0-15]'
345345
rbh: 'rbh[1-2]'
346346

347+
348+
If you wish to define an empty group (with no nodes), you can either use an
349+
empty string ``''`` or any valid YAML null value (``null`` or ``~``).
350+
347351
.. highlight:: console
348352

349353
Testing the syntax of your group file can be quickly performed through the

lib/ClusterShell/NodeUtils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,14 @@ def _load(self):
329329
fmt = "%s: invalid content (group source '%s' is not a dict)"
330330
raise GroupResolverConfigError(fmt % (self.filename, srcname))
331331

332-
for grp in groups:
332+
for grp, grpnodes in groups.items():
333333
if not isinstance(grp, basestring):
334334
fmt = '%s: %s: group name %s not a string (add quotes?)'
335335
raise GroupResolverConfigError(fmt % (self.filename,
336336
srcname, grp))
337+
# GH#533: interpret null value as empty set
338+
if grpnodes is None:
339+
groups[grp] = ''
337340

338341
if first:
339342
self._groups[srcname] = groups

tests/NodeSetGroupTest.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1814,7 +1814,6 @@ def test_yaml_unsafe_yaml(self):
18141814
yamlfile.close()
18151815
tdir.cleanup()
18161816

1817-
18181817
def test_wrong_autodir(self):
18191818
"""test wrong autodir (doesn't exist)"""
18201819
f = make_temp_file(dedent("""
@@ -1880,3 +1879,29 @@ def test_yaml_permission_denied(self):
18801879
yamlfile1.close()
18811880
yamlfile2.close()
18821881
tdir.cleanup()
1882+
1883+
def test_yaml_null_value(self):
1884+
"""test null value in groups yaml file"""
1885+
tdir = make_temp_dir()
1886+
f = make_temp_file(dedent("""
1887+
[Main]
1888+
default: yaml
1889+
autodir: %s
1890+
""" % tdir.name).encode('ascii'))
1891+
yamlfile = make_temp_file(dedent("""
1892+
yaml:
1893+
c0: nid[0001-0032]
1894+
c1:
1895+
c0r7: nid[0017-0032]
1896+
""").encode('ascii'), suffix=".yaml", dir=tdir.name)
1897+
try:
1898+
res = GroupResolverConfig(f.name)
1899+
nodeset = NodeSet.fromall(resolver=res)
1900+
self.assertEqual(str(nodeset), "nid[0001-0032]")
1901+
nodeset = NodeSet("@c1", resolver=res)
1902+
self.assertEqual(len(nodeset), 0)
1903+
self.assertEqual(str(nodeset), "")
1904+
finally:
1905+
yamlfile.close()
1906+
tdir.cleanup()
1907+

0 commit comments

Comments
 (0)