The branch, master has been updated via 014e9a5c9b1535aa2a53114654f17f61d01cdf8c (commit) from 6f11897f570fdea9e1c1353ac2a614b253183a7e (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 014e9a5c9b1535aa2a53114654f17f61d01cdf8c Author: Mike Gabriel <mike.gabriel@das-netzwerkteam.de> Date: Wed Oct 2 16:50:36 2013 +0200 Add utils function: matching_hostnames(): test hostname lists for matching hostnames (with/without domain name). ----------------------------------------------------------------------- Summary of changes: debian/changelog | 2 ++ x2gobroker/tests/test_utils.py | 37 +++++++++++++++++++++++++++++++++++++ x2gobroker/utils.py | 21 +++++++++++++++++++++ 3 files changed, 60 insertions(+) The diff of changes is: diff --git a/debian/changelog b/debian/changelog index 8a05da2..bb2cb50 100644 --- a/debian/changelog +++ b/debian/changelog @@ -40,6 +40,8 @@ x2gobroker (0.0.3.0-0~x2go1) UNRELEASED; urgency=low - Fix the ping task in x2gobroker-agent.pl, process it without checking the given username. - Fix remote agent detection in case of some agents being down. + - Add utils function: matching_hostnames(): test hostname lists for + matching hostnames (with/without domain name). * /debian/control: + Replace LDAP support with session brokerage support in LONG_DESCRIPTION. * /debian/x2gobroker-agent.dirs: diff --git a/x2gobroker/tests/test_utils.py b/x2gobroker/tests/test_utils.py index 2480ffb..96ce51e 100644 --- a/x2gobroker/tests/test_utils.py +++ b/x2gobroker/tests/test_utils.py @@ -94,6 +94,43 @@ class TestX2GoBrokerUtils(unittest.TestCase): self.assertEqual(esl_keys, sln_keys) self.assertEqual(['extern', 'intern'], subdomains) + def test_matching_hostnames(self): + + server_list_a = ['server1', 'server2', 'server3'] + server_list_b = ['server2', 'server3', 'server4'] + matching_hostnames = x2gobroker.utils.matching_hostnames(server_list_a, server_list_b) + self.assertEqual(matching_hostnames, ['server2', 'server3']) + + server_list_a = ['server1.domain1', 'server2.domain1', 'server3.domain1'] + server_list_b = ['server2', 'server3', 'server4'] + matching_hostnames = x2gobroker.utils.matching_hostnames(server_list_a, server_list_b) + self.assertEqual(matching_hostnames, ['server2', 'server3']) + + server_list_a = ['server1', 'server2', 'server3'] + server_list_b = ['server2.domain2', 'server3.domain2', 'server4.domain2'] + matching_hostnames = x2gobroker.utils.matching_hostnames(server_list_a, server_list_b) + self.assertEqual(matching_hostnames, ['server2', 'server3']) + + server_list_a = ['server1.domain1', 'server2.domain1', 'server3.domain1'] + server_list_b = ['server2.domain2', 'server3.domain2', 'server4.domain2'] + matching_hostnames = x2gobroker.utils.matching_hostnames(server_list_a, server_list_b) + self.assertEqual(matching_hostnames, []) + + server_list_a = ['server1.domain1', 'server2.domain2', 'server3.domain1'] + server_list_b = ['server2.domain2', 'server3.domain2', 'server4.domain2'] + matching_hostnames = x2gobroker.utils.matching_hostnames(server_list_a, server_list_b) + self.assertEqual(matching_hostnames, ['server2.domain2']) + + server_list_a = ['server1.domain1', 'server2', 'server3.domain1'] + server_list_b = ['server2.domain2', 'server3.domain2', 'server4.domain2'] + matching_hostnames = x2gobroker.utils.matching_hostnames(server_list_a, server_list_b) + self.assertEqual(matching_hostnames, []) + + server_list_a = ['server1.domain1', 'server2', 'server3.domain1'] + server_list_b = ['server2', 'server3.domain2', 'server4.domain2'] + matching_hostnames = x2gobroker.utils.matching_hostnames(server_list_a, server_list_b) + self.assertEqual(matching_hostnames, ['server2']) + def test_suite(): from unittest import TestSuite, makeSuite diff --git a/x2gobroker/utils.py b/x2gobroker/utils.py index 83656ec..cc01eae 100644 --- a/x2gobroker/utils.py +++ b/x2gobroker/utils.py @@ -148,3 +148,24 @@ def normalize_hostnames(servers): servers_normalized = servers return servers_normalized, subdomains + +def matching_hostnames(server_list_a, server_list_b): + + matching_hosts = [] + + ### NORMALIZE (=reduce to hostname only) server names (list A) if possible + server_list_a_normalized, subdomains_a = normalize_hostnames(server_list_a) + + ### NORMALIZE server names (in list B), only if we have a unique domain match in list A + if len(subdomains_a) <= 1: + + server_list_b_normalized, subdomains_b = normalize_hostnames(server_list_b) + if len(subdomains_b) <= 1: + + if len(subdomains_a) == 0 or len(subdomains_b) == 0: + matching_hosts = list(set(server_list_a_normalized).intersection(set(server_list_b_normalized))) + + if not matching_hosts: + matching_hosts = list(set(server_list_a).intersection(set(server_list_b))) + + return matching_hosts hooks/post-receive -- x2gobroker.git (HTTP(S) Session broker for X2Go) This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "x2gobroker.git" (HTTP(S) Session broker for X2Go).