def setUp(self): super(MockupSSHTestCase, self).setUp() self.ssh_users = {"user1": join(TEST_STUFF_DIR, 'user1.key')} self.key_file = join(TEST_STUFF_DIR, 'user1.key') self.mockup_server = mockssh.Server(self.ssh_users) print('Starting mocked-up SSH server.') self.mockup_server.__enter__()
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() == 'hello'
def ssh_server(test_config): import mockssh test_config.requires("ssh") users = {TEST_SSH_USER: TEST_SSH_KEY_PATH} with mockssh.Server(users) as s: yield s
def ssh(): users = {user: key_path} with mockssh.Server(users) as s: yield SSHConnection(s.host, username=user, port=s.port, key_filename=key_path)
def ssh_server(): with mockssh.Server( {default_config["username"]: default_config["keyfile"]}, host=default_config["host"], port=default_config["port"], ) as s: yield s
def ssh_session(): uid = pwd.getpwuid(os.geteuid()).pw_name private_key_path = ssh_private_key_path() with mockssh.Server({uid: private_key_path}) as s: with utils.SshSession(uid, s.host, s.port, private_key_path) as session: yield session
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() == 'hello'
def test_get_shell_plugin(self): with mockssh.Server( users={self.username: self.ssh_keys.private_key_file }) 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 ssh_server(): users = {user: key_path} with mockssh.Server(users) as s: s.test_creds = { "host": s.host, "port": s.port, "username": user, "key_filename": key_path, } yield s
def mock_remote_ssh(): with contextlib.ExitStack() as exit_stack: users = {'ssh-user': '******'} server = exit_stack.enter_context(mockssh.Server(users)) client = exit_stack.enter_context(server.client('ssh-user')) connect_mock = exit_stack.enter_context( mock.patch( 'camille.source.bazefetcher.RemoteIO._create_connection')) connect_mock.return_value = client #disable disconnect exit_stack.enter_context( mock.patch('camille.source.bazefetcher.RemoteIO.__exit__')) yield
def TmpSFTP(): users = {'ssh-user': '******'} with contextlib.ExitStack() as stack: tmpdirname = stack.enter_context(tempfile.TemporaryDirectory()) server = stack.enter_context(mockssh.Server(users)) client = stack.enter_context(server.client('ssh-user')) ssh_mock = stack.enter_context( mock.patch('xun.functions.store.sftp.SFTPDriver.ssh', new_callable=mock.PropertyMock)) ssh_mock.return_value = client store = xun.functions.store.SFTP( '127.0.0.1', tmpdirname, username='******', missing_host_key_policy=paramiko.MissingHostKeyPolicy()) yield store
def test_ssh_session(self): pkey = pkg_resources.resource_filename("mockssh", 'server-key') data_folder = pkg_resources.resource_filename(__name__, 'data') users = { "mockuser": pkey, } scores = {} mutex = Lock() config = { 'workingdir': data_folder, 'n_parallel': 2, 'resource': 'node', 'proposer': 'random', 'script': os.path.join(data_folder, "script", "rosenbrock_hpo.py"), 'n_samples': 10, 'random_seed': 10, 'parameter_config': [{ 'name': 'x', 'type': 'float', 'range': [-5, 5] }, { 'name': 'y', 'type': 'float', 'range': [-5, 5] }], "runtime_args": { "prescript": "export CUDA_VISIBLE_DEVICES=-1", "postscript": "echo $CUDA_VISIBLE_DEVICES", "overwrite": 'true' } } m = rp.RandomProposer(config) def callback_fun(score, jid): mutex.acquire() scores[jid] = score mutex.release() with mockssh.Server(users) as server1, mockssh.Server( users) as server2: mngr = SSHResourceManager(None, config['n_parallel'], auppath=data_folder, reconn_wait_time=3, max_retries=3) mngr.mapping[1] = "[email protected]:" + str( server1.port) + " " + pkey mngr.mapping[2] = "[email protected]:" + str( server2.port) + " " + pkey for i in range(0, config['n_samples'], 2): proposal = m.get() job1 = Job(config['script'], BasicConfig(**proposal), config['workingdir']) job1.jid = i mngr.run(job1, 1, None, callback_fun, overwrite=True) proposal = m.get() job2 = Job(config['script'], BasicConfig(**proposal), config['workingdir']) job2.jid = i + 1 mngr.run(job2, 2, None, callback_fun, overwrite=True) mngr.executor.shutdown(wait=True) for key in scores: self.assertTrue(scores[key] != "ERROR")
def ssh_server(): import mockssh users = {TEST_SSH_USER: TEST_SSH_KEY_PATH} with mockssh.Server(users) as s: yield s
def server(): ''' Mock SSH Server. ''' users = {'sample-user': SAMPLE_USER_KEY} with mockssh.Server(users) as s: yield s
def server(): with mockssh.Server({'test': KEY_FILENAME}) as s: yield s
def ssh_server(): users = {user: key_path} with mockssh.Server(users) as s: yield s
def setUp(self): self.serv = mockssh.Server(_USERS) self.serv.__enter__() self.addCleanup(self.serv.__exit__) self.tr = SshBasedTransport("localhost", self.serv.port, "username", 'files/test.key')
def __init__(self): super(MockProvider, self).__init__() self.ssh_server = mockssh.Server({})