Skip to content

Commit

Permalink
Output exit code (#203)
Browse files Browse the repository at this point in the history
Migrated exit code to HostOutput property. Added tests.
Updated output generation for existing commands via get_last_output
Updated travis cfg, osx wheels
Updated changelog, readme and docs
  • Loading branch information
pkittenis authored Aug 20, 2020
1 parent be376f1 commit 89985ce
Show file tree
Hide file tree
Showing 15 changed files with 309 additions and 262 deletions.
99 changes: 30 additions & 69 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ install:
script:
# For testing SSH agent related functionality
- eval `ssh-agent -s`
- pytest --reruns 5 --cov-append --cov=pssh -s tests/test_native_tunnel.py
- pytest --reruns 5 --cov-append --cov=pssh -s tests/test_native_*_client.py
- pytest --reruns 5 --cov-append --cov=pssh -s tests/test_paramiko*.py
- pytest --reruns 5 --cov-append --cov=pssh tests/test_native_tunnel.py
- pytest --reruns 5 --cov-append --cov=pssh tests/test_native_*_client.py
- pytest --reruns 5 --cov-append --cov=pssh tests/test_paramiko*.py
- flake8 pssh
- cd doc; make html; cd ..
# Test building from source distribution
Expand All @@ -43,7 +43,34 @@ after_success:
jobs:
include:

- stage: test
if: (type = push OR \
(type = pull_request AND fork = true)) AND \
tag IS blank

- &osx-wheels
stage: build packages
if: tag IS present
os: osx
osx_image: xcode11.6
before_install:
- sudo -H pip install twine
- which twine
install: skip
script:
- ./ci/osx-wheel.sh
after_success:
- if [[ ! -z "$TRAVIS_TAG" ]]; then
twine upload --skip-existing -u $PYPI_U -p $PYPI_P wheels/*.whl;
fi
language: generic
python: skip

- <<: *osx-wheels
osx_image: xcode11.3

- stage: build packages
if: tag IS present
env:
- WHEELS=1
os: linux
Expand All @@ -69,69 +96,3 @@ jobs:
distributions: sdist
skip_upload_docs: true
skip_cleanup: true

- &osx-wheels
stage: build packages
os: osx
osx_image: xcode11.6
env:
- PYENV: 3.6.11
before_install:
- sudo -H pip install twine
- which twine
- mkdir -p wheels
install: skip
script:
- ./ci/travis/pyenv-wheel.sh
after_success:
- if [[ ! -z "$TRAVIS_TAG" ]]; then
twine upload --skip-existing -u $PYPI_U -p $PYPI_P wheels/*.whl;
fi
language: generic
python: skip

- <<: *osx-wheels
osx_image: xcode11.3
env:
- PYENV: 3.6.11

- <<: *osx-wheels
osx_image: xcode11.6
env:
- PYENV: 3.7.8

- <<: *osx-wheels
osx_image: xcode11.3
env:
- PYENV: 3.7.8

- <<: *osx-wheels
osx_image: xcode11.3
env:
- PYENV: 3.8.5

- <<: *osx-wheels
osx_image: xcode11.6
env:
- PYENV: 3.8.5

# - os: linux
# stage: build packages
# env:
# - SYSTEM_PACKAGES=1
# python: 3.6
# before_install: skip
# install: skip
# script:
# - docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
# - ./ci/docker/build-packages.sh
# deploy:
# - provider: releases
# skip_cleanup: true
# api_key:
# secure: hKf+D9ZWRCJWNQtlOWeFh7z1a+VSz+GK5qOY0e1+iV/PrM0f41wy2yej0bxG1zS6CQAnJBK6/gmq5uXXhQhGNQeIQs7zElyKlrijQAn5UstPPJTRIk2oywRr2b+q0k3V42tto6WbhjqPRpOQl/pNTjKJCc/UPgd6kOVZEhCfAec=
# file_glob: true
# file: '*.{deb,rpm}'
# on:
# repo: ParallelSSH/parallel-ssh
# tags: true
19 changes: 19 additions & 0 deletions Changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
Change Log
============

1.11.0
++++++

Changes
-------

* Moved polling to gevent.select.poll to increase performance and better handle high number of sockets - #189
* ``HostOutput.exit_code`` is now a dynamic property returning either ``None`` when exit code not ready or the exit code as reported by channel. ``ParallelSSHClient.get_exit_codes`` is now a no-op and scheduled to be removed.

Packaging
---------

* Removed OSX Python 3.6 and 3.7 wheels. OSX wheels for brew python, currently 3.8, on OSX 10.14 and 10.15 are provided.

Fixes
------

* Native client would fail on opening sockets with large file descriptor values - #189

1.10.0
+++++++

Expand Down
11 changes: 8 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,13 @@ Native Code Client Features
Exit codes
***********

Once *either* standard output is iterated on *to completion*, or ``client.join(output)`` is called, exit codes become available in host output. Iteration ends *only when remote command has completed*, though it may be interrupted and resumed at any point.
Once *either* standard output is iterated on *to completion*, or ``client.join(output)`` is called, exit codes become available in host output.

Iteration ends *only when remote command has completed*, though it may be interrupted and resumed at any point.

``HostOutput.exit_code`` is a dynamic property and will return ``None`` when exit code is not ready, meaning command has not finished, or channel is unavailable due to error.

Once all output has been gathered exit codes become available even without calling ``join``.

.. code-block:: python
Expand Down Expand Up @@ -144,8 +150,7 @@ Similarly, output and exit codes are available after ``client.join`` is called:
output = client.run_command('exit 0')
# Wait for commands to complete and gather exit codes.
# Output is updated in-place.
# Wait for commands to complete
client.join(output)
pprint(output.values()[0].exit_code)
Expand Down
25 changes: 25 additions & 0 deletions ci/osx-wheel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash -xe

pip3 install -U virtualenv
python3 -m virtualenv -p "$(which python3)" venv

set +x
source venv/bin/activate
set -x

python -V
pip3 install -U setuptools pip
pip3 install -U delocate wheel
python3 setup.py bdist_wheel
delocate-listdeps dist/*.whl
delocate-wheel -v -w wheels dist/*.whl
delocate-listdeps wheels/*.whl

ls -l wheels/*.whl
pip3 install -v wheels/*.whl
pwd; mkdir -p temp; cd temp; pwd
python3 -c "from pssh.clients import ParallelSSHClient"
cd ..; pwd
set +x
deactivate
set -x
14 changes: 12 additions & 2 deletions doc/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,26 @@ It is advised that client code uses ``return_list=True`` to avoid breaking on up
Exit codes
-------------

Exit codes are available on the host output object.
Exit codes are available on the host output object as a dynamic property. Exit code will be ``None`` if not available, or the exit code as reported by channel.

First, ensure that all commands have finished and exit codes gathered by joining on the output object, then iterate over all host's output to print their exit codes.
First, ensure that all commands have finished by either joining on the output object or gathering all output, then iterate over all host's output to print their exit codes.

.. code-block:: python
client.join(output)
for host, host_output in output.items():
print("Host %s exit code: %s" % (host, host_output.exit_code))
As of ``1.11.0``, ``client.join`` is not required as long as output has been gathered.

.. code-block:: python
for host_out in output.values():
for line in host_out.stdout:
print(line)
print(host_out.exit_code)
.. seealso::

:py:class:`pssh.output.HostOutput`
Expand Down
2 changes: 1 addition & 1 deletion pssh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
asynchronously and with minimal system load on the client host.
New users should start with
:py:func:`pssh.pssh_client.ParallelSSHClient.run_command`
:py:func:`pssh.clients.ParallelSSHClient.run_command`
See also :py:class:`pssh.ParallelSSHClient` and :py:class:mod:`pssh.SSHClient`
for class documentation.
Expand Down
Loading

0 comments on commit 89985ce

Please sign in to comment.