Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_run_command_string_unsafe_with_pipe unit test failing in devel on Mac #6542

Closed
sivel opened this issue Mar 18, 2014 · 2 comments
Closed
Assignees
Labels
bug This issue/PR relates to a bug.

Comments

@sivel
Copy link
Member

sivel commented Mar 18, 2014

Issue Type:

Bug Report

Ansible Version:

ansible 1.6 (devel f96568a) last updated 2014/03/17 07:40:34 (GMT -500)

Environment:

Control: Mac OS, virtualenv, python 2.7.5

Target: N/A

Summary:
======================================================================
FAIL: test_run_command_string_unsafe_with_pipe (TestModuleUtilsBasic.TestModuleUtilsBasic)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/matt/python_venvs/ansibledev/ansible/test/units/TestModuleUtilsBasic.py", line 100, in test_run_command_string_unsafe_with_pipe
    self.assertEqual(out, 'foo bar')
AssertionError: '-n foo bar\n' != 'foo bar'

----------------------------------------------------------------------
Steps To Reproduce:
  1. Run unit tests on Mac
Expected Results:

Tests Pass

Actual Results:

test_run_command_string_unsafe_with_pipe is failing, and it appears to be a difference in how /bin/sh works on Mac with respect to echo.

A simple test of the following shows the behavior:

>>> p = subprocess.Popen('echo -n "foo bar"', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
>>> p.communicate()
('-n foo bar\n', '')

Whereas specifying executable=/bin/bash gives what we expect:

>>> p = subprocess.Popen('echo -n "foo bar"', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, executable='/bin/bash')
>>> p.communicate()
('foo bar', '')

This appears to be a result of the /bin/sh in OS X having been configured with --enable-xpg-echo-default, so unless you disable xpg_echo, echo interprets escape sequences and does not support any options.

@sivel
Copy link
Member Author

sivel commented Mar 18, 2014

Probably just acceptable to make the following change:

diff --git a/test/units/TestModuleUtilsBasic.py b/test/units/TestModuleUtilsBasic.py
index 3d85b61..d1ee95a 100644
--- a/test/units/TestModuleUtilsBasic.py
+++ b/test/units/TestModuleUtilsBasic.py
@@ -95,9 +95,9 @@ class TestModuleUtilsBasic(unittest.TestCase):

     # test run_command with a command pipe (with both use_unsafe_shell=True|False)
     def test_run_command_string_unsafe_with_pipe(self):
-        (rc, out, err) = self.module.run_command('echo -n "foo bar" | cat', use_unsafe_shell=True)
+        (rc, out, err) = self.module.run_command('echo "foo bar" | cat', use_unsafe_shell=True)
         self.assertEqual(rc, 0)
-        self.assertEqual(out, 'foo bar')
+        self.assertEqual(out, 'foo bar\n')

     # test run_command with a shell redirect in (with both use_unsafe_shell=True|False)
     def test_run_command_string_unsafe_with_redirect_in(self):

Since this test wasn't meant to test echo -n functionality, I think the above is an ok solution. Perhaps we can create another test and see if it possible to fix the echo -n on a bash shell that has xpg_echo enabled.

@jctanner
Copy link
Contributor

@sivel thanks!

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 6, 2018
@ansible ansible locked and limited conversation to collaborators Apr 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue/PR relates to a bug.
Projects
None yet
Development

No branches or pull requests

3 participants