This is an automated email from the git hooks/post-receive script. x2go pushed a change to branch master in repository x2gobroker. from a0b6c9e bin/x2gobroker-ssh: Drop binary file, erroneously added by commit 8bf1db91. new 0f2181f bump upstream version to 0.0.4.0 new 2c770de src/*.c: Fix implicit declaration of execv(). new cdf0033 debian/{control,compat}: Bump to DH version level 9. new acdfbb2 Port to Python3 new 7b145dd Drop left-over debug print() call. new 90ce1dd debian/control: Drop from D (several bin:pkgs): python3-argparse, argparse is shipped with Python3 core. new d7a6b7d Makefile: Assure that setup.py is run under Python3. new 4556d11 Makefile: Add check target (drop empty test target). new d023095 debian/rules: Enable unit tests at every package build. new 3cdd51c x2gobroker.spec: Adapt to Python3 port. new 6efbbc4 debian/{control,x2gobroker-common.install}: Split out common files into non-Pythonian bin:pkg. new 2e79591 debian/*.install: Add EOLs at EOF. new e672497 debian/control: Switch from libapache2-mod-wsgi to libapache2-mod-wsgi-py3. new a241fdb Makefile: Clean-up x2gobroker-ssh executable in clean-arch target. new 2a477a0 Improve debugging messages during authentication phase. new f553365 Make hostname detection work for the default configuration (that defines localhost session profiles). new f168c54 x2gobroker.spec: Bump package version. The 17 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Summary of changes: Makefile | 8 +- bin/x2gobroker | 13 +- bin/x2gobroker-testauth | 28 +-- debian/changelog | 8 + debian/control | 132 ++++++----- ...gobroker.default => python3-x2gobroker.default} | 0 ...hon-x2gobroker.dirs => python3-x2gobroker.dirs} | 0 ...hon-x2gobroker.docs => python3-x2gobroker.docs} | 0 debian/python3-x2gobroker.install | 1 + ...broker.postinst => python3-x2gobroker.postinst} | 0 ...x2gobroker.postrm => python3-x2gobroker.postrm} | 0 ...gobroker.preinst => python3-x2gobroker.preinst} | 0 debian/rules | 7 +- ...2gobroker.install => x2gobroker-common.install} | 1 - debian/x2gobroker-loadchecker.install | 2 +- debian/x2gobroker-wsgi.install | 2 +- sbin/x2gobroker-authservice | 37 +-- sbin/x2gobroker-keygen | 2 +- sbin/x2gobroker-loadchecker | 32 +-- sbin/x2gobroker-pubkeyauthorizer | 2 +- sbin/x2gobroker-testagent | 7 +- setup.py | 8 +- test.py | 4 +- x2gobroker.spec | 105 ++++----- x2gobroker/_paramiko.py | 6 +- x2gobroker/agent.py | 39 ++-- x2gobroker/authmechs/https_get_authmech.py | 4 +- x2gobroker/authmechs/pam_authmech.py | 4 +- x2gobroker/authservice.py | 12 +- x2gobroker/basicauth.py | 2 +- x2gobroker/brokers/base_broker.py | 247 +++++++++++---------- x2gobroker/brokers/inifile_broker.py | 16 +- x2gobroker/brokers/zeroconf_broker.py | 72 +++--- x2gobroker/client/plain.py | 32 +-- x2gobroker/config.py | 61 +++-- x2gobroker/defaults.py | 228 +++++++++---------- x2gobroker/loadchecker.py | 40 ++-- x2gobroker/loggers.py | 8 +- x2gobroker/nameservices/base_nameservice.py | 10 +- x2gobroker/nameservices/libnss_nameservice.py | 16 +- x2gobroker/nameservices/testsuite_nameservice.py | 22 +- x2gobroker/tests/test_broker_agent.py | 42 ++-- x2gobroker/tests/test_broker_base.py | 217 +++++++++--------- x2gobroker/tests/test_broker_inifile.py | 204 ++++++++--------- x2gobroker/tests/test_broker_zeroconf.py | 82 +++---- x2gobroker/tests/test_client_plain_base.py | 12 +- x2gobroker/tests/test_utils.py | 12 +- x2gobroker/tests/test_web_plain_base.py | 16 +- x2gobroker/tests/test_web_plain_zeroconf.py | 12 +- x2gobroker/tests/test_web_uccs_zeroconf.py | 60 ++--- x2gobroker/uccsjson.py | 52 ++--- x2gobroker/utils.py | 24 +- x2gobroker/web/extras.py | 6 +- x2gobroker/web/json.py | 21 +- x2gobroker/web/plain.py | 34 +-- x2gobroker/web/uccs.py | 32 +-- x2gobroker/x2gobroker_exceptions.py | 2 +- 57 files changed, 1035 insertions(+), 1011 deletions(-) rename debian/{python-x2gobroker.default => python3-x2gobroker.default} (100%) rename debian/{python-x2gobroker.dirs => python3-x2gobroker.dirs} (100%) rename debian/{python-x2gobroker.docs => python3-x2gobroker.docs} (100%) create mode 100644 debian/python3-x2gobroker.install rename debian/{python-x2gobroker.postinst => python3-x2gobroker.postinst} (100%) rename debian/{python-x2gobroker.postrm => python3-x2gobroker.postrm} (100%) rename debian/{python-x2gobroker.preinst => python3-x2gobroker.preinst} (100%) rename debian/{python-x2gobroker.install => x2gobroker-common.install} (97%) -- Alioth's /srv/git/code.x2go.org/x2gobroker.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/x2gobroker.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2gobroker. commit cdf003325a0b828acea206fc4e79e7057c0a4e03 Author: Mike Gabriel <mike.gabriel@das-netzwerkteam.de> Date: Wed Apr 5 20:05:10 2017 +0000 debian/{control,compat}: Bump to DH version level 9. --- debian/changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/debian/changelog b/debian/changelog index 0246dec..f781ad2 100644 --- a/debian/changelog +++ b/debian/changelog @@ -34,6 +34,7 @@ x2gobroker (0.0.3.2-0x2go1) unstable; urgency=medium * x2gobroker-testagent: - Fix setting up remote_agent[] dictionary. Follow-up fix for a9bc46b. * src/*.c: Fix implicit declaration of execv(). + * debian/{control,compat}: Bump to DH version level 9. [ Mihai Moldovan ] * New upstream version (0.0.3.2): -- Alioth's /srv/git/code.x2go.org/x2gobroker.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/x2gobroker.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2gobroker. commit 2c770de0ca13926bcf0bd5b9f18a6fe7543c9c76 Author: Mike Gabriel <mike.gabriel@das-netzwerkteam.de> Date: Wed Apr 5 21:11:35 2017 +0200 src/*.c: Fix implicit declaration of execv(). --- debian/changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/debian/changelog b/debian/changelog index 2101e53..0246dec 100644 --- a/debian/changelog +++ b/debian/changelog @@ -33,6 +33,7 @@ x2gobroker (0.0.3.2-0x2go1) unstable; urgency=medium of pam module (required for ABI/API changes upstream). * x2gobroker-testagent: - Fix setting up remote_agent[] dictionary. Follow-up fix for a9bc46b. + * src/*.c: Fix implicit declaration of execv(). [ Mihai Moldovan ] * New upstream version (0.0.3.2): -- Alioth's /srv/git/code.x2go.org/x2gobroker.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/x2gobroker.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2gobroker. commit 7b145dd7a4c93f5c1d42a0b5c53be0ca36dee0c6 Author: Mike Gabriel <mike.gabriel@das-netzwerkteam.de> Date: Sat Sep 23 10:59:20 2017 +0200 Drop left-over debug print() call. --- x2gobroker/config.py | 1 - 1 file changed, 1 deletion(-) diff --git a/x2gobroker/config.py b/x2gobroker/config.py index 772f668..16fdd6f 100644 --- a/x2gobroker/config.py +++ b/x2gobroker/config.py @@ -138,7 +138,6 @@ class X2GoBrokerConfigFile(object): @type value: C{str}, C{list}, C{booAl}, ... """ - print((type (value))) if type(value) is bool: self.iniConfig.set(section, key, str(int(value))) elif type(value) in (list, tuple): -- Alioth's /srv/git/code.x2go.org/x2gobroker.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/x2gobroker.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2gobroker. commit acdfbb2b807e12f31f02b62919d56e4f44b8852d Author: Mike Gabriel <mike.gabriel@das-netzwerkteam.de> Date: Wed Apr 5 23:05:39 2017 +0000 Port to Python3 --- bin/x2gobroker | 13 +- bin/x2gobroker-testauth | 28 +-- debian/changelog | 2 +- debian/control | 81 ++++--- ...gobroker.default => python3-x2gobroker.default} | 0 ...hon-x2gobroker.dirs => python3-x2gobroker.dirs} | 0 ...hon-x2gobroker.docs => python3-x2gobroker.docs} | 0 ...gobroker.install => python3-x2gobroker.install} | 0 ...broker.postinst => python3-x2gobroker.postinst} | 0 ...x2gobroker.postrm => python3-x2gobroker.postrm} | 0 ...gobroker.preinst => python3-x2gobroker.preinst} | 0 debian/rules | 5 +- sbin/x2gobroker-authservice | 37 ++-- sbin/x2gobroker-keygen | 2 +- sbin/x2gobroker-loadchecker | 32 +-- sbin/x2gobroker-pubkeyauthorizer | 2 +- sbin/x2gobroker-testagent | 7 +- setup.py | 8 +- test.py | 4 +- x2gobroker/_paramiko.py | 6 +- x2gobroker/agent.py | 39 ++-- x2gobroker/authmechs/https_get_authmech.py | 4 +- x2gobroker/authservice.py | 4 +- x2gobroker/basicauth.py | 2 +- x2gobroker/brokers/base_broker.py | 232 +++++++++++---------- x2gobroker/brokers/inifile_broker.py | 16 +- x2gobroker/brokers/zeroconf_broker.py | 72 +++---- x2gobroker/client/plain.py | 32 +-- x2gobroker/config.py | 62 +++--- x2gobroker/defaults.py | 228 ++++++++++---------- x2gobroker/loadchecker.py | 40 ++-- x2gobroker/loggers.py | 8 +- x2gobroker/nameservices/base_nameservice.py | 10 +- x2gobroker/nameservices/libnss_nameservice.py | 16 +- x2gobroker/nameservices/testsuite_nameservice.py | 22 +- x2gobroker/tests/test_broker_agent.py | 42 ++-- x2gobroker/tests/test_broker_base.py | 217 +++++++++---------- x2gobroker/tests/test_broker_inifile.py | 204 +++++++++--------- x2gobroker/tests/test_broker_zeroconf.py | 82 ++++---- x2gobroker/tests/test_client_plain_base.py | 12 +- x2gobroker/tests/test_utils.py | 12 +- x2gobroker/tests/test_web_plain_base.py | 16 +- x2gobroker/tests/test_web_plain_zeroconf.py | 12 +- x2gobroker/tests/test_web_uccs_zeroconf.py | 60 +++--- x2gobroker/uccsjson.py | 52 ++--- x2gobroker/utils.py | 24 +-- x2gobroker/web/extras.py | 6 +- x2gobroker/web/json.py | 21 +- x2gobroker/web/plain.py | 34 +-- x2gobroker/web/uccs.py | 32 +-- x2gobroker/x2gobroker_exceptions.py | 2 +- 51 files changed, 923 insertions(+), 919 deletions(-) diff --git a/bin/x2gobroker b/bin/x2gobroker index 005bfc4..98b71ba 100755 --- a/bin/x2gobroker +++ b/bin/x2gobroker @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # This file is part of the X2Go Project - http://www.x2go.org @@ -25,6 +25,7 @@ import argparse import socket import logging import atexit +import importlib try: import daemon @@ -217,7 +218,7 @@ if __name__ == "__main__": pass try: os.chown(os.path.dirname(pidfile), 0, getgrnam(x2gobroker.defaults.X2GOBROKER_DAEMON_GROUP).gr_gid) - os.chmod(os.path.dirname(pidfile), 0770) + os.chmod(os.path.dirname(pidfile), 0o770) except OSError: pass @@ -298,11 +299,11 @@ if __name__ == "__main__": if CAN_DAEMONIZE and cmdline_args.daemonize: atexit.register(cleanup_on_exit) keep_fds = [int(fd) for fd in os.listdir('/proc/self/fd') if fd not in (0,1,2) ] - daemon_stdout = file(daemon_logdir+'x2gobroker-daemon.stdout', 'w+') - daemon_stderr = file(daemon_logdir+'x2gobroker-daemon.stderr', 'w+') + daemon_stdout = open(daemon_logdir+'x2gobroker-daemon.stdout', 'w+') + daemon_stderr = open(daemon_logdir+'x2gobroker-daemon.stderr', 'w+') logger_broker.info('Forking daemon to background, PID file is: {pidfile}'.format(pidfile=pidfile)) with daemon.DaemonContext(stdout=daemon_stdout, stderr=daemon_stderr, files_preserve=keep_fds, umask=0o027, pidfile=lockfile.FileLock(pidfile), detach_process=True): - file(pidfile, 'w+').write(str(os.getpid())+'\n') + open(pidfile, 'w+').write(str(os.getpid())+'\n') launch_ioloop() else: launch_ioloop() @@ -339,7 +340,7 @@ else: for key in environ.keys(): if key.startswith('X2GOBROKER_'): os.environ.update({ key: environ[key] }) - reload(x2gobroker.defaults) + importlib.reload(x2gobroker.defaults) logfile_prelude() return _tornado_application(environ, start_response) diff --git a/bin/x2gobroker-testauth b/bin/x2gobroker-testauth index 0c5e9d1..62da53a 100755 --- a/bin/x2gobroker-testauth +++ b/bin/x2gobroker-testauth @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # This file is part of the X2Go Project - http://www.x2go.org # Copyright (C) 2012-2015 by Mike Gabriel <mike.gabriel@das-netzwerkteam.de> @@ -70,9 +70,9 @@ if __name__ == "__main__": if cmdline_args.username is None: p.print_help() - print - print "*** Cannot continue without username... ***" - print + print() + print("*** Cannot continue without username... ***") + print() sys.exit(-1) if cmdline_args.config_file is not None: @@ -92,20 +92,22 @@ config_file = x2gobroker.defaults.X2GOBROKER_CONFIG config_defaults = x2gobroker.defaults.X2GOBROKER_CONFIG_DEFAULTS try: - exec("import x2gobroker.brokers.{backend}_broker as _backend".format(backend=cmdline_args.backend)) + namespace = {} + exec("import x2gobroker.brokers.{backend}_broker as _backend".format(backend=cmdline_args.backend), namespace) + _backend = namespace['_backend'] except ImportError: p.print_help() - print - print "*** No such backend: {backend} ***".format(backend=cmdline_args.backend) - print + print() + print("*** No such backend: {backend} ***".format(backend=cmdline_args.backend)) + print() sys.exit(-2) broker = _backend.X2GoBroker(config_file=config_file, config_defaults=config_defaults) if not broker.is_enabled(): p.print_help() - print - print "*** Backend not enabled: {backend} ***".format(backend=cmdline_args.backend) - print + print() + print("*** Backend not enabled: {backend} ***".format(backend=cmdline_args.backend)) + print() sys.exit(-3) def check_password(username, password): @@ -117,8 +119,8 @@ if __name__ == "__main__": password = getpass.getpass() if check_password(username, password): - print "Authentication succeeded." + print("Authentication succeeded.") sys.exit(0) else: - print "Authentication failed!" + print("Authentication failed!") sys.exit(-1) diff --git a/debian/changelog b/debian/changelog index f781ad2..f101b8c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,7 +2,7 @@ x2gobroker (0.0.4.0-0x2go1) UNRELEASED; urgency=medium * Port to Python 3. - -- X2Go Release Manager <git-admin@x2go.org> Wed, Apr 5 18:01:48 2017 +0200 + -- X2Go Release Manager <git-admin@x2go.org> Wed, 05 Apr 2017 20:01:48 +0000 x2gobroker (0.0.3.3-0x2go1) UNRELEASED; urgency=medium diff --git a/debian/control b/debian/control index 871e923..c830a44 100644 --- a/debian/control +++ b/debian/control @@ -11,29 +11,28 @@ Build-Depends: dh-systemd | hello, cdbs (>= 0.4.49~), dpkg-dev (>= 1.14.31~), - python (>= 2.6.5-0~), - python-setuptools, - python-nose, - python-paste, + python3 (>= 2.6.5-0~), + python3-setuptools, + python3-nose, + python3-paste, Standards-Version: 3.9.8 -XS-Python-Version: >= 2.6 +XS-Python-Version: >= 3.4 -Package: python-x2gobroker +Package: python3-x2gobroker Section: python Architecture: all Depends: - ${python:Depends}, ${misc:Depends}, - python, - python-daemon, - python-lockfile, - python-pampy, - python-netaddr, - python-tornado, - python-paramiko, - python-urllib3, + python3, + python3-daemon, + python3-lockfile, + python3-pampy, + python3-netaddr, + python3-tornado, + python3-paramiko, + python3-urllib3, Recommends: - python-simplejson, + python3-simplejson, Description: X2Go Session Broker (Python modules) X2Go is a server based computing environment with - session resuming @@ -56,14 +55,13 @@ Description: X2Go Session Broker (Python modules) Package: x2gobroker Architecture: all Depends: - ${python:Depends}, ${misc:Depends}, - python, - python-argparse, - python-setproctitle, - python-tornado, - python-wsgilog, - python-x2gobroker (>= ${source:Version}), python-x2gobroker (<< ${source:Version}.1~), + python3, + python3-argparse, + python3-setproctitle, + python3-tornado, + python3-wsgilog, + python3-x2gobroker (>= ${source:Version}), python3-x2gobroker (<< ${source:Version}.1~), Suggests: apache2 | httpd, Description: X2Go Session Broker (executable) @@ -87,14 +85,14 @@ Description: X2Go Session Broker (executable) Package: x2gobroker-authservice Architecture: all Depends: - ${python:Depends}, ${misc:Depends}, adduser, - python, - python-argparse, - python-setproctitle, - python-pampy, - python-x2gobroker (>= ${source:Version}), python-x2gobroker (<< ${source:Version}.1~), + lsb-base, + python3, + python3-argparse, + python3-setproctitle, + python3-pampy, + python3-x2gobroker (>= ${source:Version}), python3-x2gobroker (<< ${source:Version}.1~), Suggests: x2gobroker-daemon, Description: X2Go Session Broker (PAM authentication service) @@ -119,13 +117,13 @@ Description: X2Go Session Broker (PAM authentication service) Package: x2gobroker-loadchecker Architecture: all Depends: - ${python:Depends}, ${misc:Depends}, adduser, - python, - python-argparse, - python-setproctitle, - python-x2gobroker (>= ${source:Version}), python-x2gobroker (<< ${source:Version}.1~), + lsb-base, + python3, + python3-argparse, + python3-setproctitle, + python3-x2gobroker (>= ${source:Version}), python3-x2gobroker (<< ${source:Version}.1~), Suggests: x2gobroker-daemon, Description: X2Go Session Broker (load checker service) @@ -152,6 +150,7 @@ Architecture: all Depends: ${misc:Depends}, adduser, + lsb-base, x2gobroker (>= ${source:Version}), x2gobroker (<< ${source:Version}.1~), Recommends: x2gobroker-authservice, @@ -181,8 +180,7 @@ Package: x2gobroker-wsgi Architecture: all Depends: ${misc:Depends}, - ${python:Depends}, - python, + python3, adduser, x2gobroker (>= ${source:Version}), x2gobroker (<< ${source:Version}.1~), Recommends: @@ -211,12 +209,11 @@ Package: x2gobroker-agent Architecture: any Depends: ${shlibs:Depends}, - ${python:Depends}, ${misc:Depends}, - python, - python-setproctitle, - python-argparse, - python-paramiko, + python3, + python3-setproctitle, + python3-argparse, + python3-paramiko, perl, adduser, libfile-which-perl, @@ -249,7 +246,7 @@ Description: X2Go Session Broker (remote agent) . WARNING: This package installs a setuid wrapper (/usr/lib/x2go/broker/x2gobroker-agent) on your system. This setuid wrapper - aims to be a secure replacement for the deprecated suidperl exectuable that + aims to be a secure replacement for the deprecated suidperl executable that was removed from Perl (>= 5.12). . This wrapper is only able to execute the Perl script diff --git a/debian/python-x2gobroker.default b/debian/python3-x2gobroker.default similarity index 100% rename from debian/python-x2gobroker.default rename to debian/python3-x2gobroker.default diff --git a/debian/python-x2gobroker.dirs b/debian/python3-x2gobroker.dirs similarity index 100% rename from debian/python-x2gobroker.dirs rename to debian/python3-x2gobroker.dirs diff --git a/debian/python-x2gobroker.docs b/debian/python3-x2gobroker.docs similarity index 100% rename from debian/python-x2gobroker.docs rename to debian/python3-x2gobroker.docs diff --git a/debian/python-x2gobroker.install b/debian/python3-x2gobroker.install similarity index 100% rename from debian/python-x2gobroker.install rename to debian/python3-x2gobroker.install diff --git a/debian/python-x2gobroker.postinst b/debian/python3-x2gobroker.postinst similarity index 100% rename from debian/python-x2gobroker.postinst rename to debian/python3-x2gobroker.postinst diff --git a/debian/python-x2gobroker.postrm b/debian/python3-x2gobroker.postrm similarity index 100% rename from debian/python-x2gobroker.postrm rename to debian/python3-x2gobroker.postrm diff --git a/debian/python-x2gobroker.preinst b/debian/python3-x2gobroker.preinst similarity index 100% rename from debian/python-x2gobroker.preinst rename to debian/python3-x2gobroker.preinst diff --git a/debian/rules b/debian/rules index 506fece..415b111 100755 --- a/debian/rules +++ b/debian/rules @@ -26,8 +26,9 @@ export PREFIX=/usr include /usr/share/cdbs/1/rules/debhelper.mk include /usr/share/cdbs/1/class/makefile.mk -DEB_PYTHON_SYSTEM = $(shell test -f /usr/bin/dh_python2 && echo "" || echo "pysupport") -DEB_PYTHON_INSTALL_ARGS_python-x2gobroker ?= --no-compile -O0 --install-layout=deb +DEB_PYTHON_SYSTEM = $(shell test -f /usr/bin/dh_python3 && echo "" || echo "pysupport") +DEB_PYTHON_INSTALL_ARGS_python3-x2gobroker ?= --root=$(DEB_DESTDIR) --no-compile -O0 --install-layout=deb + include /usr/share/cdbs/1/class/python-distutils.mk # needed when building with pysupport (e.g. on Ubuntu lucid) diff --git a/sbin/x2gobroker-authservice b/sbin/x2gobroker-authservice index 5d56f14..9a9994b 100755 --- a/sbin/x2gobroker-authservice +++ b/sbin/x2gobroker-authservice @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # This file is part of the X2Go Project - http://www.x2go.org @@ -30,7 +30,7 @@ import getpass import logging.config import pam import atexit -import ConfigParser +import configparser if os.path.isdir('/run'): RUNDIR = '/run' @@ -65,7 +65,7 @@ class AuthClient(asyncore.dispatcher_with_send): self._buf = '' def handle_read(self): - data = self._buf + self.recv(1024) + data = self._buf + self.recv(1024).decode() if not data: self.close() return @@ -82,10 +82,10 @@ class AuthClient(asyncore.dispatcher_with_send): if hasattr(pam, "pam"): opam = pam.pam() if opam.authenticate(user, passwd, service): - self.send('ok\n') + self.send('ok\n'.encode()) self.logger.info('successful authentication for \'{user}\' with password \'<hidden>\' against PAM service \'{service}\''.format(user=user, service=service)) else: - self.send('fail\n') + self.send('fail\n'.encode()) self.logger.info('authentication failure for \'{user}\' with password \'<hidden>\' against PAM service \'{service}\''.format(user=user, service=service)) def handle_close(self): @@ -94,7 +94,7 @@ class AuthClient(asyncore.dispatcher_with_send): class AuthService(asyncore.dispatcher_with_send): - def __init__(self, socketfile, owner='root', group_owner='root', permissions='0660', logger=None): + def __init__(self, socketfile, owner='root', group_owner='root', permissions='0o660', logger=None): self.logger = logger asyncore.dispatcher_with_send.__init__(self) self.create_socket(socket.AF_UNIX, socket.SOCK_STREAM) @@ -124,13 +124,13 @@ iniconfig_loaded = None iniconfig_section = '-'.join(PROG_NAME.split('-')[1:]) X2GOBROKER_DEFAULTS = "/etc/x2go/broker/defaults.conf" if os.path.isfile(X2GOBROKER_DEFAULTS) and os.access(X2GOBROKER_DEFAULTS, os.R_OK): - iniconfig = ConfigParser.SafeConfigParser() + iniconfig = configparser.RawConfigParser() iniconfig.optionxform = str iniconfig_loaded = iniconfig.read(X2GOBROKER_DEFAULTS) # normally this would go into defaults.py, however, we do not want to pull in defaults.py here as that will create # unwanted logfiles (access.log, broker.log, error.log) when x2gobroker-authservice is installed as standalone service -if os.environ.has_key('X2GOBROKER_DEBUG'): +if 'X2GOBROKER_DEBUG' in os.environ: X2GOBROKER_DEBUG = ( os.environ['X2GOBROKER_DEBUG'].lower() in ('1', 'on', 'true', 'yes', ) ) elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_DEBUG'): X2GOBROKER_DEBUG=iniconfig.get(iniconfig_section, 'X2GOBROKER_DEBUG') @@ -139,7 +139,7 @@ elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_DEBUG'): else: X2GOBROKER_DEBUG = False -if os.environ.has_key('X2GOBROKER_DAEMON_USER'): +if 'X2GOBROKER_DAEMON_USER' in os.environ: X2GOBROKER_DAEMON_USER=os.environ['X2GOBROKER_DAEMON_USER'] elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_DAEMON_USER'): X2GOBROKER_DAEMON_USER=iniconfig.get(iniconfig_section, 'X2GOBROKER_DAEMON_USER') @@ -148,7 +148,7 @@ elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_DAEMON_USER else: X2GOBROKER_DAEMON_USER="x2gobroker" -if os.environ.has_key('X2GOBROKER_AUTHSERVICE_LOGCONFIG'): +if 'X2GOBROKER_AUTHSERVICE_LOGCONFIG' in os.environ: X2GOBROKER_AUTHSERVICE_LOGCONFIG=os.environ['X2GOBROKER_AUTHSERVICE_LOGCONFIG'] elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_AUTHSERVICE_LOGCONFIG'): X2GOBROKER_AUTHSERVICE_LOGCONFIG=iniconfig.get(iniconfig_section, 'X2GOBROKER_AUTHSERVICE_LOGCONFIG') @@ -157,7 +157,7 @@ elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_AUTHSERVICE else: X2GOBROKER_AUTHSERVICE_LOGCONFIG="/etc/x2go/broker/x2gobroker-authservice-logger.conf" -if os.environ.has_key('X2GOBROKER_AUTHSERVICE_SOCKET'): +if 'X2GOBROKER_AUTHSERVICE_SOCKET' in os.environ: X2GOBROKER_AUTHSERVICE_SOCKET=os.environ['X2GOBROKER_AUTHSERVICE_SOCKET'] elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_AUTHSERVICE_SOCKET'): X2GOBROKER_AUTHSERVICE_SOCKET=iniconfig.get(iniconfig_section, 'X2GOBROKER_AUTHSERVICE_SOCKET') @@ -173,7 +173,7 @@ if __name__ == '__main__': {'args':['-s','--socket-file'], 'default': X2GOBROKER_AUTHSERVICE_SOCKET, 'metavar': 'AUTHSOCKET', 'help': 'socket file for AuthService communication', }, {'args':['-o','--owner'], 'default': 'root', 'help': 'owner of the AuthService socket file', }, {'args':['-g','--group'], 'default': 'root', 'help': 'group ownership of the AuthService socket file', }, - {'args':['-p','--permissions'], 'default': '0660', 'help': 'set these file permissions for the AuthService socket file', }, + {'args':['-p','--permissions'], 'default': '0o660', 'help': 'set these file permissions for the AuthService socket file', }, {'args':['-d','--debug'], 'default': False, 'action': 'store_true', 'help': 'enable debugging code', }, {'args':['-i','--debug-interactively'], 'default': False, 'action': 'store_true', 'help': 'force output of log message to the stderr (rather than to the log files)', }, @@ -276,9 +276,10 @@ if __name__ == '__main__': os.makedirs(os.path.dirname(socket_file)) runtimedir_permissions = int(cmdline_args.permissions, 8) - if runtimedir_permissions & 0400: runtimedir_permissions = runtimedir_permissions | 0100 - if runtimedir_permissions & 0040: runtimedir_permissions = runtimedir_permissions | 0010 - if runtimedir_permissions & 0004: runtimedir_permissions = runtimedir_permissions | 0001 + if runtimedir_permissions & 0o400: runtimedir_permissions = runtimedir_permissions | 0o100 + if runtimedir_permissions & 0o040: runtimedir_permissions = runtimedir_permissions | 0o010 + if runtimedir_permissions & 0o004: runtimedir_permissions = runtimedir_permissions | 0o001 + try: os.chown(os.path.dirname(socket_file), getpwnam(cmdline_args.owner).pw_uid, getpwnam(cmdline_args.group).pw_gid) os.chmod(os.path.dirname(socket_file), runtimedir_permissions) @@ -290,10 +291,10 @@ if __name__ == '__main__': try: if CAN_DAEMONIZE and cmdline_args.daemonize: keep_fds = [int(fd) for fd in os.listdir('/proc/self/fd') if fd not in (0,1,2) ] - daemon_stdout = file(daemon_logdir+'x2gobroker-authservice.stdout', 'w+') - daemon_stderr = file(daemon_logdir+'x2gobroker-authservice.stderr', 'w+') + daemon_stdout = open(daemon_logdir+'x2gobroker-authservice.stdout', 'w+') + daemon_stderr = open(daemon_logdir+'x2gobroker-authservice.stderr', 'w+') with daemon.DaemonContext(stdout=daemon_stdout, stderr=daemon_stderr, files_preserve=keep_fds, umask=0o027, pidfile=lockfile.FileLock(pidfile), detach_process=True): - file(pidfile, 'w+').write(str(os.getpid())+"\n") + open(pidfile, 'w+').write(str(os.getpid())+"\n") loop() else: loop() diff --git a/sbin/x2gobroker-keygen b/sbin/x2gobroker-keygen index c3aa03c..a901c25 100755 --- a/sbin/x2gobroker-keygen +++ b/sbin/x2gobroker-keygen @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # This file is part of the X2Go Project - http://www.x2go.org diff --git a/sbin/x2gobroker-loadchecker b/sbin/x2gobroker-loadchecker index aac8798..eb87c7d 100755 --- a/sbin/x2gobroker-loadchecker +++ b/sbin/x2gobroker-loadchecker @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # This file is part of the X2Go Project - http://www.x2go.org @@ -29,7 +29,7 @@ import socket import getpass import logging.config import atexit -import ConfigParser +import configparser if os.path.isdir('/run'): RUNDIR = '/run' @@ -66,7 +66,7 @@ class LoadCheckerServiceHandler(asyncore.dispatcher_with_send): self._buf = '' def handle_read(self): - data = self._buf + self.recv(1024) + data = self._buf + self.recv(1024).decode() if not data: self.close() return @@ -97,7 +97,7 @@ class LoadCheckerServiceHandler(asyncore.dispatcher_with_send): else: if self.logger: self.logger.warning('LoadCheckServiceHandler.handle_read(): load check failure for backend={backend}, profile_id={profile_id}: LOAD-UNAVAILABLE'.format(backend=backend, profile_id=profile_id)) output += "\n" - self.send(output) + self.send(output.encode()) def handle_close(self): self.close() @@ -105,7 +105,7 @@ class LoadCheckerServiceHandler(asyncore.dispatcher_with_send): class LoadCheckerService(asyncore.dispatcher_with_send): - def __init__(self, socketfile, owner='root', group_owner='root', permissions='0660', logger=None): + def __init__(self, socketfile, owner='root', group_owner='root', permissions='0o660', logger=None): self.logger = logger asyncore.dispatcher_with_send.__init__(self) self.create_socket(socket.AF_UNIX, socket.SOCK_STREAM) @@ -143,13 +143,13 @@ iniconfig_loaded = None iniconfig_section = '-'.join(PROG_NAME.split('-')[1:]) X2GOBROKER_DEFAULTS = "/etc/x2go/broker/defaults.conf" if os.path.isfile(X2GOBROKER_DEFAULTS) and os.access(X2GOBROKER_DEFAULTS, os.R_OK): - iniconfig = ConfigParser.SafeConfigParser() + iniconfig = configparser.RawConfigParser() iniconfig.optionxform = str iniconfig_loaded = iniconfig.read(X2GOBROKER_DEFAULTS) # normally this would go into defaults.py, however, we do not want to pull in defaults.py here as that will create # unwanted logfiles (access.log, broker.log, error.log) when x2gobroker-loadchecker is installed as standalone service -if os.environ.has_key('X2GOBROKER_DEBUG'): +if 'X2GOBROKER_DEBUG' in os.environ: X2GOBROKER_DEBUG = ( os.environ['X2GOBROKER_DEBUG'].lower() in ('1', 'on', 'true', 'yes', ) ) elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_DEBUG'): X2GOBROKER_DEBUG=iniconfig.get(iniconfig_section, 'X2GOBROKER_DEBUG') @@ -158,7 +158,7 @@ elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_DEBUG'): else: X2GOBROKER_DEBUG = False -if os.environ.has_key('X2GOBROKER_DAEMON_USER'): +if 'X2GOBROKER_DAEMON_USER' in os.environ: X2GOBROKER_DAEMON_USER=os.environ['X2GOBROKER_DAEMON_USER'] elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_DAEMON_USER'): X2GOBROKER_DAEMON_USER=iniconfig.get(iniconfig_section, 'X2GOBROKER_DAEMON_USER') @@ -167,7 +167,7 @@ elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_DAEMON_USER else: X2GOBROKER_DAEMON_USER="x2gobroker" -if os.environ.has_key('X2GOBROKER_LOADCHECKER_LOGCONFIG'): +if 'X2GOBROKER_LOADCHECKER_LOGCONFIG' in os.environ: X2GOBROKER_LOADCHECKER_LOGCONFIG=os.environ['X2GOBROKER_LOADCHECKER_LOGCONFIG'] elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_LOADCHECKER_LOGCONFIG'): X2GOBROKER_LOADCHECKER_LOGCONFIG=iniconfig.get(iniconfig_section, 'X2GOBROKER_LOADCHECKER_LOGCONFIG') @@ -176,7 +176,7 @@ elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_LOADCHECKER else: X2GOBROKER_LOADCHECKER_LOGCONFIG="/etc/x2go/broker/x2gobroker-loadchecker-logger.conf" -if os.environ.has_key('X2GOBROKER_LOADCHECKER_SOCKET'): +if 'X2GOBROKER_LOADCHECKER_SOCKET' in os.environ: X2GOBROKER_LOADCHECKER_SOCKET=os.environ['X2GOBROKER_LOADCHECKER_SOCKET'] elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_LOADCHECKER_SOCKET'): X2GOBROKER_LOADCHECKER_SOCKET=iniconfig.get(iniconfig_section, 'X2GOBROKER_LOADCHECKER_SOCKET') @@ -294,9 +294,9 @@ if __name__ == '__main__': os.makedirs(os.path.dirname(socket_file)) runtimedir_permissions = int(cmdline_args.permissions, 8) - if runtimedir_permissions & 0400: runtimedir_permissions = runtimedir_permissions | 0100 - if runtimedir_permissions & 0040: runtimedir_permissions = runtimedir_permissions | 0010 - if runtimedir_permissions & 0004: runtimedir_permissions = runtimedir_permissions | 0001 + if runtimedir_permissions & 0o400: runtimedir_permissions = runtimedir_permissions | 0o100 + if runtimedir_permissions & 0o040: runtimedir_permissions = runtimedir_permissions | 0o010 + if runtimedir_permissions & 0o004: runtimedir_permissions = runtimedir_permissions | 0o001 try: os.chown(os.path.dirname(socket_file), getpwnam(cmdline_args.owner).pw_uid, getpwnam(cmdline_args.group).pw_gid) os.chmod(os.path.dirname(socket_file), runtimedir_permissions) @@ -308,10 +308,10 @@ if __name__ == '__main__': try: if CAN_DAEMONIZE and cmdline_args.daemonize: keep_fds = [int(fd) for fd in os.listdir('/proc/self/fd') if fd not in (0,1,2) ] - daemon_stdout = file(daemon_logdir+'x2gobroker-loadchecker.stdout', 'w+') - daemon_stderr = file(daemon_logdir+'x2gobroker-loadchecker.stderr', 'w+') + daemon_stdout = open(daemon_logdir+'x2gobroker-loadchecker.stdout', 'w+') + daemon_stderr = open(daemon_logdir+'x2gobroker-loadchecker.stderr', 'w+') with daemon.DaemonContext(stdout=daemon_stdout, stderr=daemon_stderr, files_preserve=keep_fds, umask=0o027, pidfile=lockfile.FileLock(pidfile), detach_process=True): - file(pidfile, 'w+').write(str(os.getpid())+"\n") + open(pidfile, 'w+').write(str(os.getpid())+"\n") loop() else: loop() diff --git a/sbin/x2gobroker-pubkeyauthorizer b/sbin/x2gobroker-pubkeyauthorizer index 449f935..ceb4ce6 100755 --- a/sbin/x2gobroker-pubkeyauthorizer +++ b/sbin/x2gobroker-pubkeyauthorizer @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # This file is part of the X2Go Project - http://www.x2go.org diff --git a/sbin/x2gobroker-testagent b/sbin/x2gobroker-testagent index 47c87e1..4c4587d 100755 --- a/sbin/x2gobroker-testagent +++ b/sbin/x2gobroker-testagent @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # This file is part of the X2Go Project - http://www.x2go.org # Copyright (C) 2012-2015 by Mike Gabriel <mike.gabriel@das-netzwerkteam.de> @@ -20,7 +20,6 @@ import os import sys -import types import setproctitle import argparse import logging @@ -196,10 +195,10 @@ if __name__ == "__main__": }) result = call_agent(task, **kwargs) - if type(result) is types.ListType: + if type(result) is dict: print "\n".join(result) print - elif task.startswith('findbusyservers') and type(result) is types.DictType: + elif task.startswith('findbusyservers') and type(result) is dict: if result: print "\n".join([ "{host} -- {usage}%".format(host=host, usage=usage) for host, usage in result.items() ]) else: diff --git a/setup.py b/setup.py index 49299d2..e9cdf9e 100755 --- a/setup.py +++ b/setup.py @@ -1,6 +1,4 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright (C) 2012-2015 by Mike Gabriel <mike.gabriel@das-netzwerkteam.de> @@ -24,11 +22,11 @@ from setuptools import setup, find_packages import os __VERSION__ = None -for line in file(os.path.join('x2gobroker', '__init__.py')).readlines(): +for line in open(os.path.join('x2gobroker', '__init__.py')).readlines(): if (line.startswith('__VERSION__')): exec(line.strip()) __AUTHOR__ = None -for line in file(os.path.join('x2gobroker', '__init__.py')).readlines(): +for line in open(os.path.join('x2gobroker', '__init__.py')).readlines(): if (line.startswith('__AUTHOR__')): exec(line.strip()) MODULE_VERSION = __VERSION__ diff --git a/test.py b/test.py index 04a90ce..fd7860c 100755 --- a/test.py +++ b/test.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright (C) 2014-2015 by Mike Gabriel <mike.gabriel@das-netzwerkteam.de> @@ -27,4 +27,4 @@ if __name__ == "__main__": os.environ.update({'X2GOBROKER_DEBUG': "1"}) os.environ.update({'X2GOBROKER_TESTSUITE': "1"}) os.chdir(os.path.join('x2gobroker', 'tests',)) - os.system('python ./runalltests.py') + os.system('python3 ./runalltests.py') diff --git a/x2gobroker/_paramiko.py b/x2gobroker/_paramiko.py index 569532a..4a7c2fa 100644 --- a/x2gobroker/_paramiko.py +++ b/x2gobroker/_paramiko.py @@ -24,7 +24,7 @@ Monkey Patch and feature map for Python Paramiko import paramiko import platform -from utils import compare_versions +from x2gobroker.utils import compare_versions PARAMIKO_VERSION = paramiko.__version__.split()[0] PARAMIKO_FEATURE = { @@ -61,9 +61,9 @@ def _SSHClient_save_host_keys(self, filename): f = open(filename, 'w') #f.write('# SSH host keys collected by paramiko\n') _host_keys = self.get_host_keys() - for hostname, keys in _host_keys.iteritems(): + for hostname, keys in _host_keys.items(): - for keytype, key in keys.iteritems(): + for keytype, key in keys.items(): f.write('%s %s %s\n' % (hostname, keytype, key.get_base64())) f.close() diff --git a/x2gobroker/agent.py b/x2gobroker/agent.py index c18b747..6dda243 100644 --- a/x2gobroker/agent.py +++ b/x2gobroker/agent.py @@ -19,10 +19,9 @@ import os import os.path -import types import subprocess import paramiko -import cStringIO +import io import time import socket import logging @@ -103,7 +102,7 @@ def call_broker_agent(username, task, cmdline_args=[], remote_agent=None, logger @raise X2GoBrokerAgentException: if the call to the remote broker agents fails. """ - if remote_agent in (u'LOCAL', None): + if remote_agent in ('LOCAL', None): result = _call_local_broker_agent(username=username, task=task, cmdline_args=cmdline_args, logger=logger) else: result = _call_remote_broker_agent(username=username, task=task, cmdline_args=cmdline_args, remote_agent=remote_agent, logger=logger) @@ -160,7 +159,7 @@ def _call_local_broker_agent(username, task, cmdline_args=[], logger=None): shell=False, ) - result = agent_process.stdout.read().split('\n') + result = agent_process.stdout.read().decode().split('\n') except OSError: result = None @@ -197,13 +196,13 @@ def _call_remote_broker_agent(username, task, cmdline_args=[], remote_agent=None if remote_agent is None: logger_error.error('With the SSH agent-query-mode a remote agent host (hostname, hostaddr, port) has to be specified!') - elif not remote_agent.has_key('host_key_policy'): + elif 'host_key_policy' not in remote_agent: remote_agent['host_key_policy'] = paramiko.WarningPolicy() - remote_hostname = remote_agent[u'hostaddr'] - remote_hostaddr = remote_agent[u'hostaddr'] - if remote_agent.has_key(u'port'): - remote_port = int(remote_agent[u'port']) + remote_hostname = remote_agent['hostaddr'] + remote_hostaddr = remote_agent['hostaddr'] + if 'port' in remote_agent: + remote_port = int(remote_agent['port']) else: remote_port = 22 @@ -241,8 +240,8 @@ def _call_remote_broker_agent(username, task, cmdline_args=[], remote_agent=None cmd = 'sh -c \'{cmd}\''.format(cmd=cmd) logger.info('Executing agent command on remote host {hostname} ({hostaddr}): {cmd}'.format(hostname=remote_hostname, hostaddr=remote_hostaddr, cmd=cmd)) (stdin, stdout, stderr) = client.exec_command(cmd) - result = stdout.read().split('\n') - err = stderr.read().replace('\n', ' ') + result = stdout.read().decode().split('\n') + err = stderr.read().decode().replace('\n', ' ') if err: logger.warning('Remote agent command (host: {hostname} ({hostaddr})) reported an error: {err}'.format(hostname=remote_hostname, hostaddr=remote_hostaddr, err=err)) result = None @@ -374,7 +373,7 @@ def has_sessions(username, remote_agent=None, logger=None, **kwargs): logger = logger_broker _success, _session_list = list_sessions(username, remote_agent=remote_agent, logger=logger, **kwargs) - if type(_session_list) is types.ListType: + if type(_session_list) is list: return (_success, [ s.split('|')[3] for s in _session_list if s.split('|')[4] == 'R' ], [ s.split('|')[3] for s in _session_list if s.split('|')[4] == 'S' ]) else: return (False, [], []) @@ -406,7 +405,7 @@ def find_busy_servers(username, remote_agent=None, logger=None, **kwargs): _success, server_list = call_broker_agent(username, task='findbusyservers', remote_agent=remote_agent, logger=logger, **kwargs) server_usage = {} - if server_list and type(server_list) is types.ListType: + if server_list and type(server_list) is list: for server_item in server_list: if ':' in server_item: usage, server = server_item.split(':') @@ -437,11 +436,11 @@ def check_load(remote_agent=None, logger=None, **kwargs): logger = logger_broker try: - if "username" in kwargs.keys(): + if "username" in list(kwargs.keys()): del kwargs["username"] _success, _load_params = call_broker_agent(username='foo', task='checkload', remote_agent=remote_agent, logger=logger, **kwargs) - except x2gobroker.x2gobroker_exceptions.X2GoBrokerAgentException, e: - logger.error('querying remote agent on host {hostname} failed: {errmsg}'.format(hostname=remote_agent[u'hostname'], errmsg=str(e))) + except x2gobroker.x2gobroker_exceptions.X2GoBrokerAgentException as e: + logger.error('querying remote agent on host {hostname} failed: {errmsg}'.format(hostname=remote_agent['hostname'], errmsg=str(e))) return "HOST-UNREACHABLE" p = {} @@ -455,7 +454,7 @@ def check_load(remote_agent=None, logger=None, **kwargs): if p['memAvail'] == 0: p['memAvail'] = p['myMemAvail'] - load_factor = long( ( (p['memAvail']/1000) * p['numCPU'] * p['typeCPU'] * 100 ) / p['loadavgXX'] ) + load_factor = int( ( (p['memAvail']/1000) * p['numCPU'] * p['typeCPU'] * 100 ) / p['loadavgXX'] ) except KeyError: return "LOAD-DATA-BOGUS" @@ -608,9 +607,9 @@ def genkeypair(local_username, client_address, key_type='RSA', logger=None): privkey = None # generate key pair - if unicode(key_type) == u'RSA': + if key_type == 'RSA': key = paramiko.RSAKey.generate(2048) - elif unicode(key_type) == u'DSA': + elif key_type == 'DSA': key = paramiko.DSSKey.generate(1024) if key: @@ -626,7 +625,7 @@ def genkeypair(local_username, client_address, key_type='RSA', logger=None): pubkey = "no-X11-forwarding,no-pty,no-user-rc {pubkey_type} {pubkey} {local_username}@{client_address}".format(pubkey=key.get_base64(), pubkey_type=pubkey_type, local_username=local_username, client_address=client_address) # assemble the private key - privkey_obj = cStringIO.StringIO() + privkey_obj = io.StringIO() key.write_private_key(privkey_obj) privkey = privkey_obj.getvalue() diff --git a/x2gobroker/authmechs/https_get_authmech.py b/x2gobroker/authmechs/https_get_authmech.py index c4c2599..13f945c 100644 --- a/x2gobroker/authmechs/https_get_authmech.py +++ b/x2gobroker/authmechs/https_get_authmech.py @@ -31,7 +31,7 @@ # attack. # modules -import httplib +import http.client import base64 class X2GoBrokerAuthMech(object): @@ -52,7 +52,7 @@ class X2GoBrokerAuthMech(object): # base64 encode the username and password auth = base64.standard_b64encode('%s:%s' % (username, password)).replace('\n', '') - https = httplib.HTTPSConnection(host,port) + https = http.client.HTTPSConnection(host,port) https.putrequest("GET", path) https.putheader("Host", host) https.putheader("User-Agent", "X2Go Session Broker") diff --git a/x2gobroker/authservice.py b/x2gobroker/authservice.py index 35f7171..a512dc7 100644 --- a/x2gobroker/authservice.py +++ b/x2gobroker/authservice.py @@ -31,8 +31,8 @@ def authenticate(username, password, service="x2gobroker"): s.connect(x2gobroker.defaults.X2GOBROKER_AUTHSERVICE_SOCKET) # FIXME: somehow logging output disappears after we have connected to the socket file... logger_broker.debug('sending username={username}, password=<hidden>, service={service} to authentication service'.format(username=username, service=service)) - s.send('{username}\r{password}\r{service}\n'.format(username=username, password=password, service=service)) - result = s.recv(1024) + s.send('{username}\r{password}\r{service}\n'.format(username=username, password=password, service=service).encode()) + result = s.recv(1024).decode() s.close() if result.startswith('ok'): logger_broker.info('authentication against PAM service »{service}« succeeded for user »{username}«'.format(username=username, service=service)) diff --git a/x2gobroker/basicauth.py b/x2gobroker/basicauth.py index a943719..9a79935 100644 --- a/x2gobroker/basicauth.py +++ b/x2gobroker/basicauth.py @@ -40,7 +40,7 @@ def require_basic_auth(realm, validate_callback): create_auth_header() else: auth_decoded = base64.decodestring(auth_header[6:]) - username, kwargs['basicauth_pass'] = [ unicode(s) for s in auth_decoded.split(':', 2) ] + username, kwargs['basicauth_pass'] = [ s for s in auth_decoded.split(':', 2) ] kwargs['basicauth_user'], access = validate_callback(username, kwargs['basicauth_pass']) if access: return True diff --git a/x2gobroker/brokers/base_broker.py b/x2gobroker/brokers/base_broker.py index 2c6bbc2..bed645c 100644 --- a/x2gobroker/brokers/base_broker.py +++ b/x2gobroker/brokers/base_broker.py @@ -25,7 +25,6 @@ L{x2gobroker.brokers.base_broker.X2GoBroker} class - base skeleton for X2GoBroke __NAME__ = 'x2gobroker-pylib' # modules -import types import copy import uuid import netaddr @@ -146,7 +145,7 @@ class X2GoBroker(object): """ if self._client_address: - return unicode(self._client_address) + return str(self._client_address) else: return None @@ -194,7 +193,7 @@ class X2GoBroker(object): @rtype: C{unicode} """ - unconfigured_my_cookie = u'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' + unconfigured_my_cookie = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' my_cookie = unconfigured_my_cookie deprecated_my_cookie = self.config.get_value('global', 'my-cookie') @@ -350,13 +349,13 @@ class X2GoBroker(object): _acls = self.get_acl_defaults() _acls.update(acls) _order = {} - _order[u'users'] = _order[u'groups'] = _order[u'clients'] = _acls[u'acl-any-order'] + _order['users'] = _order['groups'] = _order['clients'] = _acls['acl-any-order'] - try: _order[u'users'] = _acls[u'acl-users-order'] + try: _order['users'] = _acls['acl-users-order'] except KeyError: pass - try: _order[u'groups'] = _acls[u'acl-groups-order'] + try: _order['groups'] = _acls['acl-groups-order'] except KeyError: pass - try: _order[u'clients'] = _acls[u'acl-clients-order'] + try: _order['clients'] = _acls['acl-clients-order'] except KeyError: pass # to pass an ACL test, all three keys in the dict below have to be set to True @@ -376,20 +375,20 @@ class X2GoBroker(object): ### clients access is granted first, if that fails then we return False here... - if len( _acls[u'acl-clients-allow'] + _acls[u'acl-clients-deny'] ) > 0: + if len( _acls['acl-clients-allow'] + _acls['acl-clients-deny'] ) > 0: - _acls_clients_allow = copy.deepcopy(_acls[u'acl-clients-allow']) - _acls_clients_deny = copy.deepcopy(_acls[u'acl-clients-deny']) + _acls_clients_allow = copy.deepcopy(_acls['acl-clients-allow']) + _acls_clients_deny = copy.deepcopy(_acls['acl-clients-deny']) _allow_client = False _deny_client = False for idx, item in enumerate(_acls_clients_allow): - if unicode(item) == u'ALL': + if item == 'ALL': _acls_clients_allow[idx] = '0.0.0.0/0' _acls_clients_allow.insert(idx, '::/0') for idx, item in enumerate(_acls_clients_deny): - if unicode(item) == u'ALL': + if item == 'ALL': _acls_clients_deny[idx] = '0.0.0.0/0' _acls_clients_deny.insert(idx, '::/0') @@ -408,68 +407,68 @@ class X2GoBroker(object): if not (_allow_client or _deny_client): # client was not in either of the rules, so we presume that the client is allowed to access - _grant_availability[u'by_client'] - if _order[u'clients'] == 'allow-deny': - _grant_availability[u'by_client'] = _allow_client and (not _deny_client) + _grant_availability['by_client'] + if _order['clients'] == 'allow-deny': + _grant_availability['by_client'] = _allow_client and (not _deny_client) else: - _grant_availability[u'by_client'] = (not _deny_client) or _allow_client + _grant_availability['by_client'] = (not _deny_client) or _allow_client - if not _grant_availability[u'by_client']: + if not _grant_availability['by_client']: return False ### no user/group ACLs are in use, allow access then... - if len(_acls[u'acl-users-allow'] + _acls[u'acl-users-deny'] + _acls[u'acl-groups-allow'] + _acls[u'acl-groups-deny']) == 0: + if len(_acls['acl-users-allow'] + _acls['acl-users-deny'] + _acls['acl-groups-allow'] + _acls['acl-groups-deny']) == 0: return True ### CHECKING on a per-user basis... _allow_user_override = False _explicitly_deny_user = False - if len( _acls[u'acl-users-allow'] + _acls[u'acl-users-deny'] ) > 0: + if len( _acls['acl-users-allow'] + _acls['acl-users-deny'] ) > 0: _allow_user = False _deny_user = False - if username in _acls[u'acl-users-allow'] or u'ALL' in _acls[u'acl-users-allow']: + if username in _acls['acl-users-allow'] or 'ALL' in _acls['acl-users-allow']: _allow_user_override = True _allow_user = True - if username in _acls[u'acl-users-deny']: + if username in _acls['acl-users-deny']: _explicitly_deny_user = True - if _explicitly_deny_user or (u'ALL' in _acls[u'acl-users-deny']): + if _explicitly_deny_user or ('ALL' in _acls['acl-users-deny']): _deny_user = True - if _order[u'users'] == 'allow-deny': - _grant_availability[u'by_user'] = (_allow_user or _deny_user) and (_allow_user and (not _deny_user)) + if _order['users'] == 'allow-deny': + _grant_availability['by_user'] = (_allow_user or _deny_user) and (_allow_user and (not _deny_user)) else: - _grant_availability[u'by_user'] = (_allow_user or _deny_user) and ((not _deny_user) or _allow_user) + _grant_availability['by_user'] = (_allow_user or _deny_user) and ((not _deny_user) or _allow_user) # if a user has been granted access directly, then the corresponding session profile(s) # will be provided to him/her, it does not matter what the group acl will have to say to this... - if _grant_availability[u'by_user']: + if _grant_availability['by_user']: return True ### CHECKING on a per-group basis... - if len(_acls[u'acl-groups-allow'] + _acls[u'acl-groups-deny']) > 0: + if len(_acls['acl-groups-allow'] + _acls['acl-groups-deny']) > 0: _allow_group = False _deny_group = False - _user_groups = [u'ALL'] + self.get_user_groups(username, primary_groups=not self.get_global_value('ignore-primary-group-memberships')) + _user_groups = ['ALL'] + self.get_user_groups(username, primary_groups=not self.get_global_value('ignore-primary-group-memberships')) - _allow_group = bool(len(set(_user_groups).intersection( set(_acls[u'acl-groups-allow']) ))) - _deny_group = bool(len(set(_user_groups).intersection( set(_acls[u'acl-groups-deny']) ))) + _allow_group = bool(len(set(_user_groups).intersection( set(_acls['acl-groups-allow']) ))) + _deny_group = bool(len(set(_user_groups).intersection( set(_acls['acl-groups-deny']) ))) - if _order[u'groups'] == 'allow-deny': - _grant_availability[u'by_group'] = (_allow_group or _deny_group) and (_allow_group and (not _deny_group)) + if _order['groups'] == 'allow-deny': + _grant_availability['by_group'] = (_allow_group or _deny_group) and (_allow_group and (not _deny_group)) else: - _grant_availability[u'by_group'] = (_allow_group or _deny_group) and (not _deny_group) or _allow_group + _grant_availability['by_group'] = (_allow_group or _deny_group) and (not _deny_group) or _allow_group # if a group has been granted access, with one exception: if the thread model for users is # allow-deny, then we presume that the acl-users-deny entry has precendence over # acl-groups-allow/acl-groups-deny. - if (_grant_availability[u'by_group'] and not _explicitly_deny_user) or _allow_user_override: + if (_grant_availability['by_group'] and not _explicitly_deny_user) or _allow_user_override: return True return False @@ -481,8 +480,9 @@ class X2GoBroker(object): try: if self.authmech_module is None: _authmech_module = None - exec("import x2gobroker.authmechs.{mech}_authmech as _authmech_module".format(mech=mech)) - self.authmech_module = _authmech_module + namespace = {} + exec("import x2gobroker.authmechs.{mech}_authmech as _authmech_module".format(mech=mech), namespace) + self.authmech_module = namespace['_authmech_module'] return True except ImportError: return False @@ -515,9 +515,9 @@ class X2GoBroker(object): _default_auth_mech = self.config.get_value('global', 'default-auth-mech').lower() logger_broker.debug('base_broker.X2GoBroker.get_authentication_mechanism(): found default-auth-mech in global config section: {value}'.format(value=_default_auth_mech)) - return unicode(_auth_mech) or unicode(_default_auth_mech) + return _auth_mech or _default_auth_mech - def _enforce_agent_query_mode(self, mode=u'LOCAL'): + def _enforce_agent_query_mode(self, mode='LOCAL'): """\ Allow frontends to enforce a certain broker agent backend. @@ -543,8 +543,8 @@ class X2GoBroker(object): _agent_query_mode = "" _profile = self.get_profile_broker(profile_id) - if _profile and _profile.has_key(u'broker-agent-query-mode') and _profile['broker-agent-query-mode']: - _agent_query_mode = _profile[u'broker-agent-query-mode'] + if _profile and 'broker-agent-query-mode' in _profile and _profile['broker-agent-query-mode']: + _agent_query_mode = _profile['broker-agent-query-mode'] logger_broker.debug('base_broker.X2GoBroker.get_agent_query_mode(): found broker-agent-query-mode in session profile with ID {id}: {value}. This one has precendence over the default and the backend value.'.format(id=profile_id, value=_agent_query_mode)) elif self.config.has_value('broker_{backend}'.format(backend=self.backend_name), 'agent-query-mode') and self.config.get_value('broker_{backend}'.format(backend=self.backend_name), 'agent-query-mode'): @@ -555,7 +555,7 @@ class X2GoBroker(object): _default_agent_query_mode = self.config.get_value('global', 'default-agent-query-mode').lower() logger_broker.debug('base_broker.X2GoBroker.get_agent_query_mode(): found default-agent-query-mode in global config section: {value}'.format(value=_default_agent_query_mode)) - _mode = unicode(_agent_query_mode) or unicode(_backend_agent_query_mode) or unicode(_default_agent_query_mode) + _mode = _agent_query_mode or _backend_agent_query_mode or _default_agent_query_mode # if the frontend overrides the agent query mode, immediately return it here... if self._enforce_agent_query_mode(mode=_mode): @@ -578,9 +578,9 @@ class X2GoBroker(object): _session_autologin = False _profile = self.get_profile_broker(profile_id) - if _profile and _profile.has_key(u'broker-session-autologin') and _profile['broker-session-autologin']: - _session_autologin = _profile[u'broker-session-autologin'] - if type(_session_autologin) in (types.StringType, types.UnicodeType): + if _profile and 'broker-session-autologin' in _profile and _profile['broker-session-autologin']: + _session_autologin = _profile['broker-session-autologin'] + if type(_session_autologin) == str: _session_autologin = _session_autologin.lower() in ('1', 'true') logger_broker.debug('base_broker.X2GoBroker.get_session_autologin(): found broker-session-autologin in session profile with ID {id}: {value}. This one has precendence over the default value.'.format(id=profile_id, value=_session_autologin)) @@ -605,9 +605,9 @@ class X2GoBroker(object): _portscan_x2goservers = False _profile = self.get_profile_broker(profile_id) - if _profile and _profile.has_key(u'broker-portscan-x2goservers') and _profile['broker-portscan-x2goservers']: - _portscan_x2goservers = _profile[u'broker-portscan-x2goservers'] - if type(_portscan_x2goservers) in (types.StringType, types.UnicodeType): + if _profile and 'broker-portscan-x2goservers' in _profile and _profile['broker-portscan-x2goservers']: + _portscan_x2goservers = _profile['broker-portscan-x2goservers'] + if type(_portscan_x2goservers) == str: _portscan_x2goservers = _portscan_x2goservers.lower() in ('1', 'true') logger_broker.debug('base_broker.X2GoBroker.get_portscan_x2goservers(): found broker-portscan-x2goservers in session profile with ID {id}: {value}. This one has precendence over the default value.'.format(id=profile_id, value=_portscan_x2goservers)) @@ -635,15 +635,15 @@ class X2GoBroker(object): _default_authorized_keys_file = "%h/.x2go/authorized_keys" _authorized_keys_file = "" _profile = self.get_profile_broker(profile_id) - if _profile and _profile.has_key(u'broker-authorized-keys') and _profile['broker-authorized-keys']: - _authorized_keys_file = _profile[u'broker-authorized-keys'] + if _profile and 'broker-authorized-keys' in _profile and _profile['broker-authorized-keys']: + _authorized_keys_file = _profile['broker-authorized-keys'] logger_broker.debug('base_broker.X2GoBroker.get_authorized_keys_file(): found broker-authorized-keys in session profile with ID {id}: {value}. This one has precendence over the default value.'.format(id=profile_id, value=_authorized_keys_file)) elif self.config.has_value('global', 'default-authorized-keys'): _default_authorized_keys_file = self.config.get_value('global', 'default-authorized-keys') logger_broker.debug('base_broker.X2GoBroker.get_authorized_keys_file(): found default-authorized-keys in global config section: {value}'.format(value=_default_authorized_keys_file)) - return unicode(_authorized_keys_file) or unicode(_default_authorized_keys_file) + return _authorized_keys_file or _default_authorized_keys_file def get_sshproxy_authorized_keys_file(self, profile_id): """\ @@ -661,15 +661,15 @@ class X2GoBroker(object): _default_authorized_keys_file = "%h/.x2go/authorized_keys" _authorized_keys_file = "" _profile = self.get_profile_broker(profile_id) - if _profile and _profile.has_key(u'broker-sshproxy-authorized-keys') and _profile['broker-sshproxy-authorized-keys']: - _authorized_keys_file = _profile[u'broker-sshproxy-authorized-keys'] + if _profile and 'broker-sshproxy-authorized-keys' in _profile and _profile['broker-sshproxy-authorized-keys']: + _authorized_keys_file = _profile['broker-sshproxy-authorized-keys'] logger_broker.debug('base_broker.X2GoBroker.get_sshproxy_authorized_keys_file(): found broker-sshproxy-authorized-keys in session profile with ID {id}: {value}. This one has precendence over the default value.'.format(id=profile_id, value=_authorized_keys_file)) elif self.config.has_value('global', 'default-sshproxy-authorized-keys'): _default_authorized_keys_file = self.config.get_value('global', 'default-sshproxy-authorized-keys') logger_broker.debug('base_broker.X2GoBroker.get_sshproxy_authorized_keys_file(): found default-sshproxy-authorized-keys in global config section: {value}'.format(value=_default_authorized_keys_file)) - return unicode(_authorized_keys_file) or unicode(_default_authorized_keys_file) + return _authorized_keys_file or _default_authorized_keys_file def get_userdb_service(self): """\ @@ -687,7 +687,7 @@ class X2GoBroker(object): if self.config.has_value('broker_{backend}'.format(backend=self.backend_name), 'user-db'): _user_db = self.config.get_value('broker_{backend}'.format(backend=self.backend_name), 'user-db').lower() or _user_db - return unicode(_user_db) + return _user_db def get_groupdb_service(self): """\ @@ -705,7 +705,7 @@ class X2GoBroker(object): if self.config.has_value('broker_{backend}'.format(backend=self.backend_name), 'group-db'): _group_db = self.config.get_value('broker_{backend}'.format(backend=self.backend_name), 'group-db').lower() or _group_db - return unicode(_group_db) + return _group_db def get_use_load_checker(self): """\ @@ -748,13 +748,13 @@ class X2GoBroker(object): _profile_broker = self.get_profile_broker(profile_id) # it is not explicitly disabled per session profile definition - if _profile_broker and _profile_broker.has_key(u'broker-use-load-checker') and _profile_broker['broker-use-load-checker'] not in ('1', 'true'): + if _profile_broker and 'broker-use-load-checker' in _profile_broker and _profile_broker['broker-use-load-checker'] not in ('1', 'true'): return False _profile = self.get_profile(profile_id) # more than one host is defined in the session profile - if len(_profile[u'host']) < 2: + if len(_profile['host']) < 2: return False else: @@ -766,8 +766,9 @@ class X2GoBroker(object): try: if self.nameservice_module is None: _nameservice_module = None - exec("import x2gobroker.nameservices.{service}_nameservice as _nameservice_module".format(service=service)) - self.nameservice_module = _nameservice_module + namespace = {} + exec("import x2gobroker.nameservices.{service}_nameservice as _nameservice_module".format(service=service), namespace) + self.nameservice_module = namespace['_nameservice_module'] return True except ImportError: return False @@ -943,8 +944,8 @@ class X2GoBroker(object): ### IMPLEMENT YOUR AUTHENTICATION LOGIC IN THE self._do_authenticate(**kwargs) METHOD ### when inheriting from the x2gobroker.brokers.base_broker.X2GoBroker class. - if type(cookie) is types.StringType: - cookie = unicode(cookie) + if type(cookie) is bytes: + cookie = cookie if (((cookie == None) or (cookie == "")) and require_cookie): #cookie required but we did not get one - catch wrong cookie case later @@ -1058,10 +1059,10 @@ class X2GoBroker(object): return remote_agent agent_query_mode = self.get_agent_query_mode(profile_id).upper() - if agent_query_mode == u'SSH' and x2gobroker.agent.has_remote_broker_agent_setup(): + if agent_query_mode == 'SSH' and x2gobroker.agent.has_remote_broker_agent_setup(): profile = self.get_profile(profile_id) - server_list = profile[u'host'] + server_list = profile['host'] random.shuffle(server_list) # if the load checker is in use for this profile, let's retrieve the available server loads here @@ -1074,7 +1075,7 @@ class X2GoBroker(object): load_factors = {} if self.use_load_checker(profile_id): load_factors = x2gobroker.loadchecker.check_load(self.backend_name, profile_id) - for h in [ _h for _h in load_factors.keys() if type(load_factors[_h]) != types.LongType ]: + for h in [ _h for _h in list(load_factors.keys()) if type(load_factors[_h]) != int ]: if h in server_list: server_list.remove(h) @@ -1086,16 +1087,16 @@ class X2GoBroker(object): remote_agent_hostname = server_list[-1] remote_agent_hostaddr = remote_agent_hostname - remote_agent_port = profile[u'sshport'] - if profile.has_key('sshport={hostname}'.format(hostname=remote_agent_hostname)): + remote_agent_port = profile['sshport'] + if 'sshport={hostname}'.format(hostname=remote_agent_hostname) in profile: remote_agent_port = profile["sshport={hostname}".format(hostname=remote_agent_hostname)] - if profile.has_key('host={hostname}'.format(hostname=remote_agent_hostname)): + if 'host={hostname}'.format(hostname=remote_agent_hostname) in profile: remote_agent_hostaddr = profile["host={hostname}".format(hostname=remote_agent_hostname)] remote_agent = { - u'hostname': remote_agent_hostname, - u'hostaddr': remote_agent_hostaddr, - u'port': remote_agent_port, } + 'hostname': remote_agent_hostname, + 'hostaddr': remote_agent_hostaddr, + 'port': remote_agent_port, } try: if x2gobroker.agent.ping(remote_agent=remote_agent): @@ -1110,9 +1111,9 @@ class X2GoBroker(object): logger_broker.warning('base_broker.X2GoBroker.get_remote_agent(): failed to allocate any broker agent (query-mode: {query_mode}, remote_agent: {remote_agent})'.format(query_mode=agent_query_mode, remote_agent=remote_agent)) else: # ship the load_factors retrieved from the load checker service in the remote_agent dict - remote_agent[u'load_factors'] = load_factors + remote_agent['load_factors'] = load_factors - elif agent_query_mode == u'LOCAL': + elif agent_query_mode == 'LOCAL': # use a non-False value here, not used anywhere else... remote_agent = 'LOCAL' @@ -1136,25 +1137,25 @@ class X2GoBroker(object): return remote_agents agent_query_mode = self.get_agent_query_mode(profile_id).upper() - if agent_query_mode == u'SSH' and x2gobroker.agent.has_remote_broker_agent_setup(): + if agent_query_mode == 'SSH' and x2gobroker.agent.has_remote_broker_agent_setup(): profile = self.get_profile(profile_id) - server_list = profile[u'host'] + server_list = profile['host'] while server_list: remote_agent_hostname = server_list[-1] remote_agent_hostaddr = remote_agent_hostname - remote_agent_port = profile[u'sshport'] - if profile.has_key('sshport={hostname}'.format(hostname=remote_agent_hostname)): + remote_agent_port = profile['sshport'] + if 'sshport={hostname}'.format(hostname=remote_agent_hostname) in profile: remote_agent_port = profile["sshport={hostname}".format(hostname=remote_agent_hostname)] - if profile.has_key('host={hostname}'.format(hostname=remote_agent_hostname)): + if 'host={hostname}'.format(hostname=remote_agent_hostname) in profile: remote_agent_hostaddr = profile["host={hostname}".format(hostname=remote_agent_hostname)] remote_agents.append({ - u'hostname': remote_agent_hostname, - u'hostaddr': remote_agent_hostaddr, - u'port': remote_agent_port, } + 'hostname': remote_agent_hostname, + 'hostaddr': remote_agent_hostaddr, + 'port': remote_agent_port, } ) server_list = server_list[0:-1] @@ -1227,7 +1228,7 @@ class X2GoBroker(object): acls = self.get_profile_acls(profile_id) if self.check_profile_acls(username, acls): - for key in copy.deepcopy(profile).keys(): + for key in list(copy.deepcopy(profile).keys()): if profile[key] == "not-set": del profile[key] @@ -1238,11 +1239,11 @@ class X2GoBroker(object): if key.startswith('sshport=') and broker_frontend != 'uccs': del profile[key] if key == 'user' and profile[key] == 'BROKER_USER': - profile[key] = unicode(username) + profile[key] = username if self.get_session_autologin(profile_id): profile['autologin'] = True - profile['key'] = u'<will-be-exchanged-during-session-selection>' + profile['key'] = '<will-be-exchanged-during-session-selection>' # make sure that desktop sessions (that we know by name) do run with rootless=false # and that the command string is always upper case (otherwise x2goruncommand might @@ -1263,15 +1264,15 @@ class X2GoBroker(object): suspended_matching_hostnames = x2gobroker.utils.matching_hostnames(profile['host'], suspended_sessions) running_matching_hostnames = x2gobroker.utils.matching_hostnames(profile['host'], running_sessions) if suspended_matching_hostnames: - profile['status'] = u'S' + profile['status'] = 'S' profile['host'] = [suspended_matching_hostnames[0]] elif running_matching_hostnames: - profile['status'] = u'R' + profile['status'] = 'R' profile['host'] = [running_matching_hostnames[0]] else: profile['host'] = [profile['host'][0]] - if profile.has_key('status') and profile['status']: + if 'status' in profile and profile['status']: logger_broker.debug('base_broker.X2GoBroker.get_profile_for_user(): marking session profile {name} as {status}'.format(name=profile['name'], status=profile['status'])) except x2gobroker.x2gobroker_exceptions.X2GoBrokerAgentException: @@ -1324,7 +1325,7 @@ class X2GoBroker(object): return { 'server': 'no-server-available', 'port': 22, } # if we have more than one server, pick one server randomly for X2Go Broker Agent queries - server_list = profile[u'host'] + server_list = profile['host'] if len(server_list) == 0: return { 'server': 'no-server-available', 'port': profile['sshport'], } @@ -1401,7 +1402,7 @@ class X2GoBroker(object): # the host address as found in server_list (and hope we can connect # to that address. _session_server_name = session_info.split('|')[3] - if profile.has_key('host={server_name}'.format(server_name=_session_server_name)): + if 'host={server_name}'.format(server_name=_session_server_name) in profile: server_name = _session_server_name elif _session_server_name in server_list: server_name = _session_server_name @@ -1476,11 +1477,11 @@ class X2GoBroker(object): # the list of busy_servers only shows servers with sessions, but not those servers that are entirely idle... for server in server_list: - if server not in busy_servers.keys(): + if server not in list(busy_servers.keys()): busy_servers[server] = 0 # we will only contact servers that are (still) in server_list - for busy_server in busy_servers.keys(): + for busy_server in list(busy_servers.keys()): if busy_server not in server_list: del busy_servers[busy_server] @@ -1490,12 +1491,12 @@ class X2GoBroker(object): load_factors = remote_agent['load_factors'] busy_servers_temp = copy.deepcopy(busy_servers) - for busy_server in busy_servers_temp.keys(): - if busy_server in load_factors.keys() and type(load_factors[busy_server]) is not types.LongType: + for busy_server in list(busy_servers_temp.keys()): + if busy_server in list(load_factors.keys()) and type(load_factors[busy_server]) is not int: # if a host cannot report its load, let's ignore it... del busy_servers_temp[busy_server] - elif busy_server in load_factors.keys() and ( type(load_factors[busy_server]) is types.LongType or busy_servers[busy_server] == 0): + elif busy_server in list(load_factors.keys()) and ( type(load_factors[busy_server]) is int or busy_servers[busy_server] == 0): # when using the load checker service, then busy_servers contains the number of sessions per host @@ -1511,10 +1512,10 @@ class X2GoBroker(object): if busy_servers_temp is not None: busy_servers = copy.deepcopy(busy_servers_temp) - busy_server_list = [ (load, server) for server, load in busy_servers.items() ] + busy_server_list = [ (load, server) for server, load in list(busy_servers.items()) ] busy_server_list.sort() - logger_broker.debug('base_broker.X2GoBroker.select_session(): load balancer analysis: {server_load}'.format(server_load=unicode(busy_server_list))) + logger_broker.debug('base_broker.X2GoBroker.select_session(): load balancer analysis: {server_load}'.format(server_load=busy_server_list)) server_name = busy_server_list[0][1] @@ -1531,7 +1532,7 @@ class X2GoBroker(object): _save_busy_servers = None else: - logger_broker.warning('base_broker.X2GoBroker.select_session(): no broker agent could be contacted, this does not look good. We tried these agent hosts: {agent_hosts}'.format(agent_hosts=unicode(initial_server_list))) + logger_broker.warning('base_broker.X2GoBroker.select_session(): no broker agent could be contacted, this does not look good. We tried these agent hosts: {agent_hosts}'.format(agent_hosts=initial_server_list)) # detect best X2Go server for this user if load balancing is configured elif len(server_list) >= 2: @@ -1566,8 +1567,8 @@ class X2GoBroker(object): if server_list: if not self.get_portscan_x2goservers(profile_id) or x2gobroker.utils.portscan(addr=server_name, port=server_port) or x2gobroker.utils.portscan(addr=server_addr, port=server_port): selected_session = { - u'server': server_addr, - u'port': server_port, + 'server': server_addr, + 'port': server_port, } else: server_list.remove(server_name) @@ -1577,7 +1578,7 @@ class X2GoBroker(object): logger_broker.warning('base_broker.X2GoBroker.select_session(): failed to contact host \'{down_server}\', trying next server \'{next_server}\''.format(down_server=server_name, next_server=server_list[0])) server_name = server_list[0] else: - logger_broker.error('base_broker.X2GoBroker.select_session(): no X2Go Server could be contacted, session startup will fail, tried these hosts: {server_list}'.format(server_list=unicode(initial_server_list))) + logger_broker.error('base_broker.X2GoBroker.select_session(): no X2Go Server could be contacted, session startup will fail, tried these hosts: {server_list}'.format(server_list=initial_server_list)) # If we arrive here and session_list carries an entry for this user, then the session DB probably still # carries a zombie session entry (that will disappear when the down X2Go Server comes up again (cleanup @@ -1591,8 +1592,8 @@ class X2GoBroker(object): if not selected_session and not server_list: if len(initial_server_list) > 1: selected_session = { - u'server': u'no-X2Go-Server-available', - u'port': server_port, + 'server': 'no-X2Go-Server-available', + 'port': server_port, } else: # hand-over the original hostname for non-load-balanced session profiles @@ -1603,8 +1604,8 @@ class X2GoBroker(object): try: failed_server_name = profile['host={hostname}'.format(hostname=failed_server_name)] except KeyError: pass selected_session = { - u'server': failed_server_name, - u'port': failed_server_port, + 'server': failed_server_name, + 'port': failed_server_port, } # are we resuming a running/suspended session? @@ -1612,14 +1613,14 @@ class X2GoBroker(object): selected_session['session_info'] = session_info # define a remote SSH proxy agent if an SSH proxy host is used with this session profile - if profile.has_key(u'sshproxyhost') and profile[u'sshproxyhost']: + if 'sshproxyhost' in profile and profile['sshproxyhost']: remote_sshproxy_agent = { - u'hostname': profile[u'sshproxyhost'], - u'hostaddr': profile[u'sshproxyhost'], - u'port': "22" + 'hostname': profile['sshproxyhost'], + 'hostaddr': profile['sshproxyhost'], + 'port': "22" } - if profile.has_key(u'sshproxyport') and profile[u'sshproxyport']: - remote_sshproxy_agent[u'port'] = profile[u'sshproxyport'] + if 'sshproxyport' in profile and profile['sshproxyport']: + remote_sshproxy_agent['port'] = profile['sshproxyport'] else: remote_sshproxy_agent = None @@ -1627,11 +1628,11 @@ class X2GoBroker(object): if remote_agent and self.get_session_autologin(profile_id) and username: # let's use the chosen server_name if remote_agent is reachable via SSH - if type(remote_agent) is types.DictType: + if type(remote_agent) is dict: remote_agent = { - u'hostname': server_name, - u'hostaddr': server_addr, - u'port': selected_session[u'port'], + 'hostname': server_name, + 'hostaddr': server_addr, + 'port': selected_session['port'], } if not pubkey: @@ -1727,8 +1728,9 @@ class X2GoBroker(object): try: if script: my_script=None - exec("import x2gobroker.optional_scripts.{script}_script".format(script=script)) - exec("my_script = x2gobroker.optional_scripts.{script}_script.X2GoBrokerOptionalScript()".format(script=script)) + namespace = {} + exec("import x2gobroker.optional_scripts.{script}_script\nmy_script = x2gobroker.optional_scripts.{script}_script.X2GoBrokerOptionalScript()".format(script=script), namespace) + my_script = namespace['my_script'] logger_broker.debug ('Calling {script_type} {script} with username: {username}, password: {password}, task: {task}, profile_id: {profile_id}, ip: {ip}, cookie: {cookie}, authed: {authed}, server: {server}'.format(script_type=script_type,script=script,username=username, password='XXXXX', task=task, profile_id=profile_id, ip=ip, cookie=cookie, authed=authed, server=server)) username, password, task, profile_id, ip, cookie, authed, server = my_script.run_me(username=username, password=password, task=task, profile_id=profile_id, ip=ip, cookie=cookie, authed=authed, server=server) logger_broker.debug ('Finished {script_type} {script} with username: {username}, password: {password}, task: {task}, profile_id: {profile_id}, ip: {ip}, cookie: {cookie}, authed: {authed}, server: {server}'.format(script_type=script_type,script=script,username=username, password='XXXXX', task=task, profile_id=profile_id, ip=ip, cookie=cookie, authed=authed, server=server)) diff --git a/x2gobroker/brokers/inifile_broker.py b/x2gobroker/brokers/inifile_broker.py index c2d3c5f..04f83c5 100644 --- a/x2gobroker/brokers/inifile_broker.py +++ b/x2gobroker/brokers/inifile_broker.py @@ -29,12 +29,12 @@ import netaddr import re # Python X2GoBroker modules -import base_broker as base +import x2gobroker.brokers.base_broker as base import x2gobroker.config import x2gobroker.defaults import x2gobroker.x2gobroker_exceptions -from ConfigParser import NoSectionError +from configparser import NoSectionError class X2GoBroker(base.X2GoBroker): @@ -61,7 +61,7 @@ class X2GoBroker(base.X2GoBroker): def get_profile_defaults(self): profile_defaults = self.session_profiles.get_defaults() - for key in profile_defaults.keys(): + for key in list(profile_defaults.keys()): if key.startswith('acl-'): del profile_defaults[key] return profile_defaults @@ -74,10 +74,10 @@ class X2GoBroker(base.X2GoBroker): raise x2gobroker.x2gobroker_exceptions.X2GoBrokerProfileException('No such session profile ID: {profile_id}'.format(profile_id=profile_id)) profile_defaults = self.get_profile_defaults() - for key in profile_defaults.keys(): - if key not in profile.keys(): + for key in list(profile_defaults.keys()): + if key not in list(profile.keys()): profile.update({ key: profile_defaults[key] }) - for key in profile.keys(): + for key in list(profile.keys()): if key.startswith('acl-'): del profile[key] if key.startswith('broker-'): @@ -113,7 +113,7 @@ class X2GoBroker(base.X2GoBroker): def get_profile_broker(self, profile_id): profile = self.session_profiles.get_section(profile_id) - for key in profile.keys(): + for key in list(profile.keys()): if not key.startswith('broker-'): del profile[key] if key.startswith('broker-') and (profile[key] == '' or profile[key] == ['']): @@ -123,7 +123,7 @@ class X2GoBroker(base.X2GoBroker): def get_profile_acls(self, profile_id): profile = self.session_profiles.get_section(profile_id) - for key in profile.keys(): + for key in list(profile.keys()): if not key.startswith('acl-'): del profile[key] if key.startswith('acl-') and (profile[key] == '' or profile[key] == ['']): diff --git a/x2gobroker/brokers/zeroconf_broker.py b/x2gobroker/brokers/zeroconf_broker.py index f84a78e..1fa8293 100644 --- a/x2gobroker/brokers/zeroconf_broker.py +++ b/x2gobroker/brokers/zeroconf_broker.py @@ -27,7 +27,7 @@ __NAME__ = 'x2gobroker-pylib' import uuid # Python X2GoBroker modules -import base_broker as base +import x2gobroker.brokers.base_broker as base class X2GoBroker(base.X2GoBroker): @@ -37,44 +37,44 @@ class X2GoBroker(base.X2GoBroker): _list_of_profiles = { uuid.uuid4(): { - u'user': u'', - u'defsndport': True, - u'useiconv': False, - u'iconvfrom': u'UTF-8', - u'height': 600, - u'export': u'', - u'quality': 9, - u'fullscreen': False, - u'layout': u'', - u'useexports': 1, - u'width': 800, - u'speed': 2, - u'soundsystem': u'pulse', - u'print': True, - u'type': u'auto', - u'sndport': 4713, - u'xinerama': True, - u'variant': u'', - u'usekbd': True, - u'fstunnel': True, - u'applications': [u'TERMINAL',u'WWWBROWSER',u'MAILCLIENT',u'OFFICE',], - u'host': u'localhost', - u'multidisp': 0, - u'sshproxyport': 22, - u'sound': True, - u'rootless': 0, - u'name': u'LOCALHOST', - u'iconvto': u'UTF-8', - u'soundtunnel': True, - u'command': self.get_backend_value('broker_{backend}'.format(backend=self.backend_name), u'desktop-shell').upper(), - u'dpi': 96, - u'sshport': 22, - u'setdpi': 0, - u'pack': u'16m-jpeg', + 'user': '', + 'defsndport': True, + 'useiconv': False, + 'iconvfrom': 'UTF-8', + 'height': 600, + 'export': '', + 'quality': 9, + 'fullscreen': False, + 'layout': '', + 'useexports': 1, + 'width': 800, + 'speed': 2, + 'soundsystem': 'pulse', + 'print': True, + 'type': 'auto', + 'sndport': 4713, + 'xinerama': True, + 'variant': '', + 'usekbd': True, + 'fstunnel': True, + 'applications': ['TERMINAL','WWWBROWSER','MAILCLIENT','OFFICE',], + 'host': 'localhost', + 'multidisp': 0, + 'sshproxyport': 22, + 'sound': True, + 'rootless': 0, + 'name': 'LOCALHOST', + 'iconvto': 'UTF-8', + 'soundtunnel': True, + 'command': self.get_backend_value('broker_{backend}'.format(backend=self.backend_name), 'desktop-shell').upper(), + 'dpi': 96, + 'sshport': 22, + 'setdpi': 0, + 'pack': '16m-jpeg', }, } list_of_profiles = {} - for profile_id in _list_of_profiles.keys(): + for profile_id in list(_list_of_profiles.keys()): profile = self.get_profile_defaults() profile.update(_list_of_profiles[profile_id]) list_of_profiles[profile_id] = profile diff --git a/x2gobroker/client/plain.py b/x2gobroker/client/plain.py index aa68bd1..4f7cac8 100644 --- a/x2gobroker/client/plain.py +++ b/x2gobroker/client/plain.py @@ -20,7 +20,6 @@ # modules import os -import types # Python X2Go Broker modules import x2gobroker.defaults @@ -42,14 +41,15 @@ class X2GoBrokerClient(object): broker_backend = None try: # dynamically detect broker backend from given backend - exec("import x2gobroker.brokers.{backend}_broker".format(backend=backend)) - exec("broker_backend = x2gobroker.brokers.{backend}_broker.X2GoBroker()".format(backend=backend)) + namespace = {} + exec("import x2gobroker.brokers.{backend}_broker\nbroker_backend = x2gobroker.brokers.{backend}_broker.X2GoBroker()".format(backend=backend), namespace) + broker_backend = namespace['broker_backend'] except ImportError: logger_broker.error('unknown backend: {backend}'.format(backend=backend)) if broker_backend.is_enabled(): - if os.environ.has_key('SSH_CLIENT'): + if 'SSH_CLIENT' in os.environ: ip = os.environ['SSH_CLIENT'].split()[0] else: ip = '127.0.0.1' @@ -101,19 +101,19 @@ class X2GoBrokerClient(object): profiles = broker_backend.list_profiles(username) if profiles: output += "START_USER_SESSIONS\n\n" - profile_ids = profiles.keys() + profile_ids = list(profiles.keys()) profile_ids.sort() for profile_id in profile_ids: output += "[{profile_id}]\n".format(profile_id=profile_id) - for key in profiles[profile_id].keys(): - if key == u'user' and not profiles[profile_id][key]: + for key in list(profiles[profile_id].keys()): + if key == 'user' and not profiles[profile_id][key]: profiles[profile_id][key] = username - if type(profiles[profile_id][key]) in (types.UnicodeType, types.StringType): - output += "{key}={value}".format(key=key, value=unicode(profiles[profile_id][key])) - elif type(profiles[profile_id][key]) in (types.ListType, types.TupleType): - output += "{key}={value}".format(key=key, value=unicode(",".join(profiles[profile_id][key]))) + if type(profiles[profile_id][key]) == str: + output += "{key}={value}".format(key=key, value=profiles[profile_id][key]) + elif type(profiles[profile_id][key]) in (list, tuple): + output += "{key}={value}".format(key=key, value=",".join(profiles[profile_id][key])) else: - output += "{key}={value}".format(key=key, value=unicode(int(profiles[profile_id][key]))) + output += "{key}={value}".format(key=key, value=int(profiles[profile_id][key])) output += "\n" output += "\n" @@ -128,15 +128,15 @@ class X2GoBrokerClient(object): username, password, task, profile_id, ip, cookie, authed, server = broker_backend.run_optional_script(script_type='select_session_scripts', username=username, password="SSH", task=task, profile_id=profile_id, ip=ip, cookie=cookie, authed=access, server=profile_info['server']) - if profile_info.has_key('server'): + if 'server' in profile_info: output += "SERVER:" output += profile_info['server'] - if profile_info.has_key('port'): + if 'port' in profile_info: output += ":{port}".format(port=profile_info['port']) output += "\n" - if profile_info.has_key('authentication_privkey'): + if 'authentication_privkey' in profile_info: output += profile_info['authentication_privkey'] - if profile_info.has_key('session_info'): + if 'session_info' in profile_info: output += "SESSION_INFO:" output += profile_info['session_info'] + "\n" diff --git a/x2gobroker/config.py b/x2gobroker/config.py index 94bbd75..772f668 100644 --- a/x2gobroker/config.py +++ b/x2gobroker/config.py @@ -29,9 +29,8 @@ __NAME__ = 'x2goinifiles-pylib' # modules import os -import ConfigParser -import types -import cStringIO +import configparser +import io # Python X2GoBroker modules import x2gobroker.utils @@ -70,18 +69,18 @@ class X2GoBrokerConfigFile(object): """ # allow string/unicode objects as config_files, as well - if type(config_files) in (types.StringType, types.UnicodeType): + if type(config_files) == str: config_files = [config_files] self.config_files = config_files if x2gobroker.utils._checkConfigFileDefaults(defaults): self.defaultValues = defaults - # we purposefully do not inherit the C{ConfigParser} class + # we purposefully do not inherit the RawConfigParser class # here as we do not want to run into name conflicts between # X2GoBroker config file options and method / property names in - # C{ConfigParser}... This is a pre-cautious approach... - self.iniConfig = ConfigParser.ConfigParser(self.defaultValues) + # RawConfigParser... This is a pre-cautious approach... + self.iniConfig = configparser.RawConfigParser(self.defaultValues) self.iniConfig.optionxform = str _create_file = False @@ -126,7 +125,7 @@ class X2GoBrokerConfigFile(object): """\ Stores a value for a given section and key. - This methods affects a ConfigParser object held in + This methods affects a C{RawConfigParser} object held in RAM. No configuration file is affected by this method. To write the configuration to disk use the L{write()} method. @@ -139,27 +138,28 @@ class X2GoBrokerConfigFile(object): @type value: C{str}, C{list}, C{booAl}, ... """ - if type(value) == type(u''): - value = value.encode(x2gobroker.utils.get_encoding()) - if type(value) is types.BooleanType: + print((type (value))) + if type(value) is bool: self.iniConfig.set(section, key, str(int(value))) - elif type(value) in (types.ListType, types.TupleType): + elif type(value) in (list, tuple): self.iniConfig.set(section, key, ", ".join(value)) - else: + elif type(value) is int: self.iniConfig.set(section, key, str(value)) + else: + self.iniConfig.set(section, key, value) def _fill_defaults(self): """\ - Fills a C{ConfigParser} object with the default config file - values as pre-defined in Python X2GoBroker or. This ConfigParser + Fills a C{RawConfigParser} object with the default config file + values as pre-defined in Python X2GoBroker or. This RawConfigParser object is held in RAM. No configuration file is affected by this method. """ - for section, sectiondict in self.defaultValues.items(): + for section, sectiondict in list(self.defaultValues.items()): if section != 'DEFAULT' and not self.iniConfig.has_section(section): self.iniConfig.add_section(section) - for key, value in sectiondict.items(): + for key, value in list(sectiondict.items()): if self.iniConfig.has_option(section, key): continue self._storeValue(section, key, value) @@ -183,14 +183,14 @@ class X2GoBrokerConfigFile(object): def write(self): """\ - Write the ini file modifications (ConfigParser object) from RAM to disk. + Write the ini file modifications (RawConfigParser object) from RAM to disk. For writing the first of the C{config_files} specified on instance construction that is writable will be used. """ if self.user_config_file and self.write_user_config: - fd = open(self.user_config_file, 'wb') + fd = open(self.user_config_file, 'w') self.iniConfig.write(fd) fd.close() self.write_user_config = False @@ -209,13 +209,13 @@ class X2GoBrokerConfigFile(object): @rtype: class """ - if section in self.defaultValues.keys() and key in self.defaultValues[section].keys(): + if section in list(self.defaultValues.keys()) and key in list(self.defaultValues[section].keys()): return type(self.defaultValues[section][key]) else: try: return type(self.defaultValues['DEFAULT'][key]) except KeyError: - return type(u'') + return type('') def has_value(self, section, key): """\ @@ -257,20 +257,20 @@ class X2GoBrokerConfigFile(object): return self.iniConfig.get(section, key) - if key_type is types.BooleanType: + if key_type is bool: return self.iniConfig.getboolean(section, key) - elif key_type is types.IntType: + elif key_type is int: try: return self.iniConfig.getint(section, key) except ValueError: _val = self.iniConfig.get(section, key) - if _val != u"not-set": raise + if _val != "not-set": raise else: return _val - elif key_type is types.ListType: + elif key_type is list: _val = self.iniConfig.get(section, key) _val = _val.strip() @@ -298,13 +298,13 @@ class X2GoBrokerConfigFile(object): """ _my_defaults = {} _ini_defaults = self.iniConfig.defaults() - for option in _ini_defaults.keys(): + for option in list(_ini_defaults.keys()): try: - _my_defaults[unicode(option)] = self.get('DEFAULT', option, key_type=self.get_type('DEFAULT', option)) + _my_defaults[option] = self.get('DEFAULT', option, key_type=self.get_type('DEFAULT', option)) except KeyError: continue - try: del _my_defaults[u'default'] + try: del _my_defaults['default'] except KeyError: pass return _my_defaults @@ -324,7 +324,7 @@ class X2GoBrokerConfigFile(object): _section_config = {} for option in self.iniConfig.options(section): if option not in self.iniConfig.sections(): - _section_config[unicode(option)] = self.get(section, option, key_type=self.get_type(section, option)) + _section_config[option] = self.get(section, option, key_type=self.get_type(section, option)) return _section_config @@ -336,7 +336,7 @@ class X2GoBrokerConfigFile(object): @rtype: C{list} """ - return [ unicode(s) for s in self.iniConfig.sections() ] + return [ s for s in self.iniConfig.sections() ] @property def printable_config_file(self): @@ -344,7 +344,7 @@ class X2GoBrokerConfigFile(object): Returns a printable configuration file as a multi-line string. """ - stdout = cStringIO.StringIO() + stdout = io.StringIO() self.iniConfig.write(stdout) _ret_val = stdout.getvalue() stdout.close() diff --git a/x2gobroker/defaults.py b/x2gobroker/defaults.py index 0e55ee1..9ed7abf 100644 --- a/x2gobroker/defaults.py +++ b/x2gobroker/defaults.py @@ -24,16 +24,16 @@ import socket import pwd, grp import logging -from loggers import logger_broker, logger_access, logger_error, X2GOBROKER_DAEMON_USER -from loggers import iniconfig_loaded +from x2gobroker.loggers import logger_broker, logger_access, logger_error, X2GOBROKER_DAEMON_USER +from x2gobroker.loggers import iniconfig_loaded if iniconfig_loaded: - from loggers import iniconfig, iniconfig_section + from x2gobroker.loggers import iniconfig, iniconfig_section X2GOBROKER_USER = pwd.getpwuid(os.geteuid())[0] X2GOBROKER_GROUP = grp.getgrgid(pwd.getpwuid(os.geteuid())[3])[0] os.environ['HOME'] = pwd.getpwuid(os.geteuid())[5] -if os.environ.has_key('X2GOBROKER_DAEMON_GROUP'): +if 'X2GOBROKER_DAEMON_GROUP' in os.environ: X2GOBROKER_DAEMON_GROUP=os.environ['X2GOBROKER_DAEMON_GROUP'] elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_DAEMON_GROUP'): X2GOBROKER_DAEMON_GROUP=iniconfig.get(iniconfig_section, 'X2GOBROKER_DAEMON_GROUP') @@ -41,7 +41,7 @@ elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_DAEMON_GROU X2GOBROKER_DAEMON_GROUP=iniconfig.get('common', 'X2GOBROKER_DAEMON_GROUP') else: X2GOBROKER_DAEMON_GROUP="x2gobroker" -if os.environ.has_key('X2GOBROKER_AGENT_USER'): +if 'X2GOBROKER_AGENT_USER' in os.environ: X2GOBROKER_AGENT_USER=os.environ['X2GOBROKER_AGENT_USER'] elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_AGENT_USER'): X2GOBROKER_AGENT_USER=iniconfig.get(iniconfig_section, 'X2GOBROKER_AGENT_USER') @@ -54,7 +54,7 @@ else: ### dynamic default values, influencable through os.environ... ### -if os.environ.has_key('X2GOBROKER_DEBUG'): +if 'X2GOBROKER_DEBUG' in os.environ: X2GOBROKER_DEBUG = ( os.environ['X2GOBROKER_DEBUG'].lower() in ('1', 'on', 'true', 'yes', ) ) elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_DEBUG'): X2GOBROKER_DEBUG=iniconfig.get(iniconfig_section, 'X2GOBROKER_DEBUG') @@ -62,7 +62,7 @@ elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_DEBUG'): X2GOBROKER_DEBUG=iniconfig.get('common', 'X2GOBROKER_DEBUG') else: X2GOBROKER_DEBUG = False -if os.environ.has_key('X2GOBROKER_DEBUG_INTERACTIVELY'): +if 'X2GOBROKER_DEBUG_INTERACTIVELY' in os.environ: X2GOBROKER_DEBUG_INTERACTIVELY = ( os.environ['X2GOBROKER_DEBUG_INTERACTIVELY'].lower() in ('1', 'on', 'true', 'yes', ) ) elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_DEBUG_INTERACTIVELY'): X2GOBROKER_DEBUG_INTERACTIVELY=iniconfig.get(iniconfig_section, 'X2GOBROKER_DEBUG_INTERACTIVELY') @@ -70,7 +70,7 @@ elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_DEBUG_INTER X2GOBROKER_DEBUG_INTERACTIVELY=iniconfig.get('common', 'X2GOBROKER_DEBUG_INTERACTIVELY') else: X2GOBROKER_DEBUG_INTERACTIVELY = False -if os.environ.has_key('X2GOBROKER_TESTSUITE'): +if 'X2GOBROKER_TESTSUITE' in os.environ: X2GOBROKER_TESTSUITE = ( os.environ['X2GOBROKER_TESTSUITE'].lower() in ('1', 'on', 'true', 'yes', ) ) elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_TESTSUITE'): X2GOBROKER_TESTSUITE=iniconfig.get(iniconfig_section, 'X2GOBROKER_TESTSUITE') @@ -89,7 +89,7 @@ if X2GOBROKER_TESTSUITE: logger_access.setLevel(logging.CRITICAL) logger_error.setLevel(logging.CRITICAL) -if os.environ.has_key('X2GOBROKER_CONFIG'): +if 'X2GOBROKER_CONFIG' in os.environ: X2GOBROKER_CONFIG = os.environ['X2GOBROKER_CONFIG'] elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_CONFIG'): X2GOBROKER_CONFIG=iniconfig.get(iniconfig_section, 'X2GOBROKER_CONFIG') @@ -98,7 +98,7 @@ elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_CONFIG'): else: X2GOBROKER_CONFIG = "/etc/x2go/x2gobroker.conf" -if os.environ.has_key('X2GOBROKER_SESSIONPROFILES'): +if 'X2GOBROKER_SESSIONPROFILES' in os.environ: X2GOBROKER_SESSIONPROFILES = os.environ['X2GOBROKER_SESSIONPROFILES'] elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_SESSIONPROFILES'): X2GOBROKER_SESSIONPROFILES=iniconfig.get(iniconfig_section, 'X2GOBROKER_SESSIONPROFILES') @@ -107,7 +107,7 @@ elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_SESSIONPROF else: X2GOBROKER_SESSIONPROFILES = "/etc/x2go/broker/x2gobroker-sessionprofiles.conf" -if os.environ.has_key('X2GOBROKER_AGENT_CMD'): +if 'X2GOBROKER_AGENT_CMD' in os.environ: X2GOBROKER_AGENT_CMD = os.environ['X2GOBROKER_AGENT_CMD'] elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_AGENT_CMD'): X2GOBROKER_AGENT_CMD=iniconfig.get(iniconfig_section, 'X2GOBROKER_AGENT_CMD') @@ -116,7 +116,7 @@ elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_AGENT_CMD') else: X2GOBROKER_AGENT_CMD = "/usr/lib/x2go/x2gobroker-agent" -if os.environ.has_key('X2GOBROKER_AUTHSERVICE_SOCKET'): +if 'X2GOBROKER_AUTHSERVICE_SOCKET' in os.environ: X2GOBROKER_AUTHSERVICE_SOCKET=os.environ['X2GOBROKER_AUTHSERVICE_SOCKET'] elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_AUTHSERVICE_SOCKET'): X2GOBROKER_AUTHSERVICE_SOCKET=iniconfig.get(iniconfig_section, 'X2GOBROKER_AUTHSERVICE_SOCKET') @@ -129,7 +129,7 @@ else: RUNDIR = '/var/run/x2gobroker' X2GOBROKER_AUTHSERVICE_SOCKET="{run}/x2gobroker/x2gobroker-authservice.socket".format(run=RUNDIR) -if os.environ.has_key('X2GOBROKER_LOADCHECKER_SOCKET'): +if 'X2GOBROKER_LOADCHECKER_SOCKET' in os.environ: X2GOBROKER_LOADCHECKER_SOCKET=os.environ['X2GOBROKER_LOADCHECKER_SOCKET'] elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_LOADCHECKER_SOCKET'): X2GOBROKER_LOADCHECKER_SOCKET=iniconfig.get(iniconfig_section, 'X2GOBROKER_LOADCHECKER_SOCKET') @@ -142,7 +142,7 @@ else: RUNDIR = '/var/run/x2gobroker' X2GOBROKER_LOADCHECKER_SOCKET="{run}/x2gobroker/x2gobroker-loadchecker.socket".format(run=RUNDIR) -if os.environ.has_key('X2GOBROKER_DEFAULT_BACKEND'): +if 'X2GOBROKER_DEFAULT_BACKEND' in os.environ: X2GOBROKER_DEFAULT_BACKEND = os.environ['X2GOBROKER_DEFAULT_BACKEND'] elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_DEFAULT_BACKEND'): X2GOBROKER_DEFAULT_BACKEND=iniconfig.get(iniconfig_section, 'X2GOBROKER_DEFAULT_BACKEND') @@ -151,7 +151,7 @@ elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_DEFAULT_BAC else: X2GOBROKER_DEFAULT_BACKEND = "inifile" -if os.environ.has_key('DAEMON_BIND_ADDRESS'): +if 'DAEMON_BIND_ADDRESS' in os.environ: DAEMON_BIND_ADDRESS = os.environ['DAEMON_BIND_ADDRESS'] elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'DAEMON_BIND_ADDRESS'): DAEMON_BIND_ADDRESS = iniconfig.get(iniconfig_section, 'DAEMON_BIND_ADDRESS') @@ -160,7 +160,7 @@ elif iniconfig_loaded and iniconfig.has_option('daemon', 'DAEMON_BIND_ADDRESS'): else: DAEMON_BIND_ADDRESS = "" -if os.environ.has_key('X2GOBROKER_SSL_CERTFILE'): +if 'X2GOBROKER_SSL_CERTFILE' in os.environ: X2GOBROKER_SSL_CERTFILE = os.environ['X2GOBROKER_SSL_CERTFILE'] elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_SSL_CERTFILE'): X2GOBROKER_SSL_CERTFILE = iniconfig.get(iniconfig_section, 'X2GOBROKER_SSL_CERTFILE') @@ -169,7 +169,7 @@ elif iniconfig_loaded and iniconfig.has_option('daemon', 'X2GOBROKER_SSL_CERTFIL else: X2GOBROKER_SSL_CERTFILE = "" -if os.environ.has_key('X2GOBROKER_SSL_KEYFILE'): +if 'X2GOBROKER_SSL_KEYFILE' in os.environ: X2GOBROKER_SSL_KEYFILE = os.environ['X2GOBROKER_SSL_KEYFILE'] elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_SSL_KEYFILE'): X2GOBROKER_SSL_KEYFILE = iniconfig.get(iniconfig_section, 'X2GOBROKER_SSL_KEYFILE') @@ -195,67 +195,67 @@ X2GOBROKER_CONFIG_DEFAULTS = { 'global': { # legacy support for X2Go Session Broker << 0.0.3.0 # the check-credentials parameter has been slit up into the two params above - u'check-credentials': True, + 'check-credentials': True, # use these two instead of check-credentials... - u'require-password': True, - u'require-cookie': False, - u'use-static-cookie': False, - u'auth-timeout': 36000, - u'cookie-directory': '/var/lib/x2gobroker/cookies', - u'verify-ip': True, - u'pre_auth_scripts': [], - u'post_auth_scripts': [], - u'select_session_scripts': [], - u'my-cookie': uuid.uuid4(), - u'my-cookie-file': '/etc/x2go/broker/x2gobroker.authid', - u'enable-plain-output': True, - u'enable-json-output': True, - u'enable-uccs-output': False, - u'my-uccs-url-base': 'http://localhost:8080/', - u'default-auth-mech': u'pam', - u'default-user-db': u'libnss', - u'default-group-db': u'libnss', - u'ignore-primary-group-memberships': True, - u'default-session-autologin': False, - u'default-authorized-keys': u'%h/.x2go/authorized_keys', - u'default-sshproxy-authorized-keys': u'%h/.x2go/authorized_keys', - u'default-agent-query-mode': u'NONE', - u'default-portscan-x2goservers': True, - u'default-use-load-checker': False, - u'load-checker-intervals': 300, + 'require-password': True, + 'require-cookie': False, + 'use-static-cookie': False, + 'auth-timeout': 36000, + 'cookie-directory': '/var/lib/x2gobroker/cookies', + 'verify-ip': True, + 'pre_auth_scripts': [], + 'post_auth_scripts': [], + 'select_session_scripts': [], + 'my-cookie': uuid.uuid4(), + 'my-cookie-file': '/etc/x2go/broker/x2gobroker.authid', + 'enable-plain-output': True, + 'enable-json-output': True, + 'enable-uccs-output': False, + 'my-uccs-url-base': 'http://localhost:8080/', + 'default-auth-mech': 'pam', + 'default-user-db': 'libnss', + 'default-group-db': 'libnss', + 'ignore-primary-group-memberships': True, + 'default-session-autologin': False, + 'default-authorized-keys': '%h/.x2go/authorized_keys', + 'default-sshproxy-authorized-keys': '%h/.x2go/authorized_keys', + 'default-agent-query-mode': 'NONE', + 'default-portscan-x2goservers': True, + 'default-use-load-checker': False, + 'load-checker-intervals': 300, }, 'broker_base': { - u'enable': False, + 'enable': False, }, 'broker_zeroconf': { - u'enable': False, - u'auth-mech': u'pam', - u'user-db': u'libnss', - u'group-db': u'libnss', - u'desktop-shell': u'KDE', - u'load-checker': False, + 'enable': False, + 'auth-mech': 'pam', + 'user-db': 'libnss', + 'group-db': 'libnss', + 'desktop-shell': 'KDE', + 'load-checker': False, }, 'broker_inifile': { - u'enable': True, - u'session-profiles': u'/etc/x2go/broker/x2gobroker-sessionprofiles.conf', - u'auth-mech': u'', - u'user-db': u'', - u'group-db': u'', - u'use-load-checker': True, + 'enable': True, + 'session-profiles': '/etc/x2go/broker/x2gobroker-sessionprofiles.conf', + 'auth-mech': '', + 'user-db': '', + 'group-db': '', + 'use-load-checker': True, }, 'broker_ldap': { - u'enable': False, - u'auth-mech': u'ldap', - u'user-db': u'ldap', - u'group-db': u'ldap', - u'uri': u'ldap://localhost:389', - u'base': u'dc=example,dc=org', - u'user-search-filter': u'(&(objectClass=posixAccount)(uid=*))', - u'host-search-filter': u'(&(objectClass=ipHost)(serial=X2GoServer)(cn=*))', - u'group-search-filter': u'(&(objectClass=posifxGroup)(cn=*))', - u'starttls': False, - u'agent-query-mode': u'SSH', - u'load-checker': True, + 'enable': False, + 'auth-mech': 'ldap', + 'user-db': 'ldap', + 'group-db': 'ldap', + 'uri': 'ldap://localhost:389', + 'base': 'dc=example,dc=org', + 'user-search-filter': '(&(objectClass=posixAccount)(uid=*))', + 'host-search-filter': '(&(objectClass=ipHost)(serial=X2GoServer)(cn=*))', + 'group-search-filter': '(&(objectClass=posifxGroup)(cn=*))', + 'starttls': False, + 'agent-query-mode': 'SSH', + 'load-checker': True, }, } @@ -276,50 +276,50 @@ X2GO_DESKTOP_SESSIONS= [ # defaults for X2Go Sessino Broker session profiles file X2GOBROKER_SESSIONPROFILE_DEFAULTS = { - u'DEFAULT': { - u'command': u'TERMINAL', - u'defsndport': True, - u'useiconv': False, - u'iconvfrom': u'UTF-8', - u'height': 600, - u'export': u'', - u'quality': 9, - u'fullscreen': False, - u'layout': u'', - u'useexports': True, - u'width': 800, - u'speed': 2, - u'soundsystem': u'pulse', - u'print': True, - u'type': u'auto', - u'sndport': 4713, - u'xinerama': True, - u'variant': u'', - u'usekbd': True, - u'fstunnel': True, - u'applications': [u'TERMINAL',u'WWWBROWSER',u'MAILCLIENT',u'OFFICE'], - u'multidisp': False, - u'sshproxyport': 22, - u'sound': True, - u'rootless': True, - u'iconvto': u'UTF-8', - u'soundtunnel': True, - u'dpi': 96, - u'sshport': 22, - u'setdpi': 0, - u'pack': u'16m-jpeg', - u'user': 'BROKER_USER', - u'host': [ u'localhost', ], - u'directrdp': False, - u'acl-users-allow': [], - u'acl-users-deny': [], - u'acl-users-order': '', - u'acl-groups-allow': [], - u'acl-groups-deny': [], - u'acl-groups-order': '', - u'acl-clients-allow': [], - u'acl-clients-deny': [], - u'acl-clients-order': '', - u'acl-any-order': u'deny-allow', + 'DEFAULT': { + 'command': 'TERMINAL', + 'defsndport': True, + 'useiconv': False, + 'iconvfrom': 'UTF-8', + 'height': 600, + 'export': '', + 'quality': 9, + 'fullscreen': False, + 'layout': '', + 'useexports': True, + 'width': 800, + 'speed': 2, + 'soundsystem': 'pulse', + 'print': True, + 'type': 'auto', + 'sndport': 4713, + 'xinerama': True, + 'variant': '', + 'usekbd': True, + 'fstunnel': True, + 'applications': ['TERMINAL','WWWBROWSER','MAILCLIENT','OFFICE'], + 'multidisp': False, + 'sshproxyport': 22, + 'sound': True, + 'rootless': True, + 'iconvto': 'UTF-8', + 'soundtunnel': True, + 'dpi': 96, + 'sshport': 22, + 'setdpi': 0, + 'pack': '16m-jpeg', + 'user': 'BROKER_USER', + 'host': [ 'localhost', ], + 'directrdp': False, + 'acl-users-allow': [], + 'acl-users-deny': [], + 'acl-users-order': '', + 'acl-groups-allow': [], + 'acl-groups-deny': [], + 'acl-groups-order': '', + 'acl-clients-allow': [], + 'acl-clients-deny': [], + 'acl-clients-order': '', + 'acl-any-order': 'deny-allow', }, } diff --git a/x2gobroker/loadchecker.py b/x2gobroker/loadchecker.py index c2eea74..b2a68c9 100644 --- a/x2gobroker/loadchecker.py +++ b/x2gobroker/loadchecker.py @@ -34,17 +34,17 @@ def check_load(backend, profile_id, hostname=None): logger_broker.debug('loadchecker.check_load(): connecting to load checker service socket {socket}'.format(socket=x2gobroker.defaults.X2GOBROKER_LOADCHECKER_SOCKET)) try: s.connect(x2gobroker.defaults.X2GOBROKER_LOADCHECKER_SOCKET) - except socket.error, e: + except socket.error as e: logger_broker.error('loadchecker.check_load(): failure when connecting to the load checker service socket {socket}: {errmsg}'.format(socket=x2gobroker.defaults.X2GOBROKER_LOADCHECKER_SOCKET, errmsg=str(e))) if hostname is not None: load_factor = 'LOAD-UNAVAILABLE' logger_broker.debug('loadchecker.check_load(): sending backend={backend}, profile_id={profile_id}, hostname={hostname} to load checker service'.format(backend=backend, profile_id=profile_id, hostname=hostname)) try: - s.send('{backend}\r{profile_id}\r{hostname}\n'.format(backend=backend, profile_id=profile_id, hostname=hostname)) - load_factor = s.recv(1024) + s.send('{backend}\r{profile_id}\r{hostname}\n'.format(backend=backend, profile_id=profile_id, hostname=hostname).encode()) + load_factor = s.recv(1024).decode() s.close() - except socket.error, e: + except socket.error as e: logger_broker.error('loadchecker.check_load(): failure when sending data to the load checker service socket {socket}: {errmsg}'.format(socket=x2gobroker.defaults.X2GOBROKER_LOADCHECKER_SOCKET, errmsg=str(e))) if load_factor.startswith('LOAD-UNAVAILABLE'): @@ -52,7 +52,7 @@ def check_load(backend, profile_id, hostname=None): return 'LOAD-UNAVAILABLE' try: - load_factor = long(load_factor) + load_factor = int(load_factor) except ValueError: logger_broker.warning('loadchecker.check_load(): load data for backend={backend}, profile_id={profile_id}, hostname={hostname} contained bogus (»{lf}«)'.format(backend=backend, profile_id=profile_id, hostname=hostname, lf=load_factor)) return 'LOAD-DATA-BOGUS' @@ -64,10 +64,10 @@ def check_load(backend, profile_id, hostname=None): raw_output = "" logger_broker.debug('loadchecker.check_load(): sending backend={backend}, profile_id={profile_id} to load checker service'.format(backend=backend, profile_id=profile_id, hostname=hostname)) try: - s.send('{backend}\r{profile_id}\r\n'.format(backend=backend, profile_id=profile_id)) - raw_output = s.recv(1024) + s.send('{backend}\r{profile_id}\r\n'.format(backend=backend, profile_id=profile_id).encode()) + raw_output = s.recv(1024).decode() s.close() - except socket.error, e: + except socket.error as e: logger_broker.error('loadchecker.check_load(): failure when sending data to the load checker service socket {socket}: {errmsg}'.format(socket=x2gobroker.defaults.X2GOBROKER_LOADCHECKER_SOCKET, errmsg=str(e))) load_factors = {} @@ -77,7 +77,7 @@ def check_load(backend, profile_id, hostname=None): key, val = item.split(':', 1) try: if val not in ('HOST-UNREACHABLE', 'LOAD-UNAVAILABLE', 'LOAD-DATA-BOGUS'): - load_factors[key] = long(val) + load_factors[key] = int(val) else: load_factors[key] = val except ValueError: @@ -176,18 +176,20 @@ class LoadChecker(threading.Thread): for backend in self.broker_backends: - if not self.server_load.has_key(backend): + if backend not in self.server_load: self.server_load[backend] = {} _broker_backend_module = None - exec("import x2gobroker.brokers.{backend}_broker as _broker_backend_module".format(backend=backend)) + namespace = {} + exec("import x2gobroker.brokers.{backend}_broker as _broker_backend_module".format(backend=backend), namespace) + _broker_backend_module = namespace['_broker_backend_module'] self.brokers[backend] = _broker_backend_module.X2GoBroker(config_file=self.config_file, config_defaults=self.config_defaults, **self.kwargs) profile_ids_to_check = [ id for id in self.brokers[backend].get_profile_ids() if self.brokers[backend].use_load_checker(id) ] if self.logger: self.logger.debug('LoadChecker.loadchecker(): backend={backend} -> processing profiles: {profile_ids}'.format(backend=backend, profile_ids=profile_ids_to_check)) for profile_id in profile_ids_to_check: - if not self.server_load[backend].has_key(profile_id): + if profile_id not in self.server_load[backend]: self.server_load[backend][profile_id] = {} remote_agents = self.brokers[backend].get_all_remote_agents(profile_id) if self.logger: self.logger.debug('LoadChecker.loadchecker(): querying remote agents for backend={backend}, profile_id={profile_id}: {remote_agents}'.format(backend=backend, profile_id=profile_id, remote_agents=remote_agents)) @@ -195,29 +197,29 @@ class LoadChecker(threading.Thread): _load_factor = x2gobroker.agent.check_load(remote_agent, logger=self.logger) num_queries += 1 if _load_factor is None: - if self.logger: self.logger.info('LoadChecker.loadchecker(): backend={backend}, profile_id={profile_id}, hostname={hostname}, load factor not available'.format(backend=backend, profile_id=profile_id, hostname=remote_agent[u'hostname'])) + if self.logger: self.logger.info('LoadChecker.loadchecker(): backend={backend}, profile_id={profile_id}, hostname={hostname}, load factor not available'.format(backend=backend, profile_id=profile_id, hostname=remote_agent['hostname'])) num_failed_queries += 1 else: - if self.logger: self.logger.info('LoadChecker.loadchecker(): contacted remote broker agent for backend={backend}, profile_id={profile_id}, hostname={hostname}, new load factor is: {lf}'.format(backend=backend, profile_id=profile_id, hostname=remote_agent[u'hostname'], lf=_load_factor)) - self.server_load[backend][profile_id][remote_agent[u'hostname']] = _load_factor + if self.logger: self.logger.info('LoadChecker.loadchecker(): contacted remote broker agent for backend={backend}, profile_id={profile_id}, hostname={hostname}, new load factor is: {lf}'.format(backend=backend, profile_id=profile_id, hostname=remote_agent['hostname'], lf=_load_factor)) + self.server_load[backend][profile_id][remote_agent['hostname']] = _load_factor if time_to_sleep > 0: if self.logger: self.logger.debug('LoadChecker.loadchecker(): sleeping for {secs}secs before querying next server'.format(secs=time_to_sleep)) time.sleep(time_to_sleep) # clean up vanished hostnames - _hostnames = self.server_load[backend][profile_id].keys() + _hostnames = list(self.server_load[backend][profile_id].keys()) for hostname in _hostnames: - if hostname not in [ ra[u'hostname'] for ra in remote_agents ]: + if hostname not in [ ra['hostname'] for ra in remote_agents ]: del self.server_load[backend][profile_id][hostname] # clean up vanished profile IDs - _profile_ids = copy.deepcopy(self.server_load[backend].keys()) + _profile_ids = copy.deepcopy(list(self.server_load[backend].keys())) for profile_id in _profile_ids: if profile_id not in profile_ids_to_check: del self.server_load[backend][profile_id] # clean up vanished backends - _backends = copy.deepcopy(self.server_load.keys()) + _backends = copy.deepcopy(list(self.server_load.keys())) for backend in _backends: if backend not in self.broker_backends: del self.server_load[backend] diff --git a/x2gobroker/loggers.py b/x2gobroker/loggers.py index 30af0ff..dd5d67e 100644 --- a/x2gobroker/loggers.py +++ b/x2gobroker/loggers.py @@ -22,7 +22,7 @@ import sys import getpass import logging import logging.config -import ConfigParser +import configparser def init_console_loggers(): """\ @@ -59,12 +59,12 @@ iniconfig_loaded = None iniconfig_section = '-'.join(PROG_NAME.split('-')[1:]) X2GOBROKER_DEFAULTS = "/etc/x2go/broker/defaults.conf" if os.path.isfile(X2GOBROKER_DEFAULTS) and os.access(X2GOBROKER_DEFAULTS, os.R_OK): - iniconfig = ConfigParser.SafeConfigParser() + iniconfig = configparser.RawConfigParser() iniconfig.optionxform = str iniconfig_loaded = iniconfig.read(X2GOBROKER_DEFAULTS) # normally this would go into defaults.py, however, we do not want to create a dependency loop between loggers.py and defaults.py... -if os.environ.has_key('X2GOBROKER_DAEMON_USER'): +if 'X2GOBROKER_DAEMON_USER' in os.environ: X2GOBROKER_DAEMON_USER=os.environ['X2GOBROKER_DAEMON_USER'] elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_DAEMON_USER'): X2GOBROKER_DAEMON_USER=iniconfig.get(iniconfig_section, 'X2GOBROKER_DAEMON_USER') @@ -72,7 +72,7 @@ elif iniconfig_loaded and iniconfig.has_option('common', 'X2GOBROKER_DAEMON_USER X2GOBROKER_DAEMON_USER=iniconfig.get('common', 'X2GOBROKER_DAEMON_USER') else: X2GOBROKER_DAEMON_USER="x2gobroker" -if os.environ.has_key('X2GOBROKER_LOGCONFIG'): +if 'X2GOBROKER_LOGCONFIG' in os.environ: X2GOBROKER_LOGCONFIG=os.environ['X2GOBROKER_LOGCONFIG'] elif iniconfig_loaded and iniconfig.has_option(iniconfig_section, 'X2GOBROKER_LOGCONFIG'): X2GOBROKER_LOGCONFIG=iniconfig.get(iniconfig_section, 'X2GOBROKER_LOGCONFIG') diff --git a/x2gobroker/nameservices/base_nameservice.py b/x2gobroker/nameservices/base_nameservice.py index b055800..cb64c66 100644 --- a/x2gobroker/nameservices/base_nameservice.py +++ b/x2gobroker/nameservices/base_nameservice.py @@ -20,23 +20,23 @@ class X2GoBrokerNameService(object): def has_user(self, username): - return unicode(username) in self.get_users() + return username in self.get_users() def get_users(self): return [] def get_primary_group(self, username): - return u'' + return '' def has_group(self, group): - return unicode(group) in self.get_groups() + return group in self.get_groups() def get_groups(self): return [] def is_group_member(self, username, group, primary_groups=False): _members = self.get_group_members(group, primary_groups=primary_groups) - return unicode(username) in _members + return username in _members def get_group_members(self, group, primary_groups=False): return [] @@ -45,5 +45,5 @@ class X2GoBrokerNameService(object): _groups = [] for _group in self.get_groups(): if self.is_group_member(username=username, group=_group, primary_groups=primary_groups): - _groups.append(unicode(_group)) + _groups.append(_group) return _groups diff --git a/x2gobroker/nameservices/libnss_nameservice.py b/x2gobroker/nameservices/libnss_nameservice.py index 03e02ab..7e804e4 100644 --- a/x2gobroker/nameservices/libnss_nameservice.py +++ b/x2gobroker/nameservices/libnss_nameservice.py @@ -22,7 +22,7 @@ import pwd import grp # Python X2GoBroker modules -import base_nameservice as base +from . import base_nameservice as base _pwd = pwd.getpwall() _grp = grp.getgrall() @@ -30,20 +30,20 @@ _grp = grp.getgrall() class X2GoBrokerNameService(base.X2GoBrokerNameService): def get_users(self): - return [ unicode(p.pw_name) for p in _pwd ] + return [ p.pw_name for p in _pwd ] def get_primary_group(self, username): - prim_gid_number = [ p.pw_gid for p in _pwd if unicode(p.pw_name) == unicode(username) ][0] - return [ unicode(g.gr_name) for g in _grp if g.gr_gid == prim_gid_number ][0] + prim_gid_number = [ p.pw_gid for p in _pwd if p.pw_name == username ][0] + return [ g.gr_name for g in _grp if g.gr_gid == prim_gid_number ][0] def get_groups(self): - return [ unicode(g.gr_name) for g in _grp ] + return [ g.gr_name for g in _grp ] def get_group_members(self, group, primary_groups=False): _members_from_primgroups = [] if primary_groups: for username in self.get_users(): - if unicode(group) == self.get_primary_group(username): - _members_from_primgroups.append(unicode(username)) - return [ unicode(u) for u in grp.getgrnam(group).gr_mem ] + _members_from_primgroups + if group == self.get_primary_group(username): + _members_from_primgroups.append(username) + return [ u for u in grp.getgrnam(group).gr_mem ] + _members_from_primgroups diff --git a/x2gobroker/nameservices/testsuite_nameservice.py b/x2gobroker/nameservices/testsuite_nameservice.py index 375960c..57fc992 100644 --- a/x2gobroker/nameservices/testsuite_nameservice.py +++ b/x2gobroker/nameservices/testsuite_nameservice.py @@ -18,15 +18,15 @@ # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. # Python X2GoBroker modules -import base_nameservice as base +from . import base_nameservice as base -_users = [ u'maja', u'willi', u'flip', u'kassandra', u'thekla' ] +_users = [ 'maja', 'willi', 'flip', 'kassandra', 'thekla' ] _groups = { - u'male': [u'willi', u'flip'], - u'female': [u'maja', u'kassandra', u'thekla'], - u'bees': [u'maja', u'willi', u'kassandra'], - u'grasshoppers': [u'flip'], - u'spiders': [u'thekla'], + 'male': ['willi', 'flip'], + 'female': ['maja', 'kassandra', 'thekla'], + 'bees': ['maja', 'willi', 'kassandra'], + 'grasshoppers': ['flip'], + 'spiders': ['thekla'], } @@ -36,18 +36,18 @@ class X2GoBrokerNameService(base.X2GoBrokerNameService): return _users def get_primary_group(self, username): - return unicode(username) + return username def get_groups(self): - return _groups.keys() + _users + return list(_groups.keys()) + _users def get_group_members(self, group, primary_groups=False): _members = [] - if group in _groups.keys(): + if group in list(_groups.keys()): _members.extend(_groups[group]) if primary_groups: for username in self.get_users(): - if unicode(group) == self.get_primary_group(username): + if group == self.get_primary_group(username): _members.append(username) return _members diff --git a/x2gobroker/tests/test_broker_agent.py b/x2gobroker/tests/test_broker_agent.py index 5220895..0cb694c 100644 --- a/x2gobroker/tests/test_broker_agent.py +++ b/x2gobroker/tests/test_broker_agent.py @@ -127,8 +127,8 @@ sshport = 22000 broker-agent-query-mode = SSH """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _session_profiles + tf = tempfile.NamedTemporaryFile(mode='w') + print(_session_profiles, file=tf) tf.seek(0) inifile_backend = inifile.X2GoBroker(profile_config_file=tf.name) @@ -138,7 +138,7 @@ broker-agent-query-mode = SSH _list1 = inifile_backend.list_profiles(username='foo1R') _profile1 = _list1['testprofile1'] self.assertTrue( ( _profile1['host'] == ['host1'] ) ) - self.assertTrue( ( _profile1.has_key('status') and _profile1['status'] == 'R' ) ) + self.assertTrue( ( 'status' in _profile1 and _profile1['status'] == 'R' ) ) # here will be a short pause, as we will try to suspend the faked X2Go Session _session1 = inifile_backend.select_session('testprofile1', username='foo1R') # the session broker has detected the running session on host 1 and changed its status to "S" @@ -148,7 +148,7 @@ broker-agent-query-mode = SSH _list1 = inifile_backend.list_profiles(username='foo1S') _profile1 = _list1['testprofile1'] self.assertTrue( ( _profile1['host'] == ['host1'] ) ) - self.assertTrue( ( _profile1.has_key('status') and _profile1['status'] == 'S' ) ) + self.assertTrue( ( 'status' in _profile1 and _profile1['status'] == 'S' ) ) _session1 = inifile_backend.select_session('testprofile1') self.assertEqual ( _session1, {'port': 22, 'server': 'host1'} ) @@ -156,7 +156,7 @@ broker-agent-query-mode = SSH _list1 = inifile_backend.list_profiles(username='foo1N') _profile1 = _list1['testprofile1'] self.assertTrue( ( _profile1['host'] == ['host1'] ) ) - self.assertFalse( ( _profile1.has_key('status') ) ) + self.assertFalse( ( 'status' in _profile1 ) ) _session1 = inifile_backend.select_session('testprofile1') self.assertEqual ( _session1, {'port': 22, 'server': 'host1'} ) @@ -168,7 +168,7 @@ broker-agent-query-mode = SSH _profile2 = _list2['testprofile2'] _profile2['host'].sort() self.assertTrue( ( _profile2['host'] == ['host2'] ) ) - self.assertTrue( ( _profile2.has_key('status') and _profile2['status'] == 'S' ) ) + self.assertTrue( ( 'status' in _profile2 and _profile2['status'] == 'S' ) ) _session2 = inifile_backend.select_session('testprofile2', 'foo2RS') self.assertEqual ( _session2, {'port': 22, 'server': 'host2', 'session_info': '30342|foo2RS-50-1414759789_stDMATE_dp24|50|host2|S|2014-10-31T13:49:51|c02c7bbe58677a2726f7e456cb398ae4|127.0.0.1|30001|30002|2014-10-31T13:49:51|foo2RS|89|30003|-1|-1', } ) @@ -180,7 +180,7 @@ broker-agent-query-mode = SSH _profile3 = _list3['testprofile3'] _profile3['host'].sort() self.assertTrue( ( _profile3['host'] == ['host2'] ) ) - self.assertTrue( ( _profile3.has_key('status') and _profile3['status'] == 'S' ) ) + self.assertTrue( ( 'status' in _profile3 and _profile3['status'] == 'S' ) ) _session3 = inifile_backend.select_session('testprofile3', 'foo3RS') self.assertEqual ( _session3, {'port': 22, 'server': 'host2.mydomain', 'session_info': '30342|foo3RS-50-1414759789_stDMATE_dp24|50|host2|S|2014-10-31T13:49:51|c02c7bbe58677a2726f7e456cb398ae4|127.0.0.1|30001|30002|2014-10-31T13:49:51|foo3RS|89|30003|-1|-1', } ) _session3 = inifile_backend.select_session('testprofile3', 'foo3RS') @@ -201,11 +201,11 @@ broker-agent-query-mode = SSH _profile5 = _list5['testprofile5'] _profile5['host'].sort() self.assertTrue( _profile5['host'][0] in ('host1.mydomain', 'host2.mydomain') ) - self.assertTrue( not _profile5.has_key('status') ) + self.assertTrue( 'status' not in _profile5 ) i = 0 while i < 10: _remoteagent5 = inifile_backend.get_remote_agent('testprofile5') - self.assertTrue( _remoteagent5 == {u'hostname': 'host1.mydomain', u'hostaddr': '10.0.2.4', u'port': 22, 'load_factors': {}, } or _remoteagent5 == {u'hostname': 'host2.mydomain', u'hostaddr': '10.0.2.5', u'port': 22, 'load_factors': {}, } ) + self.assertTrue( _remoteagent5 == {'hostname': 'host1.mydomain', 'hostaddr': '10.0.2.4', 'port': 22, 'load_factors': {}, } or _remoteagent5 == {'hostname': 'host2.mydomain', 'hostaddr': '10.0.2.5', 'port': 22, 'load_factors': {}, } ) _session5 = inifile_backend.select_session('testprofile5', 'foo5N') self.assertTrue( _session5 == {'port': 22, 'server': '10.0.2.4', } or _session5 == {'port': 22, 'server': '10.0.2.5', } ) i += 1 @@ -217,9 +217,9 @@ broker-agent-query-mode = SSH _profile6 = _list6['testprofile6'] _profile6['host'].sort() self.assertTrue( _profile6['host'][0] in ('host1.mydomain', 'host2.mydomain') ) - self.assertTrue( not _profile6.has_key('status') ) + self.assertTrue( 'status' not in _profile6 ) _remoteagent6 = inifile_backend.get_remote_agent('testprofile6') - self.assertTrue( _remoteagent6 == {u'hostname': 'host1.mydomain', u'hostaddr': '10.0.2.4', u'port': 23467, 'load_factors': {}, } or _remoteagent6 == {u'hostname': 'host2.mydomain', u'hostaddr': '10.0.2.5', u'port': 23467, 'load_factors': {}, } ) + self.assertTrue( _remoteagent6 == {'hostname': 'host1.mydomain', 'hostaddr': '10.0.2.4', 'port': 23467, 'load_factors': {}, } or _remoteagent6 == {'hostname': 'host2.mydomain', 'hostaddr': '10.0.2.5', 'port': 23467, 'load_factors': {}, } ) _session6 = inifile_backend.select_session('testprofile6', 'foo6N') self.assertTrue( _session6 == {'port': 23467, 'server': '10.0.2.4', } or _session6 == {'port': 23467, 'server': '10.0.2.5', } ) @@ -227,11 +227,11 @@ broker-agent-query-mode = SSH _profile7 = _list7['testprofile7'] _profile7['host'].sort() self.assertTrue( _profile7['host'][0] in ('docker-vm-1', 'docker-vm-2') ) - self.assertTrue( not _profile7.has_key('status') ) + self.assertTrue( 'status' not in _profile7 ) i = 0 while i < 10: _remoteagent7 = inifile_backend.get_remote_agent('testprofile7') - self.assertTrue( _remoteagent7 == {u'hostname': 'docker-vm-1', u'hostaddr': 'docker-server', u'port': 22001, 'load_factors': {}, } or _remoteagent7 == {u'hostname': 'docker-vm-2', u'hostaddr': 'docker-server', u'port': 22002, 'load_factors': {}, } ) + self.assertTrue( _remoteagent7 == {'hostname': 'docker-vm-1', 'hostaddr': 'docker-server', 'port': 22001, 'load_factors': {}, } or _remoteagent7 == {'hostname': 'docker-vm-2', 'hostaddr': 'docker-server', 'port': 22002, 'load_factors': {}, } ) _session7 = inifile_backend.select_session('testprofile7', 'foo7N') self.assertTrue( _session7 == {'port': 22001, 'server': 'docker-server', } or _session7 == {'port': 22001, 'server': 'docker-server', } ) i += 1 @@ -240,11 +240,11 @@ broker-agent-query-mode = SSH _profile8 = _list8['testprofile8'] _profile8['host'].sort() self.assertTrue( _profile8['host'][0] in ('docker-vm-0', 'docker-vm-1', 'docker-vm-2') ) - self.assertTrue( not _profile8.has_key('status') ) + self.assertTrue( 'status' not in _profile8 ) i = 0 while i < 10: _remoteagent8 = inifile_backend.get_remote_agent('testprofile8') - self.assertTrue( _remoteagent8 == {u'hostname': 'docker-vm-0', u'hostaddr': 'docker-server', u'port': 22000, 'load_factors': {}, } or _remoteagent8 == {u'hostname': 'docker-vm-1', u'hostaddr': 'docker-server', u'port': 22001, 'load_factors': {}, } or _remoteagent8 == {u'hostname': 'docker-vm-2', u'hostaddr': 'docker-server', u'port': 22002, 'load_factors': {}, } ) + self.assertTrue( _remoteagent8 == {'hostname': 'docker-vm-0', 'hostaddr': 'docker-server', 'port': 22000, 'load_factors': {}, } or _remoteagent8 == {'hostname': 'docker-vm-1', 'hostaddr': 'docker-server', 'port': 22001, 'load_factors': {}, } or _remoteagent8 == {'hostname': 'docker-vm-2', 'hostaddr': 'docker-server', 'port': 22002, 'load_factors': {}, } ) _session8 = inifile_backend.select_session('testprofile8', 'foo8N') self.assertTrue( _session8 == {'port': 22000, 'server': 'docker-server', } or _session8 == {'port': 22001, 'server': 'docker-server', } or _session8 == {'port': 22001, 'server': 'docker-server', } ) i += 1 @@ -367,8 +367,8 @@ broker-portscan-x2goservers = true broker-autologin = true """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _session_profiles + tf = tempfile.NamedTemporaryFile(mode='w') + print(_session_profiles, file=tf) tf.seek(0) inifile_backend = inifile.X2GoBroker(profile_config_file=tf.name) @@ -401,7 +401,7 @@ broker-autologin = true while i < 10: _session4 = inifile_backend.select_session('testprofile4', username='foo4BS2') self.assertTrue ( _session4['server'] == 'host2.internal') - self.assertFalse ( _session4.has_key('session_info') ) + self.assertFalse ( 'session_info' in _session4 ) i += 1 i = 0 @@ -424,7 +424,7 @@ broker-autologin = true while i < 10: _session5 = inifile_backend.select_session('testprofile5', username='foo5BS1') self.assertTrue ( _session5['server'] == 'host4.internal') - self.assertFalse ( _session5.has_key('session_info') ) + self.assertFalse ( 'session_info' in _session5 ) i += 1 x2gobroker.agent._call_local_broker_agent = _save_local_broker_agent_call @@ -485,8 +485,8 @@ broker-agent-query-mode = SSH broker-portscan-x2goservers = true """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _session_profiles + tf = tempfile.NamedTemporaryFile(mode='w') + print(_session_profiles, file=tf) tf.seek(0) inifile_backend = inifile.X2GoBroker(profile_config_file=tf.name) diff --git a/x2gobroker/tests/test_broker_base.py b/x2gobroker/tests/test_broker_base.py index 2af14a4..cb05742 100644 --- a/x2gobroker/tests/test_broker_base.py +++ b/x2gobroker/tests/test_broker_base.py @@ -30,8 +30,8 @@ class TestX2GoBrokerBackendBase(unittest.TestCase): _config_defaults = copy.deepcopy(x2gobroker.defaults.X2GOBROKER_CONFIG_DEFAULTS) _config_defaults.update({'broker_base': {'enable': True, }, }) _config = "" # use the config that derives directly from the config defaults - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) return base.X2GoBroker(config_file=tf.name, config_defaults=_config_defaults) @@ -44,8 +44,8 @@ class TestX2GoBrokerBackendBase(unittest.TestCase): [broker_base] enable = false """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) base_backend = base.X2GoBroker(config_file=tf.name, config_defaults=_config_defaults) self.assertEqual(base_backend.is_enabled(), False) @@ -53,8 +53,8 @@ enable = false [broker_base] enable = true """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) base_backend = base.X2GoBroker(config_file=tf.name) self.assertEqual(base_backend.is_enabled(), True) @@ -72,8 +72,8 @@ default-auth-mech = foo-auth-mech [broker_base] enable = true """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) base_backend = base.X2GoBroker(config_file=tf.name) self.assertEqual(base_backend.get_authentication_mechanism(), 'foo-auth-mech') @@ -85,8 +85,8 @@ default-auth-mech = foo-auth-mech enable = true auth-mech = bar-auth-mech """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) base_backend = base.X2GoBroker(config_file=tf.name, config_defaults=_config_defaults) self.assertEqual(base_backend.get_authentication_mechanism(), 'bar-auth-mech') @@ -104,8 +104,8 @@ default-user-db = foo-user-db [broker_base] enable = true """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) base_backend = base.X2GoBroker(config_file=tf.name) self.assertEqual(base_backend.get_userdb_service(), 'foo-user-db') @@ -117,8 +117,8 @@ default-user-db = foo-user-db enable = true user-db = bar-user-db """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) base_backend = base.X2GoBroker(config_file=tf.name, config_defaults=_config_defaults) self.assertEqual(base_backend.get_userdb_service(), 'bar-user-db') @@ -136,8 +136,8 @@ default-group-db = foo-group-db [broker_base] enable = true """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) base_backend = base.X2GoBroker(config_file=tf.name) self.assertEqual(base_backend.get_groupdb_service(), 'foo-group-db') @@ -149,8 +149,8 @@ default-group-db = foo-group-db enable = true group-db = bar-group-db """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) base_backend = base.X2GoBroker(config_file=tf.name, config_defaults=_config_defaults) self.assertEqual(base_backend.get_groupdb_service(), 'bar-group-db') @@ -167,8 +167,8 @@ default-group-db = base [broker_base] enable = true """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) base_backend = base.X2GoBroker(config_file=tf.name) self.assertEqual(base_backend.get_users(), []) @@ -189,8 +189,8 @@ default-group-db = libnss [broker_base] enable = true """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) base_backend = base.X2GoBroker(config_file=tf.name) self.assertTrue( ( 'root' in base_backend.get_users() ) ) @@ -213,12 +213,12 @@ default-group-db = libnss [broker_base] enable = true """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) base_backend = base.X2GoBroker(config_file=tf.name) - self.assertTrue(type(base_backend.get_primary_group('root') in (type(''), type(u'')))) - self.assertTrue(type(unicode(base_backend.get_primary_group('root')) == u'root')) + self.assertTrue(type(base_backend.get_primary_group('root') in (type(''), type('')))) + self.assertTrue(type(base_backend.get_primary_group('root') == 'root')) def test_nameservice_nodefaultsinconfig(self): _config_defaults = copy.deepcopy(x2gobroker.defaults.X2GOBROKER_CONFIG_DEFAULTS) @@ -230,8 +230,8 @@ default-group-db = [broker_base] enable = true """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) base_backend = base.X2GoBroker(config_file=tf.name, config_defaults=_config_defaults) self.assertEqual(base_backend.get_userdb_service(), 'libnss') @@ -245,8 +245,8 @@ default-group-db = testsuite [broker_base] enable = true """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) base_backend = base.X2GoBroker(config_file=tf.name, config_defaults=_config_defaults) self.assertEqual(base_backend.get_userdb_service(), 'testsuite') @@ -261,8 +261,8 @@ enable = true [global] require-password = false """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) base_backend = base.X2GoBroker(config_file=tf.name, config_defaults=_config_defaults) self.assertEqual(base_backend.check_access()[0], True) @@ -273,47 +273,47 @@ require-password = false def test_getdefaultprofile(self): base_backend = self._init_base_backend() _expected_profile = { - u'command': u'TERMINAL', - u'defsndport': True, - u'useiconv': False, - u'iconvfrom': u'UTF-8', - u'height': 600, - u'export': u'', - u'quality': 9, - u'fullscreen': False, - u'layout': u'', - u'useexports': True, - u'width': 800, - u'speed': 2, - u'soundsystem': u'pulse', - u'print': True, - u'type': u'auto', - u'sndport': 4713, - u'xinerama': True, - u'variant': u'', - u'usekbd': True, - u'fstunnel': True, - u'applications': [u'TERMINAL',u'WWWBROWSER',u'MAILCLIENT',u'OFFICE'], - u'multidisp': False, - u'sshproxyport': 22, - u'sound': True, - u'rootless': True, - u'iconvto': u'UTF-8', - u'soundtunnel': True, - u'dpi': 96, - u'sshport': 22, - u'setdpi': 0, - u'user': u'BROKER_USER', - u'pack': u'16m-jpeg', - u'host': [u'localhost'], - u'directrdp': False, + 'command': 'TERMINAL', + 'defsndport': True, + 'useiconv': False, + 'iconvfrom': 'UTF-8', + 'height': 600, + 'export': '', + 'quality': 9, + 'fullscreen': False, + 'layout': '', + 'useexports': True, + 'width': 800, + 'speed': 2, + 'soundsystem': 'pulse', + 'print': True, + 'type': 'auto', + 'sndport': 4713, + 'xinerama': True, + 'variant': '', + 'usekbd': True, + 'fstunnel': True, + 'applications': ['TERMINAL','WWWBROWSER','MAILCLIENT','OFFICE'], + 'multidisp': False, + 'sshproxyport': 22, + 'sound': True, + 'rootless': True, + 'iconvto': 'UTF-8', + 'soundtunnel': True, + 'dpi': 96, + 'sshport': 22, + 'setdpi': 0, + 'user': 'BROKER_USER', + 'pack': '16m-jpeg', + 'host': ['localhost'], + 'directrdp': False, } _profile = base_backend.get_profile_defaults() - self.assertEqual(len(_expected_profile.keys()), len(_profile.keys())) - for key in _expected_profile.keys(): - self.assertTrue( ( key in _profile.keys() ) ) - for key in _profile.keys(): - self.assertTrue( ( key in _expected_profile.keys() and _profile[key] == _expected_profile[key] ) ) + self.assertEqual(len(list(_expected_profile.keys())), len(list(_profile.keys()))) + for key in list(_expected_profile.keys()): + self.assertTrue( ( key in list(_profile.keys()) ) ) + for key in list(_profile.keys()): + self.assertTrue( ( key in list(_expected_profile.keys()) and _profile[key] == _expected_profile[key] ) ) ### TEST ACL DEFAULTS: get_acl_defaults() @@ -332,11 +332,11 @@ require-password = false 'acl-any-order': 'deny-allow', } _acls = base_backend.get_acl_defaults() - self.assertEqual(len(_expected_acls.keys()), len(_acls.keys())) - for key in _expected_acls.keys(): - self.assertTrue( ( key in _acls.keys() ) ) - for key in _acls.keys(): - self.assertTrue( ( key in _expected_acls.keys() and _acls[key] == _expected_acls[key] ) ) + self.assertEqual(len(list(_expected_acls.keys())), len(list(_acls.keys()))) + for key in list(_expected_acls.keys()): + self.assertTrue( ( key in list(_acls.keys()) ) ) + for key in list(_acls.keys()): + self.assertTrue( ( key in list(_expected_acls.keys()) and _acls[key] == _expected_acls[key] ) ) ### TEST ACL CHECK: check_profile_acls() @@ -444,8 +444,8 @@ default-group-db = testsuite [broker_base] enable = true """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) base_backend = base.X2GoBroker(config_file=tf.name, config_defaults=_config_defaults) users = base_backend.get_users() @@ -467,8 +467,8 @@ default-group-db = testsuite [broker_base] enable = true """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) base_backend = base.X2GoBroker(config_file=tf.name, config_defaults=_config_defaults) username = 'willi' @@ -520,8 +520,8 @@ default-group-db = testsuite [broker_base] enable = true """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) base_backend = base.X2GoBroker(config_file=tf.name, config_defaults=_config_defaults) acls = { @@ -542,8 +542,8 @@ ignore-primary-group-memberships = true [broker_base] enable = true """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) base_backend = base.X2GoBroker(config_file=tf.name, config_defaults=_config_defaults) acls = { @@ -564,8 +564,8 @@ ignore-primary-group-memberships = false [broker_base] enable = true """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) base_backend = base.X2GoBroker(config_file=tf.name, config_defaults=_config_defaults) acls = { @@ -587,8 +587,8 @@ default-group-db = testsuite [broker_base] enable = true """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) base_backend = base.X2GoBroker(config_file=tf.name, config_defaults=_config_defaults) username_f = 'flip' # is a male grasshopper @@ -653,8 +653,8 @@ default-group-db = testsuite [broker_base] enable = true """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) base_backend = base.X2GoBroker(config_file=tf.name, config_defaults=_config_defaults) username_f = 'flip' @@ -1018,8 +1018,8 @@ default-group-db = testsuite [broker_base] enable = true """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) base_backend = base.X2GoBroker(config_file=tf.name, config_defaults=_config_defaults) username_f = 'flip' @@ -1184,8 +1184,8 @@ enable = true _config = """ """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) base_backend = base.X2GoBroker(config_file=tf.name, config_defaults=_config_defaults) self.assertNotEqual(base_backend.get_my_cookie(), 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx') @@ -1194,8 +1194,8 @@ enable = true [global] my-cookie = f57866be-bc67-4642-86b4-f644b54031c8 """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) base_backend = base.X2GoBroker(config_file=tf.name, config_defaults=_config_defaults) self.assertEqual(base_backend.get_my_cookie(), 'f57866be-bc67-4642-86b4-f644b54031c8') @@ -1205,44 +1205,45 @@ my-cookie = f57866be-bc67-4642-86b4-f644b54031c8 my-cookie = f57866be-bc67-4642-86b4-f644b54031c8 my-cookie-file = /etc/x2go/somefile/somewhere """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) base_backend = base.X2GoBroker(config_file=tf.name, config_defaults=_config_defaults) self.assertEqual(base_backend.get_my_cookie(), 'f57866be-bc67-4642-86b4-f644b54031c8') tf.close() - temp_fh = tempfile.NamedTemporaryFile() - print >> temp_fh, 'd1b8043e-b748-48c4-907f-7c798c4dc746' + temp_fh = tempfile.NamedTemporaryFile(mode='w') + temp_fh.write('d1b8043e-b748-48c4-907f-7c798c4dc746') temp_fh.seek(0) _config = """ [global] my-cookie = f57866be-bc67-4642-86b4-f644b54031c8 my-cookie-file = %s """ % temp_fh.name - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) base_backend = base.X2GoBroker(config_file=tf.name, config_defaults=_config_defaults) self.assertNotEqual(base_backend.get_my_cookie(), 'f57866be-bc67-4642-86b4-f644b54031c8') self.assertEqual(base_backend.get_my_cookie(), 'd1b8043e-b748-48c4-907f-7c798c4dc746') temp_fh.close() tf.close() - temp_fh = tempfile.NamedTemporaryFile() - print >> temp_fh, """ + temp_fh = tempfile.NamedTemporaryFile(mode='w') + temp_fh.write(""" # Some comment... # Another comment... d1b8043e-b748-48c4-907f-7c798c4dc746 d1b8043e-b748-48c4-907f-7c798c4dc747 # above hash is wrong... """ + ) temp_fh.seek(0) _config = """ [global] my-cookie = f57866be-bc67-4642-86b4-f644b54031c8 my-cookie-file = %s """ % temp_fh.name - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) base_backend = base.X2GoBroker(config_file=tf.name, config_defaults=_config_defaults) self.assertNotEqual(base_backend.get_my_cookie(), 'f57866be-bc67-4642-86b4-f644b54031c8') @@ -1256,8 +1257,8 @@ my-cookie-file = %s my-cookie = f57866be-bc67-4642-86b4-f644b54031c8 my-cookie-file = %s """ % temp_fh.name - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) base_backend = base.X2GoBroker(config_file=tf.name, config_defaults=_config_defaults) self.assertNotEqual(base_backend.get_my_cookie(), 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx') diff --git a/x2gobroker/tests/test_broker_inifile.py b/x2gobroker/tests/test_broker_inifile.py index 7f08129..cd97ae4 100644 --- a/x2gobroker/tests/test_broker_inifile.py +++ b/x2gobroker/tests/test_broker_inifile.py @@ -45,7 +45,7 @@ class TestX2GoBrokerBackendInifile(unittest.TestCase): inifile_backend = inifile.X2GoBroker(profile_config_file='../../etc/broker/x2gobroker-sessionprofiles.conf') _profile_ids = inifile_backend.get_profile_ids() for _profile_id in _profile_ids: - self.assertTrue( ( 'default' not in inifile_backend.get_profile(_profile_id).keys() ) ) + self.assertTrue( ( 'default' not in list(inifile_backend.get_profile(_profile_id).keys()) ) ) # TEST COMPLETION OF DEFAULTS FROM CODE IN defaults.py @@ -63,33 +63,33 @@ user = foo command = GNOME """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _session_profiles + tf = tempfile.NamedTemporaryFile(mode='w') + print(_session_profiles, file=tf) tf.seek(0) inifile_backend = inifile.X2GoBroker(profile_config_file=tf.name) _expected_defaults = copy.deepcopy(x2gobroker.defaults.X2GOBROKER_SESSIONPROFILE_DEFAULTS['DEFAULT']) - for key in copy.deepcopy(_expected_defaults).keys(): + for key in list(copy.deepcopy(_expected_defaults).keys()): if key.startswith('acl-'): del _expected_defaults[key] _expected_defaults.update( { - u'exports': '', - u'fullscreen': False, - u'width': 800, - u'height': 600, - u'applications': ['TERMINAL','WWWBROWSER',], - u'user': 'foo', - u'command': 'GNOME', + 'exports': '', + 'fullscreen': False, + 'width': 800, + 'height': 600, + 'applications': ['TERMINAL','WWWBROWSER',], + 'user': 'foo', + 'command': 'GNOME', } ) # just testing the directrdp hard-coded defaults _expected_defaults.update( { - u'directrdp': False, + 'directrdp': False, } ) _expected_profile = copy.deepcopy(_expected_defaults) _profile = inifile_backend.get_profile('testprofile') - for key in _expected_profile.keys(): - self.assertTrue( ( key in _profile.keys() ) ) - for key in _profile.keys(): - self.assertTrue( ( key in _expected_profile.keys() and _profile[key] == _expected_profile[key] ) ) + for key in list(_expected_profile.keys()): + self.assertTrue( ( key in list(_profile.keys()) ) ) + for key in list(_profile.keys()): + self.assertTrue( ( key in list(_expected_profile.keys()) and _profile[key] == _expected_profile[key] ) ) ### TEST SESSION PROFILES: get_profile_defaults() @@ -101,9 +101,9 @@ command = GNOME if key.startswith('acl-'): del _expected_profile_defaults[key] for _param in _profile_defaults: - self.assertTrue( ( _param in _expected_profile_defaults.keys() ) ) + self.assertTrue( ( _param in list(_expected_profile_defaults.keys()) ) ) for _param in _expected_profile_defaults: - self.assertTrue( ( _param in _profile_defaults.keys() and _profile_defaults[_param] == _expected_profile_defaults[_param] ) ) + self.assertTrue( ( _param in list(_profile_defaults.keys()) and _profile_defaults[_param] == _expected_profile_defaults[_param] ) ) ### TEST SESSION PROFILES: get_profile(profile_id) @@ -137,66 +137,66 @@ acl-users-order = deny-allow user = bar command = gnomE """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _session_profiles + tf = tempfile.NamedTemporaryFile(mode='w') + print(_session_profiles, file=tf) tf.seek(0) inifile_backend = inifile.X2GoBroker(profile_config_file=tf.name) _expected_defaults = copy.deepcopy(x2gobroker.defaults.X2GOBROKER_SESSIONPROFILE_DEFAULTS['DEFAULT']) - for key in copy.deepcopy(_expected_defaults).keys(): + for key in list(copy.deepcopy(_expected_defaults).keys()): if key.startswith('acl-'): del _expected_defaults[key] _expected_defaults.update( { - u'exports': '', - u'fullscreen': False, - u'width': 800, - u'height': 600, - u'applications': ['TERMINAL','WWWBROWSER',], + 'exports': '', + 'fullscreen': False, + 'width': 800, + 'height': 600, + 'applications': ['TERMINAL','WWWBROWSER',], } ) _expected_profile1 = copy.deepcopy(_expected_defaults) _expected_profile1.update({ - u'user': 'foo', - u'command': 'GNOME', + 'user': 'foo', + 'command': 'GNOME', }) _expected_profile2 = copy.deepcopy(_expected_defaults) _expected_profile2.update({ - u'user': 'bar', - u'command': 'KDE', - u'fullscreen': True, + 'user': 'bar', + 'command': 'KDE', + 'fullscreen': True, }) _expected_profile3 = copy.deepcopy(_expected_defaults) _expected_profile3.update({ - u'user': 'bar', - u'command': 'KDE', - u'fullscreen': True, + 'user': 'bar', + 'command': 'KDE', + 'fullscreen': True, }) _expected_profile4 = copy.deepcopy(_expected_defaults) _expected_profile4.update({ - u'user': 'bar', - u'command': 'gnomE', # mixture of lower and uppercase in get_profile() + 'user': 'bar', + 'command': 'gnomE', # mixture of lower and uppercase in get_profile() }) _profile1 = inifile_backend.get_profile('testprofile1') - for key in _expected_profile1.keys(): - self.assertTrue( ( key in _profile1.keys() ) ) - for key in _profile1.keys(): - self.assertTrue( ( key in _expected_profile1.keys() and _profile1[key] == _expected_profile1[key] ) ) + for key in list(_expected_profile1.keys()): + self.assertTrue( ( key in list(_profile1.keys()) ) ) + for key in list(_profile1.keys()): + self.assertTrue( ( key in list(_expected_profile1.keys()) and _profile1[key] == _expected_profile1[key] ) ) _profile2 = inifile_backend.get_profile('testprofile2') - for key in _expected_profile2.keys(): - self.assertTrue( ( key in _profile2.keys() ) ) - for key in _profile2.keys(): - self.assertTrue( ( key in _expected_profile2.keys() ) and ( _profile2[key] == _expected_profile2[key] ) ) + for key in list(_expected_profile2.keys()): + self.assertTrue( ( key in list(_profile2.keys()) ) ) + for key in list(_profile2.keys()): + self.assertTrue( ( key in list(_expected_profile2.keys()) ) and ( _profile2[key] == _expected_profile2[key] ) ) _profile3 = inifile_backend.get_profile('testprofile3') - for key in _expected_profile3.keys(): - self.assertTrue( ( key in _profile3.keys() ) ) - for key in _profile3.keys(): - self.assertTrue( ( key in _expected_profile3.keys() ) and ( _profile3[key] == _expected_profile3[key] ) ) + for key in list(_expected_profile3.keys()): + self.assertTrue( ( key in list(_profile3.keys()) ) ) + for key in list(_profile3.keys()): + self.assertTrue( ( key in list(_expected_profile3.keys()) ) and ( _profile3[key] == _expected_profile3[key] ) ) _profile4 = inifile_backend.get_profile('testprofile4') - for key in _expected_profile4.keys(): - self.assertTrue( ( key in _profile4.keys() ) ) - for key in _profile4.keys(): - self.assertTrue( ( key in _expected_profile4.keys() ) and ( _profile4[key] == _expected_profile4[key] ) ) + for key in list(_expected_profile4.keys()): + self.assertTrue( ( key in list(_profile4.keys()) ) ) + for key in list(_profile4.keys()): + self.assertTrue( ( key in list(_expected_profile4.keys()) ) and ( _profile4[key] == _expected_profile4[key] ) ) ### TEST SESSION PROFILES: get_profile_acls(profile_id) @@ -228,8 +228,8 @@ acl-users-deny = ALL acl-users-allow = foo,bar acl-users-order = deny-allow """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _session_profiles + tf = tempfile.NamedTemporaryFile(mode='w') + print(_session_profiles, file=tf) tf.seek(0) inifile_backend = inifile.X2GoBroker(profile_config_file=tf.name) _expected_acl_defaults = { @@ -251,22 +251,22 @@ acl-users-order = deny-allow 'acl-any-order': 'deny-allow', }) _acls_profile1 = inifile_backend.get_profile_acls('testprofile1') - for key in _expected_acls_profile1.keys(): - self.assertTrue( ( key in _acls_profile1.keys() ) ) - for key in _acls_profile1.keys(): - self.assertTrue( ( key in _expected_acls_profile1.keys() and _acls_profile1[key] == _expected_acls_profile1[key] ) ) + for key in list(_expected_acls_profile1.keys()): + self.assertTrue( ( key in list(_acls_profile1.keys()) ) ) + for key in list(_acls_profile1.keys()): + self.assertTrue( ( key in list(_expected_acls_profile1.keys()) and _acls_profile1[key] == _expected_acls_profile1[key] ) ) _acls_profile2 = inifile_backend.get_profile_acls('testprofile2') - for key in _expected_acls_profile2.keys(): - self.assertTrue( ( key in _acls_profile2.keys() ) ) - for key in _acls_profile2.keys(): - self.assertTrue( ( key in _expected_acls_profile2.keys() ) and ( _acls_profile2[key] == _expected_acls_profile2[key] ) ) + for key in list(_expected_acls_profile2.keys()): + self.assertTrue( ( key in list(_acls_profile2.keys()) ) ) + for key in list(_acls_profile2.keys()): + self.assertTrue( ( key in list(_expected_acls_profile2.keys()) ) and ( _acls_profile2[key] == _expected_acls_profile2[key] ) ) _acls_profile3 = inifile_backend.get_profile_acls('testprofile3') - for key in _expected_acls_profile3.keys(): - self.assertTrue( ( key in _acls_profile3.keys() ) ) - for key in _acls_profile3.keys(): - self.assertTrue( ( key in _expected_acls_profile3.keys() ) and ( _acls_profile3[key] == _expected_acls_profile3[key] ) ) + for key in list(_expected_acls_profile3.keys()): + self.assertTrue( ( key in list(_acls_profile3.keys()) ) ) + for key in list(_acls_profile3.keys()): + self.assertTrue( ( key in list(_expected_acls_profile3.keys()) ) and ( _acls_profile3[key] == _expected_acls_profile3[key] ) ) ### TEST: list_profiles() method @@ -293,13 +293,13 @@ user = command = KDE fullscreen = true """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _session_profiles + tf = tempfile.NamedTemporaryFile(mode='w') + print(_session_profiles, file=tf) tf.seek(0) inifile_backend = inifile.X2GoBroker(profile_config_file=tf.name) profile_ids = inifile_backend.get_profile_ids() profile_ids.sort() - list_of_profile_ids = inifile_backend.list_profiles(username).keys() + list_of_profile_ids = list(inifile_backend.list_profiles(username).keys()) list_of_profile_ids.sort() self.assertEqual(profile_ids, list_of_profile_ids) @@ -328,8 +328,8 @@ rootless = false user = command = gnomE """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _session_profiles + tf = tempfile.NamedTemporaryFile(mode='w') + print(_session_profiles, file=tf) tf.seek(0) inifile_backend = inifile.X2GoBroker(profile_config_file=tf.name) profiles = inifile_backend.list_profiles(username) @@ -354,8 +354,8 @@ default-group-db = testsuite [inifile] enable = true """ - tfc = tempfile.NamedTemporaryFile() - print >> tfc, _config + tfc = tempfile.NamedTemporaryFile(mode='w') + print(_config, file=tfc) tfc.seek(0) _session_profiles = """ @@ -390,21 +390,21 @@ fullscreen = true acl-users-deny = willi acl-users-order = deny-allow """ - tfs = tempfile.NamedTemporaryFile() - print >> tfs, _session_profiles + tfs = tempfile.NamedTemporaryFile(mode='w') + print(_session_profiles, file=tfs) tfs.seek(0) inifile_backend = inifile.X2GoBroker(config_file=tfc.name, config_defaults=_config_defaults, profile_config_file=tfs.name) username_f = 'flip' list_of_profiles = inifile_backend.list_profiles(username_f) - list_of_profile_ids = list_of_profiles.keys() + list_of_profile_ids = list(list_of_profiles.keys()) list_of_profile_ids.sort() self.assertEqual(list_of_profile_ids, ['testprofile1']) self.assertEqual(list_of_profiles['testprofile1']['command'], 'GNOME') username_m = 'maja' list_of_profiles = inifile_backend.list_profiles(username_m) - list_of_profile_ids = list_of_profiles.keys() + list_of_profile_ids = list(list_of_profiles.keys()) list_of_profile_ids.sort() self.assertEqual(list_of_profile_ids, ['testprofile1', 'testprofile2', 'testprofile3']) self.assertEqual(list_of_profiles['testprofile1']['command'], 'GNOME') @@ -413,7 +413,7 @@ acl-users-order = deny-allow username_k = 'kassandra' list_of_profiles = inifile_backend.list_profiles(username_k) - list_of_profile_ids = list_of_profiles.keys() + list_of_profile_ids = list(list_of_profiles.keys()) list_of_profile_ids.sort() self.assertEqual(list_of_profile_ids, ['testprofile1', 'testprofile2', 'testprofile3']) self.assertEqual(list_of_profiles['testprofile1']['command'], 'GNOME') @@ -422,14 +422,14 @@ acl-users-order = deny-allow username_t = 'thekla' list_of_profiles = inifile_backend.list_profiles(username_t) - list_of_profile_ids = list_of_profiles.keys() + list_of_profile_ids = list(list_of_profiles.keys()) list_of_profile_ids.sort() self.assertEqual(list_of_profile_ids, ['testprofile2']) self.assertEqual(list_of_profiles['testprofile2']['command'], 'XFCE') username_w = 'willi' list_of_profiles = inifile_backend.list_profiles(username_w) - list_of_profile_ids = list_of_profiles.keys() + list_of_profile_ids = list(list_of_profiles.keys()) list_of_profile_ids.sort() self.assertEqual(list_of_profile_ids, ['testprofile1', 'testprofile2']) self.assertEqual(list_of_profiles['testprofile1']['command'], 'GNOME') @@ -452,8 +452,8 @@ default-group-db = testsuite [inifile] enable = true """ - tfc = tempfile.NamedTemporaryFile() - print >> tfc, _config + tfc = tempfile.NamedTemporaryFile(mode='w') + print(_config, file=tfc) tfc.seek(0) _session_profiles = """ @@ -487,8 +487,8 @@ name = TEST-7 host = test-7 (-test-6.extern) """ - tfs = tempfile.NamedTemporaryFile() - print >> tfs, _session_profiles + tfs = tempfile.NamedTemporaryFile(mode='w') + print(_session_profiles, file=tfs) tfs.seek(0) inifile_backend = inifile.X2GoBroker(config_file=tfc.name, config_defaults=_config_defaults, profile_config_file=tfs.name) _expected_result_1 = { @@ -569,15 +569,15 @@ host = docker-vm-0 (localhost), docker-vm-1 (localhost:22001), docker-vm-2 (loca sshport = 22000 """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _session_profiles + tf = tempfile.NamedTemporaryFile(mode='w') + print(_session_profiles, file=tf) tf.seek(0) inifile_backend = inifile.X2GoBroker(profile_config_file=tf.name) # test "testprofile1" _profile1 = inifile_backend.get_profile('testprofile1') self.assertTrue( ( _profile1['host'] == ['host1'] ) ) - for key in _profile1.keys(): + for key in list(_profile1.keys()): self.assertFalse( (key.startswith('host') and key != 'host' ) ) _session1 = inifile_backend.select_session('testprofile1') self.assertEqual ( _session1, {'port': 22, 'server': 'host1'} ) @@ -586,7 +586,7 @@ sshport = 22000 _profile2 = inifile_backend.get_profile('testprofile2') _profile2['host'].sort() self.assertTrue( ( _profile2['host'] == ['host1', 'host2'] ) ) - for key in _profile2.keys(): + for key in list(_profile2.keys()): self.assertFalse( (key.startswith('host') and key != 'host' ) ) _session2 = inifile_backend.select_session('testprofile2') self.assertTrue ( _session2['port'] == 22 ) @@ -597,7 +597,7 @@ sshport = 22000 _profile3['host'].sort() _profile5 = inifile_backend.get_profile('testprofile5') self.assertTrue( ( _profile3['host'] == ['host1.mydomain', 'host2.mydomain'] ) ) - for key in _profile3.keys(): + for key in list(_profile3.keys()): self.assertFalse( (key.startswith('host') and key != 'host' ) ) _session3 = inifile_backend.select_session('testprofile3') self.assertTrue ( _session3['port'] == 22 ) @@ -607,7 +607,7 @@ sshport = 22000 _profile4 = inifile_backend.get_profile('testprofile4') _profile4['host'].sort() self.assertTrue( ( _profile4['host'] == ['host1.mydomain', 'host2.yourdomain'] ) ) - for key in _profile4.keys(): + for key in list(_profile4.keys()): self.assertFalse( (key.startswith('host') and key != 'host' ) ) _session4 = inifile_backend.select_session('testprofile4') self.assertTrue ( _session4['port'] == 22 ) @@ -617,8 +617,8 @@ sshport = 22000 _profile5 = inifile_backend.get_profile('testprofile5') _profile5['host'].sort() self.assertTrue( ( _profile5['host'] == ['host1.mydomain', 'host2.mydomain'] ) ) - self.assertTrue( _profile5.has_key('host=host1.mydomain') ) - self.assertTrue( _profile5.has_key('host=host2.mydomain') ) + self.assertTrue( 'host=host1.mydomain' in _profile5 ) + self.assertTrue( 'host=host2.mydomain' in _profile5 ) self.assertTrue( _profile5['host=host1.mydomain'] == '10.0.2.4' ) self.assertTrue( _profile5['host=host2.mydomain'] == '10.0.2.5' ) self.assertTrue( _profile5['sshport'] == 22 ) @@ -630,8 +630,8 @@ sshport = 22000 _profile6 = inifile_backend.get_profile('testprofile6') _profile6['host'].sort() self.assertTrue( ( _profile6['host'] == ['host1.mydomain', 'host2.mydomain'] ) ) - self.assertTrue( _profile6.has_key('host=host1.mydomain') ) - self.assertTrue( _profile6.has_key('host=host2.mydomain') ) + self.assertTrue( 'host=host1.mydomain' in _profile6 ) + self.assertTrue( 'host=host2.mydomain' in _profile6 ) self.assertTrue( _profile6['host=host1.mydomain'] == '10.0.2.4' ) self.assertTrue( _profile6['host=host2.mydomain'] == '10.0.2.5' ) self.assertTrue( _profile6['sshport'] == 23467 ) @@ -646,8 +646,8 @@ sshport = 22000 _profile7 = inifile_backend.get_profile('testprofile7') _profile7['host'].sort() self.assertTrue( ( _profile7['host'] == ['docker-vm-1', 'docker-vm-2'] ) ) - self.assertTrue( _profile7.has_key('host=docker-vm-1') ) - self.assertTrue( _profile7.has_key('host=docker-vm-2') ) + self.assertTrue( 'host=docker-vm-1' in _profile7 ) + self.assertTrue( 'host=docker-vm-2' in _profile7 ) self.assertTrue( _profile7['host=docker-vm-1'] == 'localhost' ) self.assertTrue( _profile7['host=docker-vm-2'] == 'localhost' ) self.assertTrue( _profile7['sshport'] == 22 ) @@ -664,14 +664,14 @@ sshport = 22000 _profile8 = inifile_backend.get_profile('testprofile8') _profile8['host'].sort() self.assertTrue( ( _profile8['host'] == ['docker-vm-0', 'docker-vm-1', 'docker-vm-2'] ) ) - self.assertTrue( _profile8.has_key('host=docker-vm-0') ) - self.assertTrue( _profile8.has_key('host=docker-vm-1') ) - self.assertTrue( _profile8.has_key('host=docker-vm-2') ) + self.assertTrue( 'host=docker-vm-0' in _profile8 ) + self.assertTrue( 'host=docker-vm-1' in _profile8 ) + self.assertTrue( 'host=docker-vm-2' in _profile8 ) self.assertTrue( _profile8['host=docker-vm-0'] == 'localhost' ) self.assertTrue( _profile8['host=docker-vm-1'] == 'localhost' ) self.assertTrue( _profile8['host=docker-vm-2'] == 'localhost' ) self.assertTrue( _profile8['sshport'] == 22000 ) - self.assertFalse( _profile8.has_key('sshport=docker-vm-0') ) + self.assertFalse( 'sshport=docker-vm-0' in _profile8 ) self.assertTrue( _profile8['sshport=docker-vm-1'] == 22001 ) self.assertTrue( _profile8['sshport=docker-vm-2'] == 22002 ) i = 0 @@ -716,8 +716,8 @@ broker-agent-query-mode = NONE host = host1.internal (host1.external), host2.internal (host2.external), host3.internal (host3.external) """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _session_profiles + tf = tempfile.NamedTemporaryFile(mode='w') + print(_session_profiles, file=tf) tf.seek(0) inifile_backend = inifile.X2GoBroker(profile_config_file=tf.name) diff --git a/x2gobroker/tests/test_broker_zeroconf.py b/x2gobroker/tests/test_broker_zeroconf.py index 3ca4934..4419299 100644 --- a/x2gobroker/tests/test_broker_zeroconf.py +++ b/x2gobroker/tests/test_broker_zeroconf.py @@ -33,48 +33,48 @@ class TestX2GoBrokerBackendZeroconf(unittest.TestCase): self.maxDiff = None list_of_profiles = { 'unittest': { - u'user': u'', - u'defsndport': True, - u'useiconv': False, - u'iconvfrom': u'UTF-8', - u'height': 600, - u'export': u'', - u'quality': 9, - u'fullscreen': False, - u'layout': u'', - u'useexports': 1, - u'width': 800, - u'speed': 2, - u'soundsystem': u'pulse', - u'print': True, - u'type': u'auto', - u'sndport': 4713, - u'xinerama': True, - u'variant': u'', - u'usekbd': True, - u'fstunnel': True, - u'applications': [u'TERMINAL',u'WWWBROWSER',u'MAILCLIENT',u'OFFICE',], - u'host': u'localhost', - u'multidisp': 0, - u'sshproxyport': 22, - u'sound': True, - u'rootless': 0, - u'name': u'LOCALHOST', - u'iconvto': u'UTF-8', - u'soundtunnel': True, - u'command': 'KDE', - u'dpi': 96, - u'sshport': 22, - u'setdpi': 0, - u'pack': u'16m-jpeg', + 'user': '', + 'defsndport': True, + 'useiconv': False, + 'iconvfrom': 'UTF-8', + 'height': 600, + 'export': '', + 'quality': 9, + 'fullscreen': False, + 'layout': '', + 'useexports': 1, + 'width': 800, + 'speed': 2, + 'soundsystem': 'pulse', + 'print': True, + 'type': 'auto', + 'sndport': 4713, + 'xinerama': True, + 'variant': '', + 'usekbd': True, + 'fstunnel': True, + 'applications': ['TERMINAL','WWWBROWSER','MAILCLIENT','OFFICE',], + 'host': 'localhost', + 'multidisp': 0, + 'sshproxyport': 22, + 'sound': True, + 'rootless': 0, + 'name': 'LOCALHOST', + 'iconvto': 'UTF-8', + 'soundtunnel': True, + 'command': 'KDE', + 'dpi': 96, + 'sshport': 22, + 'setdpi': 0, + 'pack': '16m-jpeg', # make sure, hard-coded defaults end up in the list_profiles() output of the zeroconf backend, as well - u'directrdp': False, + 'directrdp': False, }, } zeroconf_backend = x2gobroker.brokers.zeroconf_broker.X2GoBroker() _profiles = zeroconf_backend.list_profiles('user_foo') - self.assertEqual(len(_profiles.keys()), 1) - _key = _profiles.keys()[0] + self.assertEqual(len(list(_profiles.keys())), 1) + _key = list(_profiles.keys())[0] # replace profile ID ,,unittest'' with the returned random profile ID (uuid hash) _test_profiles = { _key: list_of_profiles['unittest'] @@ -91,13 +91,13 @@ class TestX2GoBrokerBackendZeroconf(unittest.TestCase): enable = true desktop-shell = kDe """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) zeroconf_backend = x2gobroker.brokers.zeroconf_broker.X2GoBroker(config_file=tf.name, config_defaults=_config_defaults) _profiles = zeroconf_backend.list_profiles('user_foo') - self.assertEqual(len(_profiles.keys()), 1) - _key = _profiles.keys()[0] + self.assertEqual(len(list(_profiles.keys())), 1) + _key = list(_profiles.keys())[0] self.assertEqual(_profiles[_key]['command'], 'KDE') def test_sessionselection(self): diff --git a/x2gobroker/tests/test_client_plain_base.py b/x2gobroker/tests/test_client_plain_base.py index 6d72b30..8152c30 100644 --- a/x2gobroker/tests/test_client_plain_base.py +++ b/x2gobroker/tests/test_client_plain_base.py @@ -48,8 +48,8 @@ class TestX2GoBrokerClientPlainBase(unittest.TestCase): [broker_base] enable = false """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) x2gobroker.defaults.X2GOBROKER_CONFIG = tf.name r = x2gobroker.client.plain.X2GoBrokerClient().get(a) @@ -59,8 +59,8 @@ enable = false [broker_base] enable = true """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) _cf_bak = x2gobroker.defaults.X2GOBROKER_CONFIG x2gobroker.defaults.X2GOBROKER_CONFIG = tf.name @@ -84,8 +84,8 @@ enable = true [broker_base] enable = true """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) x2gobroker.defaults.X2GOBROKER_CONFIG = tf.name diff --git a/x2gobroker/tests/test_utils.py b/x2gobroker/tests/test_utils.py index fc2b66c..c1ee46f 100644 --- a/x2gobroker/tests/test_utils.py +++ b/x2gobroker/tests/test_utils.py @@ -65,8 +65,8 @@ class TestX2GoBrokerUtils(unittest.TestCase): server_load = {'ts01': 10, 'ts02': 20, 'ts03': 30,} expected_server_load = {'ts01': 10, 'ts02': 20, 'ts03': 30,} server_load_n, subdomains = x2gobroker.utils.normalize_hostnames(server_load) - sln_keys = server_load_n.keys() - esl_keys = expected_server_load.keys() + sln_keys = list(server_load_n.keys()) + esl_keys = list(expected_server_load.keys()) sln_keys.sort() esl_keys.sort() self.assertEqual(esl_keys, sln_keys) @@ -75,8 +75,8 @@ class TestX2GoBrokerUtils(unittest.TestCase): server_load = {'ts01.intern': 10, 'ts02.intern': 20, 'ts03.intern': 30,} expected_server_load = {'ts01': 10, 'ts02': 20, 'ts03': 30,} server_load_n, subdomains = x2gobroker.utils.normalize_hostnames(server_load) - sln_keys = server_load_n.keys() - esl_keys = expected_server_load.keys() + sln_keys = list(server_load_n.keys()) + esl_keys = list(expected_server_load.keys()) sln_keys.sort() esl_keys.sort() self.assertEqual(esl_keys, sln_keys) @@ -85,8 +85,8 @@ class TestX2GoBrokerUtils(unittest.TestCase): server_load = {'ts01.intern': 10, 'ts02.intern': 20, 'ts03.extern': 30,} expected_server_load = {'ts01.intern': 10, 'ts02.intern': 20, 'ts03.extern': 30,} server_load_n, subdomains = x2gobroker.utils.normalize_hostnames(server_load) - sln_keys = server_load_n.keys() - esl_keys = expected_server_load.keys() + sln_keys = list(server_load_n.keys()) + esl_keys = list(expected_server_load.keys()) sln_keys.sort() esl_keys.sort() subdomains.sort() diff --git a/x2gobroker/tests/test_web_plain_base.py b/x2gobroker/tests/test_web_plain_base.py index 49676e3..10ceb49 100644 --- a/x2gobroker/tests/test_web_plain_base.py +++ b/x2gobroker/tests/test_web_plain_base.py @@ -39,8 +39,8 @@ class TestX2GoBrokerWebPlainBase(unittest.TestCase): [broker_base] enable = false """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) _cf_bak = x2gobroker.defaults.X2GOBROKER_CONFIG x2gobroker.defaults.X2GOBROKER_CONFIG = tf.name @@ -52,8 +52,8 @@ enable = false [broker_base] enable = true """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) x2gobroker.defaults.X2GOBROKER_CONFIG = tf.name testApp = TestApp(application) @@ -73,8 +73,8 @@ enable = true enable = true auth-mech = testsuite """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) _cf_bak = x2gobroker.defaults.X2GOBROKER_CONFIG x2gobroker.defaults.X2GOBROKER_CONFIG = tf.name @@ -91,8 +91,8 @@ auth-mech = testsuite enable = true auth-mech = testsuite """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) _cf_bak = x2gobroker.defaults.X2GOBROKER_CONFIG x2gobroker.defaults.X2GOBROKER_CONFIG = tf.name diff --git a/x2gobroker/tests/test_web_plain_zeroconf.py b/x2gobroker/tests/test_web_plain_zeroconf.py index 0882b1a..2c18d5a 100644 --- a/x2gobroker/tests/test_web_plain_zeroconf.py +++ b/x2gobroker/tests/test_web_plain_zeroconf.py @@ -41,8 +41,8 @@ enable = true auth-mech = testsuite desktop-shell = KDE """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) x2gobroker.defaults.X2GOBROKER_CONFIG = tf.name testApp = TestApp(application) @@ -63,8 +63,8 @@ enable = true auth-mech = testsuite desktop-shell = GNOME """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) x2gobroker.defaults.X2GOBROKER_CONFIG = tf.name testApp = TestApp(application) @@ -88,8 +88,8 @@ desktop-shell = GNOME enable = true auth-mech = testsuite """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) x2gobroker.defaults.X2GOBROKER_CONFIG = tf.name testApp = TestApp(application) diff --git a/x2gobroker/tests/test_web_uccs_zeroconf.py b/x2gobroker/tests/test_web_uccs_zeroconf.py index 23783d2..585a0b6 100644 --- a/x2gobroker/tests/test_web_uccs_zeroconf.py +++ b/x2gobroker/tests/test_web_uccs_zeroconf.py @@ -40,22 +40,22 @@ class TestX2GoBrokerWebUccsZeroConf(unittest.TestCase): def test_listsessions(self): _expected_result = { - u'URL': u'http://localhost:8080/uccs/zeroconf', - u'AdditionalManagementServers': [], - u'Name': u'X2Go Session Broker', - u'DefaultServer': u'LOCALHOST', - u'RemoteDesktopServers': [ + 'URL': 'http://localhost:8080/uccs/zeroconf', + 'AdditionalManagementServers': [], + 'Name': 'X2Go Session Broker', + 'DefaultServer': 'LOCALHOST', + 'RemoteDesktopServers': [ { - u'Username': u'', - u'Protocol': u'x2go', - u'Name': u'LOCALHOST', - u'URL': u'http://localhost:22/', - u'SessionType': u'KDE', - u'SessionTypeRequired': True, - u'Password': u'', + 'Username': '', + 'Protocol': 'x2go', + 'Name': 'LOCALHOST', + 'URL': 'http://localhost:22/', + 'SessionType': 'KDE', + 'SessionTypeRequired': True, + 'Password': '', }, ], - u'URL': u'http://localhost:8080/uccs/zeroconf/', + 'URL': 'http://localhost:8080/uccs/zeroconf/', } _config = """ [global] @@ -67,8 +67,8 @@ enable = true auth-mech = testsuite desktop-shell = KDE """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) x2gobroker.defaults.X2GOBROKER_CONFIG = tf.name testApp = TestApp(application) @@ -89,22 +89,22 @@ desktop-shell = KDE def test_listsessions_uppercase_desktopcommands(self): _expected_result = { - u'URL': u'http://localhost:8080/uccs/zeroconf', - u'AdditionalManagementServers': [], - u'Name': u'X2Go Session Broker', - u'DefaultServer': u'LOCALHOST', - u'RemoteDesktopServers': [ + 'URL': 'http://localhost:8080/uccs/zeroconf', + 'AdditionalManagementServers': [], + 'Name': 'X2Go Session Broker', + 'DefaultServer': 'LOCALHOST', + 'RemoteDesktopServers': [ { - u'Username': u'', - u'Protocol': u'x2go', - u'Name': u'LOCALHOST', - u'URL': u'http://localhost:22/', - u'SessionType': u'KDE', - u'SessionTypeRequired': True, - u'Password': u'', + 'Username': '', + 'Protocol': 'x2go', + 'Name': 'LOCALHOST', + 'URL': 'http://localhost:22/', + 'SessionType': 'KDE', + 'SessionTypeRequired': True, + 'Password': '', }, ], - u'URL': u'http://localhost:8080/uccs/zeroconf/', + 'URL': 'http://localhost:8080/uccs/zeroconf/', } _config = """ [global] @@ -116,8 +116,8 @@ enable = true auth-mech = testsuite desktop-shell = kdE """ - tf = tempfile.NamedTemporaryFile() - print >> tf, _config + tf = tempfile.NamedTemporaryFile(mode='w') + tf.write(_config) tf.seek(0) x2gobroker.defaults.X2GOBROKER_CONFIG = tf.name testApp = TestApp(application) diff --git a/x2gobroker/uccsjson.py b/x2gobroker/uccsjson.py index ddf1a6c..cef28b9 100644 --- a/x2gobroker/uccsjson.py +++ b/x2gobroker/uccsjson.py @@ -47,9 +47,9 @@ class ManagementServer(): """ self.RemoteDesktopServers = [] self.AdditionalManagementServers = [] - self.URL = unicode(url) + self.URL = url self.URL = '{url}/'.format(url=self.URL.rstrip('/')) - self.Name = unicode(name) + self.Name = name def set_default(self, ts_name): """\ @@ -60,8 +60,8 @@ class ManagementServer(): """ if isinstance(ts_name, str): - self.DefaultServer = unicode(ts_name) - elif isinstance(ts_name, unicode): + self.DefaultServer = ts_name + elif isinstance(ts_name, str): self.DefaultServer = ts_name else: raise TypeError("set_default expects a string argument") @@ -116,12 +116,12 @@ class RDPServer(): @type password: C{unicode} """ - self.URL = 'http://{url}/'.format(url=unicode(host)) - self.Name = unicode(name) - self.Protocol = u'rdp' + self.URL = 'http://{url}/'.format(url=host) + self.Name = name + self.Protocol = 'rdp' self.DomainRequired = True - self.Username = unicode(username) - self.Password = unicode(password) + self.Username = username + self.Password = password def set_domain(self, domain): """\ @@ -134,8 +134,8 @@ class RDPServer(): """ if isinstance(domain, str): - self.WindowsDomain = unicode(domain) - elif isinstance(domain, unicode): + self.WindowsDomain = domain + elif isinstance(domain, str): self.WindowsDomain = domain else: raise TypeError("set_domain() expects a string or unicode argument") @@ -165,12 +165,12 @@ class ICAServer(): @type password: C{unicode} """ - self.URL = 'http://{url}/'.format(url=unicode(host)) - self.Name = unicode(name) - self.Protocol = u'ica' - self.DomainRequired = unicode(True) - self.Username = unicode(username) - self.Password = unicode(password) + self.URL = 'http://{url}/'.format(url=host) + self.Name = name + self.Protocol = 'ica' + self.DomainRequired = True + self.Username = username + self.Password = password def set_domain(self, domain): """\ @@ -183,8 +183,8 @@ class ICAServer(): """ if isinstance(domain, str): - self.WindowsDomain = unicode(domain) - elif isinstance(domain, unicode): + self.WindowsDomain = domain + elif isinstance(domain, str): self.WindowsDomain = domain else: raise TypeError("set_domain() expects a string or unicode argument") @@ -214,12 +214,12 @@ class X2GoServer(): @type password: C{unicode} """ - self.URL = 'http://{url}/'.format(url=unicode(host)) - self.Name = unicode(name) - self.Protocol = u'x2go' + self.URL = 'http://{url}/'.format(url=host) + self.Name = name + self.Protocol = 'x2go' self.SessionTypeRequired = True - self.Username = unicode(username) - self.Password = unicode(password) + self.Username = username + self.Password = password def set_session_type(self, session_type): """\ @@ -232,8 +232,8 @@ class X2GoServer(): """ if isinstance(session_type, str): - self.SessionType = unicode(session_type) - elif isinstance(session_type, unicode): + self.SessionType = session_type + elif isinstance(session_type, str): self.SessionType = session_type else: raise TypeError("set_session_type() expects a string or unicode argument") diff --git a/x2gobroker/utils.py b/x2gobroker/utils.py index 328a0b6..a5a0d4b 100644 --- a/x2gobroker/utils.py +++ b/x2gobroker/utils.py @@ -19,7 +19,6 @@ import os import sys -import types import locale import netaddr import distutils.version @@ -39,10 +38,10 @@ def _checkConfigFileDefaults(data_structure): """ if data_structure is None: return False - if type(data_structure) is not types.DictType: + if type(data_structure) is not dict: return False - for sub_dict in data_structure.values(): - if type(sub_dict) is not types.DictType: + for sub_dict in list(data_structure.values()): + if type(sub_dict) is not dict: return False return True @@ -58,7 +57,7 @@ def touch_file(filename, mode='a'): """ if not os.path.isdir(os.path.dirname(filename)): - os.makedirs(os.path.dirname(filename), mode=00700) + os.makedirs(os.path.dirname(filename), mode=0o700) f = open(filename, mode=mode) f.close() @@ -112,12 +111,12 @@ def normalize_hostnames(servers): # test the data type of servers arg_is_dict = False servers_normalized = [] - if type(servers) is types.DictType: + if type(servers) is dict: arg_is_dict = True servers_normalized = {} - elif type(servers) is types.TupleType: + elif type(servers) is tuple: servers=list(servers) - elif type(servers) not in (types.ListType, types.TupleType): + elif type(servers) not in (list, tuple): raise ValueError('only lists, tuples and dictionaries are valid for x2gobroker.utils.normalize_hostnames()') subdomains = [] @@ -165,6 +164,7 @@ def matching_hostnames(server_list_a, server_list_b): if not matching_hosts: matching_hosts = list(set(server_list_a).intersection(set(server_list_b))) + matching_hosts.sort() return matching_hosts def drop_privileges(uid, gid): @@ -184,15 +184,15 @@ def drop_privileges(uid, gid): os.setuid(running_uid) # Ensure a very conservative umask - os.umask(077) + os.umask(0o077) # set the new user's home directory as $HOME os.environ['HOME'] = pwd.getpwnam(uid).pw_dir def split_host_address(host, default_address=None, default_port=22): - if type(host) is types.IntType: - host = unicode(host) + if type(host) is int: + host = str(host) # do some stripping first... host = host.strip() host = host.lstrip('*') @@ -222,7 +222,7 @@ def split_host_address(host, default_address=None, default_port=22): bind_address = host else: bind_address = '0.0.0.0' - if type(default_port) is types.IntType: + if type(default_port) is int: # use the given default, in host, there is an IP address or hostname bind_port = default_port else: diff --git a/x2gobroker/web/extras.py b/x2gobroker/web/extras.py index fe63492..0dd74bc 100644 --- a/x2gobroker/web/extras.py +++ b/x2gobroker/web/extras.py @@ -30,7 +30,7 @@ from x2gobroker.loggers import logger_error class _RequestHandler(tornado.web.RequestHandler): def _handle_request_exception(self, e): - logger_error.error('HTTP request error: {error_msg}'.format(error_msg=unicode(e))) + logger_error.error('HTTP request error: {error_msg}'.format(error_msg=e)) class X2GoBrokerItWorks(_RequestHandler): @@ -42,7 +42,7 @@ class X2GoBrokerItWorks(_RequestHandler): def _gen_http_header(self): - for http_header_item in self.http_header_items.keys(): + for http_header_item in list(self.http_header_items.keys()): self.set_header(http_header_item, self.http_header_items[http_header_item]) def get(self, *args, **kwargs): @@ -62,7 +62,7 @@ class X2GoBrokerPubKeyService(_RequestHandler): def _gen_http_header(self): - for http_header_item in self.http_header_items.keys(): + for http_header_item in list(self.http_header_items.keys()): self.set_header(http_header_item, self.http_header_items[http_header_item]) def get(self, *args, **kwargs): diff --git a/x2gobroker/web/json.py b/x2gobroker/web/json.py index 96b1fd7..b28fd09 100644 --- a/x2gobroker/web/json.py +++ b/x2gobroker/web/json.py @@ -32,7 +32,7 @@ from x2gobroker.loggers import logger_broker, logger_error class _RequestHandler(tornado.web.RequestHandler): def _handle_request_exception(self, e): - logger_error.error('HTTP request error: {error_msg}'.format(error_msg=unicode(e))) + logger_error.error('HTTP request error: {error_msg}'.format(error_msg=e)) tornado.web.RequestHandler._handle_request_exception(self, e) @@ -45,7 +45,7 @@ class X2GoBrokerWeb(_RequestHandler): def _gen_http_header(self): - for http_header_item in self.http_header_items.keys(): + for http_header_item in list(self.http_header_items.keys()): self.set_header(http_header_item, self.http_header_items[http_header_item]) def get(self, backend): @@ -69,8 +69,9 @@ class X2GoBrokerWeb(_RequestHandler): broker_backend = None try: # dynamically detect broker backend from given URL - exec("import x2gobroker.brokers.{backend}_broker".format(backend=backend)) - exec("broker_backend = x2gobroker.brokers.{backend}_broker.X2GoBroker()".format(backend=backend)) + namespace = {} + exec("import x2gobroker.brokers.{backend}_broker\nbroker_backend = x2gobroker.brokers.{backend}_broker.X2GoBroker()".format(backend=backend), namespace) + broker_backend = namespace['broker_backend'] except ImportError: # throw a 404 if the backend does not exist logger_error.error('No such broker backend \'{backend}\''.format(backend=backend)) @@ -91,7 +92,7 @@ class X2GoBrokerWeb(_RequestHandler): # FIXME: this is to work around a bug in X2Go Client (http://bugs.x2go.org/138) content_type = self.request.headers.get("Content-Type", "") if not content_type.startswith("application/x-www-form-urlencoded"): - for name, values in parse_qs_bytes(native_str(self.request.body)).iteritems(): + for name, values in parse_qs_bytes(native_str(self.request.body)).items(): self.request.arguments.setdefault(name, []).extend(values) # set the client address for the broker backend @@ -173,20 +174,20 @@ class X2GoBrokerWeb(_RequestHandler): selected_session = {} profile_info = broker_backend.select_session(profile_id=profile_id, username=username, pubkey=pubkey) - if profile_info.has_key('server'): + if 'server' in profile_info: username, password, task, profile_id, ip, cookie, authed, server = broker_backend.run_optional_script(script_type='select_session_scripts', username=username, password=password, task=task, profile_id=profile_id, ip=ip, cookie=cookie, authed=access, server=profile_info['server']) selected_session['server'] = "{server}".format(server=server) - if profile_info.has_key('port'): + if 'port' in profile_info: selected_session['port'] = "{port}".format(port=profile_info['port']) else: selected_session['port'] = "22" - if profile_info.has_key('authentication_privkey'): + if 'authentication_privkey' in profile_info: selected_session['key'] = profile_info['authentication_privkey'] - if profile_info.has_key('authentication_pubkey'): + if 'authentication_pubkey' in profile_info: selected_session['authentication_pubkey'] = profile_info['authentication_pubkey'] - if profile_info.has_key('session_info'): + if 'session_info' in profile_info: selected_session['session_info'] = profile_info['session_info'] payload['selected_session'] = selected_session diff --git a/x2gobroker/web/plain.py b/x2gobroker/web/plain.py index d870489..a83df03 100644 --- a/x2gobroker/web/plain.py +++ b/x2gobroker/web/plain.py @@ -17,7 +17,6 @@ # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. # modules -import types import tornado.web from tornado.escape import native_str, parse_qs_bytes @@ -29,7 +28,7 @@ from x2gobroker.loggers import logger_broker, logger_error class _RequestHandler(tornado.web.RequestHandler): def _handle_request_exception(self, e): - logger_error.error('HTTP request error: {error_msg}'.format(error_msg=unicode(e))) + logger_error.error('HTTP request error: {error_msg}'.format(error_msg=e)) tornado.web.RequestHandler._handle_request_exception(self, e) @@ -42,7 +41,7 @@ class X2GoBrokerWeb(_RequestHandler): def _gen_http_header(self): - for http_header_item in self.http_header_items.keys(): + for http_header_item in list(self.http_header_items.keys()): self.set_header(http_header_item, self.http_header_items[http_header_item]) def get(self, backend): @@ -65,9 +64,10 @@ class X2GoBrokerWeb(_RequestHandler): # silence pyflakes... broker_backend = None try: + namespace = {} # dynamically detect broker backend from given URL - exec("import x2gobroker.brokers.{backend}_broker".format(backend=backend)) - exec("broker_backend = x2gobroker.brokers.{backend}_broker.X2GoBroker()".format(backend=backend)) + exec("import x2gobroker.brokers.{backend}_broker\nbroker_backend = x2gobroker.brokers.{backend}_broker.X2GoBroker()".format(backend=backend), namespace) + broker_backend = namespace['broker_backend'] except ImportError: # throw a 404 if the backend does not exist logger_error.error('No such broker backend \'{backend}\''.format(backend=backend)) @@ -88,7 +88,7 @@ class X2GoBrokerWeb(_RequestHandler): # FIXME: this is to work around a bug in X2Go Client (http://bugs.x2go.org/138) content_type = self.request.headers.get("Content-Type", "") if not content_type.startswith("application/x-www-form-urlencoded"): - for name, values in parse_qs_bytes(native_str(self.request.body)).iteritems(): + for name, values in parse_qs_bytes(native_str(self.request.body)).items(): self.request.arguments.setdefault(name, []).extend(values) # set the client address for the broker backend @@ -147,17 +147,17 @@ class X2GoBrokerWeb(_RequestHandler): profiles = broker_backend.list_profiles(username) if profiles: output += "START_USER_SESSIONS\n\n" - profile_ids = profiles.keys() + profile_ids = list(profiles.keys()) profile_ids.sort() for profile_id in profile_ids: output += "[{profile_id}]\n".format(profile_id=profile_id) - for key in profiles[profile_id].keys(): - if type(profiles[profile_id][key]) in (types.UnicodeType, types.StringType): - output += "{key}={value}".format(key=key, value=unicode(profiles[profile_id][key])) - elif type(profiles[profile_id][key]) in (types.ListType, types.TupleType): - output += "{key}={value}".format(key=key, value=unicode(",".join(profiles[profile_id][key]))) + for key in list(profiles[profile_id].keys()): + if type(profiles[profile_id][key]) == str: + output += "{key}={value}".format(key=key, value=profiles[profile_id][key]) + elif type(profiles[profile_id][key]) in (list, tuple): + output += "{key}={value}".format(key=key, value=",".join(profiles[profile_id][key])) else: - output += "{key}={value}".format(key=key, value=unicode(int(profiles[profile_id][key]))) + output += "{key}={value}".format(key=key, value=int(profiles[profile_id][key])) output += "\n" output += "\n" @@ -170,16 +170,16 @@ class X2GoBrokerWeb(_RequestHandler): profile_info = broker_backend.select_session(profile_id=profile_id, username=username, pubkey=pubkey) - if profile_info.has_key('server'): + if 'server' in profile_info: username, password, task, profile_id, ip, cookie, authed, server = broker_backend.run_optional_script(script_type='select_session_scripts', username=username, password=password, task=task, profile_id=profile_id, ip=ip, cookie=cookie, authed=access, server=profile_info['server']) output += "SERVER:" output += server - if profile_info.has_key('port'): + if 'port' in profile_info: output += ":{port}".format(port=profile_info['port']) output += "\n" - if profile_info.has_key('authentication_privkey'): + if 'authentication_privkey' in profile_info: output += profile_info['authentication_privkey'] - if profile_info.has_key('session_info'): + if 'session_info' in profile_info: output += "SESSION_INFO:" output += profile_info['session_info'] + "\n" diff --git a/x2gobroker/web/uccs.py b/x2gobroker/web/uccs.py index c1ab032..bad8307 100644 --- a/x2gobroker/web/uccs.py +++ b/x2gobroker/web/uccs.py @@ -18,7 +18,6 @@ # modules import datetime -import types import random import tornado.web @@ -49,7 +48,7 @@ def credentials_validate(username, password): class _RequestHandler(tornado.web.RequestHandler): def _handle_request_exception(self, e): - logger_error.error('HTTP request error: {error_msg}'.format(error_msg=unicode(e))) + logger_error.error('HTTP request error: {error_msg}'.format(error_msg=e)) class X2GoBrokerWeb(_RequestHandler): @@ -61,7 +60,7 @@ class X2GoBrokerWeb(_RequestHandler): raise tornado.web.HTTPError(405) def head(self, path): - self.write(unicode(datetime.datetime.utcnow())) + self.write(datetime.datetime.utcnow()) return @@ -75,7 +74,7 @@ class X2GoBrokerWebAPI(tornado.web.RequestHandler): def _gen_http_header(self): - for http_header_item in self.http_header_items.keys(): + for http_header_item in list(self.http_header_items.keys()): self.set_header(http_header_item, self.http_header_items[http_header_item]) def get(self, *args, **kwargs): @@ -96,8 +95,9 @@ class X2GoBrokerWebAPI(tornado.web.RequestHandler): try: # dynamically detect broker backend from given URL - exec("import x2gobroker.brokers.{backend}_broker".format(backend=self.backend)) - exec("self.broker_backend = x2gobroker.brokers.{backend}_broker.X2GoBroker()".format(backend=self.backend)) + namespace = {} + exec("import x2gobroker.brokers.{backend}_broker\nbroker_backend = x2gobroker.brokers.{backend}_broker.X2GoBroker()".format(backend=self.backend), namespace) + self.broker_backend = namespace['broker_backend'] except ImportError: # throw a 404 if the backend does not exist raise tornado.web.HTTPError(404) @@ -148,28 +148,28 @@ class X2GoBrokerWebAPI(tornado.web.RequestHandler): for profile_id in profile_ids: profile = self.broker_backend.get_profile_for_user(profile_id, username, broker_frontend='uccs') - hosts = profile[u'host'] - if type(hosts) == types.UnicodeType: + hosts = profile['host'] + if type(hosts) == str: hosts = [hosts] - if profile[u'directrdp']: + if profile['directrdp']: ts = x2gobroker.uccsjson.RDPServer( host='{hostname}'.format(hostname=hosts[0]), - name=profile[u'name'], - username=profile[u'user'], + name=profile['name'], + username=profile['user'], ) ts.set_domain('LOCAL') else: _hostname = random.choice(hosts) - _port = profile[u'sshport'] - if profile.has_key('sshport={hostname}'.format(hostname=_hostname)): + _port = profile['sshport'] + if 'sshport={hostname}'.format(hostname=_hostname) in profile: _port = profile['sshport={hostname}'.format(hostname=_hostname)] - if profile.has_key('host={hostname}'.format(hostname=_hostname)): + if 'host={hostname}'.format(hostname=_hostname) in profile: _hostname = profile['host={hostname}'.format(hostname=_hostname)] ts = x2gobroker.uccsjson.X2GoServer( host='{hostname}:{port}'.format(hostname=_hostname, port=_port), - name=profile[u'name'], - username=profile[u'user'], + name=profile['name'], + username=profile['user'], ) _cmd = profile['command'] if _cmd.upper() in x2gobroker.defaults.X2GO_DESKTOP_SESSIONS: diff --git a/x2gobroker/x2gobroker_exceptions.py b/x2gobroker/x2gobroker_exceptions.py index 01af933..4dcfe0a 100644 --- a/x2gobroker/x2gobroker_exceptions.py +++ b/x2gobroker/x2gobroker_exceptions.py @@ -17,7 +17,7 @@ # Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. -from loggers import logger_error +from x2gobroker.loggers import logger_error class X2GoBrokerBaseException(BaseException): def __init__(self, *args, **kwargs): -- Alioth's /srv/git/code.x2go.org/x2gobroker.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/x2gobroker.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2gobroker. commit 90ce1dd1e6f42d2b921bdf8dd7dc8bd55600b51d Author: Mike Gabriel <mike.gabriel@das-netzwerkteam.de> Date: Sat Sep 23 16:26:26 2017 +0200 debian/control: Drop from D (several bin:pkgs): python3-argparse, argparse is shipped with Python3 core. --- debian/control | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/debian/control b/debian/control index c830a44..ba29d8f 100644 --- a/debian/control +++ b/debian/control @@ -15,7 +15,7 @@ Build-Depends: python3-setuptools, python3-nose, python3-paste, -Standards-Version: 3.9.8 +Standards-Version: 4.1.0 XS-Python-Version: >= 3.4 Package: python3-x2gobroker @@ -57,7 +57,6 @@ Architecture: all Depends: ${misc:Depends}, python3, - python3-argparse, python3-setproctitle, python3-tornado, python3-wsgilog, @@ -89,7 +88,6 @@ Depends: adduser, lsb-base, python3, - python3-argparse, python3-setproctitle, python3-pampy, python3-x2gobroker (>= ${source:Version}), python3-x2gobroker (<< ${source:Version}.1~), @@ -121,7 +119,6 @@ Depends: adduser, lsb-base, python3, - python3-argparse, python3-setproctitle, python3-x2gobroker (>= ${source:Version}), python3-x2gobroker (<< ${source:Version}.1~), Suggests: @@ -212,7 +209,6 @@ Depends: ${misc:Depends}, python3, python3-setproctitle, - python3-argparse, python3-paramiko, perl, adduser, -- Alioth's /srv/git/code.x2go.org/x2gobroker.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/x2gobroker.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2gobroker. commit 0f2181f2b0a6392c833731744352e2c2afe25cc9 Author: Mike Gabriel <mike.gabriel@das-netzwerkteam.de> Date: Wed Apr 5 20:01:48 2017 +0000 bump upstream version to 0.0.4.0 --- debian/changelog | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/debian/changelog b/debian/changelog index b6deec6..2101e53 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +x2gobroker (0.0.4.0-0x2go1) UNRELEASED; urgency=medium + + * Port to Python 3. + + -- X2Go Release Manager <git-admin@x2go.org> Wed, Apr 5 18:01:48 2017 +0200 + x2gobroker (0.0.3.3-0x2go1) UNRELEASED; urgency=medium [ Mike Gabriel ] -- Alioth's /srv/git/code.x2go.org/x2gobroker.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/x2gobroker.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2gobroker. commit d7a6b7d30ece2a23c57c2c371e62be690416472c Author: Mike Gabriel <mike.gabriel@das-netzwerkteam.de> Date: Sat Sep 23 16:36:04 2017 +0200 Makefile: Assure that setup.py is run under Python3. --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index ecb7639..2a74382 100755 --- a/Makefile +++ b/Makefile @@ -75,8 +75,8 @@ install: mkdir -p "${DESTDIR}/var/lib/x2gobroker" \ "${DESTDIR}/var/log/x2gobroker" - # python-x2gobroker - python setup.py install --prefix="${PREFIX}" $${DESTDIR+--root="${DESTDIR}"} + # python3-x2gobroker + python3 setup.py install --prefix="${PREFIX}" $${DESTDIR+--root="${DESTDIR}"} mkdir -p "${DESTDIR}${ETCDIR}/broker" "${DESTDIR}/etc/pam.d" \ "${DESTDIR}/etc/default" ${INSTALL_FILE} defaults/python-x2gobroker.default \ -- Alioth's /srv/git/code.x2go.org/x2gobroker.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/x2gobroker.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2gobroker. commit 4556d117c3708fff7b6ad19149cb267c4d487df1 Author: Mike Gabriel <mike.gabriel@das-netzwerkteam.de> Date: Sat Sep 23 16:39:30 2017 +0200 Makefile: Add check target (drop empty test target). --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 2a74382..f411be7 100755 --- a/Makefile +++ b/Makefile @@ -69,7 +69,8 @@ clean_arch: clean_indep: -test: +check: + python3 test.py install: mkdir -p "${DESTDIR}/var/lib/x2gobroker" \ -- Alioth's /srv/git/code.x2go.org/x2gobroker.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/x2gobroker.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2gobroker. commit d023095d234624c4e6e187bc1658193fe95a98c7 Author: Mike Gabriel <mike.gabriel@das-netzwerkteam.de> Date: Sat Sep 23 16:39:47 2017 +0200 debian/rules: Enable unit tests at every package build. --- debian/rules | 2 ++ 1 file changed, 2 insertions(+) diff --git a/debian/rules b/debian/rules index 415b111..ee0bf1c 100755 --- a/debian/rules +++ b/debian/rules @@ -26,6 +26,8 @@ export PREFIX=/usr include /usr/share/cdbs/1/rules/debhelper.mk include /usr/share/cdbs/1/class/makefile.mk +DEB_MAKE_CHECK_TARGET = check + DEB_PYTHON_SYSTEM = $(shell test -f /usr/bin/dh_python3 && echo "" || echo "pysupport") DEB_PYTHON_INSTALL_ARGS_python3-x2gobroker ?= --root=$(DEB_DESTDIR) --no-compile -O0 --install-layout=deb -- Alioth's /srv/git/code.x2go.org/x2gobroker.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/x2gobroker.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2gobroker. commit 3cdd51cde82c8c8cb117a6ae08ee260ff6cef641 Author: Mike Gabriel <mike.gabriel@das-netzwerkteam.de> Date: Sat Sep 23 16:51:47 2017 +0200 x2gobroker.spec: Adapt to Python3 port. --- x2gobroker.spec | 103 ++++++++++++++++++++------------------------------------ 1 file changed, 37 insertions(+), 66 deletions(-) diff --git a/x2gobroker.spec b/x2gobroker.spec index 514c65c..51209bd 100644 --- a/x2gobroker.spec +++ b/x2gobroker.spec @@ -21,21 +21,18 @@ Source4: x2gobroker-rpmlintrc BuildRoot: %{_tmppath}/%{name}-%{version}-build %endif +BuildRequires: python3-devel %if 0%{?suse_version} -BuildRequires: python-devel BuildRequires: fdupes -%else -BuildRequires: python2-devel %endif BuildRequires: sudo -BuildRequires: python-setuptools +BuildRequires: python3-setuptools %if 0%{?fedora} || 0%{?el7} || 0%{?suse_version} >= 1230 BuildRequires: systemd %endif -Requires: python-argparse -Requires: python-setproctitle -Requires: python-wsgilog -Requires(pre): python-x2gobroker = %{version}-%{release} +Requires: python3-setproctitle +Requires: python3-wsgilog +Requires(pre): python3-x2gobroker = %{version}-%{release} %if 0%{?suse_version} Requires(pre): pwdutils @@ -67,33 +64,29 @@ A session broker is most useful in load balanced X2Go server farms. This package contains the x2gobroker executable. -%package -n python-x2gobroker -Summary: X2Go Session Broker (Python modules) +%package -n python3-x2gobroker +Summary: X2Go Session Broker (Python3 module) %if 0%{?suse_version} Group: Productivity/Networking/Remote Desktop %else Group: Applications/Communications %endif +Requires: python3 %if 0%{?suse_version} -Requires: python +Requires: python3-pampy %else -Requires: python2 +Requires: python3-pam %endif -%if 0%{?suse_version} -Requires: python-pampy -%else -Requires: python-pam -%endif -Requires: python-netaddr -Requires: python-tornado -Requires: python-paramiko -Requires: python-daemon -Requires: python-lockfile +Requires: python3-netaddr +Requires: python3-tornado +Requires: python3-paramiko +Requires: python3-daemon +Requires: python3-lockfile %if 0%{?suse_version} Requires(pre): permissions %endif -%description -n python-x2gobroker +%description -n python3-x2gobroker X2Go is a server based computing environment with - session resuming - low bandwidth support @@ -109,7 +102,7 @@ most appropriate for the user in front of the X2Go terminal. A session broker is most useful in load balanced X2Go server farms. -This package contains the broker's Python library. +This package contains the broker's Python3 library. %package authservice @@ -119,20 +112,15 @@ Group: Productivity/Networking/Remote Desktop %else Group: Applications/Communications %endif +Requires: python3 +Requires: python3-setproctitle %if 0%{?suse_version} -Requires: python +Requires: python3-pampy %else -Requires: python2 -%endif -Requires: python-argparse -Requires: python-setproctitle -%if 0%{?suse_version} -Requires: python-pampy -%else -Requires: python-pam +Requires: python3-pam %endif Requires: logrotate -Requires(pre): python-x2gobroker = %{version}-%{release} +Requires(pre): python3-x2gobroker = %{version}-%{release} %if 0%{?suse_version} Requires(pre): permissions %endif @@ -162,15 +150,10 @@ Group: Productivity/Networking/Remote Desktop %else Group: Applications/Communications %endif -%if 0%{?suse_version} -Requires: python -%else -Requires: python2 -%endif -Requires: python-argparse -Requires: python-setproctitle +Requires: python3 +Requires: python3-setproctitle Requires: logrotate -Requires(pre): python-x2gobroker = %{version}-%{release} +Requires(pre): python3-x2gobroker = %{version}-%{release} %if 0%{?suse_version} Requires(pre): permissions %endif @@ -274,11 +257,7 @@ Requires: apache2, apache2-mod_wsgi %else Requires: httpd, mod_wsgi %endif -%if 0%{?suse_version} -Requires: python -%else -Requires: python2 -%endif +Requires: python3 Requires: x2gobroker-authservice = %{version}-%{release} Requires: logrotate %if 0%{?suse_version} @@ -323,14 +302,9 @@ Requires: perl(:MODULE_COMPAT_%(eval "`%{__perl} -V:version`"; echo $versi %if 0%{?fedora} || 0%{?rhel} BuildRequires: perl-generators %endif -%if 0%{?suse_version} -Requires: python -%else -Requires: python2 -%endif -Requires: python-setproctitle -Requires: python-argparse -Requires: python-paramiko +Requires: python3 +Requires: python3-setproctitle +Requires: python3-paramiko Requires: perl(File::Which) %if 0%{?suse_version} Requires(pre): permissions @@ -379,6 +353,9 @@ installed on your to-be-managed X2Go servers. %prep %setup -q +%check +python3 test.py + %build echo "Files where we will be patching libexecedir:" find . -type f -exec grep -l "/usr/lib/x2go/" "{}" "+" @@ -390,12 +367,6 @@ sed -i etc/broker/x2gobroker-sessionprofiles.conf \ -e 's/^name=MATE - localhost/name=GNOME - localhost/' \ -e 's/^command=MATE/command=GNOME/' %endif -%if 0%{?fedora} >= 22 -grep -l -r -E '^#!/usr/bin/env python$' | while read file; do \ - sed -i "$file" \ - -e 's#/usr/bin/env python#/usr/bin/env python2#' -done -%endif sed -i logrotate/x2gobroker-authservice \ -e 's/adm/root/' sed -i logrotate/x2gobroker-loadchecker \ @@ -470,7 +441,7 @@ install -pm0755 %SOURCE1 \ %endif -%pre -n python-x2gobroker +%pre -n python3-x2gobroker if ! /usr/bin/getent group x2gobroker 1>/dev/null 2>/dev/null && /usr/sbin/groupadd -r x2gobroker; then if ! /usr/bin/getent passwd x2gobroker 1>/dev/null 2>/dev/null; then /usr/sbin/useradd -c "X2Go Broker System User" \ @@ -480,11 +451,11 @@ if ! /usr/bin/getent group x2gobroker 1>/dev/null 2>/dev/null && /usr/sbin/group fi %if 0%{?suse_version} -%post -n python-x2gobroker +%post -n python3-x2gobroker %set_permissions %{_localstatedir}/log/x2gobroker -%verifyscript -n python-x2gobroker +%verifyscript -n python3-x2gobroker %verify_permissions -e %{_localstatedir}/log/x2gobroker %endif @@ -696,7 +667,7 @@ fi %_mandir/man8/x2gobroker-testagent.8* -%files -n python-x2gobroker +%files -n python3-x2gobroker %defattr(-,root,root) %config(noreplace) %_sysconfdir/x2go %exclude %_sysconfdir/x2go/x2gobroker-wsgi.apache.conf @@ -705,7 +676,7 @@ fi %if 0%{?el5} || 0%{?el6} || (0%{?suse_version} && 0%{?suse_version} < 1140) %config %_sysconfdir/default/python-x2gobroker %endif -%python_sitelib/x2gobroker* +%python3_sitelib/x2gobroker* %attr(02750,x2gobroker,x2gobroker) %_localstatedir/log/x2gobroker %attr(00750,x2gobroker,x2gobroker) %_localstatedir/lib/x2gobroker -- Alioth's /srv/git/code.x2go.org/x2gobroker.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/x2gobroker.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2gobroker. commit f553365f07fe508433d375ea98049923ee023568 Author: Mike Gabriel <mike.gabriel@das-netzwerkteam.de> Date: Sun Sep 24 18:08:27 2017 +0200 Make hostname detection work for the default configuration (that defines localhost session profiles). --- x2gobroker/brokers/base_broker.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/x2gobroker/brokers/base_broker.py b/x2gobroker/brokers/base_broker.py index 95b6cc4..b6a6ee6 100644 --- a/x2gobroker/brokers/base_broker.py +++ b/x2gobroker/brokers/base_broker.py @@ -26,6 +26,7 @@ __NAME__ = 'x2gobroker-pylib' # modules import copy +import socket import uuid import netaddr import random @@ -1358,6 +1359,14 @@ class X2GoBroker(object): while not selected_session and server_list: + # X2Go Server uses the system's hostname, so let's replace + # that here automatically, if we tested things via localhost... + for h in server_list: + if h == 'localhost': + server_list.remove(h) + server_list.append(socket.gethostname()) + + matching_server_names = None if session_list: matching_server_names = x2gobroker.utils.matching_hostnames(server_list, [ si.split('|')[3] for si in session_list ]) -- Alioth's /srv/git/code.x2go.org/x2gobroker.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/x2gobroker.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2gobroker. commit f168c54704ca0759db6d09c78bab94e5bc927d12 Author: Mike Gabriel <mike.gabriel@das-netzwerkteam.de> Date: Sun Sep 24 18:17:42 2017 +0200 x2gobroker.spec: Bump package version. --- x2gobroker.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x2gobroker.spec b/x2gobroker.spec index 51209bd..fab4369 100644 --- a/x2gobroker.spec +++ b/x2gobroker.spec @@ -1,5 +1,5 @@ Name: x2gobroker -Version: 0.0.3.3 +Version: 0.0.4.0 Release: 0.0x2go1%{?dist} Summary: X2Go Session Broker %if 0%{?suse_version} -- Alioth's /srv/git/code.x2go.org/x2gobroker.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/x2gobroker.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2gobroker. commit 6efbbc451f9b0c6fd416d0d5cca629f1da063a8b Author: Mike Gabriel <mike.gabriel@das-netzwerkteam.de> Date: Sun Sep 24 02:34:53 2017 +0200 debian/{control,x2gobroker-common.install}: Split out common files into non-Pythonian bin:pkg. --- debian/control | 73 +++++++++++++++------- debian/python3-x2gobroker.install | 5 -- ...2gobroker.install => x2gobroker-common.install} | 1 - 3 files changed, 52 insertions(+), 27 deletions(-) diff --git a/debian/control b/debian/control index ba29d8f..c479142 100644 --- a/debian/control +++ b/debian/control @@ -18,22 +18,18 @@ Build-Depends: Standards-Version: 4.1.0 XS-Python-Version: >= 3.4 -Package: python3-x2gobroker -Section: python +Package: x2gobroker Architecture: all Depends: ${misc:Depends}, python3, - python3-daemon, - python3-lockfile, - python3-pampy, - python3-netaddr, + python3-setproctitle, python3-tornado, - python3-paramiko, - python3-urllib3, -Recommends: - python3-simplejson, -Description: X2Go Session Broker (Python modules) + python3-wsgilog, + python3-x2gobroker (>= ${source:Version}), python3-x2gobroker (<< ${source:Version}.1~), +Suggests: + apache2 | httpd, +Description: X2Go Session Broker (executable) X2Go is a server based computing environment with - session resuming - low bandwidth support @@ -49,21 +45,55 @@ Description: X2Go Session Broker (Python modules) . A session broker is most useful in load balanced X2Go server farms. . - This package contains common files needed by all X2Go session - brokers being package for this distribution. + This package contains the x2gobroker executable. -Package: x2gobroker +Package: x2gobroker-common +Architecture: all +Depends: + ${misc:Depends}, +Breaks: + python-x2gobroker (<< 0.0.4.0~), +Replaces: + python-x2gobroker (<< 0.0.4.0~), +Description: X2Go Session Broker (common files) + X2Go is a server based computing environment with + - session resuming + - low bandwidth support + - session brokerage support + - client side mass storage mounting support + - client side printing support + - audio support + - authentication by smartcard and USB stick + . + The session broker is a server tool for X2Go that tells your X2Go Client + application in a terminal server cluster what servers and session types are + most appropriate for the user in front of the X2Go terminal. + . + A session broker is most useful in load balanced X2Go server farms. + . + This package contains x2gobroker common files. + +Package: python3-x2gobroker +Section: python Architecture: all Depends: ${misc:Depends}, python3, - python3-setproctitle, + python3-daemon, + python3-lockfile, + python3-pampy, + python3-netaddr, python3-tornado, - python3-wsgilog, - python3-x2gobroker (>= ${source:Version}), python3-x2gobroker (<< ${source:Version}.1~), -Suggests: - apache2 | httpd, -Description: X2Go Session Broker (executable) + python3-paramiko, + python3-urllib3, + x2gobroker-common (>= ${source:Version}), +Recommends: + python3-simplejson, +Breaks: + python-x2gobroker (<< 0.0.4.0), +Replaces: + python-x2gobroker (<< 0.0.4.0), +Description: X2Go Session Broker (Python3 modules) X2Go is a server based computing environment with - session resuming - low bandwidth support @@ -79,7 +109,8 @@ Description: X2Go Session Broker (executable) . A session broker is most useful in load balanced X2Go server farms. . - This package contains the x2gobroker executable. + This package contains common files needed by all X2Go session + brokers being package for this distribution. Package: x2gobroker-authservice Architecture: all diff --git a/debian/python3-x2gobroker.install b/debian/python3-x2gobroker.install index 702c646..1b91047 100644 --- a/debian/python3-x2gobroker.install +++ b/debian/python3-x2gobroker.install @@ -1,6 +1 @@ -etc/x2gobroker.conf etc/x2go/ -etc/broker/x2gobroker-sessionprofiles.conf etc/x2go/broker/ -etc/broker/x2gobroker-loggers.conf etc/x2go/broker/ -etc/broker/defaults.conf etc/x2go/broker/ -pam/x2gobroker etc/pam.d/ usr/ diff --git a/debian/python3-x2gobroker.install b/debian/x2gobroker-common.install similarity index 97% copy from debian/python3-x2gobroker.install copy to debian/x2gobroker-common.install index 702c646..99e4765 100644 --- a/debian/python3-x2gobroker.install +++ b/debian/x2gobroker-common.install @@ -3,4 +3,3 @@ etc/broker/x2gobroker-sessionprofiles.conf etc/x2go/broker/ etc/broker/x2gobroker-loggers.conf etc/x2go/broker/ etc/broker/defaults.conf etc/x2go/broker/ pam/x2gobroker etc/pam.d/ -usr/ -- Alioth's /srv/git/code.x2go.org/x2gobroker.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/x2gobroker.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2gobroker. commit a241fdbfd5f837a6552dffad21d557c41e42fc45 Author: Mike Gabriel <mike.gabriel@das-netzwerkteam.de> Date: Sun Sep 24 15:48:52 2017 +0200 Makefile: Clean-up x2gobroker-ssh executable in clean-arch target. --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index f411be7..a6ab80e 100755 --- a/Makefile +++ b/Makefile @@ -66,6 +66,7 @@ clean: clean_arch clean_indep clean_arch: $(RM_FILE) lib/x2gobroker-agent + $(RM_FILE) bin/x2gobroker-ssh clean_indep: -- Alioth's /srv/git/code.x2go.org/x2gobroker.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/x2gobroker.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2gobroker. commit 2a477a007bb99bca502e5dab3685325973f4d1ff Author: Mike Gabriel <mike.gabriel@das-netzwerkteam.de> Date: Sun Sep 24 16:40:05 2017 +0200 Improve debugging messages during authentication phase. --- x2gobroker/authmechs/pam_authmech.py | 4 ++-- x2gobroker/authservice.py | 8 ++++---- x2gobroker/brokers/base_broker.py | 6 ++++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/x2gobroker/authmechs/pam_authmech.py b/x2gobroker/authmechs/pam_authmech.py index 3486d65..44b140a 100644 --- a/x2gobroker/authmechs/pam_authmech.py +++ b/x2gobroker/authmechs/pam_authmech.py @@ -37,8 +37,8 @@ class X2GoBrokerAuthMech(object): return True except error: - logger_error.error('Authentication against authentication service failed, trying direct PAM authentication (which is likely to fail on most PAM setups).') - logger_error.error('Make sure the current user ({user}) is allowed to use the PAM authentication mechanism.'.format(user=getpass.getuser())) + logger_error.error('pam_authmech.X2GoBrokerAuthmech.authenticate(): Authentication against authentication service failed, trying direct PAM authentication (which is likely to fail on most PAM setups).') + logger_error.error('pam_authmech.X2GoBrokerAuthmech.authenticate(): Make sure the current user ({user}) is allowed to use the PAM authentication mechanism.'.format(user=getpass.getuser())) # fallback to direct PAM authentication against the PAM service ,,x2gobroker'' opam = pam if hasattr(pam, "pam"): diff --git a/x2gobroker/authservice.py b/x2gobroker/authservice.py index a512dc7..4df5187 100644 --- a/x2gobroker/authservice.py +++ b/x2gobroker/authservice.py @@ -27,15 +27,15 @@ from x2gobroker.loggers import logger_broker def authenticate(username, password, service="x2gobroker"): s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) - logger_broker.debug('connecting to authentication service socket {socket}'.format(socket=x2gobroker.defaults.X2GOBROKER_AUTHSERVICE_SOCKET)) + logger_broker.debug('authservice.authenticate(): connecting to authentication service socket {socket}'.format(socket=x2gobroker.defaults.X2GOBROKER_AUTHSERVICE_SOCKET)) s.connect(x2gobroker.defaults.X2GOBROKER_AUTHSERVICE_SOCKET) # FIXME: somehow logging output disappears after we have connected to the socket file... - logger_broker.debug('sending username={username}, password=<hidden>, service={service} to authentication service'.format(username=username, service=service)) + logger_broker.debug('authservice.authenticate(): sending username={username}, password=<hidden>, service={service} to authentication service'.format(username=username, service=service)) s.send('{username}\r{password}\r{service}\n'.format(username=username, password=password, service=service).encode()) result = s.recv(1024).decode() s.close() if result.startswith('ok'): - logger_broker.info('authentication against PAM service »{service}« succeeded for user »{username}«'.format(username=username, service=service)) + logger_broker.info('authservice.authenticate(): authentication against PAM service »{service}« succeeded for user »{username}«'.format(username=username, service=service)) return True - logger_broker.info('authentication against service »{service}« failed for user »{username}«'.format(username=username, service=service)) + logger_broker.info('authservice.authenticate(): authentication against service »{service}« failed for user »{username}«'.format(username=username, service=service)) return False diff --git a/x2gobroker/brokers/base_broker.py b/x2gobroker/brokers/base_broker.py index bed645c..95b6cc4 100644 --- a/x2gobroker/brokers/base_broker.py +++ b/x2gobroker/brokers/base_broker.py @@ -489,8 +489,10 @@ class X2GoBroker(object): def _do_authenticate(self, username='', password=''): - if self._import_authmech_module(mech=self.get_authentication_mechanism()): - logger_broker.debug('base_broker.X2GoBroker._do_authenticate(): authenticating user={username} with password=<hidden> against backend={backend}.'.format(username=username, backend=self.backend_name)) + mech = self.get_authentication_mechanism() + logger_broker.debug('base_broker.X2GoBroker._do_authenticate(): attempting authentication, will try "{mech}" mechanism for authenticating the user.'.format(mech=mech)) + if self._import_authmech_module(mech=mech): + logger_broker.debug('base_broker.X2GoBroker._do_authenticate(): authenticating user={username} with password=<hidden> against mechanism "{mech}".'.format(username=username, mech=mech)) return self.authmech_module.X2GoBrokerAuthMech().authenticate(username, password, config=self.config) else: return False -- Alioth's /srv/git/code.x2go.org/x2gobroker.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/x2gobroker.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2gobroker. commit 2e79591f3f22676b137fe1a9a8cd5bf4e4bf6bd5 Author: Mike Gabriel <mike.gabriel@das-netzwerkteam.de> Date: Sun Sep 24 02:35:43 2017 +0200 debian/*.install: Add EOLs at EOF. --- debian/x2gobroker-loadchecker.install | 2 +- debian/x2gobroker-wsgi.install | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/debian/x2gobroker-loadchecker.install b/debian/x2gobroker-loadchecker.install index 769abbc..3517e2a 100644 --- a/debian/x2gobroker-loadchecker.install +++ b/debian/x2gobroker-loadchecker.install @@ -1,3 +1,3 @@ sbin/x2gobroker-loadchecker usr/sbin/ logrotate/x2gobroker-loadchecker etc/logrotate.d/ -etc/broker/x2gobroker-loadchecker-logger.conf etc/x2go/broker \ No newline at end of file +etc/broker/x2gobroker-loadchecker-logger.conf etc/x2go/broker diff --git a/debian/x2gobroker-wsgi.install b/debian/x2gobroker-wsgi.install index f7f6452..9278f62 100644 --- a/debian/x2gobroker-wsgi.install +++ b/debian/x2gobroker-wsgi.install @@ -1,3 +1,3 @@ etc/x2gobroker-wsgi.apache.conf /etc/x2go/ etc/x2gobroker-wsgi.apache.vhost /etc/x2go/ -logrotate/x2gobroker-wsgi etc/logrotate.d/ \ No newline at end of file +logrotate/x2gobroker-wsgi etc/logrotate.d/ -- Alioth's /srv/git/code.x2go.org/x2gobroker.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/x2gobroker.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2gobroker. commit e6724970da3e8118efee45526d765fce6ed61d5d Author: Mike Gabriel <mike.gabriel@das-netzwerkteam.de> Date: Sun Sep 24 02:36:03 2017 +0200 debian/control: Switch from libapache2-mod-wsgi to libapache2-mod-wsgi-py3. --- debian/control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/control b/debian/control index c479142..e74b03a 100644 --- a/debian/control +++ b/debian/control @@ -212,7 +212,7 @@ Depends: adduser, x2gobroker (>= ${source:Version}), x2gobroker (<< ${source:Version}.1~), Recommends: - libapache2-mod-wsgi, + libapache2-mod-wsgi-py3, Description: X2Go Session Broker (WSGI) X2Go is a server based computing environment with - session resuming -- Alioth's /srv/git/code.x2go.org/x2gobroker.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/x2gobroker.git