-
Notifications
You must be signed in to change notification settings - Fork 967
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reuse Shell objects after initialization
- Loading branch information
Showing
2 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import os | ||
import tempfile | ||
import unittest | ||
|
||
import mockssh | ||
|
||
from Crypto.PublicKey import RSA | ||
|
||
from galaxy.jobs.runners.cli import CliInterface | ||
|
||
|
||
class TestCliInterface(unittest.TestCase): | ||
|
||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
os.remove(cls.private_key) | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
cls.private_key = make_private_key() | ||
cls.username = 'testuser' | ||
cls.shell_params = {'username': cls.username, | ||
'private_key': cls.private_key, | ||
'hostname': 'localhost'} | ||
cls.cli_interface = CliInterface() | ||
|
||
def test_secure_shell_plugin_without_strict(self): | ||
with mockssh.Server(users={self.username: self.private_key}) as server: | ||
self.shell_params['port'] = server.port | ||
self.shell_params['plugin'] = 'SecureShell' | ||
self.shell_params['strict_host_key_checking'] = False | ||
self.shell = self.cli_interface.get_shell_plugin(self.shell_params) | ||
result = self.shell.execute(cmd='echo hello') | ||
assert result.stdout.strip() == 'hello1' | ||
|
||
def test_get_shell_plugin(self): | ||
with mockssh.Server(users={self.username: self.private_key}) as server: | ||
self.shell_params['port'] = server.port | ||
self.shell_params['plugin'] = 'ParamikoShell' | ||
self.shell = self.cli_interface.get_shell_plugin(self.shell_params) | ||
assert self.shell.username == self.username | ||
|
||
def test_paramiko_shell_plugin(self): | ||
with mockssh.Server(users={self.username: self.private_key}) as server: | ||
self.shell_params['port'] = server.port | ||
self.shell_params['plugin'] = 'ParamikoShell' | ||
self.shell = self.cli_interface.get_shell_plugin(self.shell_params) | ||
result = self.shell.execute(cmd='echo hello') | ||
assert result.stdout.strip() == 'hello1' | ||
|
||
|
||
def make_private_key(): | ||
key = RSA.generate(1024) | ||
private_fd, private_path = tempfile.mkstemp() | ||
open(private_path, 'w').write(key.exportKey('PEM')) | ||
return private_path |