Skip to content

Commit 85180f1

Browse files
committed
Clush.py: display full tree in debug mode only
When tree mode is enabled and in verbose mode, clush will now display "enabling tree topology" (one line) with the number of gateways available in the topology (from the current root node). In debug mode, a dump of the full tree is also printed. Closes #315. Change-Id: I6f079c9e5a0ec25d914aae2c22bc36f926cb88c5
1 parent 0848ae1 commit 85180f1

File tree

4 files changed

+38
-12
lines changed

4 files changed

+38
-12
lines changed

doc/sphinx/tools/clush.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ This file defines the following topology graph::
156156

157157

158158
At runtime, ClusterShell will pick an initial propagation tree from this
159-
topology graph definition.
159+
topology graph definition and the current root node. Multiple admin/root
160+
nodes may be defined in the file.
160161

161162
.. note:: The algorithm used in Tree mode does not rely on gateway system
162163
hostnames anymore. In topology.conf, just use the hosts or aliases needed
@@ -173,7 +174,7 @@ file is present. When the configuration file
173174
target nodes that are defined there. The topology file path can be changed
174175
using the ``--topology`` command line option.
175176

176-
.. note:: If using ``clush -v`` (verbose option), clush will display an ASCII
177+
.. note:: If using ``clush -d`` (debug option), clush will display an ASCII
177178
representation of the initial propagation tree used. This is useful when
178179
working on Tree mode configuration.
179180

lib/ClusterShell/CLI/Clush.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -974,15 +974,19 @@ def main():
974974
clush_exit(1, task)
975975

976976
if options.topofile or task._default_tree_is_enabled():
977-
if config.verbosity >= VERB_VERB:
978-
print Display.COLOR_RESULT_FMT % "TREE MODE enabled"
979977
if options.topofile:
980978
task.load_topology(options.topofile)
979+
if config.verbosity >= VERB_VERB:
980+
roots = len(task.topology.root.nodeset)
981+
gws = task.topology.inner_node_count() - roots
982+
msg = "enabling tree topology (%d gateways)" % gws
983+
print >> sys.stderr, "clush: %s" % msg
981984

982985
if options.grooming_delay:
983986
if config.verbosity >= VERB_VERB:
984-
print Display.COLOR_RESULT_FMT % ("Grooming delay: %f"
985-
% options.grooming_delay)
987+
msg = Display.COLOR_RESULT_FMT % ("Grooming delay: %f" %
988+
options.grooming_delay)
989+
print >> sys.stderr, msg
986990
task.set_info("grooming_delay", options.grooming_delay)
987991
elif options.rcopy:
988992
# By default, --rcopy should inhibit grooming
@@ -1050,7 +1054,7 @@ def main():
10501054
config.command_timeout,
10511055
op))
10521056
if not task.default("USER_interactive"):
1053-
if display.verbosity >= VERB_VERB and task.topology:
1057+
if display.verbosity >= VERB_DEBUG and task.topology:
10541058
print Display.COLOR_RESULT_FMT % '-' * 15
10551059
print Display.COLOR_RESULT_FMT % task.topology,
10561060
print Display.COLOR_RESULT_FMT % '-' * 15

lib/ClusterShell/Topology.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22
#
3-
# Copyright CEA/DAM/DIF (2010-2015)
3+
# Copyright CEA/DAM/DIF (2010-2016)
44
# Contributor: Henri DOREAU <[email protected]>
55
# Contributor: Stephane THIELL <[email protected]>
66
#
@@ -220,6 +220,15 @@ def find_nodegroup(self, node):
220220
return group
221221
raise TopologyError('TopologyNodeGroup not found for node %s' % node)
222222

223+
def inner_node_count(self):
224+
"""helper to get inner node count (root and gateway nodes)"""
225+
return sum(len(group.nodeset) for group in self.groups
226+
if group.children_len() > 0)
227+
228+
def leaf_node_count(self):
229+
"""helper to get leaf node count"""
230+
return sum(len(group.nodeset) for group in self.groups
231+
if group.children_len() == 0)
223232

224233
class TopologyRoute(object):
225234
"""A single route between two nodesets"""

tests/TreeTopologyTest.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,10 @@ def testMultipleAdminGroups(self):
190190

191191
ns_all = NodeSet('admin2,nodes[2-3,20-29]')
192192
ns_tree = NodeSet()
193-
for nodegroup in parser.tree('admin2'):
193+
tree = parser.tree('admin2')
194+
self.assertEqual(tree.inner_node_count(), 3)
195+
self.assertEqual(tree.leaf_node_count(), 10)
196+
for nodegroup in tree:
194197
ns_tree.add(nodegroup.nodeset)
195198
self.assertEqual(str(ns_all), str(ns_tree))
196199

@@ -304,7 +307,10 @@ def testConfigurationLongSyntax(self):
304307

305308
ns_all = NodeSet('admin,proxy,STA[0-1],STB[0-3],nodes[0-10]')
306309
ns_tree = NodeSet()
307-
for nodegroup in parser.tree('admin'):
310+
tree = parser.tree('admin')
311+
self.assertEqual(tree.inner_node_count(), 8)
312+
self.assertEqual(tree.leaf_node_count(), 11)
313+
for nodegroup in tree:
308314
ns_tree.add(nodegroup.nodeset)
309315
self.assertEqual(str(ns_all), str(ns_tree))
310316

@@ -325,7 +331,10 @@ def testConfigurationParserDeepTree(self):
325331

326332
ns_all = NodeSet('admin,nodes[0-159]')
327333
ns_tree = NodeSet()
328-
for nodegroup in parser.tree('admin'):
334+
tree = parser.tree('admin')
335+
self.assertEqual(tree.inner_node_count(), 151)
336+
self.assertEqual(tree.leaf_node_count(), 10)
337+
for nodegroup in tree:
329338
ns_tree.add(nodegroup.nodeset)
330339
self.assertEqual(str(ns_all), str(ns_tree))
331340

@@ -343,7 +352,10 @@ def testConfigurationParserBigTree(self):
343352

344353
ns_all = NodeSet('admin,ST[0-4],STA[0-49],nodes[0-10000]')
345354
ns_tree = NodeSet()
346-
for nodegroup in parser.tree('admin'):
355+
tree = parser.tree('admin')
356+
self.assertEqual(tree.inner_node_count(), 56)
357+
self.assertEqual(tree.leaf_node_count(), 10001)
358+
for nodegroup in tree:
347359
ns_tree.add(nodegroup.nodeset)
348360
self.assertEqual(str(ns_all), str(ns_tree))
349361

0 commit comments

Comments
 (0)