def _run_main(self, parsed_args, parsed_globals): master_dns = sshutils.validate_and_find_master_dns( session=self._session, parsed_globals=parsed_globals, cluster_id=parsed_args.cluster_id) key_file = parsed_args.key_pair_file sshutils.validate_ssh_with_key_file(key_file) f = tempfile.NamedTemporaryFile(delete=False) if (sshutils.check_command_key_format(key_file, ['cer', 'pem']) and (emrutils.which('ssh') or emrutils.which('ssh.exe'))): command = ['ssh', '-o', 'StrictHostKeyChecking=no', '-o', 'ServerAliveInterval=10', '-i', parsed_args.key_pair_file, constants.SSH_USER + '@' + master_dns] if parsed_args.command: command.append(parsed_args.command) else: command = ['putty', '-ssh', '-i', parsed_args.key_pair_file, constants.SSH_USER + '@' + master_dns, '-t'] if parsed_args.command: f.write(parsed_args.command) f.write('\nread -n1 -r -p "Command completed. Press any key."') command.append('-m') command.append(f.name) f.close() print(' '.join(command)) rc = subprocess.call(command) os.remove(f.name) return rc
def test_validate_and_find_master_dns_waits(self, emrutils): emrutils.get_cluster_state.return_value = 'STARTING' session = mock.Mock() client = mock.Mock() emrutils.get_client.return_value = client sshutils.validate_and_find_master_dns(session, None, 'cluster-id') # We should have: # 1. Waiter for the cluster to be running. client.get_waiter.assert_called_with('cluster_running') client.get_waiter.return_value.wait.assert_called_with( ClusterId='cluster-id') # 2. Found the master public DNS self.assertTrue(emrutils.find_master_dns.called)
def _run_main(self, parsed_args, parsed_globals): master_dns = sshutils.validate_and_find_master_dns( session=self._session, parsed_globals=parsed_globals, cluster_id=parsed_args.cluster_id) key_file = parsed_args.key_pair_file sshutils.validate_scp_with_key_file(key_file) if (sshutils.check_command_key_format(key_file, ['cer', 'pem']) and (emrutils.which('scp') or emrutils.which('scp.exe'))): command = ['scp', '-r', '-o StrictHostKeyChecking=no', '-i', parsed_args.key_pair_file, constants.SSH_USER + '@' + master_dns + ':' + parsed_args.src] else: command = ['pscp', '-scp', '-r', '-i', parsed_args.key_pair_file, constants.SSH_USER + '@' + master_dns + ':' + parsed_args.src] if parsed_args.dest: command.append(parsed_args.dest) else: command.append(parsed_args.src.split('/')[-1]) print(' '.join(command)) rc = subprocess.call(command) return rc
def _run_main(self, parsed_args, parsed_globals): try: master_dns = sshutils.validate_and_find_master_dns( session=self._session, parsed_globals=parsed_globals, cluster_id=parsed_args.cluster_id) key_file = parsed_args.key_pair_file sshutils.validate_ssh_with_key_file(key_file) f = tempfile.NamedTemporaryFile(delete=False) if (sshutils.check_command_key_format(key_file, ['cer', 'pem']) and (emrutils.which('ssh') or emrutils.which('ssh.exe'))): command = ['ssh', '-o', 'StrictHostKeyChecking=no', '-o', 'ServerAliveInterval=10', '-ND', '8157', '-i', parsed_args.key_pair_file, constants.SSH_USER + '@' + master_dns] else: command = ['putty', '-ssh', '-i', parsed_args.key_pair_file, constants.SSH_USER + '@' + master_dns, '-N', '-D', '8157'] print(' '.join(command)) rc = subprocess.call(command) return rc except KeyboardInterrupt: print('Disabling Socks Tunnel.') return 0
def _run_main_command(self, parsed_args, parsed_globals): try: master_dns = sshutils.validate_and_find_master_dns( session=self._session, parsed_globals=parsed_globals, cluster_id=parsed_args.cluster_id) key_file = parsed_args.key_pair_file sshutils.validate_ssh_with_key_file(key_file) f = tempfile.NamedTemporaryFile(delete=False) if (emrutils.which('ssh') or emrutils.which('ssh.exe')): command = [ 'ssh', '-o', 'StrictHostKeyChecking=no', '-o', 'ServerAliveInterval=10', '-ND', '8157', '-i', parsed_args.key_pair_file, constants.SSH_USER + '@' + master_dns ] else: command = [ 'putty', '-ssh', '-i', parsed_args.key_pair_file, constants.SSH_USER + '@' + master_dns, '-N', '-D', '8157' ] print(' '.join(command)) rc = subprocess.call(command) return rc except KeyboardInterrupt: print('Disabling Socks Tunnel.') return 0
def _run_main_command(self, parsed_args, parsed_globals): master_dns = sshutils.validate_and_find_master_dns( session=self._session, parsed_globals=parsed_globals, cluster_id=parsed_args.cluster_id) key_file = parsed_args.key_pair_file sshutils.validate_ssh_with_key_file(key_file) f = tempfile.NamedTemporaryFile(delete=False) if (emrutils.which('ssh') or emrutils.which('ssh.exe')): command = [ 'ssh', '-o', 'StrictHostKeyChecking=no', '-o', 'ServerAliveInterval=10', '-i', parsed_args.key_pair_file, constants.SSH_USER + '@' + master_dns, '-t' ] if parsed_args.command: command.append(parsed_args.command) else: command = [ 'putty', '-ssh', '-i', parsed_args.key_pair_file, constants.SSH_USER + '@' + master_dns, '-t' ] if parsed_args.command: f.write(parsed_args.command) f.write('\nread -n1 -r -p "Command completed. Press any key."') command.append('-m') command.append(f.name) f.close() print(' '.join(command)) rc = subprocess.call(command) os.remove(f.name) return rc
def _run_main_command(self, parsed_args, parsed_globals): master_dns = sshutils.validate_and_find_master_dns( session=self._session, parsed_globals=parsed_globals, cluster_id=parsed_args.cluster_id) key_file = parsed_args.key_pair_file sshutils.validate_scp_with_key_file(key_file) if (emrutils.which('scp') or emrutils.which('scp.exe')): command = [ 'scp', '-r', '-o StrictHostKeyChecking=no', '-i', parsed_args.key_pair_file, constants.SSH_USER + '@' + master_dns + ':' + parsed_args.src ] else: command = [ 'pscp', '-scp', '-r', '-i', parsed_args.key_pair_file, constants.SSH_USER + '@' + master_dns + ':' + parsed_args.src ] if parsed_args.dest: command.append(parsed_args.dest) else: command.append(parsed_args.src.split('/')[-1]) print(' '.join(command)) rc = subprocess.call(command) return rc
def _run_main_command(self, parsed_args, parsed_globals): master_dns = sshutils.validate_and_find_master_dns( session=self._session, parsed_globals=parsed_globals, cluster_id=parsed_args.cluster_id) key_file = parsed_args.key_pair_file sshutils.validate_scp_with_key_file(key_file) if (sshutils.check_command_key_format(key_file, ['cer', 'pem']) and (emrutils.which('scp') or emrutils.which('scp.exe'))): command = [ 'scp', '-r', '-o StrictHostKeyChecking=no', '-i', parsed_args.key_pair_file, parsed_args.src, constants.SSH_USER + '@' + master_dns ] else: command = [ 'pscp', '-scp', '-r', '-i', parsed_args.key_pair_file, parsed_args.src, constants.SSH_USER + '@' + master_dns ] # if the instance is not terminated if parsed_args.dest: command[-1] = command[-1] + ":" + parsed_args.dest else: command[-1] = command[-1] + ":" + parsed_args.src.split('/')[-1] print(' '.join(command)) rc = subprocess.call(command) return rc
def test_validate_and_find_master_dns_waits(self, emrutils): emrutils.get_cluster_state.return_value = 'STARTING' session = mock.Mock() fake_endpoint = mock.sentinel.fake_endpoint emrutils.get_endpoint.return_value = fake_endpoint sshutils.validate_and_find_master_dns(session, None, 'cluster-id') # We should have: # 1. Waiter for the cluster to be running. session.get_service.return_value.get_waiter.assert_called_with( 'ClusterRunning', fake_endpoint) service = session.get_service.return_value service.get_waiter.return_value.wait.assert_called_with( ClusterId='cluster-id') # 2. Found the master public DNS self.assertTrue(emrutils.find_master_public_dns.called)
def _run_main_command(self, parsed_args, parsed_globals): master_dns = sshutils.validate_and_find_master_dns( session=self._session, parsed_globals=parsed_globals, cluster_id=parsed_args.cluster_id) key_file = parsed_args.key_pair_file sshutils.validate_scp_with_key_file(key_file) if (emrutils.which('scp') or emrutils.which('scp.exe')): command = ['scp', '-r', '-o StrictHostKeyChecking=no', '-i', parsed_args.key_pair_file, parsed_args.src, constants.SSH_USER + '@' + master_dns] else: command = ['pscp', '-scp', '-r', '-i', parsed_args.key_pair_file, parsed_args.src, constants.SSH_USER + '@' + master_dns] # if the instance is not terminated if parsed_args.dest: command[-1] = command[-1] + ":" + parsed_args.dest else: command[-1] = command[-1] + ":" + parsed_args.src.split('/')[-1] print(' '.join(command)) rc = subprocess.call(command) return rc
def test_cluster_in_terminated_states(self, emrutils): emrutils.get_cluster_state.return_value = 'TERMINATED' with self.assertRaises(exceptions.ClusterTerminatedError): sshutils.validate_and_find_master_dns( mock.Mock(), None, 'cluster-id')
def test_cluster_in_terminated_states(self, emrutils): emrutils.get_cluster_state.return_value = 'TERMINATED' with self.assertRaises(exceptions.ClusterTerminatedError): sshutils.validate_and_find_master_dns(mock.Mock(), None, 'cluster-id')