Skip to content

Commit

Permalink
CI: baremetal: make cleanup scripts more generic
Browse files Browse the repository at this point in the history
Enable the bare metal slave machine cleanup scripts to be
called from any arch (lifting out the good work done for the
ARM slave cleanups).

Fixes: clearcontainers#888

Signed-off-by: Graham Whaley <[email protected]>
  • Loading branch information
Graham Whaley committed Nov 7, 2018
1 parent aff2c79 commit e1a3b67
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 72 deletions.
74 changes: 3 additions & 71 deletions .ci/aarch64/clean_up_aarch64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,76 +6,8 @@

set -e

stale_process_union=( "docker-containerd-shim" )
#docker supports different storage driver, such like overlay2, aufs, etc.
docker_storage_driver=$(docker info --format='{{.Driver}}')
stale_docker_mount_point_union=( "/var/lib/docker/containers" "/var/lib/docker/${docker_storage_driver}" )
stale_docker_dir_union=( "/var/lib/docker" )
stale_kata_dir_union=( "/var/lib/vc" "/run/vc" )

lib_script="${GOPATH}/src/${tests_repo}/lib/common.bash"

tests_repo="${tests_repo:-github.com/kata-containers/tests}"
lib_script="${GOPATH}/src/${tests_repo}/.ci/lib.sh"
source "${lib_script}"

info() {
echo -e "INFO: $*"
}

kill_stale_process()
{
clean_env
extract_kata_env
stale_process_union=( "${stale_process_union[@]}" "${PROXY_PATH}" "${HYPERVISOR_PATH}" "${SHIM_PATH}" )
for stale_process in "${stale_process_union[@]}"; do
if pgrep -f "${stale_process}"; then
sudo killall -9 "${stale_process}" || true
fi
done
}

delete_stale_docker_resource()
{
local docker_status=false
# check if docker service is running
systemctl is-active --quiet docker
if [ $? -eq 0 ]; then
docker_status=true
sudo systemctl stop docker
fi
# before removing stale docker dir, you should umount related resource
for stale_docker_mount_point in "${stale_docker_mount_point_union[@]}"; do
local mount_point_union=$(mount | grep "${stale_docker_mount_point}" | awk '{print $3}')
if [ -n "${mount_point_union}" ]; then
while IFS='$\n' read mount_point; do
sudo umount "${mount_point}"
done <<< "${mount_point_union}"
fi
done
# remove stale docker dir
for stale_docker_dir in "${stale_docker_dir_union[@]}"; do
if [ -d "${stale_docker_dir}" ]; then
sudo rm -rf "${stale_docker_dir}"
fi
done
[ "${docker_status}" = true ] && sudo systemctl restart docker
}

delete_stale_kata_resource()
{
for stale_kata_dir in "${stale_kata_dir_union[@]}"; do
if [ -d "${stale_kata_dir}" ]; then
sudo rm -rf "${stale_kata_dir}"
fi
done
}

main() {
info "kill stale process"
kill_stale_process
info "delete stale docker resource under ${stale_docker_dir_union[@]}"
delete_stale_docker_resource
info "delete stale kata resource under ${stale_kata_dir_union[@]}"
delete_stale_kata_resource
}

main
gen_clean_arch
9 changes: 8 additions & 1 deletion .ci/jenkins_job_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,15 @@ mkdir -p $(dirname "${kata_repo_dir}")

# If CI running on bare-metal, a few clean-up work before walking into test repo
if [ "${BAREMETAL}" == true ]; then
arch=$("${tests_repo_dir}/.ci/kata-arch.sh")
echo "Looking for baremetal cleanup script for arch ${arch}"
clean_up_script="${tests_repo_dir}/.ci/${arch}/clean_up_${arch}.sh"
[ -f "${clean_up_script}" ] && source "${clean_up_script}"
if [ -f "${clean_up_script}" ]; then
echo "Running baremetal cleanup script for arch ${arch}"
"${clean_up_script}"
else
echo "No baremetal cleanup script for arch ${arch}"
fi
fi

pushd "${kata_repo_dir}"
Expand Down
71 changes: 71 additions & 0 deletions .ci/lib.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash
#
# Copyright (c) 2017-2018 Intel Corporation
# Copyright (c) 2018 ARM Limited
#
# SPDX-License-Identifier: Apache-2.0
#
Expand All @@ -9,6 +10,10 @@ set -e

export KATA_RUNTIME=${KATA_RUNTIME:-kata-runtime}

tests_repo="${tests_repo:-github.com/kata-containers/tests}"
lib_script="${GOPATH}/src/${tests_repo}/lib/common.bash"
source "${lib_script}"

# If we fail for any reason a message will be displayed
die() {
msg="$*"
Expand Down Expand Up @@ -186,3 +191,69 @@ function waitForProcess(){
done
return 1
}

kill_stale_process()
{
clean_env
extract_kata_env
stale_process_union=( "${stale_process_union[@]}" "${PROXY_PATH}" "${HYPERVISOR_PATH}" "${SHIM_PATH}" )
for stale_process in "${stale_process_union[@]}"; do
if pgrep -f "${stale_process}"; then
sudo killall -9 "${stale_process}" || true
fi
done
}

delete_stale_docker_resource()
{
local docker_status=false
# check if docker service is running
systemctl is-active --quiet docker
if [ $? -eq 0 ]; then
docker_status=true
sudo systemctl stop docker
fi
# before removing stale docker dir, you should umount related resource
for stale_docker_mount_point in "${stale_docker_mount_point_union[@]}"; do
local mount_point_union=$(mount | grep "${stale_docker_mount_point}" | awk '{print $3}')
if [ -n "${mount_point_union}" ]; then
while IFS='$\n' read mount_point; do
sudo umount "${mount_point}"
done <<< "${mount_point_union}"
fi
done
# remove stale docker dir
for stale_docker_dir in "${stale_docker_dir_union[@]}"; do
if [ -d "${stale_docker_dir}" ]; then
sudo rm -rf "${stale_docker_dir}"
fi
done
[ "${docker_status}" = true ] && sudo systemctl restart docker
}

delete_stale_kata_resource()
{
for stale_kata_dir in "${stale_kata_dir_union[@]}"; do
if [ -d "${stale_kata_dir}" ]; then
sudo rm -rf "${stale_kata_dir}"
fi
done
}

gen_clean_arch() {
# Set up some vars
stale_process_union=( "docker-containerd-shim" )
#docker supports different storage driver, such like overlay2, aufs, etc.
docker_storage_driver=$(docker info --format='{{.Driver}}')
stale_docker_mount_point_union=( "/var/lib/docker/containers" "/var/lib/docker/${docker_storage_driver}" )
stale_docker_dir_union=( "/var/lib/docker" )
stale_kata_dir_union=( "/var/lib/vc" "/run/vc" )

info "kill stale process"
kill_stale_process
info "delete stale docker resource under ${stale_docker_dir_union[@]}"
delete_stale_docker_resource
info "delete stale kata resource under ${stale_kata_dir_union[@]}"
delete_stale_kata_resource
}

13 changes: 13 additions & 0 deletions .ci/x86_64/clean_up_x86_64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
#
# Copyright (c) 2018 ARM Limited
# Copyright (c) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0

set -e

lib_script="${GOPATH}/src/${tests_repo}/.ci/lib.sh"
source "${lib_script}"

gen_clean_arch

0 comments on commit e1a3b67

Please sign in to comment.