mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Merge pull request #31352 from ticosax/pull-image-on-running
[dockerng] Pull missing images when calling dockerng.running
This commit is contained in:
commit
105821efc7
@ -1461,6 +1461,20 @@ def running(name,
|
||||
except TypeError:
|
||||
image = ':'.join(_get_repo_tag(str(image)))
|
||||
|
||||
if image not in __salt__['dockerng.list_tags']():
|
||||
try:
|
||||
# Pull image
|
||||
pull_result = __salt__['dockerng.pull'](
|
||||
image,
|
||||
client_timeout=client_timeout,
|
||||
)
|
||||
except Exception as exc:
|
||||
comments = ['Failed to pull {0}: {1}'.format(image, exc)]
|
||||
ret['comment'] = _format_comments(comments)
|
||||
return ret
|
||||
else:
|
||||
ret['changes']['image'] = pull_result
|
||||
|
||||
image_id = __salt__['dockerng.inspect_image'](image)['Id']
|
||||
|
||||
if name not in __salt__['dockerng.list_containers'](all=True):
|
||||
|
@ -376,7 +376,8 @@ class DockerngTestCase(TestCase):
|
||||
__salt__ = {'dockerng.list_containers': dockerng_list_containers,
|
||||
'dockerng.inspect_container': dockerng_inspect_container,
|
||||
'dockerng.inspect_image': dockerng_inspect_image,
|
||||
'dockerng.list_tags': MagicMock(),
|
||||
'dockerng.list_tags': MagicMock(
|
||||
return_value=['image:latest']),
|
||||
'dockerng.pull': MagicMock(),
|
||||
'dockerng.state': MagicMock(side_effect=['stopped',
|
||||
'running']),
|
||||
@ -466,7 +467,7 @@ class DockerngTestCase(TestCase):
|
||||
'dockerng.inspect_container': dockerng_inspect_container,
|
||||
'dockerng.inspect_image': dockerng_inspect_image,
|
||||
'dockerng.list_tags': MagicMock(),
|
||||
'dockerng.pull': MagicMock(),
|
||||
'dockerng.pull': MagicMock(return_value=True),
|
||||
'dockerng.state': MagicMock(side_effect=['stopped',
|
||||
'running']),
|
||||
'dockerng.create': dockerng_create,
|
||||
@ -482,7 +483,8 @@ class DockerngTestCase(TestCase):
|
||||
self.assertEqual(ret, {'name': 'cont',
|
||||
'comment': "Container 'cont' changed state.",
|
||||
'changes': {'state': {'new': 'running',
|
||||
'old': 'stopped'}},
|
||||
'old': 'stopped'},
|
||||
'image': True},
|
||||
'result': True,
|
||||
})
|
||||
|
||||
@ -508,7 +510,8 @@ class DockerngTestCase(TestCase):
|
||||
- KEY: "1"
|
||||
'''
|
||||
__salt__ = {'dockerng.list_containers': MagicMock(),
|
||||
'dockerng.list_tags': MagicMock(),
|
||||
'dockerng.list_tags': MagicMock(
|
||||
return_value=['image:latest']),
|
||||
'dockerng.inspect_image': MagicMock(),
|
||||
'dockerng.pull': MagicMock(),
|
||||
'dockerng.state': MagicMock(),
|
||||
|
Loading…
Reference in New Issue
Block a user