Commit 83120012 authored by Zenon Mousmoulas's avatar Zenon Mousmoulas

In servdata consumer templates, use a deduplicated list rather than a set so as

to preserve server order

Ordered ManyToMany in InstRealm.proxyto would come in handy
parent a5696ec0
...@@ -17,6 +17,9 @@ def wildcard_realm_least_precedence(a, b): ...@@ -17,6 +17,9 @@ def wildcard_realm_least_precedence(a, b):
return 1 return 1
else: else:
return 0 return 0
def deduplicated_list(seq):
seen = set()
return [x for x in seq if not (x in seen or seen.add(x))]
%>\ %>\
% for inst in insts: % for inst in insts:
% if inst['type'] in (1, 3) and 'realms' in inst: % if inst['type'] in (1, 3) and 'realms' in inst:
...@@ -24,13 +27,15 @@ def wildcard_realm_least_precedence(a, b): ...@@ -24,13 +27,15 @@ def wildcard_realm_least_precedence(a, b):
<%doc> <%doc>
The following one-liner does the equivalent of: The following one-liner does the equivalent of:
inst_servers = set() inst_servers = []
for r in inst['realms']: for r in inst['realms']:
if 'proxy_to' in inst['realms'][r]: if 'proxy_to' in inst['realms'][r]:
inst_servers.update(inst['realms'][r]['proxy_to']) inst_servers.append(inst['realms'][r]['proxy_to'])
# deduplicate like set, but preserve order
inst_servers = deduplicated_list(inst_servers)
for srv in inst_servers: for srv in inst_servers:
</%doc>\ </%doc>\
% for srv in set([s for r in inst['realms'] for s in inst['realms'][r]['proxy_to'] if 'proxy_to' in inst['realms'][r]]): % for srv in deduplicated_list([s for r in inst['realms'] for s in inst['realms'][r]['proxy_to'] if 'proxy_to' in inst['realms'][r]]):
% if 'seen' in servers[srv]: % if 'seen' in servers[srv]:
# server ${srv} defined previously # server ${srv} defined previously
% else: % else:
...@@ -59,7 +64,7 @@ servers[srv]['seen'] = True ...@@ -59,7 +64,7 @@ servers[srv]['seen'] = True
<% <%
realm_servers = {} realm_servers = {}
for t in ['auth', 'acct', 'auth+acct']: for t in ['auth', 'acct', 'auth+acct']:
realm_servers[t] = set([s for s in inst['realms'][realm]['proxy_to'] realm_servers[t] = deduplicated_list([s for s in inst['realms'][realm]['proxy_to']
if servers[s]['rad_pkt_type'] == t]) if servers[s]['rad_pkt_type'] == t])
%>\ %>\
% if len(realm_servers['auth+acct']) == len(inst['realms'][realm]['proxy_to']): % if len(realm_servers['auth+acct']) == len(inst['realms'][realm]['proxy_to']):
......
...@@ -17,6 +17,9 @@ def wildcard_realm_least_precedence(a, b): ...@@ -17,6 +17,9 @@ def wildcard_realm_least_precedence(a, b):
return 1 return 1
else: else:
return 0 return 0
def deduplicated_list(seq):
seen = set()
return [x for x in seq if not (x in seen or seen.add(x))]
%>\ %>\
<% <%
for inst in insts: for inst in insts:
...@@ -62,13 +65,15 @@ clients[client]['seen'] = True ...@@ -62,13 +65,15 @@ clients[client]['seen'] = True
<%doc> <%doc>
The following one-liner does the equivalent of: The following one-liner does the equivalent of:
inst_servers = set() inst_servers = []
for r in inst['realms']: for r in inst['realms']:
if 'proxy_to' in inst['realms'][r]: if 'proxy_to' in inst['realms'][r]:
inst_servers.update(inst['realms'][r]['proxy_to']) inst_servers.append(inst['realms'][r]['proxy_to'])
# deduplicate like set, but preserve order
inst_servers = deduplicated_list(inst_servers)
for srv in inst_servers: for srv in inst_servers:
</%doc>\ </%doc>\
% for srv in set([s for r in inst['realms'] for s in inst['realms'][r]['proxy_to'] if 'proxy_to' in inst['realms'][r]]): % for srv in deduplicated_list([s for r in inst['realms'] for s in inst['realms'][r]['proxy_to'] if 'proxy_to' in inst['realms'][r]]):
% if 'seen' in servers[srv]: % if 'seen' in servers[srv]:
# server ${srv} defined previously # server ${srv} defined previously
% else: % else:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment