Fix python3 iteration over dictionary.
In python3 python prevents modifying the dictionary that is iterated over.
Instead of modifying the dictionary a new one is constructed instead.
Fixes bsc#1123497
@@ -23,10 +23,9 @@ def get_hosts():
:return: Dict(ip_address -> [aliases])
"""
hosts = __salt__['hosts.list_hosts']() # type: dict
- for key in hosts.keys():
- if key.startswith("comment-"):
- hosts.pop(key)
- return hosts
+ # Python3 (correctly) prevents modifying a dictionary we are iterating
+ # over, so we have to copy it first, so we can remove comment entries.
+ return {k:v for k,v in hosts.items() if not k.startswith("comment-")}
def get_aliases(hostname):
