Skip to content

Commit

Permalink
CLI/Display.py: fix unwanted linefeed issue in header (#352)
Browse files Browse the repository at this point in the history
Fix Display.format_header() to return a full header with linefeed or
nothing if -N, allowing to use it easily by concatenating buffers.

Fix erroneous tests...

Closes #352

Change-Id: Ied90458a7c1db5334d31ac3011cca10b40dd8271
  • Loading branch information
thiell committed Sep 6, 2017
1 parent 5aee33c commit 563315e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/ClusterShell/CLI/Clubak.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def display_tree(tree, disp, out):
if line_mode:
out.write(str(nodeset).encode() + b':\n')
else:
out.write(disp.format_header(nodeset, reldepth) + b'\n')
out.write(disp.format_header(nodeset, reldepth))
out.write(b' ' * reldepth + msgline + b'\n')
togh = nchildren != 1

Expand Down
9 changes: 4 additions & 5 deletions lib/ClusterShell/CLI/Display.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,17 @@ def _format_nodeset(self, nodeset):

def format_header(self, nodeset, indent=0):
"""Format nodeset-based header."""
if not self.label:
return b""
indstr = " " * indent
nodecntstr = ""
if self.verbosity >= VERB_STD and self.node_count and len(nodeset) > 1:
nodecntstr = " (%d)" % len(nodeset)
if not self.label:
return b""
hdr = self.color_stdout_fmt % ("%s%s\n%s%s%s\n%s%s" % \
(indstr, self.SEP,
indstr, self._format_nodeset(nodeset), nodecntstr,
indstr, self.SEP))
return hdr.encode('ascii')
return hdr.encode('ascii') + b'\n'

def print_line(self, nodeset, line):
"""Display a line with optional label."""
Expand Down Expand Up @@ -201,8 +201,7 @@ def print_gather_keys(self, keys, obj):

def _print_content(self, nodeset, content):
"""Display a dshbak-like header block and content."""
self.out.write(self.format_header(nodeset) + b'\n' + bytes(content)
+ b'\n')
self.out.write(self.format_header(nodeset) + bytes(content) + b'\n')

def _print_diff(self, nodeset, content):
"""Display unified diff between remote gathered outputs."""
Expand Down
8 changes: 4 additions & 4 deletions tests/CLIClubakTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ def test_003_L(self):

def test_004_N(self):
"""test clubak (no header -N)"""
self._clubak_t(["-N"], b"foo: bar\n", b"\n bar\n")
self._clubak_t(["-N"], b"foo: bar\n", b" bar\n")
self._clubak_t(["-NL"], b"foo: bar\n", b" bar\n")
self._clubak_t(["-N", "-S", ": "], b"foo: bar\n", b"\nbar\n")
self._clubak_t(["-bN"], b"foo: bar\n", b"\n bar\n")
self._clubak_t(["-bN", "-S", ": "], b"foo: bar\n", b"\nbar\n")
self._clubak_t(["-N", "-S", ": "], b"foo: bar\n", b"bar\n")
self._clubak_t(["-bN"], b"foo: bar\n", b" bar\n")
self._clubak_t(["-bN", "-S", ": "], b"foo: bar\n", b"bar\n")

def test_005_fast(self):
"""test clubak (fast mode --fast)"""
Expand Down
4 changes: 4 additions & 0 deletions tests/CLIClushTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ def test_000_display(self):
self._clush_t(["-w", HOSTNAME, "--color=never", "echo", "ok"], None,
self.output_ok)

# issue #352
self._clush_t(["-N", "-R", "exec", "-w", 'foo[1-2]', "-b",
"echo", "test"], None, b"test\n")

def test_001_display_tty(self):
"""test clush (display options) [tty]"""
setattr(ClusterShell.CLI.Clush, '_f_user_interaction', True)
Expand Down

0 comments on commit 563315e

Please sign in to comment.