mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 15:42:02 +00:00
Merge pull request #31605 from vitlibar/fix-cleanup-in-integration-tests
Fix cleanup in integration tests
This commit is contained in:
commit
ef6079633d
@ -422,20 +422,17 @@ class ClickHouseCluster:
|
|||||||
|
|
||||||
# Just in case kill unstopped containers from previous launch
|
# Just in case kill unstopped containers from previous launch
|
||||||
try:
|
try:
|
||||||
# docker-compose names containers using the following formula:
|
unstopped_containers = self.get_running_containers()
|
||||||
# container_name = project_name + '_' + instance_name + '_1'
|
if unstopped_containers:
|
||||||
# We need to have "^/" and "$" in the "--filter name" option below to filter by exact name of the container, see
|
logging.debug(f"Trying to kill unstopped containers: {unstopped_containers}")
|
||||||
# https://stackoverflow.com/questions/48767760/how-to-make-docker-container-ls-f-name-filter-by-exact-name
|
|
||||||
filter_name = f'^/{self.project_name}_.*_1$'
|
|
||||||
if int(run_and_check(f'docker container list --all --filter name={filter_name} | wc -l', shell=True)) > 1:
|
|
||||||
logging.debug(f"Trying to kill unstopped containers for project {self.project_name}:")
|
|
||||||
unstopped_containers = run_and_check(f'docker container list --all --filter name={filter_name}', shell=True).splitlines()
|
|
||||||
logging.debug(f"Unstopped containers {unstopped_containers}")
|
|
||||||
for id in unstopped_containers:
|
for id in unstopped_containers:
|
||||||
run_and_check(f'docker kill {id}', shell=True, nothrow=True)
|
run_and_check(f'docker kill {id}', shell=True, nothrow=True)
|
||||||
run_and_check(f'docker rm {id}', shell=True, nothrow=True)
|
run_and_check(f'docker rm {id}', shell=True, nothrow=True)
|
||||||
left_ids = run_and_check(f'docker container list --all --filter name={filter_name}', shell=True)
|
unstopped_containers = self.get_running_containers()
|
||||||
logging.debug(f"Unstopped containers killed. Left {left_ids}")
|
if unstopped_containers:
|
||||||
|
logging.debug(f"Left unstopped containers: {unstopped_containers}")
|
||||||
|
else:
|
||||||
|
logging.debug(f"Unstopped containers killed.")
|
||||||
else:
|
else:
|
||||||
logging.debug(f"No running containers for project: {self.project_name}")
|
logging.debug(f"No running containers for project: {self.project_name}")
|
||||||
except:
|
except:
|
||||||
@ -487,6 +484,19 @@ class ClickHouseCluster:
|
|||||||
cmd += " client"
|
cmd += " client"
|
||||||
return cmd
|
return cmd
|
||||||
|
|
||||||
|
# Returns the list of currently running docker containers corresponding to this ClickHouseCluster.
|
||||||
|
def get_running_containers(self):
|
||||||
|
# docker-compose names containers using the following formula:
|
||||||
|
# container_name = project_name + '_' + instance_name + '_1'
|
||||||
|
# We need to have "^/" and "$" in the "--filter name" option below to filter by exact name of the container, see
|
||||||
|
# https://stackoverflow.com/questions/48767760/how-to-make-docker-container-ls-f-name-filter-by-exact-name
|
||||||
|
filter_name = f'^/{self.project_name}_.*_1$'
|
||||||
|
# We want the command "docker container list" to show only containers' ID and their names, separated by colon.
|
||||||
|
format = '{{.ID}}:{{.Names}}'
|
||||||
|
containers = run_and_check(f"docker container list --all --filter name='{filter_name}' --format '{format}'", shell=True)
|
||||||
|
containers = dict(line.split(':', 1) for line in containers.decode('utf8').splitlines())
|
||||||
|
return containers
|
||||||
|
|
||||||
def copy_file_from_container_to_container(self, src_node, src_path, dst_node, dst_path):
|
def copy_file_from_container_to_container(self, src_node, src_path, dst_node, dst_path):
|
||||||
fname = os.path.basename(src_path)
|
fname = os.path.basename(src_path)
|
||||||
run_and_check([f"docker cp {src_node.docker_id}:{src_path} {self.instances_dir}"], shell=True)
|
run_and_check([f"docker cp {src_node.docker_id}:{src_path} {self.instances_dir}"], shell=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user