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 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. diff --git a/setup.cfg b/setup.cfg index fbc4961..c733165 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,10 +3,10 @@ verbosity=1 with-doctest=1 [coverage:run] -source=sshutil +source=sshutil,tests [pytest] -addopts = --doctest-modules --doctest-glob='sshutil/*.py' +addopts = --doctest-modules testpaths = sshutil [flake8] diff --git a/sshutil/cmd.py b/sshutil/cmd.py index b1fe962..b0df20b 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_travis __author__ = 'Christian Hopps' __version__ = '1.0' @@ -370,6 +371,9 @@ def run (self, command): return self.cmd_class(self.get_cmd(command)).run() +def setup_module (unused): + setup_travis() + if __name__ == "__main__": import time import gc diff --git a/sshutil/conn.py b/sshutil/conn.py index fa15707..a34eb4a 100644 --- a/sshutil/conn.py +++ b/sshutil/conn.py @@ -334,9 +334,11 @@ def recv (self, size=MAXSSHBUF): return self.chan.recv(size) -def _setup_module (unused): +def setup_travis (): + import sys global private_key # pylint: disable=W0603 - from sshutil.cmd import ShellCommand + + logging.basicConfig(level=logging.DEBUG, stream=sys.stderr) print("Setup called.") if 'USER' in os.environ: if os.environ['USER'] != "travis": @@ -355,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 diff --git a/tests/test_cmd.py b/tests/test_cmd.py new file mode 100644 index 0000000..5102b48 --- /dev/null +++ b/tests/test_cmd.py @@ -0,0 +1,35 @@ +# -*- 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_travis + setup_travis() + + +def test_ssh_command (): + cmd = SSHCommand("ls -d /etc", "localhost", debug=True) + print(cmd.run()) diff --git a/tox.ini b/tox.ini index 42472a6..260a4c8 100644 --- a/tox.ini +++ b/tox.ini @@ -3,10 +3,11 @@ envlist = py27,py33,py34,py35,pypy,pypy3 platform = linux2|darwin [testenv] -commands = py.test -deps = pytest - pytest-capturelog -passenv = SSH_AUTH_SOCK TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH +# commands = py.test -s +# deps = pytest +commands = nosetests -v +deps = nose +passenv = HOME USER SSH_AUTH_SOCK TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH setenv = OBJDIR={envtmpdir} usedevelop = True @@ -17,7 +18,7 @@ whitelist_externals = test deps = coveralls coverage {[testenv]deps} -commands = coverage run {envbindir}/py.test +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' @@ -25,6 +26,6 @@ commands = coverage run {envbindir}/py.test deps = coveralls coverage {[testenv]deps} -commands = coverage run {envbindir}/py.test +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'