mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #46183 from oeuftete/fix-docker-container-running-host-config-ulimits
Fix docker_container.running HostConfig Ulimits comparison
This commit is contained in:
commit
da60399b8f
3 changed files with 46 additions and 2 deletions
|
@ -575,6 +575,15 @@ def _scrub_links(links, name):
|
|||
return ret
|
||||
|
||||
|
||||
def _ulimit_sort(ulimit_val):
|
||||
if isinstance(ulimit_val, list):
|
||||
return sorted(ulimit_val,
|
||||
key=lambda x: (x.get('Name'),
|
||||
x.get('Hard', 0),
|
||||
x.get('Soft', 0)))
|
||||
return ulimit_val
|
||||
|
||||
|
||||
def _size_fmt(num):
|
||||
'''
|
||||
Format bytes as human-readable file sizes
|
||||
|
@ -912,6 +921,9 @@ def compare_container(first, second, ignore=None):
|
|||
if item == 'Links':
|
||||
val1 = sorted(_scrub_links(val1, first))
|
||||
val2 = sorted(_scrub_links(val2, second))
|
||||
if item == 'Ulimits':
|
||||
val1 = _ulimit_sort(val1)
|
||||
val2 = _ulimit_sort(val2)
|
||||
if val1 != val2:
|
||||
ret.setdefault(conf_dict, {})[item] = {'old': val1, 'new': val2}
|
||||
# Check for optionally-present items that were in the second container
|
||||
|
@ -935,6 +947,9 @@ def compare_container(first, second, ignore=None):
|
|||
if item == 'Links':
|
||||
val1 = sorted(_scrub_links(val1, first))
|
||||
val2 = sorted(_scrub_links(val2, second))
|
||||
if item == 'Ulimits':
|
||||
val1 = _ulimit_sort(val1)
|
||||
val2 = _ulimit_sort(val2)
|
||||
if val1 != val2:
|
||||
ret.setdefault(conf_dict, {})[item] = {'old': val1, 'new': val2}
|
||||
return ret
|
||||
|
|
|
@ -1445,14 +1445,14 @@ def running(name,
|
|||
.. code-block:: yaml
|
||||
|
||||
foo:
|
||||
dockerng.running:
|
||||
docker_container.running:
|
||||
- image: bar/baz:latest
|
||||
- ulimits: nofile=1024:1024,nproc=60
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
foo:
|
||||
dockerng.running:
|
||||
docker_container.running:
|
||||
- image: bar/baz:latest
|
||||
- ulimits:
|
||||
- nofile=1024:1024
|
||||
|
|
|
@ -725,6 +725,35 @@ class DockerTestCase(TestCase, LoaderModuleMockMixin):
|
|||
ret = docker_mod.compare_container('container1', 'container2')
|
||||
self.assertEqual(ret, {})
|
||||
|
||||
def test_compare_container_ulimits_order(self):
|
||||
'''
|
||||
Test comparing two containers when the order of the Ulimits HostConfig
|
||||
values are different, but the values are the same.
|
||||
'''
|
||||
def _inspect_container_effect(id_):
|
||||
return {
|
||||
'container1': {'Config': {},
|
||||
'HostConfig': {
|
||||
'Ulimits': [
|
||||
{u'Hard': -1, u'Soft': -1, u'Name': u'core'},
|
||||
{u'Hard': 65536, u'Soft': 65536, u'Name': u'nofile'}
|
||||
]
|
||||
}},
|
||||
'container2': {'Config': {},
|
||||
'HostConfig': {
|
||||
'Ulimits': [
|
||||
{u'Hard': 65536, u'Soft': 65536, u'Name': u'nofile'},
|
||||
{u'Hard': -1, u'Soft': -1, u'Name': u'core'}
|
||||
]
|
||||
}},
|
||||
}[id_]
|
||||
|
||||
inspect_container_mock = MagicMock(side_effect=_inspect_container_effect)
|
||||
|
||||
with patch.object(docker_mod, 'inspect_container', inspect_container_mock):
|
||||
ret = docker_mod.compare_container('container1', 'container2')
|
||||
self.assertEqual(ret, {})
|
||||
|
||||
def test_resolve_tag(self):
|
||||
'''
|
||||
Test the resolve_tag function
|
||||
|
|
Loading…
Add table
Reference in a new issue