mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #43155 from terminalmage/issue43001
Resolve image ID during container comparison
This commit is contained in:
commit
a6a327b1e5
2 changed files with 37 additions and 0 deletions
|
@ -902,6 +902,11 @@ def compare_container(first, second, ignore=None):
|
|||
if item in ('OomKillDisable',):
|
||||
if bool(val1) != bool(val2):
|
||||
ret.setdefault(conf_dict, {})[item] = {'old': val1, 'new': val2}
|
||||
elif item == 'Image':
|
||||
image1 = inspect_image(val1)['Id']
|
||||
image2 = inspect_image(val2)['Id']
|
||||
if image1 != image2:
|
||||
ret.setdefault(conf_dict, {})[item] = {'old': image1, 'new': image2}
|
||||
else:
|
||||
if item == 'Links':
|
||||
val1 = _scrub_links(val1, first)
|
||||
|
@ -920,6 +925,11 @@ def compare_container(first, second, ignore=None):
|
|||
if item in ('OomKillDisable',):
|
||||
if bool(val1) != bool(val2):
|
||||
ret.setdefault(conf_dict, {})[item] = {'old': val1, 'new': val2}
|
||||
elif item == 'Image':
|
||||
image1 = inspect_image(val1)['Id']
|
||||
image2 = inspect_image(val2)['Id']
|
||||
if image1 != image2:
|
||||
ret.setdefault(conf_dict, {})[item] = {'old': image1, 'new': image2}
|
||||
else:
|
||||
if item == 'Links':
|
||||
val1 = _scrub_links(val1, first)
|
||||
|
|
|
@ -697,3 +697,30 @@ class DockerTestCase(TestCase, LoaderModuleMockMixin):
|
|||
result = docker_mod.images()
|
||||
self.assertEqual(result,
|
||||
{'sha256:abcdefg': {'RepoTags': ['image:latest']}})
|
||||
|
||||
def test_compare_container_image_id_resolution(self):
|
||||
'''
|
||||
Test comparing two containers when one's inspect output is an ID and
|
||||
not formatted in image:tag notation.
|
||||
'''
|
||||
def _inspect_container_effect(id_):
|
||||
return {
|
||||
'container1': {'Config': {'Image': 'realimage:latest'},
|
||||
'HostConfig': {}},
|
||||
'container2': {'Config': {'Image': 'image_id'},
|
||||
'HostConfig': {}},
|
||||
}[id_]
|
||||
|
||||
def _inspect_image_effect(id_):
|
||||
return {
|
||||
'realimage:latest': {'Id': 'image_id'},
|
||||
'image_id': {'Id': 'image_id'},
|
||||
}[id_]
|
||||
|
||||
inspect_container_mock = MagicMock(side_effect=_inspect_container_effect)
|
||||
inspect_image_mock = MagicMock(side_effect=_inspect_image_effect)
|
||||
|
||||
with patch.object(docker_mod, 'inspect_container', inspect_container_mock):
|
||||
with patch.object(docker_mod, 'inspect_image', inspect_image_mock):
|
||||
ret = docker_mod.compare_container('container1', 'container2')
|
||||
self.assertEqual(ret, {})
|
||||
|
|
Loading…
Add table
Reference in a new issue