Hi all,<br><br>I am trying to execute a remote command using fabric in my test run by py.test. Fabric is a library for using SSH and I myself is quite new to it and just want to start using it. The problem is when i run it with py.test I am getting an error, but not when invoking with python. Does anyone understand what the issue is and how to mitigate it? Below is the output. <br>
<br>Thank you very much.<br>-hans<br><br><br><font face="courier new,monospace">(env26)[hsebastian@puri integration]$ py.test test_magic.py <br>=========================================================================================== test session starts ===========================================================================================<br>
platform darwin -- Python 2.6.1 -- pytest-2.1.1<br>collected 1 items <br><br>test_magic.py F<br><br>================================================================================================ FAILURES =================================================================================================<br>
__________________________________________________________________________________________ TestMagic.test_magic ___________________________________________________________________________________________<br><br>self = <test_magic.TestMagic object at 0x10124a8d0><br>
<br> def test_magic(self):<br> env.key_filename = os.path.join('test.pem')<br> env.user = 'ubuntu'<br> env.host_string = '<a href="http://ec2-50-56-84-105.compute-1.amazonaws.com" target="_blank">ec2-50-56-84-105.compute-1.amazonaws.com</a>'<br>
> output = run('ls -al')<br><br>test_magic.py:13: <br>_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _<br>
<br> @wraps(func)<br> def host_prompting_wrapper(*args, **kwargs):<br> while not env.get('host_string', False):<br> handle_prompt_abort()<br> host_string = raw_input("No hosts found. Please specify (single)"<br>
" host string for connection: ")<br> interpret_host_string(host_string)<br>> return func(*args, **kwargs)<br><br>../../../env26/lib/python2.6/site-packages/fabric/network.py:331: <br>
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _<br><br>command = 'ls -al', shell = True, pty = True, combine_stderr = None<br>
<br> @needs_host<br> def run(command, shell=True, pty=True, combine_stderr=None):<br> """<br> Run a shell command on a remote host.<br> <br> If ``shell`` is True (the default), `run` will execute the given command<br>
string via a shell interpreter, the value of which may be controlled by<br> setting ``env.shell`` (defaulting to something similar to ``/bin/bash -l -c<br> "<command>"``.) Any double-quote (``"``) or dollar-sign (``$``) characters<br>
in ``command`` will be automatically escaped when ``shell`` is True.<br> <br> `run` will return the result of the remote program's stdout as a single<br> (likely multiline) string. This string will exhibit ``failed`` and<br>
``succeeded`` boolean attributes specifying whether the command failed or<br> succeeded, and will also include the return code as the ``return_code``<br> attribute.<br> <br> Any text entered in your local terminal will be forwarded to the remote<br>
program as it runs, thus allowing you to interact with password or other<br> prompts naturally. For more on how this works, see<br> :doc:`/usage/interactivity`.<br> <br> You may pass ``pty=False`` to forego creation of a pseudo-terminal on the<br>
remote end in case the presence of one causes problems for the command in<br> question. However, this will force Fabric itself to echo any and all input<br> you type while the command is running, including sensitive passwords. (With<br>
``pty=True``, the remote pseudo-terminal will echo for you, and will<br> intelligently handle password-style prompts.) See :ref:`pseudottys` for<br> details.<br> <br> Similarly, if you need to programmatically examine the stderr stream of the<br>
remote program (exhibited as the ``stderr`` attribute on this function's<br> return value), you may set ``combine_stderr=False``. Doing so has a high<br> chance of causing garbled output to appear on your terminal (though the<br>
resulting strings returned by `~fabric.operations.run` will be properly<br> separated). For more info, please read :ref:`combine_streams`.<br> <br> Examples::<br> <br> run("ls /var/www/")<br>
run("ls /home/myuser", shell=False)<br> output = run('ls /var/www/site1')<br> <br> .. versionadded:: 1.0<br> The ``succeeded`` and ``stderr`` return value attributes, the<br>
``combine_stderr`` kwarg, and interactive behavior.<br> <br> .. versionchanged:: 1.0<br> The default value of ``pty`` is now ``True``.<br> <br> .. versionchanged:: 1.0.2<br> The default value of ``combine_stderr`` is now ``None`` instead of<br>
``True``. However, the default *behavior* is unchanged, as the global<br> setting is still ``True``.<br> """<br>> return _run_command(command, shell, pty, combine_stderr)<br>
<br> <br> @needs_host<br> def sudo(command, shell=True, pty=True, combine_stderr=None, user=None):<br><br>../../../env26/lib/python2.6/site-packages/fabric/operations.py:945: <br>_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _<br>
<br>command = 'ls -al', shell = True, pty = True, combine_stderr = None, sudo = False, user = None<br><br> def _run_command(command, shell=True, pty=True, combine_stderr=True,<br> sudo=False, user=None):<br>
"""<br> Underpinnings of `run` and `sudo`. See their docstrings for more info.<br> """<br> # Set up new var so original argument can be displayed verbatim later.<br>
given_command = command<br> # Handle context manager modifications, and shell wrapping<br> wrapped_command = _shell_wrap(<br> _prefix_commands(_prefix_env_vars(command), 'remote'),<br>
shell,<br> _sudo_prefix(user) if sudo else None<br> )<br> # Execute info line<br> which = 'sudo' if sudo else 'run'<br> if output.debug:<br> print("[%s] %s: %s" % (env.host_string, which, wrapped_command))<br>
elif output.running:<br> print("[%s] %s: %s" % (env.host_string, which, given_command))<br> <br> # Actual execution, stdin/stdout/stderr handling, and termination<br> stdout, stderr, status = _execute(default_channel(), wrapped_command, pty,<br>
> combine_stderr)<br><br>../../../env26/lib/python2.6/site-packages/fabric/operations.py:864: <br>_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _<br>
<br> def wrapper(*args, **kwargs):<br> try:<br>> callable(*args, **kwargs)<br><br>../../../env26/lib/python2.6/site-packages/fabric/thread_handling.py:12: <br>_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _<br>
<br>chan = <paramiko.Channel 1 (closed) -> <paramiko.Transport at 0x124a810L (cipher aes128-ctr, 128 bits) (active; 0 open channel(s))>>, using_pty = True<br><br> def input_loop(chan, using_pty):<br> while not chan.exit_status_ready():<br>
if win32:<br> have_char = msvcrt.kbhit()<br> else:<br>> r, w, x = select([sys.stdin], [], [], 0.0)<br><br>../../../env26/lib/python2.6/site-packages/fabric/io.py:120: <br>
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _<br><br>self = <py._io.capture.DontReadFromInput instance at 0x10124e908><br>
<br> def fileno(self):<br>> raise ValueError("redirected Stdin is pseudofile, has no fileno()")<br>E ValueError: redirected Stdin is pseudofile, has no fileno()<br><br>../../../env26/lib/python2.6/site-packages/py/_io/capture.py:346: ValueError<br>
--------------------------------------------------------------------------------------------- Captured stdout ---------------------------------------------------------------------------------------------<br>[<a href="http://ec2-50-56-84-105.compute-1.amazonaws.com" target="_blank">ec2-50-56-84-105.compute-1.amazonaws.com</a>] run: ls -al<br>
[<a href="http://ec2-50-56-84-105.compute-1.amazonaws.com" target="_blank">ec2-50-56-84-105.compute-1.amazonaws.com</a>] out: total 40<br>[<a href="http://ec2-50-56-84-105.compute-1.amazonaws.com" target="_blank">ec2-50-56-84-105.compute-1.amazonaws.com</a>] out: drwxr-xr-x 5 ubuntu ubuntu 4096 2011-12-07 00:38 .<br>
[<a href="http://ec2-50-56-84-105.compute-1.amazonaws.com" target="_blank">ec2-50-56-84-105.compute-1.amazonaws.com</a>] out: drwxr-xr-x 3 root root 4096 2011-02-01 22:08 ..<br>[<a href="http://ec2-50-56-84-105.compute-1.amazonaws.com" target="_blank">ec2-50-56-84-105.compute-1.amazonaws.com</a>] out: -rw------- 1 ubuntu ubuntu 37 2011-12-07 00:38 .bash_history<br>
[<a href="http://ec2-50-56-84-105.compute-1.amazonaws.com" target="_blank">ec2-50-56-84-105.compute-1.amazonaws.com</a>] out: -rw-r--r-- 1 ubuntu ubuntu 220 2011-02-01 22:08 .bash_logout<br>[<a href="http://ec2-50-56-84-105.compute-1.amazonaws.com" target="_blank">ec2-50-56-84-105.compute-1.amazonaws.com</a>] out: -rw-r--r-- 1 ubuntu ubuntu 3103 2011-02-01 22:08 .bashrc<br>
[<a href="http://ec2-50-56-84-105.compute-1.amazonaws.com" target="_blank">ec2-50-56-84-105.compute-1.amazonaws.com</a>] out: drwx------ 2 ubuntu ubuntu 4096 2011-09-29 20:51 .cache<br>[<a href="http://ec2-50-56-84-105.compute-1.amazonaws.com" target="_blank">ec2-50-56-84-105.compute-1.amazonaws.com</a>] out: -rw-r--r-- 1 ubuntu ubuntu <br>
======================================================================================== 1 failed in 1.65 seconds =========================================================================================<br>(env26)[hsebastian@puri integration]$ cat test_magic.py <br>
from fabric.api import run, env<br>import os<br>import logging<br><br><br>logging.basicConfig(filename='magic.log')<br><br>class TestMagic(object):<br> def test_magic(self):<br> env.key_filename = os.path.join('test.pem')<br>
env.user = 'ubuntu'<br> env.host_string = '<a href="http://ec2-50-16-84-105.compute-1.amazonaws.com" target="_blank">ec2-50-56-84-105.compute-1.amazonaws.com</a>'<br> output = run('ls -al')<br>
<br></font><br>