Skip to content

Commit

Permalink
Added codecov cfg, updated cfgs. Code cleanup, more tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
pkittenis committed Oct 10, 2017
1 parent 613209c commit 13ba5ed
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ignore:
- "embedded_server/.*"
- "tests/.*"
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ exclude_lines =
raise NotImplementedError
if __name__ == .__main__.:
logger.debug
continue
24 changes: 11 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ jobs:
- if: tag IS present
os: osx
# tag =~ ^\d+\.\d+(\.\d+)?(-\S*)?$
before_install: skip
before_install:
- brew update
install:
- brew install libssh2
- pip install -U delocate twine wheel pip setuptools
Expand All @@ -54,14 +55,13 @@ jobs:
fi
language: generic
python: skip
- stage: build_packages
- stage: build system packages
if: tag IS present
os: linux
python: 3.6
before_install: skip
install: skip
script:
- docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
- ./ci/docker/build-packages.sh
script: skip
after_success: skip
before_deploy:
- docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
Expand All @@ -76,7 +76,7 @@ jobs:
on:
repo: ParallelSSH/parallel-ssh
tags: true
- stage: deploy_pypi
- stage: deploy pypi sdist
if: tag IS present
os: linux
python: 3.6
Expand All @@ -95,7 +95,8 @@ jobs:
distributions: sdist
skip_upload_docs: true
skip_cleanup: true
- stage: build wheels
- stage: build and deploy wheels
if: tag IS present
os: linux
python: 3.6
before_install: skip
Expand All @@ -104,10 +105,7 @@ jobs:
script:
- docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" &&
./ci/travis/build-manylinux.sh;
# - if [[ ! -z "$TRAVIS_TAG" ]]; then
# echo "Building wheels for tag ${TRAVIS_TAG}" &&
# docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" &&
# ./ci/travis/build-manylinux.sh;
# fi
after_success:
- twine upload -u $PYPI_U -p $PYPI_P wheelhouse/*.whl
- if [[ ! -z "$TRAVIS_TAG" ]]; then
twine upload -u $PYPI_U -p $PYPI_P wheelhouse/*.whl;
fi
1 change: 1 addition & 0 deletions Changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Changes
---------

* New ``ssh2-python`` (``libssh2``) native library based clients
* Added ``retry_delay`` keyword parameter to parallel clients

Fixes
--------
Expand Down
7 changes: 5 additions & 2 deletions pssh/base_pssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
import logging

import gevent.pool
import gevent.hub
from gevent.hub import Hub

from .exceptions import HostArgumentException
from .constants import DEFAULT_RETRIES, RETRY_DELAY
from .output import HostOutput

gevent.hub.Hub.NOT_ERROR = (Exception,)

Hub.NOT_ERROR = (Exception,)
logger = logging.getLogger(__name__)

try:
Expand Down Expand Up @@ -165,6 +166,8 @@ def get_exit_codes(self, output):
:rtype: None
"""
for host in output:
if output[host] is None:
continue
output[host].exit_code = self.get_exit_code(output[host])

def get_exit_code(self, host_output):
Expand Down
4 changes: 0 additions & 4 deletions pssh/pssh2_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,11 @@

import logging

import gevent.pool
import gevent.hub

from .base_pssh import BaseParallelSSHClient
from .constants import DEFAULT_RETRIES, RETRY_DELAY
from .ssh2_client import SSHClient


gevent.hub.Hub.NOT_ERROR = (Exception,)
logger = logging.getLogger(__name__)


Expand Down
9 changes: 6 additions & 3 deletions pssh/pssh_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

from .base_pssh import BaseParallelSSHClient # noqa: E402
from .exceptions import HostArgumentException # noqa: E402
from .constants import DEFAULT_RETRIES # noqa: E402
from .constants import DEFAULT_RETRIES, RETRY_DELAY # noqa: E402
from .ssh_client import SSHClient # noqa: E402


Expand All @@ -43,7 +43,7 @@ def __init__(self, hosts, user=None, password=None, port=None, pkey=None,
timeout=120, pool_size=10, proxy_host=None, proxy_port=22,
proxy_user=None, proxy_password=None, proxy_pkey=None,
agent=None, allow_agent=True, host_config=None,
channel_timeout=None):
channel_timeout=None, retry_delay=RETRY_DELAY):
"""
:param hosts: Hosts to connect to
:type hosts: list(str)
Expand All @@ -61,6 +61,9 @@ def __init__(self, hosts, user=None, password=None, port=None, pkey=None,
:param num_retries: (Optional) Number of retries for connection attempts
before the client gives up. Defaults to 3.
:type num_retries: int
:param retry_delay: Number of seconds to wait between retries. Defaults
to :py:class:`pssh.constants.RETRY_DELAY`
:type retry_delay: int
:param timeout: (Optional) Number of seconds to wait before connection
and authentication attempt times out. Note that total time before
timeout will be
Expand Down Expand Up @@ -111,7 +114,7 @@ def __init__(self, hosts, user=None, password=None, port=None, pkey=None,
self, hosts, user=user, password=password, port=port, pkey=pkey,
allow_agent=allow_agent, num_retries=num_retries,
timeout=timeout, pool_size=pool_size,
host_config=host_config)
host_config=host_config, retry_delay=retry_delay)
self.forward_ssh_agent = forward_ssh_agent
self.proxy_host, self.proxy_port, self.proxy_user, \
self.proxy_password, self.proxy_pkey = proxy_host, proxy_port, \
Expand Down
2 changes: 2 additions & 0 deletions pssh/ssh2_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from gevent import sleep, get_hub
from gevent import socket
from gevent.hub import Hub
from ssh2.error_codes import LIBSSH2_ERROR_EAGAIN
from ssh2.exceptions import AuthenticationError, AgentError, \
SessionHandshakeError, SFTPHandleError, SFTPIOError as SFTPIOError_ssh2
Expand All @@ -37,6 +38,7 @@
from .native.ssh2 import wait_select, _read_output # , sftp_get, sftp_put


Hub.NOT_ERROR = (Exception,)
host_logger = logging.getLogger('pssh.host_logger')
logger = logging.getLogger(__name__)
THREAD_POOL = get_hub().threadpool
Expand Down
12 changes: 12 additions & 0 deletions tests/test_pssh_ssh2_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ def test_client_join_consume_output(self):
self.assertTrue(len(stdout) == 0)
self.assertTrue(len(stderr) == 0)
self.assertEqual(expected_exit_code, exit_code)
output = self.client.run_command('echo "me" >&2', use_pty=False)
self.client.join(output, consume_output=True)
exit_code = output[self.host].exit_code
stdout = list(output[self.host]['stdout'])
stderr = list(output[self.host]['stderr'])
self.assertTrue(len(stdout) == 0)
self.assertTrue(len(stderr) == 0)
self.assertEqual(expected_exit_code, exit_code)

def test_client_join_stdout(self):
output = self.client.run_command(self.cmd)
Expand Down Expand Up @@ -1122,6 +1130,10 @@ def test_open_channel_failure(self):
client.host_clients[self.host].session.disconnect()
self.assertRaises(SessionError, client.host_clients[self.host].open_session)

def test_host_no_client(self):
output = {'blah': None}
self.client.join(output)

# def test_proxy_remote_host_failure_timeout(self):
# """Test that timeout setting is passed on to proxy to be used for the
# proxy->remote host connection timeout
Expand Down
34 changes: 34 additions & 0 deletions tests/test_ssh2_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import logging
import time

from gevent import socket

from .base_ssh2_test import SSH2TestCase
from .embedded_server.openssh import OpenSSHServer
from pssh.ssh2_client import SSHClient, logger as ssh_logger
from pssh.exceptions import AuthenticationException, ConnectionErrorException


ssh_logger.setLevel(logging.DEBUG)
Expand Down Expand Up @@ -40,3 +43,34 @@ def test_long_running_cmd(self):
self.client.wait_finished(channel)
exit_code = channel.get_exit_status()
self.assertEqual(exit_code, 2)

def test_manual_auth(self):
client = SSHClient(self.host, port=self.port,
pkey=self.user_key,
num_retries=1)
client.session.disconnect()
del client.session
del client.sock
client.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client._connect()
client._init()

def test_identity_auth_failure(self):
self.assertRaises(AuthenticationException,
SSHClient, self.host, port=self.port, num_retries=1,
allow_agent=False)

def test_agent_auth_failure(self):
self.assertRaises(AuthenticationException,
SSHClient, self.host, port=self.port, num_retries=1,
allow_agent=True)

def test_password_auth_failure(self):
self.assertRaises(AuthenticationException,
SSHClient, self.host, port=self.port, num_retries=1,
password='blah blah blah')

def test_retry_failure(self):
self.assertRaises(ConnectionErrorException,
SSHClient, self.host, port=12345,
num_retries=2)

0 comments on commit 13ba5ed

Please sign in to comment.