Do not force remove containers

Paunch does docker/podman rm -f, when removes containers. It seems it
returns too early, having some leftovers (like docker service
endpoints) behind or pending for it to be removed later, in case of
big fat deamons.

Long story short, don't do rm -f and allow it to do its job gracefully
and without a hurry.

Change-Id: I346c49cb204f273bd7077ca5153412cda9846534
Closes-Bug: #1860004
Co-authored-by: Sergii Golovatiuk <sgolovat@redhat.com>
Signed-off-by: Bogdan Dobrelya <bdobreli@redhat.com>
(cherry picked from commit d39414e433)
This commit is contained in:
Bogdan Dobrelya 2020-01-16 16:41:59 +01:00
parent f8ede6b362
commit d2a7acfa22
3 changed files with 15 additions and 5 deletions

View File

@ -78,7 +78,8 @@ class DockerRunner(object):
self.remove_container(container) self.remove_container(container)
def remove_container(self, container): def remove_container(self, container):
cmd = [self.docker_cmd, 'rm', '-f', container] self.execute([self.docker_cmd, 'stop', container], self.log)
cmd = [self.docker_cmd, 'rm', container]
cmd_stdout, cmd_stderr, returncode = self.execute(cmd, self.log) cmd_stdout, cmd_stderr, returncode = self.execute(cmd, self.log)
if returncode != 0: if returncode != 0:
self.log.error('Error removing container: %s' % container) self.log.error('Error removing container: %s' % container)

View File

@ -219,12 +219,18 @@ class TestComposeV1Builder(base.TestCase):
six six six six
two-12345678 two two-12345678 two
three-12345678 three''', '', 0), three-12345678 three''', '', 0),
# stop five
('', '', 0),
# rm five # rm five
('', '', 0), ('', '', 0),
# stop six
('', '', 0),
# rm six # rm six
('', '', 0), ('', '', 0),
# inspect two # inspect two
('{"start_order": 1, "image": "centos:6"}', '', 0), ('{"start_order": 1, "image": "centos:6"}', '', 0),
# stop two, changed config data
('', '', 0),
# rm two, changed config data # rm two, changed config data
('', '', 0), ('', '', 0),
# inspect three # inspect three
@ -268,13 +274,16 @@ three-12345678 three''', '', 0),
mock.ANY mock.ANY
), ),
# rm containers not in config # rm containers not in config
mock.call(['docker', 'rm', '-f', 'five'], mock.ANY), mock.call(['docker', 'stop', 'five'], mock.ANY),
mock.call(['docker', 'rm', '-f', 'six'], mock.ANY), mock.call(['docker', 'rm', 'five'], mock.ANY),
mock.call(['docker', 'stop', 'six'], mock.ANY),
mock.call(['docker', 'rm', 'six'], mock.ANY),
# rm two, changed config # rm two, changed config
mock.call(['docker', 'inspect', '--type', 'container', mock.call(['docker', 'inspect', '--type', 'container',
'--format', '{{index .Config.Labels "config_data"}}', '--format', '{{index .Config.Labels "config_data"}}',
'two-12345678'], mock.ANY), 'two-12345678'], mock.ANY),
mock.call(['docker', 'rm', '-f', 'two-12345678'], mock.ANY), mock.call(['docker', 'stop', 'two-12345678'], mock.ANY),
mock.call(['docker', 'rm', 'two-12345678'], mock.ANY),
# check three, config hasn't changed # check three, config hasn't changed
mock.call(['docker', 'inspect', '--type', 'container', mock.call(['docker', 'inspect', '--type', 'container',
'--format', '{{index .Config.Labels "config_data"}}', '--format', '{{index .Config.Labels "config_data"}}',

View File

@ -95,7 +95,7 @@ class TestDockerRunner(base.TestCase):
self.runner.remove_container('one') self.runner.remove_container('one')
self.assert_execute( self.assert_execute(
popen, ['docker', 'rm', '-f', 'one'] popen, ['docker', 'rm', 'one']
) )
@mock.patch('subprocess.Popen') @mock.patch('subprocess.Popen')