Skip to content

Commit

Permalink
fix: python3 missing iteritems() for OrderedDict
Browse files Browse the repository at this point in the history
Changing it to using items() instead fixes it.
  • Loading branch information
nicolas.delossantos committed Nov 26, 2019
1 parent fe611c7 commit 9fb1e0b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
6 changes: 3 additions & 3 deletions _modules/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def manage_repos(present={}, absent=[], exclusive=False, **kwargs):
"failed": []
}

for name, url in present.iteritems():
for name, url in present.items():
if not name or not url:
raise CommandExecutionError(('Supplied repo to add must have a name (%s) '
'and url (%s)' % (name, url)))
Expand All @@ -217,7 +217,7 @@ def manage_repos(present={}, absent=[], exclusive=False, **kwargs):
'stdout': add_repo(name, url, **kwargs)['stdout']
})
existing_repos = {
n: u for (n, u) in existing_repos.iteritems() if name != n
n: u for (n, u) in existing_repos.items() if name != n
}
except CommandExecutionError as e:
result['failed'].append({
Expand All @@ -231,7 +231,7 @@ def manage_repos(present={}, absent=[], exclusive=False, **kwargs):
# Handle removal of repositories configured to be absent (or not configured
# to be present if the `exclusive` flag is set)
#
existing_names = [name for (name, url) in existing_repos.iteritems()]
existing_names = [name for (name, url) in existing_repos.items()]
if exclusive:
present['stable'] = "exclude"
absent = [name for name in existing_names if not name in present]
Expand Down
40 changes: 20 additions & 20 deletions _states/helm_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,35 @@
def managed(name, present={}, absent=[], exclusive=False, helm_home=None):
'''
Ensure the supplied repositories are available to the helm client. If the
`exclusive` flag is set to a truthy value, any extra repositories in the
`exclusive` flag is set to a truthy value, any extra repositories in the
helm client will be removed.
name
The name of the state
present
A dict of repository names to urls to ensure are registered with the
A dict of repository names to urls to ensure are registered with the
Helm client
absent
A list of repository names to ensure are unregistered from the Helm client
exclusive
A boolean flag indicating whether the state should ensure only the
A boolean flag indicating whether the state should ensure only the
supplied repositories are availabe to the target minion.
helm_home
An optional path to the Helm home directory
An optional path to the Helm home directory
'''
ret = {'name': name,
'changes': {},
'result': True,
'comment': ''}

try:
result = __salt__['helm.manage_repos'](
present=present,
absent=absent,
present=present,
absent=absent,
exclusive=exclusive,
helm_home=helm_home
)
Expand All @@ -50,7 +50,7 @@ def managed(name, present={}, absent=[], exclusive=False, helm_home=None):
return ret

ret['comment'] = ("Repositories were in the desired state: "
"%s" % [name for (name, url) in present.iteritems()])
"%s" % [name for (name, url) in present.items()])
return ret
except CommandExecutionError as e:
ret['result'] = False
Expand All @@ -59,24 +59,24 @@ def managed(name, present={}, absent=[], exclusive=False, helm_home=None):

def updated(name, helm_home=None):
'''
Ensure the local Helm repository cache is up to date with each of the
helm client's configured remote chart repositories. Because the `helm repo
update` command doesn't indicate whether any changes were made to the local
Ensure the local Helm repository cache is up to date with each of the
helm client's configured remote chart repositories. Because the `helm repo
update` command doesn't indicate whether any changes were made to the local
cache, this will only indicate change if the Helm client failed to retrieve
an update from one or more of the repositories, regardless of whether an
an update from one or more of the repositories, regardless of whether an
update was made to the local Helm chart repository cache.
name
The name of the state
helm_home
An optional path to the Helm home directory
An optional path to the Helm home directory
'''
ret = {'name': name,
'changes': {},
'result': True,
'comment': 'Successfully synced repositories: ' }


try:
result = __salt__['helm.update_repos'](helm_home=helm_home)
Expand All @@ -86,20 +86,20 @@ def updated(name, helm_home=None):
r'Successfully got an update from the \"([^\"]+)\"', result['stdout'])
failed_repos = re.findall(
r'Unable to get an update from the \"([^\"]+)\"', result['stdout'])

if failed_repos and len(failed_repos) > 0:
ret['result'] = False
ret['changes']['succeeded'] = success_repos
ret['changes']['failed'] = failed_repos
ret['comment'] = 'Failed to sync against some repositories' + cmd_str
else:
ret['comment'] += "%s" % success_repos + cmd_str

except CommandExecutionError as e:
ret['name'] = e.cmd
ret['result'] = False
ret['comment'] = ("Failed to update repos: %s" % e.error +
ret['comment'] = ("Failed to update repos: %s" % e.error +
"\nExecuted command: %s" % e.cmd)
return ret

return ret
return ret

0 comments on commit 9fb1e0b

Please sign in to comment.