Skip to content

Commit

Permalink
fix(stress-threads): kill only labeled docker containers on loaders
Browse files Browse the repository at this point in the history
There is no any filtering of docker instances, when killing containerized stress threads on
loader nodes during teardown of a test. In the case of docker backend this can result in
deleting all containers in the system.

The change fixes this by labeling stress thread related docker containers when they
are created; and deleting only the labeled containers during the teardown.

Fixes: #9027
  • Loading branch information
dimakr authored and soyacz committed Nov 18, 2024
1 parent d7ad4c8 commit 87ffeb7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion sdcm/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -5269,9 +5269,12 @@ def kill_cs_process(loader, filter_cmd):
str(loader), str(ex))

def kill_docker_loaders(self):
test_id = self.tags.get('TestId')
for loader in self.nodes:
try:
loader.remoter.run(cmd='docker ps -a -q | xargs docker rm -f', verbose=True, ignore_status=True)
loader.remoter.run(
cmd=f'docker ps -a -q --filter label=TestId={test_id} | xargs docker rm -f',
verbose=True, ignore_status=True)
self.log.info("Killed docker loader on node: %s", loader.name)
except Exception as ex: # pylint: disable=broad-except # noqa: BLE001
self.log.warning("failed to kill docker stress command on [%s]: [%s]",
Expand Down
1 change: 1 addition & 0 deletions sdcm/utils/docker_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def __init__(self, node, image_name, ports=None, command_line="tail -f /dev/null
if docker_network:
extra_docker_opts += f" --network {docker_network}"
self.create_network(docker_network)
extra_docker_opts += f" --label TestId={node.test_config.test_id()}"
res = self.node.remoter.run(
f'{self.sudo_needed} docker run {extra_docker_opts} -d {ports} {image_name} {command_line}',
verbose=True, retry=3)
Expand Down

0 comments on commit 87ffeb7

Please sign in to comment.