Skip to content

Commit 217bd07

Browse files
author
Dan
committed
Cleanup - simplified server exec request and command handling
1 parent 257eda3 commit 217bd07

File tree

2 files changed

+4
-18
lines changed

2 files changed

+4
-18
lines changed

fake_server/fake_server.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -101,33 +101,18 @@ def check_channel_forward_agent_request(self, channel):
101101

102102
def check_channel_exec_request(self, channel, cmd):
103103
logger.debug("Got exec request on channel %s for cmd %s" % (channel, cmd,))
104-
# Remove any 'bash -c' and/or quotes from command
105-
# cmd = cmd.replace('bash -c ', "")
106-
# cmd = cmd.replace('\"', "")
107-
# cmd = cmd.replace('\'', "")
108-
# if not cmd in self.cmd_req_response:
109-
# return False
110104
self.event.set()
111105
process = gevent.subprocess.Popen(cmd, stdout=gevent.subprocess.PIPE, shell=True)
112-
# Check if response is an iterator in which case we
113-
# do not return but read from iterator and send responses.
114-
# This is to simulate a long running command that has not
115-
# finished executing yet.
116106
gevent.spawn(self._read_response, channel, process)
117-
# gevent.sleep(1)
118-
# else:
119-
# channel.send(self.cmd_req_response[cmd] + os.linesep)
120-
# channel.send_exit_status(0)
121107
return True
122108

123109
def _read_response(self, channel, process):
124-
# import ipdb; ipdb.set_trace()
125110
for line in process.stdout:
126111
channel.send(line)
127-
gevent.sleep(0)
128112
process.communicate()
129113
channel.send_exit_status(process.returncode)
130-
channel.close()
114+
logger.debug("Command finished with return code %s", process.returncode)
115+
gevent.sleep(0)
131116

132117
def make_socket(listen_ip, port=0):
133118
"""Make socket on given address and available port chosen by OS"""

fake_server/tunnel.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ def tunnel(self, dest_socket, source_chan):
4646
logger.debug("Tunnel waiting for data..")
4747
data = source_chan.recv(1024)
4848
dest_socket.sendall(data)
49+
gevent.sleep(.1)
4950
response_data = dest_socket.recv(1024)
5051
source_chan.sendall(response_data)
5152
logger.debug("Tunnel sent data..")
52-
gevent.sleep(1)
53+
gevent.sleep(0)
5354
finally:
5455
source_chan.close()
5556
dest_socket.close()

0 commit comments

Comments
 (0)