コード例 #1
0
 def test_auto_add_policy():
     """Test the auto add policy."""
     with SshTransport(machine='localhost',
                       timeout=30,
                       load_system_host_keys=True,
                       key_policy='AutoAddPolicy'):
         pass
コード例 #2
0
    def test_no_host_key(self):
        # Disable logging to avoid output during test
        logging.disable(logging.ERROR)

        with self.assertRaises(paramiko.SSHException):
            with SshTransport(machine='localhost', timeout=30, load_system_host_keys=False):
                pass

        # Reset logging level
        logging.disable(logging.NOTSET)
コード例 #3
0
ファイル: test_ssh.py プロジェクト: timostrunk/aiida-core
def test_gotocomputer():
    """Test gotocomputer"""
    with SshTransport(machine='localhost',
                      timeout=30,
                      use_login_shell=False,
                      key_policy='AutoAddPolicy') as transport:
        cmd_str = transport.gotocomputer_command('/remote_dir/')

        expected_str = (
            """ssh -t localhost   "if [ -d '/remote_dir/' ] ;"""
            """ then cd '/remote_dir/' ; bash  ; else echo '  ** The directory' ; """
            """echo '  ** /remote_dir/' ; echo '  ** seems to have been deleted, I logout...' ; fi" """
        )
        assert cmd_str == expected_str
コード例 #4
0
 def test_auto_add_policy(self):
     with SshTransport(machine='localhost',
                       timeout=30,
                       load_system_host_keys=True,
                       key_policy='AutoAddPolicy'):
         pass
コード例 #5
0
 def test_invalid_param(self):
     with self.assertRaises(ValueError):
         SshTransport(machine='localhost', invalid_param=True)
コード例 #6
0
 def test_closed_connection_sftp(self):
     with self.assertRaises(
             aiida.transports.transport.TransportInternalError):
         t = SshTransport(machine='localhost')
         t.listdir()
コード例 #7
0
 def test_closed_connection_ssh(self):
     with self.assertRaises(
             aiida.transports.transport.TransportInternalError):
         t = SshTransport(machine='localhost')
         t._exec_command_internal('ls')
コード例 #8
0
"""
from __future__ import division
from __future__ import print_function
from __future__ import absolute_import
import unittest
import logging

import aiida.transports
import aiida.transports.transport
import paramiko
from aiida.transports.plugins.ssh import SshTransport

# This will be used by test_all_plugins

plugin_transport = SshTransport(machine='localhost',
                                timeout=30,
                                load_system_host_keys=True,
                                key_policy='AutoAddPolicy')


class TestBasicConnection(unittest.TestCase):
    """
    Test basic connections.
    """
    def test_closed_connection_ssh(self):
        with self.assertRaises(
                aiida.transports.transport.TransportInternalError):
            t = SshTransport(machine='localhost')
            t._exec_command_internal('ls')

    def test_closed_connection_sftp(self):
        with self.assertRaises(
コード例 #9
0
 def test_closed_connection_sftp(self):
     """Test calling sftp command on a closed connection."""
     with self.assertRaises(TransportInternalError):
         transport = SshTransport(machine='localhost')
         transport.listdir()
コード例 #10
0
 def test_closed_connection_ssh(self):
     """Test calling command on a closed connection."""
     with self.assertRaises(TransportInternalError):
         transport = SshTransport(machine='localhost')
         transport._exec_command_internal('ls')  # pylint: disable=protected-access