def ssh_connect(self, username, credential, credential_is_key=True): self.ssh_logger = logging.getLogger('ssh') res = self.vm.command('human-monitor-command', command_line='info usernet') port = get_info_usernet_hostfwd_port(res) self.assertIsNotNone(port) self.assertGreater(port, 0) self.log.debug('sshd listening on port: %d', port) if credential_is_key: self.ssh_session = ssh.Session('127.0.0.1', port=port, user=username, key=credential) else: self.ssh_session = ssh.Session('127.0.0.1', port=port, user=username, password=credential) for i in range(10): try: self.ssh_session.connect() return except: time.sleep(i) self.fail('ssh connection timeout')
def test_minimal(self): session = ssh.Session("host") self.assertEqual(session.host, "host") self.assertIsNone(session.port) self.assertIsNone(session.user) self.assertIsNone(session.key) self.assertIsNone(session._connection)
def test_master_connection_ssh_askpass_script(self): password = "******" session = ssh.Session("hostname", user="******", password=password) ssh_askpass_path = session._create_ssh_askpass() ssh_askpass_password = process.run(ssh_askpass_path) os.unlink(ssh_askpass_path) self.assertEqual(ssh_askpass_password.stdout_text.rstrip(), password)
def ssh_connect(self, username, keyfile): self.ssh_logger = logging.getLogger('ssh') port = self.get_portfwd() self.ssh_session = ssh.Session('127.0.0.1', port=port, user=username, key=keyfile) for i in range(10): try: self.ssh_session.connect() return except: time.sleep(4) pass self.fail('ssh connection timeout')
def ssh_connect(self, username, password): self.ssh_logger = logging.getLogger('ssh') port = self.get_portfwd() self.ssh_session = ssh.Session(self.VM_IP, port=int(port), user=username, password=password) for i in range(10): try: self.ssh_session.connect() return except: time.sleep(4) pass self.fail("sshd timeout")
def test_no_ssh_client_binary(self): session = ssh.Session("hostname") with unittest.mock.patch("avocado.utils.ssh.SSH_CLIENT_BINARY", None): self.assertFalse(session.connect())
def test_master_connection_no_password(self): session = ssh.Session("hostname", user="******") master_connection = session._master_connection() self.assertIn(" -o 'PasswordAuthentication=no'", master_connection)
def test_master_connection_password(self): session = ssh.Session("hostname", user="******", password="******") master_connection = session._master_connection() self.assertIn(" -o 'PasswordAuthentication=yes'", master_connection)
def test_master_connection_key(self): session = ssh.Session("hostname", user="******", key="/path/to/key") master_connection = session._master_connection() self.assertIn(" -o 'PubkeyAuthentication=yes'", master_connection)
def test_ssh_cmd_user_key(self): session = ssh.Session("hostname", user="******", key="/path/to/key") ssh_cmd = session._ssh_cmd() self.assertIn(" -l ", ssh_cmd) self.assertIn(" -i ", ssh_cmd)
def test_ssh_cmd_port(self): session = ssh.Session("hostname", port=22) ssh_cmd = session._ssh_cmd() self.assertIn(" -p ", ssh_cmd)
def test_master_connection_password(self): session = ssh.Session('hostname', user='******', password='******') master_connection = session._master_connection() self.assertIn(" -o 'PasswordAuthentication=yes'", master_connection)
def test_master_connection_no_key(self): session = ssh.Session('hostname', user='******') master_connection = session._master_connection() self.assertIn(" -o 'PubkeyAuthentication=no'", master_connection)
def test_master_connection_key(self): session = ssh.Session('hostname', user='******', key='/path/to/key') master_connection = session._master_connection() self.assertIn(" -o 'PubkeyAuthentication=yes'", master_connection)
def test_ssh_cmd_user_key(self): session = ssh.Session('hostname', user='******', key='/path/to/key') ssh_cmd = session._ssh_cmd() self.assertIn(" -l ", ssh_cmd) self.assertIn(" -i ", ssh_cmd)