From 263d7e997cb9166b2f4d180377f7c8684b705995 Mon Sep 17 00:00:00 2001 From: "Christian E. Hopps" Date: Fri, 2 Oct 2015 11:25:48 -0400 Subject: [PATCH 01/13] fix travis --- sshutil/cmd.py | 1 + tox.ini | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/sshutil/cmd.py b/sshutil/cmd.py index b1fe962..249f17b 100644 --- a/sshutil/cmd.py +++ b/sshutil/cmd.py @@ -20,6 +20,7 @@ import os import subprocess from sshutil import conn +from sshutil.conn import _setup_module as setup_module __author__ = 'Christian Hopps' __version__ = '1.0' diff --git a/tox.ini b/tox.ini index 42472a6..bda50e9 100644 --- a/tox.ini +++ b/tox.ini @@ -5,7 +5,6 @@ platform = linux2|darwin [testenv] commands = py.test deps = pytest - pytest-capturelog passenv = SSH_AUTH_SOCK TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH setenv = OBJDIR={envtmpdir} usedevelop = True From 41b3a1773e510b1910f2562afb297ea7a2c11409 Mon Sep 17 00:00:00 2001 From: "Christian E. Hopps" Date: Fri, 2 Oct 2015 12:12:24 -0400 Subject: [PATCH 02/13] move test to test file for triage --- setup.cfg | 7 ++++--- sshutil/conn.py | 5 ++++- tests/test_cmd.py | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 tests/test_cmd.py diff --git a/setup.cfg b/setup.cfg index fbc4961..2d31666 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,11 +3,12 @@ verbosity=1 with-doctest=1 [coverage:run] -source=sshutil +source=sshutil,tests [pytest] -addopts = --doctest-modules --doctest-glob='sshutil/*.py' -testpaths = sshutil +#addopts = --doctest-modules +#testpaths = sshutil,tests +testpaths = tests [flake8] max-line-length=120 diff --git a/sshutil/conn.py b/sshutil/conn.py index fa15707..25da4df 100644 --- a/sshutil/conn.py +++ b/sshutil/conn.py @@ -335,8 +335,11 @@ def recv (self, size=MAXSSHBUF): def _setup_module (unused): - global private_key # pylint: disable=W0603 from sshutil.cmd import ShellCommand + import sys + global private_key # pylint: disable=W0603 + + logging.basicConfig(level=logging.DEBUG, stream=sys.stderr) print("Setup called.") if 'USER' in os.environ: if os.environ['USER'] != "travis": diff --git a/tests/test_cmd.py b/tests/test_cmd.py new file mode 100644 index 0000000..917c437 --- /dev/null +++ b/tests/test_cmd.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*-# +# +# Copyright (c) 2015 by Christian E. Hopps. +# All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from __future__ import absolute_import, division, unicode_literals, print_function, nested_scopes +import os +import paramiko as ssh +from sshutil.cmd import ShellCommand, SSHCommand + +__author__ = 'Christian Hopps' +__date__ = 'September 26 2015' +__docformat__ = "restructuredtext en" + + +def setup_module (unused): + from sshutil.conn import _setup_module + _setup_module(None) + + +def test_ssh_command (): + print("SSHCommand test") + try: + cmd = SSHCommand("ls -d /etc", "localhost", debug=True) + print(cmd.run()) + except: + import pdb + pdb.set_trace() From d57027c104854b67750b60bd8bb7feebe0abae36 Mon Sep 17 00:00:00 2001 From: "Christian E. Hopps" Date: Fri, 2 Oct 2015 12:15:04 -0400 Subject: [PATCH 03/13] triage test --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index bda50e9..1c75031 100644 --- a/tox.ini +++ b/tox.ini @@ -5,7 +5,7 @@ platform = linux2|darwin [testenv] commands = py.test deps = pytest -passenv = SSH_AUTH_SOCK TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH +passenv = HOME USER SSH_AUTH_SOCK TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH setenv = OBJDIR={envtmpdir} usedevelop = True From a7e46a15a548a1c34871c3abf3cb7423938afb35 Mon Sep 17 00:00:00 2001 From: "Christian E. Hopps" Date: Fri, 2 Oct 2015 12:52:07 -0400 Subject: [PATCH 04/13] re-enable doctest --- setup.cfg | 5 ++--- tests/test_cmd.py | 9 ++------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/setup.cfg b/setup.cfg index 2d31666..490519a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -6,9 +6,8 @@ with-doctest=1 source=sshutil,tests [pytest] -#addopts = --doctest-modules -#testpaths = sshutil,tests -testpaths = tests +addopts = --doctest-modules +testpaths = sshutil,tests [flake8] max-line-length=120 diff --git a/tests/test_cmd.py b/tests/test_cmd.py index 917c437..e6126cc 100644 --- a/tests/test_cmd.py +++ b/tests/test_cmd.py @@ -31,10 +31,5 @@ def setup_module (unused): def test_ssh_command (): - print("SSHCommand test") - try: - cmd = SSHCommand("ls -d /etc", "localhost", debug=True) - print(cmd.run()) - except: - import pdb - pdb.set_trace() + cmd = SSHCommand("ls -d /etc", "localhost", debug=True) + print(cmd.run()) From 466a7df3bf0da58c9efaafa32751c5def98c77c9 Mon Sep 17 00:00:00 2001 From: "Christian E. Hopps" Date: Fri, 2 Oct 2015 12:54:27 -0400 Subject: [PATCH 05/13] fix test config --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 490519a..c733165 100644 --- a/setup.cfg +++ b/setup.cfg @@ -7,7 +7,7 @@ source=sshutil,tests [pytest] addopts = --doctest-modules -testpaths = sshutil,tests +testpaths = sshutil [flake8] max-line-length=120 From f0f8f20bb1cb24c9258a61a85a7aebc142cae3d0 Mon Sep 17 00:00:00 2001 From: "Christian E. Hopps" Date: Fri, 2 Oct 2015 12:57:55 -0400 Subject: [PATCH 06/13] triage travis --- sshutil/cmd.py | 5 ++++- sshutil/conn.py | 2 +- tox.ini | 6 +++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/sshutil/cmd.py b/sshutil/cmd.py index 249f17b..941e515 100644 --- a/sshutil/cmd.py +++ b/sshutil/cmd.py @@ -20,7 +20,7 @@ import os import subprocess from sshutil import conn -from sshutil.conn import _setup_module as setup_module +from sshutil.conn import _setup_module __author__ = 'Christian Hopps' __version__ = '1.0' @@ -371,6 +371,9 @@ def run (self, command): return self.cmd_class(self.get_cmd(command)).run() +def setup_module (unused): + _setup_module(unused) + if __name__ == "__main__": import time import gc diff --git a/sshutil/conn.py b/sshutil/conn.py index 25da4df..6c09d2f 100644 --- a/sshutil/conn.py +++ b/sshutil/conn.py @@ -334,7 +334,7 @@ def recv (self, size=MAXSSHBUF): return self.chan.recv(size) -def _setup_module (unused): +def setup_module (unused): from sshutil.cmd import ShellCommand import sys global private_key # pylint: disable=W0603 diff --git a/tox.ini b/tox.ini index 1c75031..8563393 100644 --- a/tox.ini +++ b/tox.ini @@ -3,7 +3,7 @@ envlist = py27,py33,py34,py35,pypy,pypy3 platform = linux2|darwin [testenv] -commands = py.test +commands = py.test -s deps = pytest passenv = HOME USER SSH_AUTH_SOCK TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH setenv = OBJDIR={envtmpdir} @@ -16,7 +16,7 @@ whitelist_externals = test deps = coveralls coverage {[testenv]deps} -commands = coverage run {envbindir}/py.test +commands = coverage run {envbindir}/py.test -s bash -c '[ -n "{env:TRAVIS:}" ] && coveralls || exit 0' bash -c '[ -z "{env:TRAVIS:}" ] && coverage report -i --omit=.tox* || exit 0' @@ -24,6 +24,6 @@ commands = coverage run {envbindir}/py.test deps = coveralls coverage {[testenv]deps} -commands = coverage run {envbindir}/py.test +commands = coverage run {envbindir}/py.test -s bash -c '[ -n "{env:TRAVIS:}" ] && coveralls || exit 0' bash -c '[ -z "{env:TRAVIS:}" ] && coverage report -i --omit=.tox* || exit 0' From 38df5c86f29752fdb1e7cdca1fa3cfb45df1f4e7 Mon Sep 17 00:00:00 2001 From: "Christian E. Hopps" Date: Fri, 2 Oct 2015 13:03:47 -0400 Subject: [PATCH 07/13] triage travis --- sshutil/cmd.py | 4 ++-- sshutil/conn.py | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/sshutil/cmd.py b/sshutil/cmd.py index 941e515..b0df20b 100644 --- a/sshutil/cmd.py +++ b/sshutil/cmd.py @@ -20,7 +20,7 @@ import os import subprocess from sshutil import conn -from sshutil.conn import _setup_module +from sshutil.conn import setup_travis __author__ = 'Christian Hopps' __version__ = '1.0' @@ -372,7 +372,7 @@ def run (self, command): def setup_module (unused): - _setup_module(unused) + setup_travis() if __name__ == "__main__": import time diff --git a/sshutil/conn.py b/sshutil/conn.py index 6c09d2f..a34eb4a 100644 --- a/sshutil/conn.py +++ b/sshutil/conn.py @@ -334,8 +334,7 @@ def recv (self, size=MAXSSHBUF): return self.chan.recv(size) -def setup_module (unused): - from sshutil.cmd import ShellCommand +def setup_travis (): import sys global private_key # pylint: disable=W0603 @@ -358,7 +357,7 @@ def setup_module (unused): else: logger.error("Creating ssh dir " + ssh_dir) print("Creating ssh dir " + ssh_dir) - ShellCommand("mkdir -p {}".format(ssh_dir)).run() + os.system("mkdir -p {}".format(ssh_dir)) priv = ssh.RSAKey.generate(bits=1024) private_key = priv From 6414196b3b9dfeaaac66957293734230dfcf5eff Mon Sep 17 00:00:00 2001 From: "Christian E. Hopps" Date: Fri, 2 Oct 2015 13:25:41 -0400 Subject: [PATCH 08/13] triage travis --- tox.ini | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/tox.ini b/tox.ini index 8563393..272a70e 100644 --- a/tox.ini +++ b/tox.ini @@ -3,27 +3,29 @@ envlist = py27,py33,py34,py35,pypy,pypy3 platform = linux2|darwin [testenv] -commands = py.test -s -deps = pytest +# commands = py.test -s +# deps = pytest +commands = nosetests -v +deps = nosetests passenv = HOME USER SSH_AUTH_SOCK TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH setenv = OBJDIR={envtmpdir} usedevelop = True -whitelist_externals = test - bash +# whitelist_externals = test +# bash -[testenv:py27] -deps = coveralls - coverage - {[testenv]deps} -commands = coverage run {envbindir}/py.test -s - bash -c '[ -n "{env:TRAVIS:}" ] && coveralls || exit 0' - bash -c '[ -z "{env:TRAVIS:}" ] && coverage report -i --omit=.tox* || exit 0' +# [testenv:py27] +# deps = coveralls +# coverage +# {[testenv]deps} +# commands = coverage run {envbindir}/py.test -s +# bash -c '[ -n "{env:TRAVIS:}" ] && coveralls || exit 0' +# bash -c '[ -z "{env:TRAVIS:}" ] && coverage report -i --omit=.tox* || exit 0' -[testenv:py35] -deps = coveralls - coverage - {[testenv]deps} -commands = coverage run {envbindir}/py.test -s - bash -c '[ -n "{env:TRAVIS:}" ] && coveralls || exit 0' - bash -c '[ -z "{env:TRAVIS:}" ] && coverage report -i --omit=.tox* || exit 0' +# [testenv:py35] +# deps = coveralls +# coverage +# {[testenv]deps} +# commands = coverage run {envbindir}/py.test -s +# bash -c '[ -n "{env:TRAVIS:}" ] && coveralls || exit 0' +# bash -c '[ -z "{env:TRAVIS:}" ] && coverage report -i --omit=.tox* || exit 0' From e4912537f8eb6ba96e9b6383b653f854b760e4e7 Mon Sep 17 00:00:00 2001 From: "Christian E. Hopps" Date: Fri, 2 Oct 2015 14:16:37 -0400 Subject: [PATCH 09/13] triage travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 7b04857..9687a02 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,7 @@ env: install: - pip install tox - pip install coveralls + - pip install nose script: - tox -e $TOXENV From 54b297e678097e45e823f2720d8c96e225623f4f Mon Sep 17 00:00:00 2001 From: "Christian E. Hopps" Date: Fri, 2 Oct 2015 14:19:01 -0400 Subject: [PATCH 10/13] triage travis --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 272a70e..13d59c3 100644 --- a/tox.ini +++ b/tox.ini @@ -6,7 +6,7 @@ platform = linux2|darwin # commands = py.test -s # deps = pytest commands = nosetests -v -deps = nosetests +deps = nose passenv = HOME USER SSH_AUTH_SOCK TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH setenv = OBJDIR={envtmpdir} usedevelop = True From d04ec394bf5eb5c6b609f5a93107c72de821e102 Mon Sep 17 00:00:00 2001 From: "Christian E. Hopps" Date: Fri, 2 Oct 2015 14:24:28 -0400 Subject: [PATCH 11/13] travis works with nose --- tests/test_cmd.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_cmd.py b/tests/test_cmd.py index e6126cc..5102b48 100644 --- a/tests/test_cmd.py +++ b/tests/test_cmd.py @@ -26,8 +26,8 @@ def setup_module (unused): - from sshutil.conn import _setup_module - _setup_module(None) + from sshutil.conn import setup_travis + setup_travis() def test_ssh_command (): From ebcf92b07ffdf825ee9e7c0949f866fc480f8e5c Mon Sep 17 00:00:00 2001 From: "Christian E. Hopps" Date: Fri, 2 Oct 2015 14:26:50 -0400 Subject: [PATCH 12/13] enable coverage --- tox.ini | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tox.ini b/tox.ini index 13d59c3..260a4c8 100644 --- a/tox.ini +++ b/tox.ini @@ -11,21 +11,21 @@ passenv = HOME USER SSH_AUTH_SOCK TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH setenv = OBJDIR={envtmpdir} usedevelop = True -# whitelist_externals = test -# bash +whitelist_externals = test + bash -# [testenv:py27] -# deps = coveralls -# coverage -# {[testenv]deps} -# commands = coverage run {envbindir}/py.test -s -# bash -c '[ -n "{env:TRAVIS:}" ] && coveralls || exit 0' -# bash -c '[ -z "{env:TRAVIS:}" ] && coverage report -i --omit=.tox* || exit 0' +[testenv:py27] +deps = coveralls + coverage + {[testenv]deps} +commands = coverage run {envbindir}/nosetests + bash -c '[ -n "{env:TRAVIS:}" ] && coveralls || exit 0' + bash -c '[ -z "{env:TRAVIS:}" ] && coverage report -i --omit=.tox* || exit 0' -# [testenv:py35] -# deps = coveralls -# coverage -# {[testenv]deps} -# commands = coverage run {envbindir}/py.test -s -# bash -c '[ -n "{env:TRAVIS:}" ] && coveralls || exit 0' -# bash -c '[ -z "{env:TRAVIS:}" ] && coverage report -i --omit=.tox* || exit 0' +[testenv:py35] +deps = coveralls + coverage + {[testenv]deps} +commands = coverage run {envbindir}/nosetests + bash -c '[ -n "{env:TRAVIS:}" ] && coveralls || exit 0' + bash -c '[ -z "{env:TRAVIS:}" ] && coverage report -i --omit=.tox* || exit 0' From b09a46a54598a3a1b965aac6f90da2161431cb08 Mon Sep 17 00:00:00 2001 From: "Christian E. Hopps" Date: Fri, 2 Oct 2015 14:47:35 -0400 Subject: [PATCH 13/13] update readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b88a656..b811792 100644 --- a/README.md +++ b/README.md @@ -7,5 +7,6 @@ The following modules are a collection of classes and functions useful for efficiently interacting with local and remote hosts using ssh. - * `host` - A Host class for interacting with a host. * `cmd` - Execute commands either locally or remotely (wiht ssh). + * `conn` - SSH channel and socket connections with caching. + * `host` - A Host class for interacting with a host.