Skip to content

Commit

Permalink
tests: remove bashisms
Browse files Browse the repository at this point in the history
Remove bash-specific code parts from the tests to allow the use of
strict POSIX shell like dash (eg. the default shell used by Travis CI).

Change-Id: I6d35fc1369b6f77e801bf5706021ace76d9e7a2a
  • Loading branch information
thiell committed Sep 11, 2017
1 parent 059548e commit 2535c86
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
15 changes: 8 additions & 7 deletions tests/CLIClushTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ def test_012_diff_null(self):
"""test clush (diff w/o output)"""
rxs = r"^--- %s\n\+\+\+ localhost\n@@ -1(,1)? \+[01],0 @@\n-ok\n$" % HOSTNAME
self._clush_t(["-w", "%s,localhost" % HOSTNAME, "--diff",
'echo "${SSH_CLIENT%% *}" | egrep "^(127.0.0.1|::1)$" >/dev/null || echo ok'],
'echo $SSH_CONNECTION | cut -d " " -f 3 |'
'egrep "^(127.0.0.1|::1)$" >/dev/null || echo ok'],
None, re.compile(rxs.encode()))

def test_013_stdin(self):
Expand Down Expand Up @@ -516,25 +517,25 @@ def test_035_sorted_line_mode(self):
self.output_ok)

# Issue #326
cmd = 's=%h; n=${s//[!0-9]/}; if [[ $(expr $n %% 2) == 0 ]]; then ' \
'echo foo; else echo bar; fi'
cmd = "bash -c 's=%h; n=${s//[!0-9]/}; if [[ $(expr $n %% 2) == 0 ]]; then " \
"echo foo; else echo bar; fi'"

self._clush_t(["-w", "cs[01-03]", "--worker=exec", "-L", cmd], None,
b'cs01: bar\ncs02: foo\ncs03: bar\n', 0)

def test_036_sorted_gather(self):
"""test clush (CLI.Utils.bufnodeset_cmpkey)"""
# test 1st sort criteria: largest nodeset first
cmd = 's=%h; n=${s//[!0-9]/}; if [[ $(expr $n %% 2) == 0 ]]; then ' \
'echo foo; else echo bar; fi'
cmd = "bash -c 's=%h; n=${s//[!0-9]/}; if [[ $(expr $n %% 2) == 0 ]];" \
"then echo foo; else echo bar; fi'"

self._clush_t(["-w", "cs[01-03]", "--worker=exec", "-b", cmd], None,
b'---------------\ncs[01,03] (2)\n---------------\nbar\n'
b'---------------\ncs02\n---------------\nfoo\n', 0)

# test 2nd sort criteria: smaller node index first
cmd = 's=%h; n=${s//[!0-9]/}; if [[ $(expr $n %% 2) == 0 ]]; then ' \
'echo bar; else echo foo; fi'
cmd = "bash -c 's=%h; n=${s//[!0-9]/}; if [[ $(expr $n %% 2) == 0 ]];" \
"then echo bar; else echo foo; fi'"

self._clush_t(["-w", "cs[01-04]", "--worker=exec", "-b", cmd], None,
b'---------------\ncs[01,03] (2)\n---------------\nfoo\n'
Expand Down
4 changes: 2 additions & 2 deletions tests/NodeSetGroupTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ def testConfigListAllNDWithoutAll(self):
default: local
[local]
map: if [[ $GROUP == "x1y[3-4]" ]]; then exit 1; elif [[ $GROUP == "x1y1" ]]; then echo rack[1-5]z[1-42]; else echo rack[6-10]z[1-42]; fi
map: if [ "$GROUP" = "x1y[3-4]" ]; then exit 1; elif [ "$GROUP" = "x1y1" ]; then echo rack[1-5]z[1-42]; else echo rack[6-10]z[1-42]; fi
#all:
list: echo x1y1 x1y2 x1y[3-4]
#reverse:
Expand Down Expand Up @@ -688,7 +688,7 @@ def testConfigCrossRefs(self):
map: echo "foo: @local:foo" | sed -n 's/^$GROUP:\(.*\)/\\1/p'
[third]
map: echo -e "bar: @ref-rel\\nref-rel: @other:foo\\nref-all: @*" | sed -n 's/^$GROUP:\(.*\)/\\1/p'
map: printf "bar: @ref-rel\\nref-rel: @other:foo\\nref-all: @*\\n" | sed -n 's/^$GROUP:\(.*\)/\\1/p'
list: echo bar
""").encode('ascii'))
res = GroupResolverConfig(f.name)
Expand Down
2 changes: 1 addition & 1 deletion tests/TaskLocalMixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def testHugeOutputCommand(self):
task = task_self()

# init worker
worker = task.shell("for i in {1..100000}; do echo -n ' huge! '; done")
worker = task.shell("for i in $(seq 1 100000); do echo -n ' huge! '; done")

# run task
task.resume()
Expand Down

0 comments on commit 2535c86

Please sign in to comment.