Ejemplo n.º 1
0
    def run_command(self, server, username, network, port, ip_version,
                    interpreter, script):
        """Create SSH connection for server, wait for server to become
        available (there is a delay between server being set to ACTIVE
        and sshd being available). Then call __run_command to actually
        execute the command.
        """

        if network not in server.addresses:
            raise ValueError(
                "Can't find cloud network %(network)s, so cannot boot "
                "instance for Rally scenario boot-runcommand-delete. "
                "Available networks: %(networks)s" % (
                    dict(network=network,
                         networks=server.addresses.keys()
                         )
                )
            )
        server_ip = [ip for ip in server.addresses[network] if
                     ip["version"] == ip_version][0]["addr"]
        ssh = sshutils.SSH(username, server_ip, port=port,
                           pkey=self.context()["user"]["keypair"]["private"])

        self.wait_for_network(ssh)
        return self.run_action(ssh, interpreter, script)
Ejemplo n.º 2
0
 def __init__(self, host, user, key=None, password=None, port=22):
     self.host = host
     self.port = port
     self.user = user
     self.key = key
     self.password = password
     self.ssh = sshutils.SSH(user,
                             host,
                             key_filename=key,
                             port=port,
                             password=password)
     super(Server, self).__init__()
Ejemplo n.º 3
0
    def run_command(self, server_ip, port, username, interpreter, script):
        """Run command via SSH on server.

        Create SSH connection for server, wait for server to become
        available (there is a delay between server being set to ACTIVE
        and sshd being available). Then call __run_command to actually
        execute the command.
        """
        self.wait_for_ping(server_ip)
        ssh = sshutils.SSH(username, server_ip, port=port,
                           pkey=self.context()["user"]["keypair"]["private"])

        self.wait_for_ssh(ssh)
        return self.run_action(ssh, interpreter, script)
Ejemplo n.º 4
0
 def test_construct(self, m_pkey):
     m_pkey.return_value = 'pkey'
     ssh = sshutils.SSH('root',
                        'example.net',
                        port=33,
                        pkey='key',
                        key_filename='kf',
                        password='******')
     m_pkey.assert_called_once_with('key')
     self.assertEqual('root', ssh.user)
     self.assertEqual('example.net', ssh.host)
     self.assertEqual(33, ssh.port)
     self.assertEqual('pkey', ssh.pkey)
     self.assertEqual('kf', ssh.key_filename)
     self.assertEqual('secret', ssh.password)
Ejemplo n.º 5
0
    def setUp(self):
        super(SSHRunTestCase, self).setUp()

        self.fake_client = mock.Mock()
        self.fake_session = mock.Mock()
        self.fake_transport = mock.Mock()

        self.fake_transport.open_session.return_value = self.fake_session
        self.fake_client.get_transport.return_value = self.fake_transport

        self.fake_session.recv_ready.return_value = False
        self.fake_session.recv_stderr_ready.return_value = False
        self.fake_session.send_ready.return_value = False
        self.fake_session.exit_status_ready.return_value = True
        self.fake_session.recv_exit_status.return_value = 0

        self.ssh = sshutils.SSH('admin', 'example.net')
        self.ssh._get_client = mock.Mock(return_value=self.fake_client)
Ejemplo n.º 6
0
    def test__get_client(self, m_paramiko, m_pkey):
        m_pkey.return_value = 'key'
        fake_client = mock.Mock()
        m_paramiko.SSHClient.return_value = fake_client
        m_paramiko.AutoAddPolicy.return_value = 'autoadd'

        ssh = sshutils.SSH('admin', 'example.net', pkey='key')
        client = ssh._get_client()

        self.assertEqual(fake_client, client)
        client_calls = [
            mock.call.set_missing_host_key_policy('autoadd'),
            mock.call.connect('example.net',
                              username='******',
                              port=22,
                              pkey='key',
                              key_filename=None,
                              password=None),
        ]
        self.assertEqual(client_calls, client.mock_calls)
Ejemplo n.º 7
0
 def setUp(self):
     super(SSHTestCase, self).setUp()
     self.ssh = sshutils.SSH('root', 'example.net')