Skip to content

Commit

Permalink
fix(docker): fix reuse_cluster to find instance
Browse files Browse the repository at this point in the history
code was looking for docker instance by prefix, but
the api need to have `*` at the end for it to actully
find any instances
  • Loading branch information
fruch committed Nov 20, 2022
1 parent 32caa88 commit 259bd1f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion sdcm/cluster_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def _create_nodes(self, count, enable_auto_bootstrap=False):

def _get_nodes(self):
containers = ContainerManager.get_containers_by_prefix(self.node_prefix)
for node_index, container in sorted((int(c.labels["NodeIndex"]), c) for c in containers):
for node_index, container in sorted(((int(c.labels["NodeIndex"]), c) for c in containers), key=lambda x: x[0]):
LOGGER.debug("Found container %s with name `%s' and index=%d", container, container.name, node_index)
node = self._create_node(node_index, container)
self.nodes.append(node)
Expand Down
2 changes: 1 addition & 1 deletion sdcm/utils/docker_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def _build_args(**kwargs):
@classmethod
def get_containers_by_prefix(cls, prefix: str, docker_client: DockerClient = None) -> List[Container]:
docker_client = docker_client or cls.default_docker_client
return docker_client.containers.list(all=True, filters={"name": prefix})
return docker_client.containers.list(all=True, filters={"name": f'{prefix}*'})

@classmethod
def get_container_name_by_id(cls, c_id: str, docker_client: DockerClient = None) -> str:
Expand Down
2 changes: 1 addition & 1 deletion unit_tests/test_utils_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def test_get_environ(self):

def test_get_containers_by_prefix(self):
self.assertEqual(ContainerManager.get_containers_by_prefix("blah"),
((), {"all": True, "filters": {"name": "blah"}, }, ))
((), {"all": True, "filters": {"name": "blah*"}, }, ))

def test_get_container_name_by_id(self):
with self.subTest("Try to get name of non-existent container"):
Expand Down

0 comments on commit 259bd1f

Please sign in to comment.