ansible/filter_plugins/fedmsg.py
Adam Williamson 0d3460f03a Drop fedmsg_qa_network concept
I don't think this is needed any more. openQA publishes natively
to fedora-messaging these days, and these groups never have done
anything there. ResultsDB still publishes to fedmsg, it seems,
but the new instances were not added to these groups and I don't
think we need/want to do that, we should just make sure they
have the necessary access via other more widely-used groups if
anything. (It seems like the restrictions these groups used to
affect have been - possibly temporarily - removed entirely at
present, but we can figure out any necessary changes there if the
restrictions are restored).

Signed-off-by: Adam Williamson <awilliam@redhat.com>
2020-06-11 22:49:59 +00:00

39 lines
1.2 KiB
Python

import operator
def invert_fedmsg_policy(groups, vars, env):
""" Given hostvars that map hosts -> topics, invert that
and return a dict that maps topics -> hosts.
Really, returns a list of tuples -- not a dict.
"""
if env == 'staging':
hosts = groups['all'] + groups['staging']
else:
hosts = [h for h in groups['all'] if h not in groups['staging']]
inverted = {}
for host in hosts:
prefix = '.'.join([vars[host]['fedmsg_prefix'],
vars[host]['fedmsg_env']])
fqdn = vars[host].get('fedmsg_fqdn', host)
for cert in vars[host]['fedmsg_certs']:
for topic in cert.get('can_send', []):
key = prefix + '.' + topic
inverted[key] = inverted.get(key, [])
inverted[key].append(cert['service'] + '-' + fqdn)
result = list(inverted.items())
# Sort things so they come out in a reliable order (idempotence)
[inverted[key].sort() for key in inverted]
result.sort(key=operator.itemgetter(0))
return result
class FilterModule(object):
def filters(self):
return {
"invert_fedmsg_policy": invert_fedmsg_policy,
}