-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed dockerng.list_tags #34702
Fixed dockerng.list_tags #34702
Conversation
Thanks, @farcaller |
This affects more than just Any ETA on when this will get released as a bugfix for For those who run into this issue, tagging the images missing tags will fix it: hjc1710@app-int01:/opt/app$ sudo salt-call state.highstate
# fails with the above error
hjc1710@app-int01:/opt/app$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
croscon/app int 26ad75aa118b 29 minutes ago 1.86 GB
croscon/app <none> 57c6e7e2d3ae 10 hours ago 1.859 GB
...
hjc1710@app-int01:/opt/app$ docker tag 57c6e7e2d3ae croscon/app:flkasd
hjc1710@app-int01:/opt/app$ sudo salt-call state.highstate
# proceeds to now work; clean up tags |
It also causes |
as @hjc1710 notices in dockerng.image_present: File "/usr/lib/python2.7/dist-packages/salt/modules/dockerng.py", line 2253, in list_tags
for repo_tag in item.get('RepoTags', []):
TypeError: 'NoneType' object is not iterable This happens even though I have no untagged images. So there is no known workaround. |
This is the state I've been using to work around this issue: https://gist.github.com/hjc1710/8192e95dd8adc0069bea14a05360da4f. The main thing to note is that it has to be run after ANY state that might untag an image. For me, this is pulling a new image, plus an image retag I have to do for organizational reasons. The only other thing missing from it, is that I If the The only caveat is that those images are no longer dangling, so common cleanup tools like Also, now that I see @ajslater's output, I think this bug might not really be solved. I definitely have the pre-PR code; but he has the latest code and is still getting an error, might be something missed here! |
I pulled this in and it did not fix the bug for me. The following does fix it, though I'll admit I don't quite understand why it's necessary. But for some reason it seems like item.get is still returning none instead of the default empty list. def list_tags():
'''
Returns a list of tagged images
CLI Example:
.. code-block:: bash
salt myminion dockerng.list_tags
'''
ret = set()
for item in six.itervalues(images()):
if not item['RepoTags']:
continue
for repo_tag in item.get('RepoTags', []):
ret.add(repo_tag)
return sorted(ret) |
@clinta - this is entirely expected. That's the standard behavior of >>> foo = {}
>>> foo.get('bar', [])
[]
>>> foo['bar'] = None
>>> print foo.get('bar', [])
None Basically, if key in dict_:
return dict_[key]
else:
return default And not: if key in dict_ and dict_[key]:
return dict_[key]
else:
return default |
I've tried a different approach in #35308, looks cleaner. PTAL? |
What does this PR do?
Fixes a bug in dockerng module crashing when an image doesn't have tags.
Previous Behavior
Tests written?
No