예제 #1
0
 def test_run_command(self):
     hosts = ['localhost', '127.0.0.1', 'st2build001']
     client = ParallelSSHClient(hosts=hosts,
                                user='******',
                                pkey='~/.ssh/id_rsa',
                                connect=True)
     client.run('pwd', timeout=60)
     expected_kwargs = {'timeout': 60}
     for host in hosts:
         hostname, _ = client._get_host_port_info(host)
         client._hosts_client[hostname].run.assert_called_with(
             'pwd', **expected_kwargs)
예제 #2
0
 def test_run_command(self):
     hosts = ['localhost', '127.0.0.1', 'st2build001']
     client = ParallelSSHClient(hosts=hosts,
                                user='******',
                                pkey_file='~/.ssh/id_rsa',
                                connect=True)
     client.run('pwd', timeout=60)
     expected_kwargs = {
         'timeout': 60
     }
     for host in hosts:
         hostname, _ = client._get_host_port_info(host)
         client._hosts_client[hostname].run.assert_called_with('pwd', **expected_kwargs)
예제 #3
0
 def test_run_command_json_output_transformed_to_object(self):
     hosts = ['127.0.0.1']
     client = ParallelSSHClient(hosts=hosts,
                                user='******',
                                pkey_file='~/.ssh/id_rsa',
                                connect=True)
     results = client.run('stuff', timeout=60)
     self.assertTrue('127.0.0.1' in results)
     self.assertDictEqual(results['127.0.0.1']['stdout'], {'foo': 'bar'})
예제 #4
0
 def test_run_command_json_output_transformed_to_object(self):
     hosts = ['127.0.0.1']
     client = ParallelSSHClient(hosts=hosts,
                                user='******',
                                pkey_file='~/.ssh/id_rsa',
                                connect=True)
     results = client.run('stuff', timeout=60)
     self.assertTrue('127.0.0.1' in results)
     self.assertDictEqual(results['127.0.0.1']['stdout'], {'foo': 'bar'})
예제 #5
0
    def test_run_command_timeout(self):
        # Make sure stdout and stderr is included on timeout
        hosts = ['localhost', '127.0.0.1', 'st2build001']
        client = ParallelSSHClient(hosts=hosts,
                                   user='******',
                                   pkey_file='~/.ssh/id_rsa',
                                   connect=True)
        mock_run = Mock(side_effect=SSHCommandTimeoutError(
            cmd='pwd', timeout=10, stdout='a', stderr='b'))
        for host in hosts:
            hostname, _ = client._get_host_port_info(host)
            host_client = client._hosts_client[host]
            host_client.run = mock_run

        results = client.run('pwd')
        for host in hosts:
            result = results[host]
            self.assertEqual(result['failed'], True)
            self.assertEqual(result['stdout'], 'a')
            self.assertEqual(result['stderr'], 'b')
            self.assertEqual(result['return_code'], -9)
예제 #6
0
    def test_run_command_timeout(self):
        # Make sure stdout and stderr is included on timeout
        hosts = ['localhost', '127.0.0.1', 'st2build001']
        client = ParallelSSHClient(hosts=hosts,
                                   user='******',
                                   pkey_file='~/.ssh/id_rsa',
                                   connect=True)
        mock_run = Mock(side_effect=SSHCommandTimeoutError(cmd='pwd', timeout=10,
                                                           stdout='a',
                                                           stderr='b'))
        for host in hosts:
            hostname, _ = client._get_host_port_info(host)
            host_client = client._hosts_client[host]
            host_client.run = mock_run

        results = client.run('pwd')
        for host in hosts:
            result = results[host]
            self.assertEqual(result['failed'], True)
            self.assertEqual(result['stdout'], 'a')
            self.assertEqual(result['stderr'], 'b')
            self.assertEqual(result['return_code'], -9)