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.

(cherry picked from commit 65768b996d)
pull/48323/head
Felix Fontein 6 years ago committed by Matt Clay
parent c64f15ecf7
commit 74576470c2

@ -0,0 +1,2 @@
bugfixes:
- "docker_container - fix ``paused`` option (which never worked)."

@ -1274,6 +1274,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.
@ -1828,6 +1834,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):

Loading…
Cancel
Save