Skip to content

Commit

Permalink
Docker 1.12 reports tags as null (#35447)
Browse files Browse the repository at this point in the history
Add support for this new value.
  • Loading branch information
ticosax authored and Nicole Thomas committed Aug 15, 2016
1 parent be644a5 commit 49af330
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
11 changes: 6 additions & 5 deletions salt/modules/dockerng.py
Original file line number Diff line number Diff line change
Expand Up @@ -2065,9 +2065,11 @@ def images(verbose=False, **kwargs):
if img_id is None:
continue
for item in img:
img_state = 'untagged' \
if img['RepoTags'] == ['<none>:<none>'] \
else 'tagged'
img_state = ('untagged' if
img['RepoTags'] in (
['<none>:<none>'], # docker API <1.24
None, # docker API >=1.24
) else 'tagged')
bucket = __context__.setdefault('docker.images', {})
bucket = bucket.setdefault(img_state, {})
img_key = key_map.get(item, item)
Expand Down Expand Up @@ -2250,8 +2252,7 @@ def list_tags():
'''
ret = set()
for item in six.itervalues(images()):
for repo_tag in item.get('RepoTags', []):
ret.add(repo_tag)
ret.update(set(item['RepoTags']))
return sorted(ret)


Expand Down
19 changes: 19 additions & 0 deletions tests/unit/modules/dockerng_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,25 @@ def test_wait_fails_on_exit_status_and_already_stopped(self):
'state': {'new': 'stopped',
'old': 'stopped'}})

def test_images_with_empty_tags(self):
"""
docker 1.12 reports also images without tags with `null`.
"""
client = Mock()
client.api_version = '1.24'
client.images = Mock(
return_value=[{'Id': 'sha256:abcde',
'RepoTags': None},
{'Id': 'sha256:abcdef'},
{'Id': 'sha256:abcdefg',
'RepoTags': ['image:latest']}])
with patch.dict(dockerng_mod.__context__,
{'docker.client': client}):
dockerng_mod._clear_context()
result = dockerng_mod.images()
self.assertEqual(result,
{'sha256:abcdefg': {'RepoTags': ['image:latest']}})


if __name__ == '__main__':
from integration import run_tests
Expand Down

0 comments on commit 49af330

Please sign in to comment.