[X2Go-Commits] [x2gobroker] 05/05: Get several issues around select_session fixed via tests in the broker's backend base.py.
git-admin at x2go.org
git-admin at x2go.org
Sun Nov 2 20:28:50 CET 2014
This is an automated email from the git hooks/post-receive script.
x2go pushed a commit to branch master
in repository x2gobroker.
commit 340cc71cf37f103104495e9d76861d1d8ab60a00
Author: Mike Gabriel <mike.gabriel at das-netzwerkteam.de>
Date: Sun Nov 2 20:28:40 2014 +0100
Get several issues around select_session fixed via tests in the broker's backend base.py.
---
debian/changelog | 2 +
x2gobroker/brokers/base_broker.py | 37 ++++++--
x2gobroker/tests/test_broker_inifile.py | 148 +++++++++++++++++++++++++++++++
3 files changed, 181 insertions(+), 6 deletions(-)
diff --git a/debian/changelog b/debian/changelog
index 1eeadd9..37fe2a8 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -187,6 +187,8 @@ x2gobroker (0.0.3.0-0x2go1) UNRELEASED; urgency=low
the current backend default.
- x2gobroker-authservice: Restructure logging. Enable log messages
for authentication requests.
+ - Get several issues around select_session fixed via tests in the
+ broker's backend base.py.
* debian/control:
+ Provide separate bin:package for SSH brokerage: x2gobroker-ssh.
+ Replace LDAP support with session brokerage support in LONG_DESCRIPTION.
diff --git a/x2gobroker/brokers/base_broker.py b/x2gobroker/brokers/base_broker.py
index 3e60280..93f86b3 100644
--- a/x2gobroker/brokers/base_broker.py
+++ b/x2gobroker/brokers/base_broker.py
@@ -1015,7 +1015,7 @@ class X2GoBroker(object):
if self.get_session_autologin(profile_id):
profile['autologin'] = True
- profile['key'] = u'<please-provide-during-session-selection>'
+ profile['key'] = u'<will-be-exchanged-during-session-selection>'
# make sure that desktop sessions (that we know by name) do run with rootless=false
if profile['command'] in x2gobroker.defaults.X2GO_DESKTOP_SESSIONS:
@@ -1028,21 +1028,33 @@ class X2GoBroker(object):
remote_agent = self.get_remote_agent(profile_id)
agent_query_mode = ( remote_agent == u'LOCAL') and u'LOCAL' or u'SSH'
if remote_agent:
+
+ success, running_sessions, suspended_sessions = x2gobroker.agent.has_sessions(username, remote_agent=remote_agent)
try:
success, running_sessions, suspended_sessions = x2gobroker.agent.has_sessions(username, remote_agent=remote_agent)
if running_sessions:
logger_broker.debug('base_broker.X2GoBroker.list_profiles(): found running sessions on host(s): {hosts}'.format(hosts=', '.join(running_sessions)))
if suspended_sessions:
logger_broker.debug('base_broker.X2GoBroker.list_profiles(): found running sessions on host(s): {hosts}'.format(hosts=', '.join(suspended_sessions)))
- if x2gobroker.utils.matching_hostnames(profile['host'], running_sessions): profile['status'] = u'R'
- if x2gobroker.utils.matching_hostnames(profile['host'], suspended_sessions): profile['status'] = u'S'
+ 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['host'] = [suspended_matching_hostnames[0]]
+ elif running_matching_hostnames:
+ profile['status'] = u'R'
+ profile['host'] = [running_matching_hostnames[0]]
+ else:
+ profile['host'] = [profile['host'][0]]
+
if profile.has_key('status') and profile['status']:
logger_broker.debug('base_broker.X2GoBroker.list_profiles(): marking session profile {name} as {status}'.format(name=profile['name'], status=profile['status']))
except x2gobroker.x2gobroker_exceptions.X2GoBrokerAgentException:
pass
+ else:
+ profile['host'] = [profile['host'][0]]
- profile['host'] = [profile['host'][0]]
list_of_profiles.update({profile_id: profile, })
return list_of_profiles
@@ -1104,9 +1116,11 @@ class X2GoBroker(object):
try:
running_sessions = []
suspended_sessions = []
+
+ matching_server_names = x2gobroker.utils.matching_hostnames(server_list, [ si.split('|')[3] for si in session_list ])
+
for session_info in session_list:
- session_host = session_info.split('|')[3]
- if session_host in server_list:
+ if session_info.split('|')[3] in matching_server_names:
if session_info.split('|')[4] == 'R':
running_sessions.append(session_info)
if session_info.split('|')[4] == 'S':
@@ -1133,6 +1147,17 @@ class X2GoBroker(object):
_session_server_name = session_info.split('|')[3]
if profile.has_key('host={server_name}'.format(server_name=_session_server_name)):
server_name = _session_server_name
+ elif _session_server_name in server_list:
+ server_name = _session_server_name
+ elif x2gobroker.utils.matching_hostnames(server_list, [_session_server_name]):
+ for _server_name in server_list:
+ if _server_name.startswith(_session_server_name):
+ server_name = _server_name
+ break
+ else:
+ logger_broker.error('base_broker.X2GoBroker.select_session(): configuration error. Hostnames in session profile and actual server names do not match, we won\'t be able to resume/take-over a session this time')
+ # choosing a random server from the server list, to end up anywhere at least...
+ server_name = random.choice(server_list)
except IndexError:
# FIXME: if we get here, we have to deal with a broken session info
diff --git a/x2gobroker/tests/test_broker_inifile.py b/x2gobroker/tests/test_broker_inifile.py
index 121c07f..8d86e14 100644
--- a/x2gobroker/tests/test_broker_inifile.py
+++ b/x2gobroker/tests/test_broker_inifile.py
@@ -547,6 +547,154 @@ host = test-7 (-test-6.extern)
self.assertEqual(inifile_backend.select_session('testprofile7'), _expected_result_7)
+ # TEST MULTI-HOST GET_PROFILE / SELECT_SESSION
+
+ def test_multihost_profiles(self):
+ _session_profiles = """
+[DEFAULT]
+command = MATE
+user = foo
+
+[testprofile1]
+host = host1
+
+[testprofile2]
+host = host1, host2
+
+[testprofile3]
+host = host1.mydomain, host2.mydomain
+
+[testprofile4]
+host = host1.mydomain, host2.yourdomain
+
+[testprofile5]
+host = host1.mydomain (10.0.2.4), host2.mydomain (10.0.2.5)
+
+[testprofile6]
+host = host1.mydomain (10.0.2.4), host2.mydomain (10.0.2.5)
+sshport = 23467
+
+[testprofile7]
+host = docker-vm-1 (localhost:22001), docker-vm-2 (localhost:22002)
+
+[testprofile8]
+host = docker-vm-0 (localhost), docker-vm-1 (localhost:22001), docker-vm-2 (localhost:22002)
+sshport = 22000
+
+"""
+ tf = tempfile.NamedTemporaryFile()
+ print >> tf, _session_profiles
+ 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():
+ self.assertFalse( (key.startswith('host') and key != 'host' ) )
+ _session1 = inifile_backend.select_session('testprofile1')
+ self.assertEqual ( _session1, {'port': 22, 'server': 'host1'} )
+
+ # test "testprofile2"
+ _profile2 = inifile_backend.get_profile('testprofile2')
+ _profile2['host'].sort()
+ self.assertTrue( ( _profile2['host'] == ['host1', 'host2'] ) )
+ for key in _profile2.keys():
+ self.assertFalse( (key.startswith('host') and key != 'host' ) )
+ _session2 = inifile_backend.select_session('testprofile2')
+ self.assertTrue ( _session2['port'] == 22 )
+ self.assertTrue ( _session2['server'] in ('host1', 'host2') )
+
+ # test "testprofile3"
+ _profile3 = inifile_backend.get_profile('testprofile3')
+ _profile3['host'].sort()
+ _profile5 = inifile_backend.get_profile('testprofile5')
+ self.assertTrue( ( _profile3['host'] == ['host1.mydomain', 'host2.mydomain'] ) )
+ for key in _profile3.keys():
+ self.assertFalse( (key.startswith('host') and key != 'host' ) )
+ _session3 = inifile_backend.select_session('testprofile3')
+ self.assertTrue ( _session3['port'] == 22 )
+ self.assertTrue ( _session3['server'] in ('host1.mydomain', 'host2.mydomain') )
+
+ # test "testprofile4"
+ _profile4 = inifile_backend.get_profile('testprofile4')
+ _profile4['host'].sort()
+ self.assertTrue( ( _profile4['host'] == ['host1.mydomain', 'host2.yourdomain'] ) )
+ for key in _profile4.keys():
+ self.assertFalse( (key.startswith('host') and key != 'host' ) )
+ _session4 = inifile_backend.select_session('testprofile4')
+ self.assertTrue ( _session4['port'] == 22 )
+ self.assertTrue ( _session4['server'] in ('host1.mydomain', 'host2.yourdomain') )
+
+ # test "testprofile5"
+ _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( _profile5['host=host1.mydomain'] == '10.0.2.4' )
+ self.assertTrue( _profile5['host=host2.mydomain'] == '10.0.2.5' )
+ self.assertTrue( _profile5['sshport'] == 22 )
+ _session5 = inifile_backend.select_session('testprofile5')
+ self.assertTrue ( _session5['port'] == 22 )
+ self.assertTrue ( _session5['server'] in ('10.0.2.4', '10.0.2.5') )
+
+ # test "testprofile6"
+ _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( _profile6['host=host1.mydomain'] == '10.0.2.4' )
+ self.assertTrue( _profile6['host=host2.mydomain'] == '10.0.2.5' )
+ self.assertTrue( _profile6['sshport'] == 23467 )
+ i = 0
+ while i < 10:
+ _session6 = inifile_backend.select_session('testprofile6')
+ self.assertTrue ( _session6['port'] == 23467 )
+ self.assertTrue ( _session6['server'] in ('10.0.2.4', '10.0.2.5') )
+ i += 1
+
+ # test "testprofile7"
+ _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( _profile7['host=docker-vm-1'] == 'localhost' )
+ self.assertTrue( _profile7['host=docker-vm-2'] == 'localhost' )
+ self.assertTrue( _profile7['sshport'] == 22 )
+ self.assertTrue( _profile7['sshport=docker-vm-1'] == 22001 )
+ self.assertTrue( _profile7['sshport=docker-vm-2'] == 22002 )
+ i = 0
+ while i < 10:
+ _session7 = inifile_backend.select_session('testprofile7')
+ self.assertTrue ( _session7['port'] in (22001, 22002) )
+ self.assertTrue ( _session7['server'] == 'localhost' )
+ i += 1
+
+ # test "testprofile8"
+ _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( _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.assertTrue( _profile8['sshport=docker-vm-1'] == 22001 )
+ self.assertTrue( _profile8['sshport=docker-vm-2'] == 22002 )
+ i = 0
+ while i < 10:
+ _session8 = inifile_backend.select_session('testprofile8', username='foo')
+ self.assertTrue ( _session8['port'] in (22000, 22001, 22002) )
+ self.assertTrue ( _session8['server'] == 'localhost' )
+ i += 1
+
+
def test_suite():
from unittest import TestSuite, makeSuite
suite = TestSuite()
--
Alioth's /srv/git/_hooks_/post-receive-email on /srv/git/code.x2go.org/x2gobroker.git
More information about the x2go-commits
mailing list