Skip to content

Commit a76e601

Browse files
Danpkittenis
authored andcommitted
Added coveralls test coverage. Updated readme. Moved testing code outside module into separate file.
1 parent 7a1091b commit a76e601

File tree

7 files changed

+53
-46
lines changed

7 files changed

+53
-46
lines changed

.coveragerc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[report]
2+
omit =
3+
*/python?.?/*
4+
*/site-packages/nose/*
5+
fake_server/*
6+
tests/*

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ python:
44
- "2.7"
55
install:
66
- pip install -r requirements.txt
7-
script: nosetests
7+
- pip install coveralls
8+
script: nosetests --with-coverage --cover-package=pssh
89
notifications:
910
email:
1011
on_failure: change
12+
after_success:
13+
coveralls

README.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ This is a *requirement* for commands on many (hundreds/thousands/hundreds of tho
99

1010
.. image:: https://api.travis-ci.org/pkittenis/parallel-ssh.png?branch=master
1111
:target: https://travis-ci.org/pkittenis/parallel-ssh
12+
.. image:: https://coveralls.io/repos/pkittenis/parallel-ssh/badge.png?branch=master
13+
:target: https://coveralls.io/r/pkittenis/parallel-ssh?branch=master
14+
.. image:: https://pypip.in/version/parallel-ssh/badge.png
15+
:target: https://pypip.in/version/parallel-ssh
16+
:alt: version
17+
.. image:: https://pypip.in/download/parallel-ssh/badge.png
18+
:target: https://pypip.in/download/parallel-ssh
19+
:alt: downloads
1220

1321
Module documentation can be found at the repository's `github pages`_.
1422

@@ -18,9 +26,6 @@ Module documentation can be found at the repository's `github pages`_.
1826
Installation
1927
************
2028

21-
.. note ::
22-
libevent-dev package is no longer required as of gevent 1.0 which has migrated to libev. `parallel-ssh` now requires at least gevent version 1.0.
23-
2429
::
2530

2631
$ pip install parallel-ssh

pssh.py

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,6 @@
4141
NUM_RETRIES = 3
4242

4343
logger = logging.getLogger(__name__)
44-
45-
def _setup_logger(_logger):
46-
"""Setup default logger"""
47-
_handler = logging.StreamHandler()
48-
log_format = logging.Formatter('%(name)s - %(asctime)s - %(levelname)s - %(message)s')
49-
_handler.setFormatter(log_format)
50-
_logger.addHandler(handler)
51-
_logger.setLevel(logging.DEBUG)
5244

5345
class UnknownHostException(Exception):
5446
"""Raised when a host is unknown (dns failure)"""
@@ -122,10 +114,7 @@ def __init__(self, host,
122114
'hostname' in host_config
123115
else host)
124116
_user = host_config['user'] if 'user' in host_config else None
125-
if user:
126-
user = user
127-
else:
128-
user = _user
117+
user = user if user else _user
129118
client = paramiko.SSHClient()
130119
client.set_missing_host_key_policy(paramiko.MissingHostKeyPolicy())
131120
self.forward_ssh_agent = forward_ssh_agent
@@ -489,24 +478,3 @@ def _copy_file(self, host, local_file, remote_file):
489478
port=self.port, pkey=self.pkey,
490479
forward_ssh_agent=self.forward_ssh_agent)
491480
return self.host_clients[host].copy_file(local_file, remote_file)
492-
493-
494-
def test():
495-
client = SSHClient('localhost')
496-
channel, host, stdout, stderr = client.exec_command('ls -ltrh')
497-
for line in stdout:
498-
print line.strip()
499-
client.copy_file('../test', 'test_dir/test')
500-
501-
def test_parallel():
502-
client = ParallelSSHClient(['localhost'])
503-
cmds = client.exec_command('ls -ltrh')
504-
output = [client.get_stdout(cmd, return_buffers=True) for cmd in cmds]
505-
print output
506-
cmds = client.copy_file('../test', 'test_dir/test')
507-
client.pool.join()
508-
509-
if __name__ == "__main__":
510-
_setup_logger(logger)
511-
test()
512-
test_parallel()

pssh_test.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from pssh import SSHClient, ParallelSSHClient
2+
import logging
3+
4+
logger = logging.getLogger(__name__)
5+
6+
def _setup_logger(_logger):
7+
"""Setup default logger"""
8+
_handler = logging.StreamHandler()
9+
log_format = logging.Formatter('%(name)s - %(asctime)s - %(levelname)s - %(message)s')
10+
_handler.setFormatter(log_format)
11+
_logger.addHandler(_handler)
12+
_logger.setLevel(logging.DEBUG)
13+
14+
def test():
15+
client = SSHClient('localhost')
16+
channel, host, stdout, stderr = client.exec_command('ls -ltrh')
17+
for line in stdout:
18+
print line.strip()
19+
client.copy_file('../test', 'test_dir/test')
20+
21+
def test_parallel():
22+
client = ParallelSSHClient(['localhost'])
23+
cmds = client.exec_command('ls -ltrh')
24+
output = [client.get_stdout(cmd, return_buffers=True) for cmd in cmds]
25+
print output
26+
cmds = client.copy_file('../test', 'test_dir/test')
27+
client.pool.join()
28+
29+
if __name__ == "__main__":
30+
_setup_logger(logger)
31+
test()
32+
test_parallel()

tests/test_pssh_client.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import unittest
2222
from pssh import ParallelSSHClient, UnknownHostException, \
23-
AuthenticationException, ConnectionErrorException, _setup_logger
23+
AuthenticationException, ConnectionErrorException
2424
from fake_server.fake_server import start_server, make_socket, logger as server_logger, \
2525
paramiko_logger
2626
import random
@@ -30,9 +30,6 @@
3030
import paramiko
3131
import os
3232

33-
# _setup_logger(server_logger)
34-
# _setup_logger(paramiko_logger)
35-
3633
USER_KEY = paramiko.RSAKey.from_private_key_file(
3734
os.path.sep.join([os.path.dirname(__file__), 'test_client_private_key']))
3835

tests/test_ssh_client.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,14 @@
1919
"""
2020

2121
import unittest
22-
from pssh import SSHClient, ParallelSSHClient, UnknownHostException, AuthenticationException, _setup_logger, logger
22+
from pssh import SSHClient, ParallelSSHClient, UnknownHostException, AuthenticationException, logger
2323
from fake_server.fake_server import start_server, make_socket, logger as server_logger, \
2424
paramiko_logger
2525
from fake_server.fake_agent import FakeAgent
2626
import paramiko
2727
import os
2828
from test_pssh_client import USER_KEY
2929

30-
# _setup_logger(server_logger)
31-
# _setup_logger(logger)
32-
# _setup_logger(paramiko_logger)
33-
3430
USER_KEY = paramiko.RSAKey.from_private_key_file(
3531
os.path.sep.join([os.path.dirname(__file__), 'test_client_private_key']))
3632

0 commit comments

Comments
 (0)