docker_container: fix paused and add some tests (#47900)

* cleanup is already tested.

* Add test for paused.

* Add recreate and restart tests.

* timeout is a common docker option

* Implement paused and fix paused test.

* Add changelog.

* Improve paused test.
This commit is contained in:
Felix Fontein 2018-11-01 09:08:43 +01:00 committed by John R Barker
parent 242bd512d0
commit 65768b996d
3 changed files with 177 additions and 16 deletions

View file

@ -1538,6 +1538,12 @@ class Container(DockerBaseClass):
return True
return False
@property
def paused(self):
if self.container and self.container.get('State'):
return self.container['State'].get('Paused', False)
return False
def _compare(self, a, b, compare):
'''
Compare values a and b as described in compare.
@ -2122,6 +2128,20 @@ class ContainerManager(DockerBaseClass):
self.container_stop(container.Id)
container = self._get_container(container.Id)
if state == 'started' and container.paused != self.parameters.paused:
if not self.check_mode:
try:
if self.parameters.paused:
self.client.pause(container=container.Id)
else:
self.client.unpause(container=container.Id)
except Exception as exc:
self.fail("Error %s container %s: %s" % (
"pausing" if self.parameters.paused else "unpausing", container.Id, str(exc)
))
self.results['changed'] = True
self.results['actions'].append(dict(set_paused=self.parameters.paused))
self.facts = container.raw
def absent(self):