My test setup requires to start different applications on remote machine to orchestrate each test. Remote applications like Java/Selenium etc. Good thing is these applications won't terminate unless killed. I'm using python and tried with Paramiko. Paramiko exec_command closes the channel after execution of command, which kills initiated process within a second. Reading stdout against started process stalls script progress (so far no multi-thread). What can be a work around to keep initiated process' alive and script to progress.
Paramiko device login
key = paramiko.SSHClient()
key.set_missing_host_key_policy(paramiko.AutoAddPolicy())
if testbed[name]['password_type'] == "key" :
key.connect(testbed[name]['ipaddress'], username=testbed[name]['username'], key_filename=testbed[name]['password_key'])
else:
key.connect(testbed[name]['ipaddress'], username=testbed[name]['username'],password=testbed[name]['password'])
logging.info ( "Connected to %s" % testbed[name]['ipaddress'])
except paramiko.AuthenticationException:
logging.info ( "Authentication failed when connecting to %s" % testbed[name]['ipaddress'])
sys.exit(1)
To launch process on remote machine (windows) -
command = 'javaw -jar %s' %(filename)
logging.info(command)
handle.exec_command(command)
time.sleep(1)
cmd = "wmic process where Caption='java.exe' get Processid"
stdin, stdout, stderr = handle.exec_command(cmd)
output = stdout.read().strip().split()
logging.info(output)
pid = output[1]
logging.info("java started with PID = %s" %(pid))
We get PID at this point, but after few seconds -
cmd = "wmic process where Caption='java.exe' get Processid"
stdin, stdout, stderr = handle.exec_command(cmd)
logging.info(stdout.read() + stderr.read())
returns - "No Instance(s) Available."
This error when the program is run from OSX using pycharm. Same machine using Iterm and python command following steps are executed, i don't see the channel closed (whoami on both cases returns same user profile) -
>>> dev.connect("a.b.c.d",username="pqr",password="xyz")
>>> dev.exec_command("javaw -jar selenium-server-standalone-3.1.0.jar")
(<paramiko.ChannelFile from <paramiko.Channel 0 (open) window=262144 -> <paramiko.Transport at 0xfa06b10L (cipher aes128-ctr, 128 bits) (active; 1 open channel(s))>>>, <paramiko.ChannelFile from <paramiko.Channel 0 (open) window=262144 -> <paramiko.Transport at 0xfa06b10L (cipher aes128-ctr, 128 bits) (active; 1 open channel(s))>>>, <paramiko.ChannelFile from <paramiko.Channel 0 (open) window=262144 -> <paramiko.Transport at 0xfa06b10L (cipher aes128-ctr, 128 bits) (active; 1 open channel(s))>>>)
>>> br = webdriver.Remote(command_executor=url,desired_capabilities=options.to_capabilities())
>>> dev.exec_command("START /B C:\PROGRA~1\abc.exe")
(<paramiko.ChannelFile from <paramiko.Channel 1 (open) window=262144 -> <paramiko.Transport at 0xfa06b10L (cipher aes128-ctr, 128 bits) (active; 1 open channel(s))>>>, <paramiko.ChannelFile from <paramiko.Channel 1 (open) window=262144 -> <paramiko.Transport at 0xfa06b10L (cipher aes128-ctr, 128 bits) (active; 1 open channel(s))>>>, <paramiko.ChannelFile from <paramiko.Channel 1 (open) window=262144 -> <paramiko.Transport at 0xfa06b10L (cipher aes128-ctr, 128 bits) (active; 1 open channel(s))>>>)