Subject: Bug#1445: pyhoca-cli fails to connect to suspended x2go session

From: Randy Goldenberg <[email-masked]>
Date: Fri, 6 Mar 2020 13:54:31 -0800

Package: pyhoca-cli
Version: 0.6.1.2
Tag: patch

pyhoca-cli fails to connect to suspended x2g0 sessions.

$ pyhoca-cli --server my.x2go.server -t desktop -c openbox-session -g maximize 
-R NEWEST

pyhoca-cli[13131] NOTICE: preparing requested X2Go session
pyhoca-cli[13131] (PyHocaCLI) NOTICE: preparing requested X2Go session
pyhoca-cli[13131] (x2gosessregistry-pylib) NOTICE: registering X2Go session 
Pyhoca-Client_Session...
pyhoca-cli[13131] (x2goclient-pylib) NOTICE: initializing X2Go session...
pyhoca-cli[13131] (x2gocontrolsession-pylib) NOTICE: connecting to 
[my.x2go.server]:22
/usr/lib/python3/dist-packages/Crypto/Cipher/blockalgo.py:141: FutureWarning: 
CTR mode needs counter parameter, not IV
 self._cipher = factory.new(key, *args, **kwargs)
pyhoca-cli[13131] (PyHocaCLI) NOTICE: authentication has been successful
pyhoca-cli[13131] (PyHocaCLI) NOTICE: give the X2Go session some time to come 
up...
Traceback (most recent call last):
 File "/usr/bin/pyhoca-cli", line 455, in <module>
   thisPyHocaCLI.MainLoop()
 File "/usr/lib/python3/dist-packages/pyhoca/cli/frontend.py", line 702, in 
MainLoop
   self.resume_session(self.x2go_session_hash)
 File "/usr/lib/python3/dist-packages/pyhoca/cli/frontend.py", line 229, in 
resume_session
   if available_sessions is None:
UnboundLocalError: local variable 'available_sessions' referenced before 
assignment

client OS: Ubuntu 16.04.6 LTS

server OS: Ubuntu 16.04.6 LTS

server's version of the x2goserver package:
x2goserver: 4.1.0.4
x2goserver-common: 4.1.0.4
x2goserver-desktopsharing: 4.1.0.3
x2goserver-extensions: 4.1.0.4
x2goserver-fmbindings: 4.1.0.4
x2goserver-printing: 4.1.0.4
x2goserver-xsession: 4.1.0.4

Patch attached.

----- End forwarded message -----
--- /usr/lib/python3/dist-packages/pyhoca/cli/frontend.py	2020-03-06 13:12:15.067076509 -0800
+++ /usr/lib/python3/dist-packages/pyhoca/cli/frontend.py.FIXED	2020-03-06 13:25:57.017743170 -0800
@@ -226,6 +226,7 @@
         """
         # resume a running session
         self.logger('resuming X2Go session: %s' % self.args.resume, loglevel=x2go.loglevel_INFO, )
+        available_sessions = self._X2GoClient__list_sessions(s_hash, with_command=self.args.command)
         if available_sessions is None:
             available_sessions = self._X2GoClient__list_sessions(s_hash)
         if available_sessions and self.args.resume == 'OLDEST':