Fix support of dockerng.volume_present when no volume is on present.

fixes #32493
This commit is contained in:
Nicolas Delaby 2016-04-13 15:47:13 +02:00
parent 492ebfc184
commit 958b2ec749
2 changed files with 28 additions and 1 deletions

View File

@ -2241,7 +2241,9 @@ def volume_present(name, driver=None, driver_opts=None, force=False):
'comment': ''}
if salt.utils.is_dictlist(driver_opts):
driver_opts = salt.utils.repack_dictlist(driver_opts)
volumes = [v for v in __salt__['dockerng.volumes']()['Volumes'] if v['Name'] == name]
volumes = __salt__['dockerng.volumes']()['Volumes']
if volumes is not None:
volumes = [v for v in volumes if v['Name'] == name]
if not volumes:
try:
ret['changes']['created'] = __salt__['dockerng.create_volume'](

View File

@ -871,6 +871,31 @@ class DockerngTestCase(TestCase):
'removed': 'removed'},
'result': True})
def test_volume_present_wo_existing_volumes(self):
'''
Test dockerng.volume_present without existing volumes.
'''
dockerng_create_volume = Mock(return_value='created')
dockerng_remove_volume = Mock(return_value='removed')
__salt__ = {'dockerng.create_volume': dockerng_create_volume,
'dockerng.remove_volume': dockerng_remove_volume,
'dockerng.volumes': Mock(return_value={'Volumes': None}),
}
with patch.dict(dockerng_state.__dict__,
{'__salt__': __salt__}):
ret = dockerng_state.volume_present(
'volume_foo',
driver='bar',
force=True,
)
dockerng_create_volume.assert_called_with('volume_foo',
driver='bar',
driver_opts=None)
self.assertEqual(ret, {'name': 'volume_foo',
'comment': '',
'changes': {'created': 'created'},
'result': True})
def test_volume_absent(self):
'''
Test dockerng.volume_absent